mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 18:23:57 -06:00
hw/scsi/scsi-disk: Replace magic '512' value by BDRV_SECTOR_SIZE
Use self-explicit definitions instead of magic '512' value. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Message-Id: <20200814082841.27000-8-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
parent
4a13980b10
commit
3dc516bf92
1 changed files with 23 additions and 21 deletions
|
@ -71,7 +71,7 @@ typedef struct SCSIDiskClass {
|
||||||
|
|
||||||
typedef struct SCSIDiskReq {
|
typedef struct SCSIDiskReq {
|
||||||
SCSIRequest req;
|
SCSIRequest req;
|
||||||
/* Both sector and sector_count are in terms of qemu 512 byte blocks. */
|
/* Both sector and sector_count are in terms of BDRV_SECTOR_SIZE bytes. */
|
||||||
uint64_t sector;
|
uint64_t sector;
|
||||||
uint32_t sector_count;
|
uint32_t sector_count;
|
||||||
uint32_t buflen;
|
uint32_t buflen;
|
||||||
|
@ -141,7 +141,7 @@ static void scsi_init_iovec(SCSIDiskReq *r, size_t size)
|
||||||
r->buflen = size;
|
r->buflen = size;
|
||||||
r->iov.iov_base = blk_blockalign(s->qdev.conf.blk, 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);
|
r->iov.iov_len = MIN(r->sector_count * BDRV_SECTOR_SIZE, r->buflen);
|
||||||
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
|
qemu_iovec_init_external(&r->qiov, &r->iov, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ static void scsi_read_complete_noio(SCSIDiskReq *r, int ret)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = r->qiov.size / 512;
|
n = r->qiov.size / BDRV_SECTOR_SIZE;
|
||||||
r->sector += n;
|
r->sector += n;
|
||||||
r->sector_count -= n;
|
r->sector_count -= n;
|
||||||
scsi_req_data(&r->req, r->qiov.size);
|
scsi_req_data(&r->req, r->qiov.size);
|
||||||
|
@ -505,7 +505,7 @@ static void scsi_write_complete_noio(SCSIDiskReq *r, int ret)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = r->qiov.size / 512;
|
n = r->qiov.size / BDRV_SECTOR_SIZE;
|
||||||
r->sector += n;
|
r->sector += n;
|
||||||
r->sector_count -= n;
|
r->sector_count -= n;
|
||||||
if (r->sector_count == 0) {
|
if (r->sector_count == 0) {
|
||||||
|
@ -1284,7 +1284,7 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf)
|
||||||
} else { /* MODE_SENSE_10 */
|
} else { /* MODE_SENSE_10 */
|
||||||
outbuf[7] = 8; /* Block descriptor length */
|
outbuf[7] = 8; /* Block descriptor length */
|
||||||
}
|
}
|
||||||
nb_sectors /= (s->qdev.blocksize / 512);
|
nb_sectors /= (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
if (nb_sectors > 0xffffff) {
|
if (nb_sectors > 0xffffff) {
|
||||||
nb_sectors = 0;
|
nb_sectors = 0;
|
||||||
}
|
}
|
||||||
|
@ -1342,7 +1342,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
|
||||||
start_track = req->cmd.buf[6];
|
start_track = req->cmd.buf[6];
|
||||||
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
||||||
trace_scsi_disk_emulate_read_toc(start_track, format, msf >> 1);
|
trace_scsi_disk_emulate_read_toc(start_track, format, msf >> 1);
|
||||||
nb_sectors /= s->qdev.blocksize / 512;
|
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 0:
|
case 0:
|
||||||
toclen = cdrom_read_toc(nb_sectors, outbuf, msf, start_track);
|
toclen = cdrom_read_toc(nb_sectors, outbuf, msf, start_track);
|
||||||
|
@ -1738,9 +1738,10 @@ static void scsi_write_same_complete(void *opaque, int ret)
|
||||||
|
|
||||||
block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
|
block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
|
||||||
|
|
||||||
data->nb_sectors -= data->iov.iov_len / 512;
|
data->nb_sectors -= data->iov.iov_len / BDRV_SECTOR_SIZE;
|
||||||
data->sector += data->iov.iov_len / 512;
|
data->sector += data->iov.iov_len / BDRV_SECTOR_SIZE;
|
||||||
data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
|
data->iov.iov_len = MIN(data->nb_sectors * BDRV_SECTOR_SIZE,
|
||||||
|
data->iov.iov_len);
|
||||||
if (data->iov.iov_len) {
|
if (data->iov.iov_len) {
|
||||||
block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
|
block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
|
||||||
data->iov.iov_len, BLOCK_ACCT_WRITE);
|
data->iov.iov_len, BLOCK_ACCT_WRITE);
|
||||||
|
@ -1805,9 +1806,10 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
|
||||||
|
|
||||||
data = g_new0(WriteSameCBData, 1);
|
data = g_new0(WriteSameCBData, 1);
|
||||||
data->r = r;
|
data->r = r;
|
||||||
data->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
|
data->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
data->nb_sectors = nb_sectors * (s->qdev.blocksize / 512);
|
data->nb_sectors = nb_sectors * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
data->iov.iov_len = MIN(data->nb_sectors * 512, SCSI_WRITE_SAME_MAX);
|
data->iov.iov_len = MIN(data->nb_sectors * BDRV_SECTOR_SIZE,
|
||||||
|
SCSI_WRITE_SAME_MAX);
|
||||||
data->iov.iov_base = buf = blk_blockalign(s->qdev.conf.blk,
|
data->iov.iov_base = buf = blk_blockalign(s->qdev.conf.blk,
|
||||||
data->iov.iov_len);
|
data->iov.iov_len);
|
||||||
qemu_iovec_init_external(&data->qiov, &data->iov, 1);
|
qemu_iovec_init_external(&data->qiov, &data->iov, 1);
|
||||||
|
@ -1980,7 +1982,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
|
||||||
if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) {
|
if ((req->cmd.buf[8] & 1) == 0 && req->cmd.lba) {
|
||||||
goto illegal_request;
|
goto illegal_request;
|
||||||
}
|
}
|
||||||
nb_sectors /= s->qdev.blocksize / 512;
|
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
|
||||||
/* Returned value is the address of the last sector. */
|
/* Returned value is the address of the last sector. */
|
||||||
nb_sectors--;
|
nb_sectors--;
|
||||||
/* Remember the new size for read/write sanity checking. */
|
/* Remember the new size for read/write sanity checking. */
|
||||||
|
@ -2049,7 +2051,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
|
||||||
if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) {
|
if ((req->cmd.buf[14] & 1) == 0 && req->cmd.lba) {
|
||||||
goto illegal_request;
|
goto illegal_request;
|
||||||
}
|
}
|
||||||
nb_sectors /= s->qdev.blocksize / 512;
|
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
|
||||||
/* Returned value is the address of the last sector. */
|
/* Returned value is the address of the last sector. */
|
||||||
nb_sectors--;
|
nb_sectors--;
|
||||||
/* Remember the new size for read/write sanity checking. */
|
/* Remember the new size for read/write sanity checking. */
|
||||||
|
@ -2180,8 +2182,8 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||||
if (!check_lba_range(s, r->req.cmd.lba, len)) {
|
if (!check_lba_range(s, r->req.cmd.lba, len)) {
|
||||||
goto illegal_lba;
|
goto illegal_lba;
|
||||||
}
|
}
|
||||||
r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
|
r->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
r->sector_count = len * (s->qdev.blocksize / 512);
|
r->sector_count = len * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
break;
|
break;
|
||||||
case WRITE_6:
|
case WRITE_6:
|
||||||
case WRITE_10:
|
case WRITE_10:
|
||||||
|
@ -2211,8 +2213,8 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||||
if (!check_lba_range(s, r->req.cmd.lba, len)) {
|
if (!check_lba_range(s, r->req.cmd.lba, len)) {
|
||||||
goto illegal_lba;
|
goto illegal_lba;
|
||||||
}
|
}
|
||||||
r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
|
r->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
r->sector_count = len * (s->qdev.blocksize / 512);
|
r->sector_count = len * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
|
@ -2229,9 +2231,9 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||||
}
|
}
|
||||||
assert(r->iov.iov_len == 0);
|
assert(r->iov.iov_len == 0);
|
||||||
if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
|
if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
|
||||||
return -r->sector_count * 512;
|
return -r->sector_count * BDRV_SECTOR_SIZE;
|
||||||
} else {
|
} else {
|
||||||
return r->sector_count * 512;
|
return r->sector_count * BDRV_SECTOR_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2243,7 +2245,7 @@ static void scsi_disk_reset(DeviceState *dev)
|
||||||
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
|
scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET));
|
||||||
|
|
||||||
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
||||||
nb_sectors /= s->qdev.blocksize / 512;
|
nb_sectors /= s->qdev.blocksize / BDRV_SECTOR_SIZE;
|
||||||
if (nb_sectors) {
|
if (nb_sectors) {
|
||||||
nb_sectors--;
|
nb_sectors--;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue