Skip to contentSkip to conversation

block: Remove BlockDriverState.blk

PATCH Applied Kevin Wolf 3 participants 22 messages Apr 27, 2016 – May 17, 2016 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

v2 cover block: Remove BlockDriverState.blk

This is the final patch series that is required before we can start allowing setups with more than one BlockBackend per BlockDriverState.

Depends on 'block: Move I/O throttling to BlockBackend'.

v2:
- Patch 1 ('block: Use BdrvChild callbacks for change_media/resize') Bring back an accidentally removed comment [Max]

- Patch 2 ('block: User BdrvChild callback for device name') Documented BdrvChildRole.get_name() callback [Max]

- Patch 3 ('blockjob: Don't set iostatus of target') and Patch 4 ('Don't touch BDS iostatus')

Replaces 'Use BdrvChild callbacks for iostatus operations'. The whole problematic iostatus manipulation of block jobs only affected the target node where it wasn't visible, and it doesn't make sense, so it can simply go away.

- Patch 6 ('block: Add bdrv_has_blk()') and
Patch 7 ('block: Avoid bs->blk in bdrv_next()')

Split differently to keep the bdrv_next() changes in one patch [Max] Return BDSes only once in bdrv_next() even with multiple BBs [Max] Use enum for iteration phases instead of magic int [Max]

- Patch 9 ('block: Remove BlockDriverState.blk')
Use bdrv_get_parent_name() to keep error message unchanged [Max]

Kevin Wolf (9):
block: Use BdrvChild callbacks for change_media/resize
block: User BdrvChild callback for device name
blockjob: Don't set iostatus of target
blockjob: Don't touch BDS iostatus
block: Remove bdrv_aio_multiwrite()
block: Add bdrv_has_blk()
block: Avoid bs->blk in bdrv_next()
block: Don't return throttling info in query-named-block-nodes
block: Remove BlockDriverState.blk

 block.c                        | 101 ++++++++++----------
 block/backup.c                 |  34 +------
 block/block-backend.c          | 116 +++++++++++++++--------
 block/commit.c                 |   7 --
 block/io.c                     | 207 ++---------------------------------------
 block/mirror.c                 |  38 ++------
 block/qapi.c                   |   6 +-
 block/snapshot.c               |  30 +++---
 block/stream.c                 |  10 +-
 blockdev.c                     |  19 ++--
 blockjob.c                     |   6 +-
 include/block/block.h          |  10 +-
 include/block/block_int.h      |  12 ++-
 include/block/blockjob.h       |   4 +-
 include/sysemu/block-backend.h |   3 +-
 migration/block.c              |   4 +-
 monitor.c                      |   6 +-
 qemu-io-cmds.c                 | 203 ----------------------------------------
 qmp.c                          |   5 +-
 tests/qemu-iotests/096         |   3 +-
 tests/qemu-iotests/100         | 145 -----------------------------
 tests/qemu-iotests/100.out     |  89 ------------------
 tests/qemu-iotests/136         |  20 +---
 tests/qemu-iotests/136.out     |   4 +-
 tests/qemu-iotests/group       |   2 +-
 trace-events                   |   2 -
 26 files changed, 218 insertions(+), 868 deletions(-)
 delete mode 100755 tests/qemu-iotests/100
 delete mode 100644 tests/qemu-iotests/100.out
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v2 1/9 block: Use BdrvChild callbacks for change_media/resize

We want to get rid of BlockDriverState.blk in order to allow multiple BlockBackends per BDS. Converting the device callbacks in block.c (which assume a single BlockBackend) to per-child callbacks gets us rid of the first few instances.

---
 block.c                   | 39 ++++++++++++++++++++++++++-------------
 block/block-backend.c     | 15 ++++++++++++++-
 include/block/block_int.h |  4 +++-
 3 files changed, 43 insertions(+), 15 deletions(-)
block.c +26 -13
index d8c6e98..69ee791 100644
@@ -1216,6 +1216,27 @@ void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
     bdrv_root_unref_child(child);
 }
 
+
+static void bdrv_parent_cb_change_media(BlockDriverState *bs, bool load)
+{
+    BdrvChild *c;
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->change_media) {
+            c->role->change_media(c, load);
+        }
+    }
+}
+
+static void bdrv_parent_cb_resize(BlockDriverState *bs)
+{
+    BdrvChild *c;
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->resize) {
+            c->role->resize(c);
+        }
+    }
+}
+
 /*
  * Sets the backing file link of a BDS. A new reference is created; callers
  * which don't need their own reference any more must call bdrv_unref().
@@ -1675,9 +1696,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
     }
 
     if (!bdrv_key_required(bs)) {
-        if (bs->blk) {
-            blk_dev_change_media_cb(bs->blk, true);
-        }
+        bdrv_parent_cb_change_media(bs, true);
     } else if (!runstate_check(RUN_STATE_PRELAUNCH)
                && !runstate_check(RUN_STATE_INMIGRATE)
                && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */
@@ -2123,9 +2142,7 @@ static void bdrv_close(BlockDriverState *bs)
     bdrv_release_named_dirty_bitmaps(bs);
     assert(QLIST_EMPTY(&bs->dirty_bitmaps));
 
-    if (bs->blk) {
-        blk_dev_change_media_cb(bs->blk, false);
-    }
+    bdrv_parent_cb_change_media(bs, false);
 
     if (bs->drv) {
         BdrvChild *child, *next;
@@ -2576,9 +2593,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
         bdrv_dirty_bitmap_truncate(bs);
-        if (bs->blk) {
-            blk_dev_resize_cb(bs->blk);
-        }
+        bdrv_parent_cb_resize(bs);
     }
     return ret;
 }
@@ -2688,11 +2703,9 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
     if (ret < 0) {
         bs->valid_key = 0;
     } else if (!bs->valid_key) {
+        /* call the change callback now, we skipped it on open */
         bs->valid_key = 1;
-        if (bs->blk) {
-            /* call the change callback now, we skipped it on open */
-            blk_dev_change_media_cb(bs->blk, true);
-        }
+        bdrv_parent_cb_change_media(bs, true);
     }
     return ret;
 }
block/block-backend.c +14 -1
index 063024d..7f507ba 100644
@@ -94,9 +94,15 @@ static void blk_root_inherit_options(int *child_flags, QDict *child_options,
 static void blk_root_drained_begin(BdrvChild *child);
 static void blk_root_drained_end(BdrvChild *child);
 
+static void blk_root_change_media(BdrvChild *child, bool load);
+static void blk_root_resize(BdrvChild *child);
+
 static const BdrvChildRole child_root = {
     .inherit_options    = blk_root_inherit_options,
 
+    .change_media       = blk_root_change_media,
+    .resize             = blk_root_resize,
+
     .drained_begin      = blk_root_drained_begin,
     .drained_end        = blk_root_drained_end,
 };
@@ -556,6 +562,11 @@ void blk_dev_change_media_cb(BlockBackend *blk, bool load)
     }
 }
 
+static void blk_root_change_media(BdrvChild *child, bool load)
+{
+    blk_dev_change_media_cb(child->opaque, load);
+}
+
 /*
  * Does @blk's attached device model have removable media?
  * %true if no device model is attached.
@@ -610,8 +621,10 @@ bool blk_dev_is_medium_locked(BlockBackend *blk)
 /*
  * Notify @blk's attached device model of a backend size change.
  */
