From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v6 19/20] qemu-io: Switch to byte-based block access
Date: Wed, 4 May 2016 17:55:25 -0600 [thread overview]
Message-ID: <1462406126-22946-20-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1462406126-22946-1-git-send-email-eblake@redhat.com>
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 <eblake@redhat.com>
---
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
next prev parent reply other threads:[~2016-05-04 23:57 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-04 23:55 [Qemu-devel] [PATCH v6 00/20] block: kill sector-based blk_write/read Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 01/20] block: Allow BDRV_REQ_FUA through blk_pwrite() Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 02/20] block: Drop private ioctl-only members of BlockRequest Eric Blake
2016-05-06 10:37 ` Kevin Wolf
2016-05-06 12:23 ` Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 03/20] block: Switch blk_read_unthrottled() to byte interface Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 04/20] block: Switch blk_*write_zeroes() " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 05/20] block: Introduce byte-based aio read/write Eric Blake
2016-05-06 12:31 ` Kevin Wolf
2016-05-06 14:12 ` Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 06/20] ide: Switch to byte-based aio block access Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 07/20] scsi-disk: " Eric Blake
2016-05-06 12:50 ` Kevin Wolf
2016-05-06 14:18 ` Eric Blake
2016-05-06 14:49 ` Kevin Wolf
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 08/20] virtio: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 09/20] xen_disk: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 10/20] fdc: Switch to byte-based " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 11/20] nand: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 12/20] onenand: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 13/20] pflash: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 14/20] sd: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 15/20] m25p80: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 16/20] atapi: " Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 17/20] nbd: " Eric Blake
2016-05-06 13:08 ` Kevin Wolf
2016-05-06 14:19 ` Eric Blake
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 18/20] qemu-img: " Eric Blake
2016-05-04 23:55 ` Eric Blake [this message]
2016-05-04 23:55 ` [Qemu-devel] [PATCH v6 20/20] block: Kill unused sector-based blk_* functions Eric Blake
2016-05-06 13:11 ` [Qemu-devel] [PATCH v6 00/20] block: kill sector-based blk_write/read Kevin Wolf
2016-05-06 14:20 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462406126-22946-20-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).