summaryrefslogtreecommitdiff
path: root/hw/scsi/scsi-disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/scsi/scsi-disk.c')
-rw-r--r--hw/scsi/scsi-disk.c182
1 files changed, 92 insertions, 90 deletions
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index ae9e08dd13..300ba01045 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -33,6 +33,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
#include "hw/scsi/scsi.h"
#include "block/scsi.h"
#include "sysemu/sysemu.h"
+#include "sysemu/block-backend.h"
#include "sysemu/blockdev.h"
#include "hw/block/block.h"
#include "sysemu/dma.h"
@@ -111,7 +112,7 @@ static uint32_t scsi_init_iovec(SCSIDiskReq *r, size_t size)
if (!r->iov.iov_base) {
r->buflen = size;
- r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen);
+ r->iov.iov_base = blk_blockalign(s->qdev.conf.blk, r->buflen);
}
r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
@@ -166,7 +167,7 @@ static void scsi_aio_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
goto done;
@@ -220,9 +221,9 @@ static void scsi_write_do_fua(SCSIDiskReq *r)
}
if (scsi_is_cmd_fua(&r->req.cmd)) {
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0,
BLOCK_ACCT_FLUSH);
- r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
+ r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r);
return;
}
@@ -239,7 +240,7 @@ static void scsi_dma_complete_noio(void *opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
@@ -281,7 +282,7 @@ static void scsi_read_complete(void * opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
goto done;
@@ -313,7 +314,7 @@ static void scsi_do_read(void *opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
@@ -330,16 +331,16 @@ static void scsi_do_read(void *opaque, int ret)
scsi_req_ref(&r->req);
if (r->req.sg) {
- dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_READ);
+ dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_READ);
r->req.resid -= r->req.sg->size;
- r->req.aiocb = dma_bdrv_read(s->qdev.conf.bs, r->req.sg, r->sector,
- scsi_dma_complete, r);
+ r->req.aiocb = dma_blk_read(s->qdev.conf.blk, r->req.sg, r->sector,
+ scsi_dma_complete, r);
} else {
n = scsi_init_iovec(r, SCSI_DMA_BUF_SIZE);
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
n * BDRV_SECTOR_SIZE, BLOCK_ACCT_READ);
- r->req.aiocb = bdrv_aio_readv(s->qdev.conf.bs, r->sector, &r->qiov, n,
- scsi_read_complete, r);
+ r->req.aiocb = blk_aio_readv(s->qdev.conf.blk, r->sector, &r->qiov, n,
+ scsi_read_complete, r);
}
done:
@@ -379,9 +380,9 @@ static void scsi_read_data(SCSIRequest *req)
first = !r->started;
r->started = true;
if (first && scsi_is_cmd_fua(&r->req.cmd)) {
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0,
BLOCK_ACCT_FLUSH);
- r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_do_read, r);
+ r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_do_read, r);
} else {
scsi_do_read(r, 0);
}
@@ -398,7 +399,8 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
{
bool is_read = (r->req.cmd.xfer == SCSI_XFER_FROM_DEV);
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
- BlockErrorAction action = bdrv_get_error_action(s->qdev.conf.bs, is_read, error);
+ BlockErrorAction action = blk_get_error_action(s->qdev.conf.blk,
+ is_read, error);
if (action == BLOCK_ERROR_ACTION_REPORT) {
switch (error) {
@@ -419,7 +421,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
break;
}
}
- bdrv_error_action(s->qdev.conf.bs, action, is_read, error);
+ blk_error_action(s->qdev.conf.blk, action, is_read, error);
if (action == BLOCK_ERROR_ACTION_STOP) {
scsi_req_retry(&r->req);
}
@@ -434,7 +436,7 @@ static void scsi_write_complete(void * opaque, int ret)
if (r->req.aiocb != NULL) {
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
}
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
@@ -502,16 +504,16 @@ static void scsi_write_data(SCSIRequest *req)
}
if (r->req.sg) {
- dma_acct_start(s->qdev.conf.bs, &r->acct, r->req.sg, BLOCK_ACCT_WRITE);
+ dma_acct_start(s->qdev.conf.blk, &r->acct, r->req.sg, BLOCK_ACCT_WRITE);
r->req.resid -= r->req.sg->size;
- r->req.aiocb = dma_bdrv_write(s->qdev.conf.bs, r->req.sg, r->sector,
- scsi_dma_complete, r);
+ r->req.aiocb = dma_blk_write(s->qdev.conf.blk, r->req.sg, r->sector,
+ scsi_dma_complete, r);
} else {
n = r->qiov.size / 512;
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
n * BDRV_SECTOR_SIZE, BLOCK_ACCT_WRITE);
- r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, r->sector, &r->qiov, n,
- scsi_write_complete, r);
+ r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, r->sector, &r->qiov, n,
+ scsi_write_complete, r);
}
}
@@ -578,7 +580,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
case 0x83: /* Device identification page, mandatory */
{
- const char *str = s->serial ?: bdrv_get_device_name(s->qdev.conf.bs);
+ const char *str = s->serial ?: blk_name(s->qdev.conf.blk);
int max_len = s->serial ? 20 : 255 - 8;
int id_len = strlen(str);
@@ -739,10 +741,10 @@ static inline bool media_is_dvd(SCSIDiskState *s)
if (s->qdev.type != TYPE_ROM) {
return false;
}
- if (!bdrv_is_inserted(s->qdev.conf.bs)) {
+ if (!blk_is_inserted(s->qdev.conf.blk)) {
return false;
}
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
return nb_sectors > CD_MAX_SECTORS;
}
@@ -752,10 +754,10 @@ static inline bool media_is_cd(SCSIDiskState *s)
if (s->qdev.type != TYPE_ROM) {
return false;
}
- if (!bdrv_is_inserted(s->qdev.conf.bs)) {
+ if (!blk_is_inserted(s->qdev.conf.blk)) {
return false;
}
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
return nb_sectors <= CD_MAX_SECTORS;
}
@@ -816,7 +818,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
}
if (format != 0xff) {
- if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) {
+ if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return -1;
}
@@ -838,7 +840,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
if (layer != 0) {
goto fail;
}
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
outbuf[4] = 1; /* DVD-ROM, part version 1 */
outbuf[5] = 0xf; /* 120mm disc, minimum rate unspecified */
@@ -893,7 +895,7 @@ static int scsi_event_status_media(SCSIDiskState *s, uint8_t *outbuf)
media_status = 0;
if (s->tray_open) {
media_status = MS_TRAY_OPEN;
- } else if (bdrv_is_inserted(s->qdev.conf.bs)) {
+ } else if (blk_is_inserted(s->qdev.conf.blk)) {
media_status = MS_MEDIA_PRESENT;
}
@@ -1091,7 +1093,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
case MODE_PAGE_CACHING:
length = 0x12;
if (page_control == 1 || /* Changeable Values */
- bdrv_enable_write_cache(s->qdev.conf.bs)) {
+ blk_enable_write_cache(s->qdev.conf.blk)) {
p[0] = 4; /* WCE */
}
break;
@@ -1172,7 +1174,7 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf)
if (s->qdev.type == TYPE_DISK) {
dev_specific_param = s->features & (1 << SCSI_DISK_F_DPOFUA) ? 0x10 : 0;
- if (bdrv_is_read_only(s->qdev.conf.bs)) {
+ if (blk_is_read_only(s->qdev.conf.blk)) {
dev_specific_param |= 0x80; /* Readonly. */
}
} else {
@@ -1194,7 +1196,7 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf)
p += 8;
}
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
if (!dbd && nb_sectors) {
if (r->req.cmd.buf[0] == MODE_SENSE) {
outbuf[3] = 8; /* Block descriptor length */
@@ -1257,7 +1259,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
msf = req->cmd.buf[1] & 2;
format = req->cmd.buf[2] & 0xf;
start_track = req->cmd.buf[6];
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, format, msf >> 1);
nb_sectors /= s->qdev.blocksize / 512;
switch (format) {
@@ -1297,14 +1299,14 @@ static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && loej) {
if (!start && !s->tray_open && s->tray_locked) {
scsi_check_condition(r,
- bdrv_is_inserted(s->qdev.conf.bs)
+ blk_is_inserted(s->qdev.conf.blk)
? SENSE_CODE(ILLEGAL_REQ_REMOVAL_PREVENTED)
: SENSE_CODE(NOT_READY_REMOVAL_PREVENTED));
return -1;
}
if (s->tray_open != !start) {
- bdrv_eject(s->qdev.conf.bs, !start);
+ blk_eject(s->qdev.conf.blk, !start);
s->tray_open = !start;
}
}
@@ -1371,7 +1373,7 @@ static void scsi_disk_apply_mode_select(SCSIDiskState *s, int page, uint8_t *p)
{
switch (page) {
case MODE_PAGE_CACHING:
- bdrv_set_enable_write_cache(s->qdev.conf.bs, (p[0] & 4) != 0);
+ blk_set_enable_write_cache(s->qdev.conf.blk, (p[0] & 4) != 0);
break;
default:
@@ -1474,12 +1476,12 @@ static void scsi_disk_emulate_mode_select(SCSIDiskReq *r, uint8_t *inbuf)
return;
}
}
- if (!bdrv_enable_write_cache(s->qdev.conf.bs)) {
+ if (!blk_enable_write_cache(s->qdev.conf.blk)) {
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0,
BLOCK_ACCT_FLUSH);
- r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
+ r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r);
return;
}
@@ -1548,10 +1550,10 @@ static void scsi_unmap_complete(void *opaque, int ret)
goto done;
}
- r->req.aiocb = bdrv_aio_discard(s->qdev.conf.bs,
- sector_num * (s->qdev.blocksize / 512),
- nb_sectors * (s->qdev.blocksize / 512),
- scsi_unmap_complete, data);
+ r->req.aiocb = blk_aio_discard(s->qdev.conf.blk,
+ sector_num * (s->qdev.blocksize / 512),
+ nb_sectors * (s->qdev.blocksize / 512),
+ scsi_unmap_complete, data);
data->count--;
data->inbuf += 16;
return;
@@ -1589,7 +1591,7 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf)
goto invalid_param_len;
}
- if (bdrv_is_read_only(s->qdev.conf.bs)) {
+ if (blk_is_read_only(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
return;
}
@@ -1628,7 +1630,7 @@ static void scsi_write_same_complete(void *opaque, int ret)
assert(r->req.aiocb != NULL);
r->req.aiocb = NULL;
- block_acct_done(bdrv_get_stats(s->qdev.conf.bs), &r->acct);
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
if (r->req.io_canceled) {
scsi_req_cancel_complete(&r->req);
goto done;
@@ -1644,11 +1646,11 @@ static void scsi_write_same_complete(void *opaque, int ret)
data->sector += data->iov.iov_len / 512;
data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
if (data->iov.iov_len) {
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
data->iov.iov_len, BLOCK_ACCT_WRITE);
- r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
- &data->qiov, data->iov.iov_len / 512,
- scsi_write_same_complete, data);
+ r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector,
+ &data->qiov, data->iov.iov_len / 512,
+ scsi_write_same_complete, data);
return;
}
@@ -1675,7 +1677,7 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
return;
}
- if (bdrv_is_read_only(s->qdev.conf.bs)) {
+ if (blk_is_read_only(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
return;
}
@@ -1689,13 +1691,13 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
nb_sectors * s->qdev.blocksize,
BLOCK_ACCT_WRITE);
- r->req.aiocb = bdrv_aio_write_zeroes(s->qdev.conf.bs,
- r->req.cmd.lba * (s->qdev.blocksize / 512),
- nb_sectors * (s->qdev.blocksize / 512),
- flags, scsi_aio_complete, r);
+ r->req.aiocb = blk_aio_write_zeroes(s->qdev.conf.blk,
+ r->req.cmd.lba * (s->qdev.blocksize / 512),
+ nb_sectors * (s->qdev.blocksize / 512),
+ flags, scsi_aio_complete, r);
return;
}
@@ -1704,7 +1706,8 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
data->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
data->nb_sectors = nb_sectors * (s->qdev.blocksize / 512);
data->iov.iov_len = MIN(data->nb_sectors * 512, SCSI_WRITE_SAME_MAX);
- data->iov.iov_base = buf = qemu_blockalign(s->qdev.conf.bs, data->iov.iov_len);
+ data->iov.iov_base = buf = blk_blockalign(s->qdev.conf.blk,
+ data->iov.iov_len);
qemu_iovec_init_external(&data->qiov, &data->iov, 1);
for (i = 0; i < data->iov.iov_len; i += s->qdev.blocksize) {
@@ -1712,11 +1715,11 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
}
scsi_req_ref(&r->req);
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
data->iov.iov_len, BLOCK_ACCT_WRITE);
- r->req.aiocb = bdrv_aio_writev(s->qdev.conf.bs, data->sector,
- &data->qiov, data->iov.iov_len / 512,
- scsi_write_same_complete, data);
+ r->req.aiocb = blk_aio_writev(s->qdev.conf.blk, data->sector,
+ &data->qiov, data->iov.iov_len / 512,
+ scsi_write_same_complete, data);
}
static void scsi_disk_emulate_write_data(SCSIRequest *req)
@@ -1785,7 +1788,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
break;
default:
- if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) {
+ if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return 0;
}
@@ -1806,7 +1809,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
r->buflen = MAX(4096, req->cmd.xfer);
if (!r->iov.iov_base) {
- r->iov.iov_base = qemu_blockalign(s->qdev.conf.bs, r->buflen);
+ r->iov.iov_base = blk_blockalign(s->qdev.conf.blk, r->buflen);
}
buflen = req->cmd.xfer;
@@ -1814,7 +1817,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
memset(outbuf, 0, r->buflen);
switch (req->cmd.buf[0]) {
case TEST_UNIT_READY:
- assert(!s->tray_open && bdrv_is_inserted(s->qdev.conf.bs));
+ assert(!s->tray_open && blk_is_inserted(s->qdev.conf.blk));
break;
case INQUIRY:
buflen = scsi_disk_emulate_inquiry(req, outbuf);
@@ -1862,12 +1865,12 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
break;
case ALLOW_MEDIUM_REMOVAL:
s->tray_locked = req->cmd.buf[4] & 1;
- bdrv_lock_medium(s->qdev.conf.bs, req->cmd.buf[4] & 1);
+ blk_lock_medium(s->qdev.conf.blk, req->cmd.buf[4] & 1);
break;
case READ_CAPACITY_10:
/* The normal LEN field for this command is zero. */
memset(outbuf, 0, 8);
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
if (!nb_sectors) {
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
return 0;
@@ -1936,7 +1939,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
if ((req->cmd.buf[1] & 31) == SAI_READ_CAPACITY_16) {
DPRINTF("SAI READ CAPACITY(16)\n");
memset(outbuf, 0, req->cmd.xfer);
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
if (!nb_sectors) {
scsi_check_condition(r, SENSE_CODE(LUN_NOT_READY));
return 0;
@@ -1977,9 +1980,9 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
case SYNCHRONIZE_CACHE:
/* The request is used as the AIO opaque value, so add a ref. */
scsi_req_ref(&r->req);
- block_acct_start(bdrv_get_stats(s->qdev.conf.bs), &r->acct, 0,
+ block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0,
BLOCK_ACCT_FLUSH);
- r->req.aiocb = bdrv_aio_flush(s->qdev.conf.bs, scsi_aio_complete, r);
+ r->req.aiocb = blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete, r);
return 0;
case SEEK_10:
DPRINTF("Seek(10) (sector %" PRId64 ")\n", r->req.cmd.lba);
@@ -2053,7 +2056,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
command = buf[0];
- if (s->tray_open || !bdrv_is_inserted(s->qdev.conf.bs)) {
+ if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
return 0;
}
@@ -2081,7 +2084,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
case WRITE_VERIFY_10:
case WRITE_VERIFY_12:
case WRITE_VERIFY_16:
- if (bdrv_is_read_only(s->qdev.conf.bs)) {
+ if (blk_is_read_only(s->qdev.conf.blk)) {
scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
return 0;
}
@@ -2124,7 +2127,7 @@ static void scsi_disk_reset(DeviceState *dev)
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
- bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors);
+ blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
nb_sectors /= s->qdev.blocksize / 512;
if (nb_sectors) {
nb_sectors--;
@@ -2140,7 +2143,7 @@ static void scsi_unrealize(SCSIDevice *dev, Error **errp)
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
scsi_device_purge_requests(&s->qdev, SENSE_CODE(NO_SENSE));
- blockdev_mark_auto_del(s->qdev.conf.bs);
+ blockdev_mark_auto_del(s->qdev.conf.blk);
}
static void scsi_disk_resize_cb(void *opaque)
@@ -2223,13 +2226,13 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
Error *err = NULL;
- if (!s->qdev.conf.bs) {
+ if (!s->qdev.conf.blk) {
error_setg(errp, "drive property not set");
return;
}
if (!(s->features & (1 << SCSI_DISK_F_REMOVABLE)) &&
- !bdrv_is_inserted(s->qdev.conf.bs)) {
+ !blk_is_inserted(s->qdev.conf.blk)) {
error_setg(errp, "Device needs media, but drive is empty");
return;
}
@@ -2255,20 +2258,20 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
s->vendor = g_strdup("QEMU");
}
- if (bdrv_is_sg(s->qdev.conf.bs)) {
+ if (blk_is_sg(s->qdev.conf.blk)) {
error_setg(errp, "unwanted /dev/sg*");
return;
}
if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) &&
!(s->features & (1 << SCSI_DISK_F_NO_REMOVABLE_DEVOPS))) {
- bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_removable_block_ops, s);
+ blk_set_dev_ops(s->qdev.conf.blk, &scsi_disk_removable_block_ops, s);
} else {
- bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s);
+ blk_set_dev_ops(s->qdev.conf.blk, &scsi_disk_block_ops, s);
}
- bdrv_set_guest_block_size(s->qdev.conf.bs, s->qdev.blocksize);
+ blk_set_guest_block_size(s->qdev.conf.blk, s->qdev.blocksize);
- bdrv_iostatus_enable(s->qdev.conf.bs);
+ blk_iostatus_enable(s->qdev.conf.blk);
}
static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
@@ -2299,14 +2302,14 @@ static void scsi_disk_realize(SCSIDevice *dev, Error **errp)
DriveInfo *dinfo;
Error *local_err = NULL;
- if (!dev->conf.bs) {
+ if (!dev->conf.blk) {
scsi_realize(dev, &local_err);
assert(local_err);
error_propagate(errp, local_err);
return;
}
- dinfo = drive_get_by_blockdev(dev->conf.bs);
+ dinfo = blk_legacy_dinfo(dev->conf.blk);
if (dinfo->media_cd) {
scsi_cd_realize(dev, errp);
} else {
@@ -2406,7 +2409,6 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
#ifdef __linux__
static int get_device_type(SCSIDiskState *s)
{
- BlockDriverState *bdrv = s->qdev.conf.bs;
uint8_t cmd[16];
uint8_t buf[36];
uint8_t sensebuf[8];
@@ -2429,7 +2431,7 @@ static int get_device_type(SCSIDiskState *s)
io_header.sbp = sensebuf;
io_header.timeout = 6000; /* XXX */
- ret = bdrv_ioctl(bdrv, SG_IO, &io_header);
+ ret = blk_ioctl(s->qdev.conf.blk, SG_IO, &io_header);
if (ret < 0 || io_header.driver_status || io_header.host_status) {
return -1;
}
@@ -2446,13 +2448,13 @@ static void scsi_block_realize(SCSIDevice *dev, Error **errp)
int sg_version;
int rc;
- if (!s->qdev.conf.bs) {
+ if (!s->qdev.conf.blk) {
error_setg(errp, "drive property not set");
return;
}
/* check we are using a driver managing SG_IO (version 3 and after) */
- rc = bdrv_ioctl(s->qdev.conf.bs, SG_GET_VERSION_NUM, &sg_version);
+ rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version);
if (rc < 0) {
error_setg(errp, "cannot get SG_IO version number: %s. "
"Is this a SCSI device?",
@@ -2511,7 +2513,7 @@ static bool scsi_block_is_passthrough(SCSIDiskState *s, uint8_t *buf)
* ones (such as WRITE SAME or EXTENDED COPY, etc.). So, without
* O_DIRECT everything must go through SG_IO.
*/
- if (!(bdrv_get_flags(s->qdev.conf.bs) & BDRV_O_NOCACHE)) {
+ if (!(blk_get_flags(s->qdev.conf.blk) & BDRV_O_NOCACHE)) {
break;
}
@@ -2660,7 +2662,7 @@ static const TypeInfo scsi_cd_info = {
#ifdef __linux__
static Property scsi_block_properties[] = {
- DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.bs),
+ DEFINE_PROP_DRIVE("drive", SCSIDiskState, qdev.conf.blk),
DEFINE_PROP_END_OF_LIST(),
};