[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 29/44] hw/scsi/scsi-disk: Replace magic '512' value by BDRV_SECTOR
From: |
Laurent Vivier |
Subject: |
[PULL 29/44] hw/scsi/scsi-disk: Replace magic '512' value by BDRV_SECTOR_SIZE |
Date: |
Tue, 1 Sep 2020 16:09:39 +0200 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
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>
---
hw/scsi/scsi-disk.c | 44 +++++++++++++++++++++++---------------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 8ce68a9dd64a..7612035a4e4b 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -71,7 +71,7 @@ typedef struct SCSIDiskClass {
typedef struct SCSIDiskReq {
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;
uint32_t sector_count;
uint32_t buflen;
@@ -141,7 +141,7 @@ static void scsi_init_iovec(SCSIDiskReq *r, size_t size)
r->buflen = size;
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);
}
@@ -311,7 +311,7 @@ static void scsi_read_complete_noio(SCSIDiskReq *r, int ret)
goto done;
}
- n = r->qiov.size / 512;
+ n = r->qiov.size / BDRV_SECTOR_SIZE;
r->sector += n;
r->sector_count -= n;
scsi_req_data(&r->req, r->qiov.size);
@@ -505,7 +505,7 @@ static void scsi_write_complete_noio(SCSIDiskReq *r, int
ret)
goto done;
}
- n = r->qiov.size / 512;
+ n = r->qiov.size / BDRV_SECTOR_SIZE;
r->sector += n;
r->sector_count -= n;
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 */
outbuf[7] = 8; /* Block descriptor length */
}
- nb_sectors /= (s->qdev.blocksize / 512);
+ nb_sectors /= (s->qdev.blocksize / BDRV_SECTOR_SIZE);
if (nb_sectors > 0xffffff) {
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];
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
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) {
case 0:
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);
- data->nb_sectors -= data->iov.iov_len / 512;
- data->sector += data->iov.iov_len / 512;
- data->iov.iov_len = MIN(data->nb_sectors * 512, data->iov.iov_len);
+ data->nb_sectors -= data->iov.iov_len / BDRV_SECTOR_SIZE;
+ data->sector += data->iov.iov_len / BDRV_SECTOR_SIZE;
+ data->iov.iov_len = MIN(data->nb_sectors * BDRV_SECTOR_SIZE,
+ data->iov.iov_len);
if (data->iov.iov_len) {
block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct,
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->r = r;
- 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->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+ data->nb_sectors = nb_sectors * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+ 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_len);
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) {
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. */
nb_sectors--;
/* 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) {
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. */
nb_sectors--;
/* 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)) {
goto illegal_lba;
}
- r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
- r->sector_count = len * (s->qdev.blocksize / 512);
+ r->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+ r->sector_count = len * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
break;
case WRITE_6:
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)) {
goto illegal_lba;
}
- r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
- r->sector_count = len * (s->qdev.blocksize / 512);
+ r->sector = r->req.cmd.lba * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+ r->sector_count = len * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
break;
default:
abort();
@@ -2229,9 +2231,9 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req,
uint8_t *buf)
}
assert(r->iov.iov_len == 0);
if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
- return -r->sector_count * 512;
+ return -r->sector_count * BDRV_SECTOR_SIZE;
} 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));
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) {
nb_sectors--;
}
--
2.26.2
- [PULL 26/44] hw/ide/ahci: Replace magic '512' value by BDRV_SECTOR_SIZE, (continued)
- [PULL 26/44] hw/ide/ahci: Replace magic '512' value by BDRV_SECTOR_SIZE, Laurent Vivier, 2020/09/01
- [PULL 09/44] target/cris: Remove superfluous breaks, Laurent Vivier, 2020/09/01
- [PULL 28/44] hw/ide/pci: Replace magic '512' value by BDRV_SECTOR_SIZE, Laurent Vivier, 2020/09/01
- [PULL 27/44] hw/ide/atapi: Replace magic '512' value by BDRV_SECTOR_SIZE, Laurent Vivier, 2020/09/01
- [PULL 34/44] hw/arm/omap1:Remove redundant statement in omap_clkdsp_read(), Laurent Vivier, 2020/09/01
- [PULL 43/44] main-loop: Fix comment, Laurent Vivier, 2020/09/01
- [PULL 35/44] target/arm/translate-a64:Remove dead assignment in handle_scalar_simd_shli(), Laurent Vivier, 2020/09/01
- [PULL 44/44] docs/system: Fix grammar in documentation, Laurent Vivier, 2020/09/01
- [PULL 38/44] hw/net/virtio-net:Remove redundant statement in virtio_net_rsc_tcp_ctrl_check(), Laurent Vivier, 2020/09/01
- [PULL 41/44] hw/intc: fix default registers value in exynos4210_combiner_read(), Laurent Vivier, 2020/09/01
- [PULL 29/44] hw/scsi/scsi-disk: Replace magic '512' value by BDRV_SECTOR_SIZE,
Laurent Vivier <=
- [PULL 37/44] hw/virtio/vhost-user:Remove dead assignment in scrub_shadow_regions(), Laurent Vivier, 2020/09/01
- [PULL 25/44] hw/ide/core: Trivial typo fix, Laurent Vivier, 2020/09/01
- [PULL 40/44] usb/bus: Remove dead assignment in usb_get_fw_dev_path(), Laurent Vivier, 2020/09/01
- [PULL 42/44] hw/display/vga:Remove redundant statement in vga_draw_graphic(), Laurent Vivier, 2020/09/01
- [PULL 22/44] util/vfio-helpers: Fix typo in description, Laurent Vivier, 2020/09/01
- [PULL 30/44] hw/net/xilinx_axienet: Remove unused code, Laurent Vivier, 2020/09/01
- [PULL 31/44] util/vfio-helpers: Unify trace-events size format, Laurent Vivier, 2020/09/01
- [PULL 36/44] target/arm/translate-a64:Remove redundant statement in disas_simd_two_reg_misc_fp16(), Laurent Vivier, 2020/09/01
- [PULL 33/44] hw/arm/virt-acpi-build:Remove dead assignment in build_madt(), Laurent Vivier, 2020/09/01
- [PULL 39/44] vfio/platform: Remove dead assignment in vfio_intp_interrupt(), Laurent Vivier, 2020/09/01