-void blk_dev_resize_cb(BlockBackend *blk)
+static void blk_root_resize(BdrvChild *child)
 {
+    BlockBackend *blk = child->opaque;
+
     if (blk->dev_ops && blk->dev_ops->resize_cb) {
         blk->dev_ops->resize_cb(blk->dev_opaque);
     }
include/block/block_int.h +3 -1
index 8481e80..9938a3d 100644
@@ -362,6 +362,9 @@ struct BdrvChildRole {
     void (*inherit_options)(int *child_flags, QDict *child_options,
                             int parent_flags, QDict *parent_options);
 
+    void (*change_media)(BdrvChild *child, bool load);
+    void (*resize)(BdrvChild *child);
+
     void (*drained_begin)(BdrvChild *child);
     void (*drained_end)(BdrvChild *child);
 };
@@ -706,7 +709,6 @@ bool blk_dev_has_tray(BlockBackend *blk);
 void blk_dev_eject_request(BlockBackend *blk, bool force);
 bool blk_dev_is_tray_open(BlockBackend *blk);
 bool blk_dev_is_medium_locked(BlockBackend *blk);
-void blk_dev_resize_cb(BlockBackend *blk);
 
 void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
 bool bdrv_requests_pending(BlockDriverState *bs);
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH v2 2/9 block: User BdrvChild callback for device name

In reply to Kevin Wolf

In order to get rid of bs->blk for bdrv_get_device_name() and bdrv_get_device_or_node_name(), ask all parents for their name and simply pick the first one.

---
 block.c                   | 22 ++++++++++++++++++++--
 block/block-backend.c     |  6 ++++++
 include/block/block_int.h |  5 +++++
 3 files changed, 31 insertions(+), 2 deletions(-)
block.c +20 -2
index 69ee791..a8df72f 100644
@@ -2896,10 +2896,28 @@ const char *bdrv_get_node_name(const BlockDriverState *bs)
     return bs->node_name;
 }
 
+static const char *bdrv_get_parent_name(const BlockDriverState *bs)
+{
+    BdrvChild *c;
+    const char *name;
+
+    /* If multiple parents have a name, just pick the first one. */
+    QLIST_FOREACH(c, &bs->parents, next_parent) {
+        if (c->role->get_name) {
+            name = c->role->get_name(c);
+            if (name && *name) {
+                return name;
+            }
+        }
+    }
+
+    return NULL;
+}
+
 /* TODO check what callers really want: bs->node_name or blk_name() */
 const char *bdrv_get_device_name(const BlockDriverState *bs)
 {
-    return bs->blk ? blk_name(bs->blk) : "";
+    return bdrv_get_parent_name(bs) ?: "";
 }
 
 /* This can be used to identify nodes that might not have a device
@@ -2908,7 +2926,7 @@ const char *bdrv_get_device_name(const BlockDriverState *bs)
  * absent, then this returns an empty (non-null) string. */
 const char *bdrv_get_device_or_node_name(const BlockDriverState *bs)
 {
-    return bs->blk ? blk_name(bs->blk) : bs->node_name;
+    return bdrv_get_parent_name(bs) ?: bs->node_name;
 }
 
 int bdrv_get_flags(BlockDriverState *bs)
block/block-backend.c +6 -0
index 7f507ba..34f747e 100644
@@ -97,11 +97,17 @@ static void blk_root_drained_end(BdrvChild *child);
 static void blk_root_change_media(BdrvChild *child, bool load);
 static void blk_root_resize(BdrvChild *child);
 
+static const char *blk_root_get_name(BdrvChild *child)
+{
+    return blk_name(child->opaque);
+}
+
 static const BdrvChildRole child_root = {
     .inherit_options    = blk_root_inherit_options,
 
     .change_media       = blk_root_change_media,
     .resize             = blk_root_resize,
+    .get_name           = blk_root_get_name,
 
     .drained_begin      = blk_root_drained_begin,
     .drained_end        = blk_root_drained_end,
include/block/block_int.h +5 -0
index 9938a3d..f4a0941 100644
@@ -365,6 +365,11 @@ struct BdrvChildRole {
     void (*change_media)(BdrvChild *child, bool load);
     void (*resize)(BdrvChild *child);
 
+    /* Returns a name that is supposedly more useful for human users than the
+     * node name for identifying the node in question (in particular, a BB
+     * name), or NULL if the parent can't provide a better name. */
+    const char* (*get_name)(BdrvChild *child);
+
     void (*drained_begin)(BdrvChild *child);
     void (*drained_end)(BdrvChild *child);
 };
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v2 3/9 blockjob: Don't set iostatus of target

In reply to Kevin Wolf

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
block/backup.c +4 -4
index 491fd14..ef7609d 100644
@@ -272,11 +272,11 @@ static BlockErrorAction backup_error_action(BackupBlockJob *job,
                                             bool read, int error)
 {
     if (read) {
-        return block_job_error_action(&job->common, job->common.bs,
-                                      job->on_source_error, true, error);
+        return block_job_error_action(&job->common, job->on_source_error,
+                                      true, error);
     } else {
-        return block_job_error_action(&job->common, job->target,
-                                      job->on_target_error, false, error);
+        return block_job_error_action(&job->common, job->on_target_error,
+                                      false, error);
     }
 }
 
block/mirror.c +4 -4
index 039f481..c7f51ad 100644
@@ -80,11 +80,11 @@ static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read,
 {
     s->synced = false;
     if (read) {
-        return block_job_error_action(&s->common, s->common.bs,
-                                      s->on_source_error, true, error);
+        return block_job_error_action(&s->common, s->on_source_error,
+                                      true, error);
     } else {
-        return block_job_error_action(&s->common, s->target,
-                                      s->on_target_error, false, error);
+        return block_job_error_action(&s->common, s->on_target_error,
+                                      false, error);
     }
 }
 
block/stream.c +1 -2
index 332b9a1..16c3e90 100644
@@ -163,8 +163,7 @@ wait:
         }
         if (ret < 0) {
             BlockErrorAction action =
-                block_job_error_action(&s->common, s->common.bs, s->on_error,
-                                       true, -ret);
+                block_job_error_action(&s->common, s->on_error, true, -ret);
             if (action == BLOCK_ERROR_ACTION_STOP) {
                 n = 0;
                 continue;
blockjob.c +1 -5
index 9fc37ca..5b840a7 100644
@@ -411,8 +411,7 @@ void block_job_event_ready(BlockJob *job)
                                     job->speed, &error_abort);
 }
 
-BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
-                                        BlockdevOnError on_err,
+BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
                                         int is_read, int error)
 {
     BlockErrorAction action;
@@ -443,9 +442,6 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
         job->user_paused = true;
         block_job_pause(job);
         block_job_iostatus_set_err(job, error);
-        if (bs->blk && bs != job->bs) {
-            blk_iostatus_set_err(bs->blk, error);
-        }
     }
     return action;
 }
include/block/blockjob.h +1 -3
index 8bedc49..073a433 100644
@@ -383,7 +383,6 @@ void block_job_iostatus_reset(BlockJob *job);
 /**
  * block_job_error_action:
  * @job: The job to signal an error for.
- * @bs: The block device on which to set an I/O error.
  * @on_err: The error action setting.
  * @is_read: Whether the operation was a read.
  * @error: The error that was reported.
@@ -391,8 +390,7 @@ void block_job_iostatus_reset(BlockJob *job);
  * Report an I/O error for a block job and possibly stop the VM.  Return the
  * action that was selected based on @on_err and @error.
  */
-BlockErrorAction block_job_error_action(BlockJob *job, BlockDriverState *bs,
-                                        BlockdevOnError on_err,
+BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
                                         int is_read, int error);
 
 typedef void BlockJobDeferToMainLoopFn(BlockJob *job, void *opaque);
Signature · 1 line
1.8.3.1
Reviewed-by on v2 3/9
#4 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Quoted 11 lines · Kevin Wolf

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
#5 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Quoted 21 lines · Max Reitz
Quoted 11 lines · Kevin Wolf

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
Quoted 1 line

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

e.g.:

(echo "{'execute':'qmp_capabilities'}

       {'execute':'blockdev-backup',
        'arguments':{'device':'src','target':'dst',
        'sync':'full','on-target-error':'enospc'}}";
 sleep 1;
 echo "{'execute':'query-block'}") | \
   x86_64-softmmu/qemu-system-x86_64 \
       -drive if=none,id=src,file=test.qcow2 \
       -drive if=none,id=dst,file=mnt/out.qcow2 \
       -qmp-pretty stdio -nodefaults

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Max

author
#6 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Am 06.05.2016 um 14:32 hat Max Reitz geschrieben:

Quoted 40 lines · Max Reitz
Quoted 21 lines · Kevin Wolf
Quoted 11 lines

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
Quoted 1 line

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

e.g.:

(echo "{'execute':'qmp_capabilities'}

       {'execute':'blockdev-backup',
        'arguments':{'device':'src','target':'dst',
        'sync':'full','on-target-error':'enospc'}}";
 sleep 1;
 echo "{'execute':'query-block'}") | \
   x86_64-softmmu/qemu-system-x86_64 \
       -drive if=none,id=src,file=test.qcow2 \
       -drive if=none,id=dst,file=mnt/out.qcow2 \
       -qmp-pretty stdio -nodefaults
