[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v7 18/19] qemu-io: Switch to byte-based block access
From: |
Eric Blake |
Subject: |
[Qemu-block] [PATCH v7 18/19] qemu-io: Switch to byte-based block access |
Date: |
Fri, 6 May 2016 10:26:44 -0600 |
qemu-io is the last user of several sector-based interfaces.
This patch upgrades to the new interfaces under the hood,
then deletes the resulting dead code. Note that for maximum
back-compat, while the -p option is no longer required to get
blk_pread(), it is still needed to allow for unaligned access;
this is because qemu-iotest 23 relies on qemu-io rejecting
unaligned accesses without -p. A later patch may clean up the
interface to be more user-friendly, but it's better to separate
what's done under the hood from what the user sees.
Signed-off-by: Eric Blake <address@hidden>
---
qemu-io-cmds.c | 62 ++++++++++------------------------------------------------
1 file changed, 10 insertions(+), 52 deletions(-)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index a3e3982..0bbbc72 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -419,40 +419,6 @@ fail:
return buf;
}
-static int do_read(BlockBackend *blk, char *buf, int64_t offset, int64_t count,
- int64_t *total)
-{
- int ret;
-
- if (count >> 9 > INT_MAX) {
- return -ERANGE;
- }
-
- ret = blk_read(blk, offset >> 9, (uint8_t *)buf, count >> 9);
- if (ret < 0) {
- return ret;
- }
- *total = count;
- return 1;
-}
-
-static int do_write(BlockBackend *blk, char *buf, int64_t offset, int64_t
count,
- int64_t *total)
-{
- int ret;
-
- if (count >> 9 > INT_MAX) {
- return -ERANGE;
- }
-
- ret = blk_write(blk, offset >> 9, (uint8_t *)buf, count >> 9);
- if (ret < 0) {
- return ret;
- }
- *total = count;
- return 1;
-}
-
static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
int64_t count, int64_t *total)
{
@@ -588,8 +554,7 @@ static int do_aio_readv(BlockBackend *blk, QEMUIOVector
*qiov,
{
int async_ret = NOT_DONE;
- blk_aio_readv(blk, offset >> 9, qiov, qiov->size >> 9,
- aio_rw_done, &async_ret);
+ blk_aio_preadv(blk, offset, qiov, 0, aio_rw_done, &async_ret);
while (async_ret == NOT_DONE) {
main_loop_wait(false);
}
@@ -603,8 +568,7 @@ static int do_aio_writev(BlockBackend *blk, QEMUIOVector
*qiov,
{
int async_ret = NOT_DONE;
- blk_aio_writev(blk, offset >> 9, qiov, qiov->size >> 9,
- aio_rw_done, &async_ret);
+ blk_aio_pwritev(blk, offset, qiov, 0, aio_rw_done, &async_ret);
while (async_ret == NOT_DONE) {
main_loop_wait(false);
}
@@ -670,7 +634,7 @@ static void read_help(void)
" -b, -- read from the VM state rather than the virtual disk\n"
" -C, -- report statistics in a machine parsable format\n"
" -l, -- length for pattern verification (only with -P)\n"
-" -p, -- use blk_pread to read the file\n"
+" -p, -- allow unaligned access\n"
" -P, -- use a pattern to verify read data\n"
" -q, -- quiet mode, do not show I/O statistics\n"
" -s, -- start offset for pattern verification (only with -P)\n"
@@ -805,12 +769,10 @@ static int read_f(BlockBackend *blk, int argc, char
**argv)
buf = qemu_io_alloc(blk, count, 0xab);
gettimeofday(&t1, NULL);
- if (pflag) {
- cnt = do_pread(blk, buf, offset, count, &total);
- } else if (bflag) {
+ if (bflag) {
cnt = do_load_vmstate(blk, buf, offset, count, &total);
} else {
- cnt = do_read(blk, buf, offset, count, &total);
+ cnt = do_pread(blk, buf, offset, count, &total);
}
gettimeofday(&t2, NULL);
@@ -990,7 +952,7 @@ static void write_help(void)
" filled with a set pattern (0xcdcdcdcd).\n"
" -b, -- write to the VM state rather than the virtual disk\n"
" -c, -- write compressed data with blk_write_compressed\n"
-" -p, -- use blk_pwrite to write the file\n"
+" -p, -- allow unaligned access\n"
" -P, -- use different pattern to fill file\n"
" -C, -- report statistics in a machine parsable format\n"
" -q, -- quiet mode, do not show I/O statistics\n"
@@ -1106,16 +1068,14 @@ static int write_f(BlockBackend *blk, int argc, char
**argv)
}
gettimeofday(&t1, NULL);
- if (pflag) {
- cnt = do_pwrite(blk, buf, offset, count, &total);
- } else if (bflag) {
+ if (bflag) {
cnt = do_save_vmstate(blk, buf, offset, count, &total);
} else if (zflag) {
cnt = do_co_write_zeroes(blk, offset, count, &total);
} else if (cflag) {
cnt = do_write_compressed(blk, buf, offset, count, &total);
} else {
- cnt = do_write(blk, buf, offset, count, &total);
+ cnt = do_pwrite(blk, buf, offset, count, &total);
}
gettimeofday(&t2, NULL);
@@ -1592,8 +1552,7 @@ static int aio_read_f(BlockBackend *blk, int argc, char
**argv)
gettimeofday(&ctx->t1, NULL);
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
BLOCK_ACCT_READ);
- blk_aio_readv(blk, ctx->offset >> 9, &ctx->qiov,
- ctx->qiov.size >> 9, aio_read_done, ctx);
+ blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx);
return 0;
}
@@ -1717,8 +1676,7 @@ static int aio_write_f(BlockBackend *blk, int argc, char
**argv)
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
BLOCK_ACCT_WRITE);
- blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
- ctx->qiov.size >> 9, aio_write_done, ctx);
+ blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, 0, aio_write_done, ctx);
}
return 0;
}
--
2.5.5
- Re: [Qemu-block] [PATCH v7 06/19] scsi-disk: Switch to byte-based aio block access, (continued)
- [Qemu-block] [PATCH v7 07/19] virtio: Switch to byte-based aio block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 09/19] fdc: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 11/19] onenand: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 15/19] atapi: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 16/19] nbd: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 17/19] qemu-img: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 18/19] qemu-io: Switch to byte-based block access,
Eric Blake <=
- [Qemu-block] [PATCH v7 19/19] block: Kill unused sector-based blk_* functions, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 02/19] block: Switch blk_read_unthrottled() to byte interface, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 05/19] ide: Switch to byte-based aio block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 08/19] xen_disk: Switch to byte-based aio block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 13/19] sd: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 12/19] pflash: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 14/19] m25p80: Switch to byte-based block access, Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 01/19] block: Allow BDRV_REQ_FUA through blk_pwrite(), Eric Blake, 2016/05/06
- [Qemu-block] [PATCH v7 10/19] nand: Switch to byte-based block access, Eric Blake, 2016/05/06
- Re: [Qemu-block] [PATCH v7 00/19] block: kill sector-based blk_write/read, Kevin Wolf, 2016/05/10