All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, pbonzini@redhat.com, kwolf@redhat.com,
	stefanha@redhat.com, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v2 19/19] raw_bsd: Convert to byte-based interface
Date: Fri, 15 Jul 2016 17:23:08 -0600	[thread overview]
Message-ID: <1468624988-423-20-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1468624988-423-1-git-send-email-eblake@redhat.com>

Since the raw format driver is just passing things through, we can
do byte-based read and write if the underlying protocol does
likewise.

There's one tricky part - if we probed the image format, we document
that we restrict operations on the initial sector.  It's easiest to
keep this guarantee by enforcing read-modify-write on sub-sector
operations (yes, this partially reverts commit ad82be2f).

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v2: Rather than reject sub-sector write to sector 0, enforce a
RMW by setting request_alignment [Paolo]
---
 block/raw_bsd.c | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 961aa13..588d408 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -50,33 +50,30 @@ static int raw_reopen_prepare(BDRVReopenState *reopen_state,
     return 0;
 }

-static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
-                                     int nb_sectors, QEMUIOVector *qiov)
+static int coroutine_fn raw_co_preadv(BlockDriverState *bs, uint64_t offset,
+                                      uint64_t bytes, QEMUIOVector *qiov,
+                                      int flags)
 {
     BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO);
-    return bdrv_co_readv(bs->file, sector_num, nb_sectors, qiov);
+    return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
 }

-static int coroutine_fn
-raw_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
-                    QEMUIOVector *qiov, int flags)
+static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, uint64_t offset,
+                                       uint64_t bytes, QEMUIOVector *qiov,
+                                       int flags)
 {
     void *buf = NULL;
     BlockDriver *drv;
     QEMUIOVector local_qiov;
     int ret;

-    if (bs->probed && sector_num == 0) {
-        /* As long as these conditions are true, we can't get partial writes to
-         * the probe buffer and can just directly check the request. */
+    if (bs->probed && offset < BLOCK_PROBE_BUF_SIZE && bytes) {
+        /* Handling partial writes would be a pain - so we just
+         * require that guests have 512-byte request alignment if
+         * probing occurred */
         QEMU_BUILD_BUG_ON(BLOCK_PROBE_BUF_SIZE != 512);
         QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != 512);
-
-        if (nb_sectors == 0) {
-            /* qemu_iovec_to_buf() would fail, but we want to return success
-             * instead of -EINVAL in this case. */
-            return 0;
-        }
+        assert(offset == 0 && bytes >= BLOCK_PROBE_BUF_SIZE);

         buf = qemu_try_blockalign(bs->file->bs, 512);
         if (!buf) {
@@ -105,8 +102,7 @@ raw_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     }

     BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
-    ret = bdrv_co_pwritev(bs->file, sector_num * BDRV_SECTOR_SIZE,
-                          nb_sectors * BDRV_SECTOR_SIZE, qiov, flags);
+    ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);

 fail:
     if (qiov == &local_qiov) {
@@ -150,6 +146,16 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return bdrv_get_info(bs->file->bs, bdi);
 }

+static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
+{
+    if (bs->probed) {
+        /* To make it easier to protect the first sector, any probed
+         * image is restricted to read-modify-write on sub-sector
+         * operations. */
+        bs->bl.request_alignment = BDRV_SECTOR_SIZE;
+    }
+}
+
 static int raw_truncate(BlockDriverState *bs, int64_t offset)
 {
     return bdrv_truncate(bs->file->bs, offset);
@@ -240,8 +246,8 @@ BlockDriver bdrv_raw = {
     .bdrv_open            = &raw_open,
     .bdrv_close           = &raw_close,
     .bdrv_create          = &raw_create,
-    .bdrv_co_readv        = &raw_co_readv,
-    .bdrv_co_writev_flags = &raw_co_writev_flags,
+    .bdrv_co_preadv       = &raw_co_preadv,
+    .bdrv_co_pwritev      = &raw_co_pwritev,
     .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes,
     .bdrv_co_pdiscard     = &raw_co_pdiscard,
     .bdrv_co_get_block_status = &raw_co_get_block_status,
@@ -249,6 +255,7 @@ BlockDriver bdrv_raw = {
     .bdrv_getlength       = &raw_getlength,
     .has_variable_length  = true,
     .bdrv_get_info        = &raw_get_info,
+    .bdrv_refresh_limits  = &raw_refresh_limits,
     .bdrv_probe_blocksizes = &raw_probe_blocksizes,
     .bdrv_probe_geometry  = &raw_probe_geometry,
     .bdrv_media_changed   = &raw_media_changed,
-- 
2.5.5

  parent reply	other threads:[~2016-07-15 23:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15 23:22 [Qemu-devel] [PATCH for-2.7 v2 00/19] byte-based block discard Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 01/19] block: Convert bdrv_co_discard() to byte-based Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 02/19] block: Convert bdrv_discard() " Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 03/19] block: Switch BlockRequest " Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 04/19] block: Convert bdrv_aio_discard() " Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 05/19] block: Convert BB interface to byte-based discards Eric Blake
2016-07-15 23:22   ` Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 06/19] raw-posix: Switch paio_submit() to byte-based Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 07/19] rbd: Switch rbd_start_aio() " Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 08/19] block: Convert .bdrv_aio_discard() " Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 09/19] block: Add .bdrv_co_pdiscard() driver callback Eric Blake
2016-07-15 23:22 ` [Qemu-devel] [PATCH v2 10/19] blkreplay: Switch .bdrv_co_discard() to byte-based Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 11/19] gluster: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 12/19] iscsi: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 13/19] nbd: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 14/19] qcow2: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 15/19] raw_bsd: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 16/19] sheepdog: " Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 17/19] block: Kill .bdrv_co_discard() Eric Blake
2016-07-15 23:23 ` [Qemu-devel] [PATCH v2 18/19] nbd: Convert to byte-based interface Eric Blake
2016-07-15 23:23 ` Eric Blake [this message]
2016-07-19 16:12 ` [Qemu-devel] [Qemu-block] [PATCH for-2.7 v2 00/19] byte-based block discard Stefan Hajnoczi

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=1468624988-423-20-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.