Quoted 2 lines

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Hm... Let's pretend we didn't notice. In fact, I don't think this behaviour is documented and it also doesn't make a lot of sense.

I would be surprised if libvirt made use of it, as there is still the job iostatus which works in drive-* cases, too.

(Eric?)

Quoted 3 lines

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Simply letting the field disappear sounds like a nice solution.

Kevin

#7 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Quoted 50 lines · Kevin Wolf

Am 06.05.2016 um 14:32 hat Max Reitz geschrieben:

Quoted 40 lines · Max Reitz
Quoted 21 lines · Kevin Wolf
Quoted 11 lines

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
Quoted 1 line

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

e.g.:

(echo "{'execute':'qmp_capabilities'}

       {'execute':'blockdev-backup',
        'arguments':{'device':'src','target':'dst',
        'sync':'full','on-target-error':'enospc'}}";
 sleep 1;
 echo "{'execute':'query-block'}") | \
   x86_64-softmmu/qemu-system-x86_64 \
       -drive if=none,id=src,file=test.qcow2 \
       -drive if=none,id=dst,file=mnt/out.qcow2 \
       -qmp-pretty stdio -nodefaults
Quoted 2 lines

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Hm... Let's pretend we didn't notice. In fact, I don't think this behaviour is documented and it also doesn't make a lot of sense.

I would be surprised if libvirt made use of it, as there is still the job iostatus which works in drive-* cases, too.

Quoted 7 lines

(Eric?)

Quoted 3 lines

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Simply letting the field disappear sounds like a nice solution.

I'm not sure I completely agree with that because the iostatus appears to be the only way of obtaining the information whether the block job stopped because of an ENOSPC or because of something different (the BLOCK_JOB_ERROR doesn't tell you).

I don't know whether anyone actually needs that information, though, and if you think dropping this is fine, then I guess it's fine with me, too, and my R-b stands.

Max

author
#8 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Am 06.05.2016 um 15:40 hat Max Reitz geschrieben:

Quoted 59 lines · Kevin Wolf
Quoted 50 lines

Am 06.05.2016 um 14:32 hat Max Reitz geschrieben:

Quoted 40 lines · Max Reitz
Quoted 21 lines · Kevin Wolf
Quoted 11 lines

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
Quoted 1 line

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

e.g.:

(echo "{'execute':'qmp_capabilities'}

       {'execute':'blockdev-backup',
        'arguments':{'device':'src','target':'dst',
        'sync':'full','on-target-error':'enospc'}}";
 sleep 1;
 echo "{'execute':'query-block'}") | \
   x86_64-softmmu/qemu-system-x86_64 \
       -drive if=none,id=src,file=test.qcow2 \
       -drive if=none,id=dst,file=mnt/out.qcow2 \
       -qmp-pretty stdio -nodefaults
Quoted 2 lines

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Hm... Let's pretend we didn't notice. In fact, I don't think this behaviour is documented and it also doesn't make a lot of sense.

I would be surprised if libvirt made use of it, as there is still the job iostatus which works in drive-* cases, too.

Quoted 7 lines

(Eric?)

Quoted 3 lines

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Simply letting the field disappear sounds like a nice solution.

Quoted 8 lines

I'm not sure I completely agree with that because the iostatus appears to be the only way of obtaining the information whether the block job stopped because of an ENOSPC or because of something different (the BLOCK_JOB_ERROR doesn't tell you).

I don't know whether anyone actually needs that information, though, and if you think dropping this is fine, then I guess it's fine with me, too, and my R-b stands.

But you don't have this information with the drive-* commands either.

I would be okay with reintroducing this information, but in the right place. Modifying the guest device iostatus for block jobs certainly isn't right.

Anyway, we need Eric's input to confirm that libvirt doesn't depend on this.

Kevin

Reviewed-by
#9 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

Quoted 69 lines · Kevin Wolf

Am 06.05.2016 um 15:40 hat Max Reitz geschrieben:

Quoted 59 lines · Kevin Wolf
Quoted 50 lines

Am 06.05.2016 um 14:32 hat Max Reitz geschrieben:

Quoted 40 lines · Max Reitz
Quoted 21 lines · Kevin Wolf
Quoted 11 lines

When block job errors were introduced, we assigned the iostatus of the target BDS "just in case". The field has never been accessible for the user because the target isn't listed in query-block.

Before we can allow the user to have a second BlockBackend on the target, we need to clean this up. If anything, we would want to set the iostatus for the internal BB of the job (which we can always do later), but certainly not for a separate BB which the job doesn't even use.

As a nice side effect, this gets us rid of another bs->blk use.

Quoted 8 lines
---
 block/backup.c           | 8 ++++----
 block/mirror.c           | 8 ++++----
 block/stream.c           | 3 +--
 blockjob.c               | 6 +-----
 include/block/blockjob.h | 4 +---
 5 files changed, 11 insertions(+), 18 deletions(-)
Quoted 1 line

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

e.g.:

(echo "{'execute':'qmp_capabilities'}

       {'execute':'blockdev-backup',
        'arguments':{'device':'src','target':'dst',
        'sync':'full','on-target-error':'enospc'}}";
 sleep 1;
 echo "{'execute':'query-block'}") | \
   x86_64-softmmu/qemu-system-x86_64 \
       -drive if=none,id=src,file=test.qcow2 \
       -drive if=none,id=dst,file=mnt/out.qcow2 \
       -qmp-pretty stdio -nodefaults
Quoted 2 lines

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Hm... Let's pretend we didn't notice. In fact, I don't think this behaviour is documented and it also doesn't make a lot of sense.

I would be surprised if libvirt made use of it, as there is still the job iostatus which works in drive-* cases, too.

Quoted 7 lines

(Eric?)

Quoted 3 lines

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Simply letting the field disappear sounds like a nice solution.

Quoted 8 lines

I'm not sure I completely agree with that because the iostatus appears to be the only way of obtaining the information whether the block job stopped because of an ENOSPC or because of something different (the BLOCK_JOB_ERROR doesn't tell you).

I don't know whether anyone actually needs that information, though, and if you think dropping this is fine, then I guess it's fine with me, too, and my R-b stands.

Quoted 5 lines

But you don't have this information with the drive-* commands either.

I would be okay with reintroducing this information, but in the right place. Modifying the guest device iostatus for block jobs certainly isn't right.

As discussed on IRC, that sounds right to me. Thus, have an explicit

Quoted 5 lines

Anyway, we need Eric's input to confirm that libvirt doesn't depend on this.

Kevin

#10 lore raw

Re: [Qemu-devel] [PATCH v2 3/9] blockjob: Don't set iostatus of target

In reply to Kevin Wolf
Quoted 8 lines · Kevin Wolf
Quoted 7 lines

Maybe I need to take that back. Using e.g. blockdev-backup, you can indeed see the target in query-block.

Where mnt is a file system and test.qcow2 is large enough such that an ENOSPC will occur.

Quoted 11 lines

Hm... Let's pretend we didn't notice. In fact, I don't think this behaviour is documented and it also doesn't make a lot of sense.

I would be surprised if libvirt made use of it, as there is still the job iostatus which works in drive-* cases, too.

(Eric?)

Quoted 3 lines

Before this patch, you can see "io-status": "nospace" in query-block for dst. After it, it says "io-status": "ok", and after the next it doesn't say anything about the status at all anymore.

Here's what libvirt does with "io-status":

qemuMonitorJSONGetBlockInfo():

        /* Missing io-status indicates no error */
        if ((status = virJSONValueObjectGetString(dev, "io-status"))) {
            info->io_status = qemuMonitorBlockIOStatusToError(status);
            if (info->io_status < 0)
                goto cleanup;
        }

Then it feeds info->io_status into qemuDomainGetDiskErrors().

However, I'm not sure I know the full context of your question - is io-status still available on the primary BDS, and we are only deleting it from a secondary spot used only during a job? I think libvirt is currently only checking the status of the BDS (ENOSPC when the primary runs out of room), not what happens during a block job. In fact, libvirt does not yet use 'blockdev-backup' at all, let alone blockdev-backup with 'on-target-error':'enospc' (it should, but that's a story for another day).

Quoted 2 lines

Simply letting the field disappear sounds like a nice solution.

So at first glance, I think we're okay here, dropping io-status from the block job from this location and instead exposing it from a more natural spot in QMP. And in the worst case, we can use introspection to learn which of two spots exposes the information, if libvirt is trying to be portable to 2.6 and 2.7 at the same time.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#11 lore raw

PATCH v2 4/9 blockjob: Don't touch BDS iostatus

In reply to Kevin Wolf

Block jobs don't actually make use of the iostatus for their BDSes, but they manage a separate block job iostatus. Still, they require that it is enabled for the source BDS and they enable it automatically for the target and set the error handling mode - which ends up never being used by the job.

This patch removes all of the BDS iostatus handling from the block job, which removes another few bs->blk accesses.

---
 block/backup.c | 26 --------------------------
 block/commit.c |  7 -------
 block/mirror.c | 26 --------------------------
 block/stream.c |  7 -------
 4 files changed, 66 deletions(-)
block/backup.c +0 -26
index ef7609d..fec45e8 100644
@@ -218,15 +218,6 @@ static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp)
     ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
 }
 
-static void backup_iostatus_reset(BlockJob *job)
-{
-    BackupBlockJob *s = container_of(job, BackupBlockJob, common);
-
-    if (s->target->blk) {
-        blk_iostatus_reset(s->target->blk);
-    }
-}
-
 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
 {
     BdrvDirtyBitmap *bm;
@@ -263,7 +254,6 @@ static const BlockJobDriver backup_job_driver = {
     .instance_size  = sizeof(BackupBlockJob),
     .job_type       = BLOCK_JOB_TYPE_BACKUP,
     .set_speed      = backup_set_speed,
-    .iostatus_reset = backup_iostatus_reset,
     .commit         = backup_commit,
     .abort          = backup_abort,
 };
@@ -388,7 +378,6 @@ static void coroutine_fn backup_run(void *opaque)
     BackupCompleteData *data;
     BlockDriverState *bs = job->common.bs;
     BlockDriverState *target = job->target;
-    BlockdevOnError on_target_error = job->on_target_error;
     NotifierWithReturn before_write = {
         .notify = backup_before_write_notify,
     };
@@ -404,11 +393,6 @@ static void coroutine_fn backup_run(void *opaque)
 
     job->done_bitmap = bitmap_new(end);
 
-    if (target->blk) {
-        blk_set_on_error(target->blk, on_target_error, on_target_error);
-        blk_iostatus_enable(target->blk);
-    }
-
     bdrv_add_before_write_notifier(bs, &before_write);
 
     if (job->sync_mode == MIRROR_SYNC_MODE_NONE) {
@@ -484,9 +468,6 @@ static void coroutine_fn backup_run(void *opaque)
     qemu_co_rwlock_unlock(&job->flush_rwlock);
     g_free(job->done_bitmap);
 
-    if (target->blk) {
-        blk_iostatus_disable(target->blk);
-    }
     bdrv_op_unblock_all(target, job->common.blocker);
 
     data = g_malloc(sizeof(*data));
@@ -515,13 +496,6 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target,
         return;
     }
 
-    if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
-         on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
-        (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) {
-        error_setg(errp, QERR_INVALID_PARAMETER, "on-source-error");
-        return;
-    }
-
     if (!bdrv_is_inserted(bs)) {
         error_setg(errp, "Device is not inserted: %s",
                    bdrv_get_device_name(bs));
block/commit.c +0 -7
index cba0e8c..f308c8c 100644
@@ -214,13 +214,6 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
     BlockDriverState *overlay_bs;
     Error *local_err = NULL;
 
-    if ((on_error == BLOCKDEV_ON_ERROR_STOP ||
-         on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
-        (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) {
-        error_setg(errp, "Invalid parameter combination");
-        return;
-    }
-
     assert(top != bs);
     if (top == base) {
         error_setg(errp, "Invalid files for merge: top and base are the same");
block/mirror.c +0 -26
index c7f51ad..71d7a4e 100644
@@ -710,9 +710,6 @@ immediate_exit:
     g_free(s->cow_bitmap);
     g_free(s->in_flight_bitmap);
     bdrv_release_dirty_bitmap(bs, s->dirty_bitmap);
-    if (s->target->blk) {
-        blk_iostatus_disable(s->target->blk);
-    }
 
     data = g_malloc(sizeof(*data));
     data->ret = ret;
@@ -739,15 +736,6 @@ static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
     ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
 }
 
-static void mirror_iostatus_reset(BlockJob *job)
-{
-    MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
-
-    if (s->target->blk) {
-        blk_iostatus_reset(s->target->blk);
-    }
-}
-
 static void mirror_complete(BlockJob *job, Error **errp)
 {
     MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
@@ -793,7 +781,6 @@ static const BlockJobDriver mirror_job_driver = {
     .instance_size = sizeof(MirrorBlockJob),
     .job_type      = BLOCK_JOB_TYPE_MIRROR,
     .set_speed     = mirror_set_speed,
-    .iostatus_reset= mirror_iostatus_reset,
     .complete      = mirror_complete,
 };
 
@@ -801,8 +788,6 @@ static const BlockJobDriver commit_active_job_driver = {
     .instance_size = sizeof(MirrorBlockJob),
     .job_type      = BLOCK_JOB_TYPE_COMMIT,
     .set_speed     = mirror_set_speed,
-    .iostatus_reset
-                   = mirror_iostatus_reset,
     .complete      = mirror_complete,
 };
 
@@ -827,13 +812,6 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
 
     assert ((granularity & (granularity - 1)) == 0);
 
-    if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
-         on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
-        (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) {
-        error_setg(errp, QERR_INVALID_PARAMETER, "on-source-error");
-        return;
-    }
-
     if (buf_size < 0) {
         error_setg(errp, "Invalid parameter 'buf-size'");
         return;
@@ -882,10 +860,6 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
 
     bdrv_op_block_all(s->target, s->common.blocker);
 
-    if (s->target->blk) {
-        blk_set_on_error(s->target->blk, on_target_error, on_target_error);
-        blk_iostatus_enable(s->target->blk);
-    }
     s->common.co = qemu_coroutine_create(mirror_run);
     trace_mirror_start(bs, s, s->common.co, opaque);
     qemu_coroutine_enter(s->common.co, s);
block/stream.c +0 -7
index 16c3e90..40aa322 100644
@@ -223,13 +223,6 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
 {
     StreamBlockJob *s;
 
-    if ((on_error == BLOCKDEV_ON_ERROR_STOP ||
-         on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
-        (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) {
-        error_setg(errp, QERR_INVALID_PARAMETER, "on-error");
-        return;
-    }
-
     s = block_job_create(&stream_job_driver, bs, speed, cb, opaque, errp);
     if (!s) {
         return;
Signature · 1 line
1.8.3.1
Reviewed-by on v2 4/9
#12 lore raw

Re: [Qemu-devel] [PATCH v2 4/9] blockjob: Don't touch BDS iostatus

Quoted 9 lines · Kevin Wolf

Block jobs don't actually make use of the iostatus for their BDSes, but they manage a separate block job iostatus. Still, they require that it is enabled for the source BDS and they enable it automatically for the target and set the error handling mode - which ends up never being used by the job.

This patch removes all of the BDS iostatus handling from the block job, which removes another few bs->blk accesses.

Quoted 7 lines
---
 block/backup.c | 26 --------------------------
 block/commit.c |  7 -------
 block/mirror.c | 26 --------------------------
 block/stream.c |  7 -------
 4 files changed, 66 deletions(-)
author
#13 lore raw

PATCH v2 5/9 block: Remove bdrv_aio_multiwrite()

In reply to Kevin Wolf

Since virtio-blk implements request merging itself these days, the only remaining users are test cases for the function. That doesn't make the function exactly useful any more.

---
 block/block-backend.c          |  14 ---
 block/io.c                     | 194 ---------------------------------------
 include/block/block.h          |   7 +-
 include/sysemu/block-backend.h |   1 -
 qemu-io-cmds.c                 | 203 -----------------------------------------
 tests/qemu-iotests/100         | 145 -----------------------------
 tests/qemu-iotests/100.out     |  89 ------------------
 tests/qemu-iotests/136         |  20 +---
 tests/qemu-iotests/136.out     |   4 +-
 tests/qemu-iotests/group       |   2 +-
 trace-events                   |   2 -
 11 files changed, 9 insertions(+), 672 deletions(-)
 delete mode 100755 tests/qemu-iotests/100
 delete mode 100644 tests/qemu-iotests/100.out
block/block-backend.c +0 -14
index 34f747e..d1974f5 100644
@@ -1106,20 +1106,6 @@ void blk_aio_cancel_async(BlockAIOCB *acb)
     bdrv_aio_cancel_async(acb);
 }
 
-int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs)
-{
-    int i, ret;
-
-    for (i = 0; i < num_reqs; i++) {
-        ret = blk_check_request(blk, reqs[i].sector, reqs[i].nb_sectors);
-        if (ret < 0) {
-            return ret;
-        }
-    }
-
-    return bdrv_aio_multiwrite(blk_bs(blk), reqs, num_reqs);
-}
-
 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
 {
     if (!blk_is_available(blk)) {
block/io.c +0 -194

200 lines not on this page · raw message

include/block/block.h +2 -5
index 4b04550..10ce058 100644
@@ -329,7 +329,7 @@ void bdrv_aio_cancel(BlockAIOCB *acb);
 void bdrv_aio_cancel_async(BlockAIOCB *acb);
 
 typedef struct BlockRequest {
-    /* Fields to be filled by multiwrite caller */
+    /* Fields to be filled by caller */
     union {
         struct {
             int64_t sector;
@@ -345,13 +345,10 @@ typedef struct BlockRequest {
     BlockCompletionFunc *cb;
     void *opaque;
 
-    /* Filled by multiwrite implementation */
+    /* Filled by block layer */
     int error;
 } BlockRequest;
 
-int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
-    int num_reqs);
-
 /* sg packet commands */
 int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
 BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
include/sysemu/block-backend.h +0 -1
index b79608e..8285c97 100644
@@ -141,7 +141,6 @@ BlockAIOCB *blk_aio_discard(BlockBackend *blk,
                             BlockCompletionFunc *cb, void *opaque);
 void blk_aio_cancel(BlockAIOCB *acb);
 void blk_aio_cancel_async(BlockAIOCB *acb);
-int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs);
 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
                           BlockCompletionFunc *cb, void *opaque);
qemu-io-cmds.c +0 -203

221 lines not on this page · raw message

tests/qemu-iotests/100 deleted +0 -145

145 lines not on this page · raw message

tests/qemu-iotests/100.out deleted +0 -89

89 lines not on this page · raw message

tests/qemu-iotests/136 +4 -16
index e8c6937..996265e 100644
@@ -248,14 +248,6 @@ sector = "%d"
         if failed_wr_ops > 0:
             highest_offset = max(highest_offset, bad_offset + 512)
 
-        for i in range(wr_merged):
-            first = i * wr_size * 2
-            second = first + wr_size
-            ops.append("multiwrite %d %d ; %d %d" %
-                       (first, wr_size, second, wr_size))
-
-        highest_offset = max(highest_offset, wr_merged * wr_size * 2)
-
         # Now perform all operations
         for op in ops:
             self.vm.hmp_qemu_io("drive0", op)
@@ -309,19 +301,15 @@ sector = "%d"
     def test_flush(self):
         self.do_test_stats(flush_ops = 8)
 
-    def test_merged(self):
-        for i in range(5):
-            self.do_test_stats(wr_merged = i * 3)
-
     def test_all(self):
         # rd_size, rd_ops, wr_size, wr_ops, flush_ops
         # invalid_rd_ops,  invalid_wr_ops,
         # failed_rd_ops,   failed_wr_ops
         # wr_merged
-        test_values = [[512,    1, 512,   1, 1, 4, 7, 5, 2, 1],
-                       [65536,  1, 2048, 12, 7, 7, 5, 2, 5, 5],
-                       [32768,  9, 8192,  1, 4, 3, 2, 4, 6, 4],
-                       [16384, 11, 3584, 16, 9, 8, 6, 7, 3, 4]]
+        test_values = [[512,    1, 512,   1, 1, 4, 7, 5, 2, 0],
+                       [65536,  1, 2048, 12, 7, 7, 5, 2, 5, 0],
+                       [32768,  9, 8192,  1, 4, 3, 2, 4, 6, 0],
+                       [16384, 11, 3584, 16, 9, 8, 6, 7, 3, 0]]
         for i in test_values:
             self.do_test_stats(*i)
 
tests/qemu-iotests/136.out +2 -2
index 0a5e958..cfa5c0d 100644
@@ -1,5 +1,5 @@
-........................................
+...................................
 ----------------------------------------------------------------------
-Ran 40 tests
+Ran 35 tests
 
 OK
tests/qemu-iotests/group +1 -1
index 822953b..6067673 100644
@@ -106,7 +106,7 @@
 097 rw auto backing
 098 rw auto backing quick
 099 rw auto quick
-100 rw auto quick
+# 100 was removed, do not reuse
 101 rw auto quick
 102 rw auto quick
 103 rw auto quick
trace-events +0 -2
index 8350743..21026d9 100644
@@ -62,8 +62,6 @@ bdrv_open_common(void *bs, const char *filename, int flags, const char *format_n
 bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d"
 
 # block/io.c
-multiwrite_cb(void *mcb, int ret) "mcb %p ret %d"
-bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) "mcb %p num_callbacks %d num_reqs %d"
 bdrv_aio_discard(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
 bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p"
 bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
Signature · 1 line
1.8.3.1
Reviewed-by on v2 5/9
#14 lore raw

Re: [Qemu-devel] [PATCH v2 5/9] block: Remove bdrv_aio_multiwrite()

Quoted 6 lines · Kevin Wolf

Since virtio-blk implements request merging itself these days, the only remaining users are test cases for the function. That doesn't make the function exactly useful any more.

Quoted 12 lines
---
 block/block-backend.c          |  14 ---
 block/io.c                     | 194 ---------------------------------------
 include/block/block.h          |   7 +-
 include/sysemu/block-backend.h |   1 -
 qemu-io-cmds.c                 | 203 -----------------------------------------
 tests/qemu-iotests/100         | 145 -----------------------------
 tests/qemu-iotests/100.out     |  89 ------------------
 tests/qemu-iotests/136         |  20 +---
 tests/qemu-iotests/136.out     |   4 +-
 tests/qemu-iotests/group       |   2 +-
 trace-events                   |   2 -

Now that BlockRequest is no longer used in any .h files, should we move the struct out of block.h and into io.c as a followup? I already attempted touching the struct in my series on killing blk_read(), before realizing you were killing the last public use of the struct, so maybe I'll go ahead and tackle that simplification.

include/block/block.h void bdrv_aio_cancel(BlockAIOCB *acb); · line 332

Quoted 7 lines

+++ b/include/block/block.h

include/block/block.h +1 -1
@@ -329,7 +329,7 @@ void bdrv_aio_cancel(BlockAIOCB *acb);
 void bdrv_aio_cancel_async(BlockAIOCB *acb);
 
 typedef struct BlockRequest {
-    /* Fields to be filled by multiwrite caller */
+    /* Fields to be filled by caller */

Technically, the caller...

include/block/block.h typedef struct BlockRequest { · line 348

Quoted 9 lines
include/block/block.h +1 -1
     union {
         struct {
             int64_t sector;
@@ -345,13 +345,10 @@ typedef struct BlockRequest {
     BlockCompletionFunc *cb;
     void *opaque;
 
-    /* Filled by multiwrite implementation */
+    /* Filled by block layer */

...is now always the block layer.

include/block/block.h typedef struct BlockRequest { · line 350

Quoted 2 lines
include/block/block.h +0 -0
     int error;
 } BlockRequest;

Hence my suggestion to move this to io.c and perhaps inline it into the other structs already there.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#15 lore raw

Re: [Qemu-devel] [PATCH v2 5/9] block: Remove bdrv_aio_multiwrite()

In reply to Kevin Wolf
Quoted 11 lines · Kevin Wolf

Since virtio-blk implements request merging itself these days, the only remaining users are test cases for the function. That doesn't make the function exactly useful any more.

---

+++ b/tests/qemu-iotests/136

tests/qemu-iotests/136 +0 -0
@@ -248,14 +248,6 @@ sector = "%d"
         if failed_wr_ops > 0:

tests/qemu-iotests/136 sector = "%d" · line 258

Quoted 10 lines
tests/qemu-iotests/136 +0 -8
             highest_offset = max(highest_offset, bad_offset + 512)
 
-        for i in range(wr_merged):
-            first = i * wr_size * 2
-            second = first + wr_size
-            ops.append("multiwrite %d %d ; %d %d" %
-                       (first, wr_size, second, wr_size))
-
-        highest_offset = max(highest_offset, wr_merged * wr_size * 2)
-

Why not delete the wr_merged parameter from do_test_stats()...

Quoted 11 lines
tests/qemu-iotests/136 +0 -4
         # Now perform all operations
         for op in ops:
             self.vm.hmp_qemu_io("drive0", op)
@@ -309,19 +301,15 @@ sector = "%d"
     def test_flush(self):
         self.do_test_stats(flush_ops = 8)
 
-    def test_merged(self):
-        for i in range(5):
-            self.do_test_stats(wr_merged = i * 3)
-

tests/qemu-iotests/136 sector = "%d" · line 309

Quoted 10 lines
tests/qemu-iotests/136 +1 -4
     def test_all(self):
         # rd_size, rd_ops, wr_size, wr_ops, flush_ops
         # invalid_rd_ops,  invalid_wr_ops,
         # failed_rd_ops,   failed_wr_ops
         # wr_merged
-        test_values = [[512,    1, 512,   1, 1, 4, 7, 5, 2, 1],
-                       [65536,  1, 2048, 12, 7, 7, 5, 2, 5, 5],
-                       [32768,  9, 8192,  1, 4, 3, 2, 4, 6, 4],
-                       [16384, 11, 3584, 16, 9, 8, 6, 7, 3, 4]]
+        test_values = [[512,    1, 512,   1, 1, 4, 7, 5, 2, 0],

as well as remove the # wr_merged comment and the now-useless final member of each test_values[] array entry?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#16 lore raw

PATCH v2 6/9 block: Add bdrv_has_blk()

In reply to Kevin Wolf

In many cases we just want to know whether a BDS has at least one BB attached, without needing to know the exact BB that is attached. In contrast to bs->blk, this is still a valid question when more than one BB can be attached, so just answer it by checking the parents list.

---
 block/block-backend.c          | 17 +++++++++++++++++
 include/sysemu/block-backend.h |  1 +
 2 files changed, 18 insertions(+)
block/block-backend.c +17 -0
index d1974f5..bd1bf14 100644
@@ -395,6 +395,23 @@ BlockDriverState *blk_bs(BlockBackend *blk)
 }
 
 /*
+ * Returns true if @bs has an associated BlockBackend.
+ */
+bool bdrv_has_blk(BlockDriverState *bs)
+{
+    BdrvChild *child;
+    QLIST_FOREACH(child, &bs->parents, next_parent) {
+        if (child->role == &child_root) {
+            assert(bs->blk);
+            return true;
+        }
+    }
+
+    assert(!bs->blk);
+    return false;
+}
+
+/*
  * Return @blk's DriveInfo if any, else null.
  */
 DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
include/sysemu/block-backend.h +1 -0
index 8285c97..60db46c 100644
@@ -99,6 +99,7 @@ BlockBackend *blk_by_public(BlockBackendPublic *public);
 BlockDriverState *blk_bs(BlockBackend *blk);
 void blk_remove_bs(BlockBackend *blk);
 void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);
+bool bdrv_has_blk(BlockDriverState *bs);
 
 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
 void blk_iostatus_enable(BlockBackend *blk);
Signature · 1 line
1.8.3.1
author
#17 lore raw

PATCH v2 7/9 block: Avoid bs->blk in bdrv_next()

In reply to Kevin Wolf

We need to introduce a separate BdrvNextIterator struct that can keep more state than just the current BDS in order to avoid using the bs->blk pointer.

---
 block.c                        | 34 ++++++--------------
 block/block-backend.c          | 72 +++++++++++++++++++++++++++++-------------
 block/io.c                     | 13 ++++----
 block/snapshot.c               | 30 +++++++++++-------
 blockdev.c                     |  3 +-
 include/block/block.h          |  3 +-
 include/sysemu/block-backend.h |  1 -
 migration/block.c              |  4 ++-
 monitor.c                      |  6 ++--
 qmp.c                          |  5 ++-
 10 files changed, 99 insertions(+), 72 deletions(-)
block.c +9 -25
index a8df72f..117bef7 100644
@@ -2872,25 +2872,6 @@ BlockDriverState *bdrv_next_node(BlockDriverState *bs)
     return QTAILQ_NEXT(bs, node_list);
 }
 
-/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are owned by
- * the monitor or attached to a BlockBackend */
-BlockDriverState *bdrv_next(BlockDriverState *bs)
-{
-    if (!bs || bs->blk) {
-        bs = blk_next_root_bs(bs);
-        if (bs) {
-            return bs;
-        }
-    }
-
-    /* Ignore all BDSs that are attached to a BlockBackend here; they have been
-     * handled by the above block already */
-    do {
-        bs = bdrv_next_monitor_owned(bs);
-    } while (bs && bs->blk);
-    return bs;
-}
-
 const char *bdrv_get_node_name(const BlockDriverState *bs)
 {
     return bs->node_name;
@@ -3214,10 +3195,11 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 
 void bdrv_invalidate_cache_all(Error **errp)
 {
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
     Error *local_err = NULL;
+    BdrvNextIterator *it = NULL;
 
-    while ((bs = bdrv_next(bs)) != NULL) {
+    while ((it = bdrv_next(it, &bs)) != NULL) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
         aio_context_acquire(aio_context);
@@ -3247,10 +3229,11 @@ static int bdrv_inactivate(BlockDriverState *bs)
 
 int bdrv_inactivate_all(void)
 {
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
     int ret;
 
-    while ((bs = bdrv_next(bs)) != NULL) {
+    while ((it = bdrv_next(it, &bs)) != NULL) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
         aio_context_acquire(aio_context);
@@ -3750,10 +3733,11 @@ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
  */
 bool bdrv_is_first_non_filter(BlockDriverState *candidate)
 {
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
     /* walk down the bs forest recursively */
-    while ((bs = bdrv_next(bs)) != NULL) {
+    while ((it = bdrv_next(it, &bs)) != NULL) {
         bool perm;
 
         /* try to recurse in this top level bs */
block/block-backend.c +50 -22

105 lines not on this page · raw message

block/io.c +7 -6
index 5baccda..2019441 100644
@@ -300,10 +300,11 @@ void bdrv_drain_all(void)
 {
     /* Always run first iteration so any pending completion BHs run */
     bool busy = true;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
     GSList *aio_ctxs = NULL, *ctx;
 
-    while ((bs = bdrv_next(bs))) {
+    while ((it = bdrv_next(it, &bs))) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
         aio_context_acquire(aio_context);
@@ -331,10 +332,10 @@ void bdrv_drain_all(void)
 
         for (ctx = aio_ctxs; ctx != NULL; ctx = ctx->next) {
             AioContext *aio_context = ctx->data;
-            bs = NULL;
+            it = NULL;
 
             aio_context_acquire(aio_context);
-            while ((bs = bdrv_next(bs))) {
+            while ((it = bdrv_next(it, &bs))) {
                 if (aio_context == bdrv_get_aio_context(bs)) {
                     if (bdrv_requests_pending(bs)) {
                         busy = true;
@@ -347,8 +348,8 @@ void bdrv_drain_all(void)
         }
     }
 
-    bs = NULL;
-    while ((bs = bdrv_next(bs))) {
+    it = NULL;
+    while ((it = bdrv_next(it, &bs))) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
         aio_context_acquire(aio_context);
block/snapshot.c +18 -12
index e9d721d..3917ec5 100644
@@ -373,9 +373,10 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
 bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs)
 {
     bool ok = true;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    while (ok && (bs = bdrv_next(bs))) {
+    while (ok && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
@@ -393,10 +394,11 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
                              Error **err)
 {
     int ret = 0;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
     QEMUSnapshotInfo sn1, *snapshot = &sn1;
 
-    while (ret == 0 && (bs = bdrv_next(bs))) {
+    while (ret == 0 && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
@@ -415,9 +417,10 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
 int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs)
 {
     int err = 0;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    while (err == 0 && (bs = bdrv_next(bs))) {
+    while (err == 0 && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
@@ -435,9 +438,10 @@ int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs)
 {
     QEMUSnapshotInfo sn;
     int err = 0;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    while (err == 0 && (bs = bdrv_next(bs))) {
+    while (err == 0 && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
@@ -457,9 +461,10 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
                              BlockDriverState **first_bad_bs)
 {
     int err = 0;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    while (err == 0 && (bs = bdrv_next(bs))) {
+    while (err == 0 && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
@@ -480,9 +485,10 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn,
 BlockDriverState *bdrv_all_find_vmstate_bs(void)
 {
     bool not_found = true;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    while (not_found && (bs = bdrv_next(bs))) {
+    while (not_found && (it = bdrv_next(it, &bs))) {
         AioContext *ctx = bdrv_get_aio_context(bs);
 
         aio_context_acquire(ctx);
blockdev.c +2 -1
index 7441212..445a213 100644
@@ -4080,8 +4080,9 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
 {
     BlockJobInfoList *head = NULL, **p_next = &head;
     BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
-    for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+    while ((it = bdrv_next(it, &bs))) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
         aio_context_acquire(aio_context);
include/block/block.h +2 -1
index 10ce058..3603be9 100644
@@ -17,6 +17,7 @@ typedef struct BlockJob BlockJob;
 typedef struct BdrvChild BdrvChild;
 typedef struct BdrvChildRole BdrvChildRole;
 typedef struct BlockJobTxn BlockJobTxn;
+typedef struct BdrvNextIterator BdrvNextIterator;
 
 typedef struct BlockDriverInfo {
     /* in bytes, 0 if irrelevant */
@@ -401,7 +402,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device,
                                  Error **errp);
 bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
 BlockDriverState *bdrv_next_node(BlockDriverState *bs);
-BlockDriverState *bdrv_next(BlockDriverState *bs);
+BdrvNextIterator *bdrv_next(BdrvNextIterator *it, BlockDriverState **bs);
 BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs);
 int bdrv_is_encrypted(BlockDriverState *bs);
 int bdrv_key_required(BlockDriverState *bs);
include/sysemu/block-backend.h +0 -1
index 60db46c..12e4585 100644
@@ -89,7 +89,6 @@ void blk_remove_all_bs(void);
 const char *blk_name(BlockBackend *blk);
 BlockBackend *blk_by_name(const char *name);
 BlockBackend *blk_next(BlockBackend *blk);
-BlockDriverState *blk_next_root_bs(BlockDriverState *bs);
 bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp);
 void monitor_remove_blk(BlockBackend *blk);
 
migration/block.c +3 -1
index 1743317..a7a76a0 100644
@@ -383,6 +383,7 @@ static void init_blk_migration(QEMUFile *f)
     BlockDriverState *bs;
     BlkMigDevState *bmds;
     int64_t sectors;
+    BdrvNextIterator *it = NULL;
 
     block_mig_state.submitted = 0;
     block_mig_state.read_done = 0;
@@ -392,7 +393,8 @@ static void init_blk_migration(QEMUFile *f)
     block_mig_state.bulk_completed = 0;
     block_mig_state.zero_blocks = migrate_zero_blocks();
 
-    for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+
+    while ((it = bdrv_next(it, &bs))) {
         if (bdrv_is_read_only(bs)) {
             continue;
         }
monitor.c +4 -2
index d1c1930..2c87244 100644
@@ -3427,11 +3427,13 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
 static void vm_completion(ReadLineState *rs, const char *str)
 {
     size_t len;
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
+    BdrvNextIterator *it = NULL;
 
     len = strlen(str);
     readline_set_completion_index(rs, len);
-    while ((bs = bdrv_next(bs))) {
+
+    while ((it = bdrv_next(it, &bs))) {
         SnapshotInfoList *snapshots, *snapshot;
         AioContext *ctx = bdrv_get_aio_context(bs);
         bool ok = false;
qmp.c +4 -1
index 9d0953b..3fe8f87 100644
@@ -181,6 +181,7 @@ void qmp_cont(Error **errp)
     Error *local_err = NULL;
     BlockBackend *blk;
     BlockDriverState *bs;
+    BdrvNextIterator *it;
 
     /* if there is a dump in background, we should wait until the dump
      * finished */
@@ -199,7 +200,9 @@ void qmp_cont(Error **errp)
     for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
         blk_iostatus_reset(blk);
     }
-    for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
+
+    it = NULL;
+    while ((it = bdrv_next(it, &bs))) {
         bdrv_add_key(bs, NULL, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
Signature · 1 line
1.8.3.1
Reviewed-by on v2 7/9
#18 lore raw

Re: [Qemu-devel] [PATCH v2 7/9] block: Avoid bs->blk in bdrv_next()

Quoted 5 lines · Kevin Wolf

We need to introduce a separate BdrvNextIterator struct that can keep more state than just the current BDS in order to avoid using the bs->blk pointer.

Quoted 12 lines
---
 block.c                        | 34 ++++++--------------
 block/block-backend.c          | 72 +++++++++++++++++++++++++++++-------------
 block/io.c                     | 13 ++++----
 block/snapshot.c               | 30 +++++++++++-------
 blockdev.c                     |  3 +-
 include/block/block.h          |  3 +-
 include/sysemu/block-backend.h |  1 -
 migration/block.c              |  4 ++-
 monitor.c                      |  6 ++--
 qmp.c                          |  5 ++-
 10 files changed, 99 insertions(+), 72 deletions(-)

[...]

Quoted 21 lines
block/block-backend.c +2 -6
@@ -394,21 +417,26 @@ BlockDriverState *blk_bs(BlockBackend *blk)
     return blk->root ? blk->root->bs : NULL;
 }
 
-/*
- * Returns true if @bs has an associated BlockBackend.
- */
-bool bdrv_has_blk(BlockDriverState *bs)
+static BlockBackend *bdrv_first_blk(BlockDriverState *bs)
 {
     BdrvChild *child;
     QLIST_FOREACH(child, &bs->parents, next_parent) {
         if (child->role == &child_root) {
             assert(bs->blk);
-            return true;
+            return child->opaque;
         }
     }
 
     assert(!bs->blk);
-    return false;

block/block-backend.c BlockDriverState *blk_bs(BlockBackend *blk) · line 440

Quoted 10 lines
block/block-backend.c +9 -0
+    return NULL;
+}
+
+/*
+ * Returns true if @bs has an associated BlockBackend.
+ */
+bool bdrv_has_blk(BlockDriverState *bs)
+{
+    return bdrv_first_blk(bs) != NULL;
 }

Not sure whether I'm supposed to, but I find this pretty clever. Nice.

Max

author
#19 lore raw

PATCH v2 8/9 block: Don't return throttling info in query-named-block-nodes

In reply to Kevin Wolf

query-named-block-nodes should not return information that is related to the attached BlockBackend rather than the node itself, so throttling information needs to be removed from it.

---
 block/qapi.c           | 6 +++---
 tests/qemu-iotests/096 | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)
block/qapi.c +3 -3
index b0d8d6b..5594f74 100644
@@ -67,10 +67,10 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
     info->backing_file_depth = bdrv_get_backing_file_depth(bs);
     info->detect_zeroes = bs->detect_zeroes;
 
-    if (bs->blk && blk_get_public(bs->blk)->throttle_state) {
+    if (blk && blk_get_public(blk)->throttle_state) {
         ThrottleConfig cfg;
 
-        throttle_group_get_config(bs->blk, &cfg);
+        throttle_group_get_config(blk, &cfg);
 
         info->bps     = cfg.buckets[THROTTLE_BPS_TOTAL].avg;
         info->bps_rd  = cfg.buckets[THROTTLE_BPS_READ].avg;
@@ -118,7 +118,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
         info->iops_size = cfg.op_size;
 
         info->has_group = true;
-        info->group = g_strdup(throttle_group_get_name(bs->blk));
+        info->group = g_strdup(throttle_group_get_name(blk));
     }
 
     info->write_threshold = bdrv_write_threshold_get(bs);
tests/qemu-iotests/096 +2 -1
index e34204b..aeeb375 100644
@@ -45,8 +45,9 @@ class TestLiveSnapshot(iotests.QMPTestCase):
         os.remove(self.target_img)
 
     def checkConfig(self, active_layer):
-        result = self.vm.qmp('query-named-block-nodes')
+        result = self.vm.qmp('query-block')
         for r in result['return']:
+            r = r['inserted']
             if r['node-name'] == active_layer:
                 self.assertEqual(r['group'], self.group)
                 self.assertEqual(r['iops'], self.iops)
Signature · 1 line
1.8.3.1
author
#20 lore raw

PATCH v2 9/9 block: Remove BlockDriverState.blk

In reply to Kevin Wolf

This patch removes the remaining users of bs->blk, which will allow us to have multiple BBs on top of a single BDS. In the meantime, all checks that are currently in place to prevent the user from creating such setups can be switched to bdrv_has_blk() instead of accessing BDS.blk.

Future patches can allow them and e.g. enable users to mirror to a block device that already has a BlockBackend on it.

---
 block.c                   | 10 +---------
 block/block-backend.c     |  8 --------
 block/mirror.c            |  4 ++--
 blockdev.c                | 16 ++++++++--------
 include/block/block_int.h |  3 +--
 5 files changed, 12 insertions(+), 29 deletions(-)
block.c +1 -9
index 117bef7..cf813ef 100644
@@ -2228,14 +2228,6 @@ static void change_parent_backing_link(BlockDriverState *from,
 {
     BdrvChild *c, *next;
 
-    if (from->blk) {
-        /* FIXME We bypass blk_set_bs(), so we need to make these updates
-         * manually. The root problem is not in this change function, but the
-         * existence of BlockDriverState.blk. */
-        to->blk = from->blk;
-        from->blk = NULL;
-    }
-
     QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
         assert(c->role != &child_backing);
         c->bs = to;
@@ -2877,7 +2869,7 @@ const char *bdrv_get_node_name(const BlockDriverState *bs)
     return bs->node_name;
 }
 
-static const char *bdrv_get_parent_name(const BlockDriverState *bs)
+const char *bdrv_get_parent_name(const BlockDriverState *bs)
 {
     BdrvChild *c;
     const char *name;
block/block-backend.c +0 -8
index a355590..ffcd44a 100644
@@ -152,7 +152,6 @@ BlockBackend *blk_new_with_bs(Error **errp)
     bs = bdrv_new_root();
     blk->root = bdrv_root_attach_child(bs, "root", &child_root);
     blk->root->opaque = blk;
-    bs->blk = blk;
     return blk;
 }
 
@@ -422,12 +421,10 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs)
     BdrvChild *child;
     QLIST_FOREACH(child, &bs->parents, next_parent) {
         if (child->role == &child_root) {
-            assert(bs->blk);
             return child->opaque;
         }
     }
 
-    assert(!bs->blk);
     return NULL;
 }
 
@@ -495,8 +492,6 @@ BlockBackend *blk_by_public(BlockBackendPublic *public)
  */
 void blk_remove_bs(BlockBackend *blk)
 {
-    assert(blk->root->bs->blk == blk);
-
     notifier_list_notify(&blk->remove_bs_notifiers, blk);
     if (blk->public.throttle_state) {
         throttle_timers_detach_aio_context(&blk->public.throttle_timers);
@@ -504,7 +499,6 @@ void blk_remove_bs(BlockBackend *blk)
 
     blk_update_root_state(blk);
 
-    blk->root->bs->blk = NULL;
     bdrv_root_unref_child(blk->root);
     blk->root = NULL;
 }
@@ -514,11 +508,9 @@ void blk_remove_bs(BlockBackend *blk)
  */
 void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs)
 {
-    assert(!blk->root && !bs->blk);
     bdrv_ref(bs);
     blk->root = bdrv_root_attach_child(bs, "root", &child_root);
     blk->root->opaque = blk;
-    bs->blk = blk;
 
     notifier_list_notify(&blk->insert_bs_notifiers, blk);
     if (blk->public.throttle_state) {
block/mirror.c +2 -2
index 71d7a4e..b9986d8 100644
@@ -468,7 +468,7 @@ static void mirror_exit(BlockJob *job, void *opaque)
 
         /* This was checked in mirror_start_job(), but meanwhile one of the
          * nodes could have been newly attached to a BlockBackend. */
-        if (to_replace->blk && s->target->blk) {
+        if (bdrv_has_blk(to_replace) && bdrv_has_blk(s->target)) {
             error_report("block job: Can't create node with two BlockBackends");
             data->ret = -EINVAL;
             goto out;
@@ -831,7 +831,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
     } else {
         replaced_bs = bs;
     }
-    if (replaced_bs->blk && target->blk) {
+    if (bdrv_has_blk(replaced_bs) && bdrv_has_blk(target)) {
         error_setg(errp, "Can't create node with two BlockBackends");
         return;
     }
blockdev.c +8 -8
index 445a213..e667b8c 100644
@@ -1776,9 +1776,9 @@ static void external_snapshot_prepare(BlkActionState *common,
         return;
     }
 
-    if (state->new_bs->blk != NULL) {
+    if (bdrv_has_blk(state->new_bs)) {
         error_setg(errp, "The snapshot is already in use by %s",
-                   blk_name(state->new_bs->blk));
+                   bdrv_get_parent_name(state->new_bs));
         return;
     }
 
@@ -2494,9 +2494,9 @@ void qmp_x_blockdev_insert_medium(const char *device, const char *node_name,
         return;
     }
 
-    if (bs->blk) {
+    if (bdrv_has_blk(bs)) {
         error_setg(errp, "Node '%s' is already in use by '%s'", node_name,
-                   blk_name(bs->blk));
+                   bdrv_get_parent_name(bs));
         return;
     }
 
@@ -3441,7 +3441,7 @@ static void blockdev_mirror_common(BlockDriverState *bs,
     if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_MIRROR_TARGET, errp)) {
         return;
     }
-    if (target->blk) {
+    if (bdrv_has_blk(target)) {
         error_setg(errp, "Cannot mirror to an attached block device");
         return;
     }
@@ -4030,15 +4030,15 @@ void qmp_x_blockdev_del(bool has_id, const char *id,
         bs = blk_bs(blk);
         aio_context = blk_get_aio_context(blk);
     } else {
+        blk = NULL;
         bs = bdrv_find_node(node_name);
         if (!bs) {
             error_setg(errp, "Cannot find node %s", node_name);
             return;
         }
-        blk = bs->blk;
-        if (blk) {
+        if (bdrv_has_blk(bs)) {
             error_setg(errp, "Node %s is in use by %s",
-                       node_name, blk_name(blk));
+                       node_name, bdrv_get_parent_name(bs));
             return;
         }
         aio_context = bdrv_get_aio_context(bs);
include/block/block_int.h +1 -2
index f4a0941..647e9b3 100644
@@ -407,8 +407,6 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
-    BlockBackend *blk;          /* owning backend, if any */
-
     AioContext *aio_context; /* event loop used for fd handlers, timers, etc */
     /* long-running tasks intended to always use the same AioContext as this
      * BDS may register themselves in this list to be notified of changes
@@ -708,6 +706,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
                                   const BdrvChildRole *child_role);
 void bdrv_root_unref_child(BdrvChild *child);
 
+const char *bdrv_get_parent_name(const BlockDriverState *bs);
 void blk_dev_change_media_cb(BlockBackend *blk, bool load);
 bool blk_dev_has_removable_media(BlockBackend *blk);
 bool blk_dev_has_tray(BlockBackend *blk);
Signature · 1 line
1.8.3.1
author Applied
#21 lore raw
In reply to Kevin Wolf

Am 27.04.2016 um 15:20 hat Kevin Wolf geschrieben:

Quoted 4 lines

This is the final patch series that is required before we can start allowing setups with more than one BlockBackend per BlockDriverState.

Depends on 'block: Move I/O throttling to BlockBackend'.

Applied to the block branch.

Kevin