Skip to contentSkip to conversation

Block patches

GIT PULL Applied Stefan Hajnoczi 2 participants 8 messages Jul 7, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

The following changes since commit f6e3035f75e5c6a73485335765ae070304c7a110:

Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream-smm' into staging (2015-07-06 23:37:53 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 970311646a701eecb103eb28093e8924d2fa6861:

blockjob: add block_job_release function (2015-07-07 14:27:14 +0100)

----------------------------------------------------------------
Pull request

v2:
* Drop block/nfs patch since it exposes an unfinished QAPI interface [kwolf]

----------------------------------------------------------------

Alberto Garcia (1):
qcow2: remove unnecessary check

Fam Zheng (2):
block: Initialize local_err in bdrv_append_temp_snapshot
block: Use bdrv_drain to replace uncessary bdrv_drain_all

Richard W.M. Jones (1):
block/raw-posix: Don't think /dev/fd/<NN> is a floppy drive.

Stefan Hajnoczi (1):
block: update bdrv_drain_all()/bdrv_drain() comments

Ting Wang (1):
blockjob: add block_job_release function

 block.c                  |  8 ++++----
 block/io.c               | 20 ++++++++++----------
 block/mirror.c           |  2 ++
 block/qcow2-cache.c      |  3 ---
 block/raw-posix.c        |  3 ++-
 block/snapshot.c         |  2 +-
 blockjob.c               | 20 ++++++++++++--------
 include/block/blockjob.h |  8 ++++++++
 migration/block.c        |  2 +-
 9 files changed, 40 insertions(+), 28 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

[Qemu-devel] [PULL for-2.4 v2 2/6] block: update bdrv_drain_all()/bdrv_drain() comments

The doc comments for bdrv_drain_all() and bdrv_drain() are outdated:

* The bdrv_drain() comment is a poor man's bdrv_lock()/bdrv_unlock() which Fam Zheng is currently developing. Unfortunately this warning was never really enough because devices keep submitting I/O and op blockers don't prevent that.

* The bdrv_drain_all() comment is still partially correct but reflects the nature of the implementation rather than API documentation.

Do make it clear that bdrv_drain() is only appropriate within an AioContext. For anything spanning AioContexts you need bdrv_drain_all().

Message-id: [email protected]

---
 block/io.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
block/io.c +10 -10
index 305e0d9..d4bc83b 100644
@@ -236,12 +236,12 @@ static bool bdrv_requests_pending(BlockDriverState *bs)
 /*
  * Wait for pending requests to complete on a single BlockDriverState subtree
  *
- * See the warning in bdrv_drain_all().  This function can only be called if
- * you are sure nothing can generate I/O because you have op blockers
- * installed.
- *
  * Note that unlike bdrv_drain_all(), the caller must hold the BlockDriverState
  * AioContext.
+ *
+ * Only this BlockDriverState's AioContext is run, so in-flight requests must
+ * not depend on events in other AioContexts.  In that case, use
+ * bdrv_drain_all() instead.
  */
 void bdrv_drain(BlockDriverState *bs)
 {
@@ -260,12 +260,6 @@ void bdrv_drain(BlockDriverState *bs)
  *
  * This function does not flush data to disk, use bdrv_flush_all() for that
  * after calling this function.
- *
- * Note that completion of an asynchronous I/O operation can trigger any
- * number of other I/O operations on other devices---for example a coroutine
- * can be arbitrarily complex and a constant flow of I/O can come until the
- * coroutine is complete.  Because of this, it is not possible to have a
- * function to drain a single device's I/O queue.
  */
 void bdrv_drain_all(void)
 {
@@ -288,6 +282,12 @@ void bdrv_drain_all(void)
         }
     }
 
+    /* Note that completion of an asynchronous I/O operation can trigger any
+     * number of other I/O operations on other devices---for example a
+     * coroutine can submit an I/O request to another device in response to
+     * request completion.  Therefore we must keep looping until there was no
+     * more activity rather than simply draining each device independently.
+     */
     while (busy) {
         busy = false;
 
Signature · 1 line
2.4.3
#2 lore raw

[Qemu-devel] [PULL for-2.4 v2 3/6] block: Initialize local_err in bdrv_append_temp_snapshot

In reply to Stefan Hajnoczi

From: Fam Zheng <[email protected]>

Message-id: [email protected]

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index 7e130cc..42eb8e3 100644
@@ -1271,7 +1271,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
     QemuOpts *opts = NULL;
     QDict *snapshot_options;
     BlockDriverState *bs_snapshot;
-    Error *local_err;
+    Error *local_err = NULL;
     int ret;
 
     /* if snapshot, we create a temporary backing file and open it
Signature · 1 line
2.4.3
#3 lore raw

[Qemu-devel] [PULL for-2.4 v2 1/6] qcow2: remove unnecessary check

In reply to Stefan Hajnoczi

From: Alberto Garcia <[email protected]>

The value of 'i' is guaranteed to be >= 0

Message-id: [email protected]

---
 block/qcow2-cache.c | 3 ---
 1 file changed, 3 deletions(-)
block/qcow2-cache.c +0 -3
index ed92a09..53b8afc 100644
@@ -281,9 +281,6 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
     i = min_lru_index;
     trace_qcow2_cache_get_replace_entry(qemu_coroutine_self(),
                                         c == s->l2_table_cache, i);
-    if (i < 0) {
-        return i;
-    }
 
     ret = qcow2_cache_entry_flush(bs, c, i);
     if (ret < 0) {
Signature · 1 line
2.4.3
#4 lore raw

[Qemu-devel] [PULL for-2.4 v2 4/6] block: Use bdrv_drain to replace uncessary bdrv_drain_all

In reply to Stefan Hajnoczi

From: Fam Zheng <[email protected]>

There callers work on a single BlockDriverState subtree, where using bdrv_drain() is more accurate.

---
 block.c           | 6 +++---
 block/snapshot.c  | 2 +-
 migration/block.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
block.c +3 -3
index 42eb8e3..5e80336 100644
@@ -1841,9 +1841,9 @@ void bdrv_close(BlockDriverState *bs)
     if (bs->job) {
         block_job_cancel_sync(bs->job);
     }
-    bdrv_drain_all(); /* complete I/O */
+    bdrv_drain(bs); /* complete I/O */
     bdrv_flush(bs);
-    bdrv_drain_all(); /* in case flush left pending I/O */
+    bdrv_drain(bs); /* in case flush left pending I/O */
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->drv) {
@@ -3906,7 +3906,7 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
 
 void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
 {
-    bdrv_drain_all(); /* ensure there are no in-flight requests */
+    bdrv_drain(bs); /* ensure there are no in-flight requests */
 
     bdrv_detach_aio_context(bs);
 
block/snapshot.c +1 -1
index 19395ae..49e143e 100644
@@ -239,7 +239,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
     }
 
     /* drain all pending i/o before deleting snapshot */
-    bdrv_drain_all();
+    bdrv_drain(bs);
 
     if (drv->bdrv_snapshot_delete) {
         return drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp);
migration/block.c +1 -1
index ddb59cc..ed865ed 100644
@@ -457,7 +457,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
         blk_mig_lock();
         if (bmds_aio_inflight(bmds, sector)) {
             blk_mig_unlock();
-            bdrv_drain_all();
+            bdrv_drain(bmds->bs);
         } else {
             blk_mig_unlock();
         }
Signature · 1 line
2.4.3
#5 lore raw

[Qemu-devel] [PULL for-2.4 v2 5/6] block/raw-posix: Don't think /dev/fd/<NN> is a floppy drive.

In reply to Stefan Hajnoczi

From: "Richard W.M. Jones" <[email protected]>

In libguestfs we use /dev/fd/<NN> to pass pre-opened file descriptors to qemu-img. Lately I've discovered that although this works, qemu believes that these are floppy disk images. That in itself isn't much of a problem, but now qemu prints a warning about host floppy pass-thru being deprecated.

Extend the existing test so that it ignores /dev/fd/ as well as /dev/fdset/

A simple test of this, if you are using the bash shell, is:

qemu-img info <( cat /dev/null )

without this patch:

  $ qemu-img info <( cat /dev/null )
  qemu-img: Host floppy pass-through is deprecated
  Support for it will be removed in a future release.
  qemu-img: Could not open '/dev/fd/63': Could not refresh total sector count: Illegal seek

with this patch:

  $ qemu-img info <( cat /dev/null )
  qemu-img: Could not open '/dev/fd/63': Could not refresh total sector count: Illegal seek

Message-id: [email protected]

---
 block/raw-posix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/raw-posix.c +2 -1
index cbe6574..855febe 100644
@@ -2430,7 +2430,8 @@ static int floppy_probe_device(const char *filename)
     struct stat st;
 
     if (strstart(filename, "/dev/fd", NULL) &&
-        !strstart(filename, "/dev/fdset/", NULL)) {
+        !strstart(filename, "/dev/fdset/", NULL) &&
+        !strstart(filename, "/dev/fd/", NULL)) {
         prio = 50;
     }
 
Signature · 1 line
2.4.3
#6 lore raw

[Qemu-devel] [PULL for-2.4 v2 6/6] blockjob: add block_job_release function

In reply to Stefan Hajnoczi

From: Ting Wang <[email protected]>

There is job resource leak in function mirror_start_job, although bdrv_create_dirty_bitmap is unlikely failed. Add block_job_release for each release when needed.

Message-id: [email protected]

---
 block/mirror.c           |  2 ++
 blockjob.c               | 20 ++++++++++++--------
 include/block/blockjob.h |  8 ++++++++
 3 files changed, 22 insertions(+), 8 deletions(-)
block/mirror.c +2 -0
index 8888cea..d409337 100644
@@ -708,6 +708,8 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
 
     s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
     if (!s->dirty_bitmap) {
+        g_free(s->replaces);
+        block_job_release(bs);
         return;
     }
     bdrv_set_enable_write_cache(s->target, true);
blockjob.c +12 -8
index ec46fad..62bb906 100644
@@ -66,10 +66,7 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
 
         block_job_set_speed(job, speed, &local_err);
         if (local_err) {
-            bs->job = NULL;
-            bdrv_op_unblock_all(bs, job->blocker);
-            error_free(job->blocker);
-            g_free(job);
+            block_job_release(bs);
             error_propagate(errp, local_err);
             return NULL;
         }
@@ -77,18 +74,25 @@ void *block_job_create(const BlockJobDriver *driver, BlockDriverState *bs,
     return job;
 }
 
-void block_job_completed(BlockJob *job, int ret)
+void block_job_release(BlockDriverState *bs)
 {
-    BlockDriverState *bs = job->bs;
+    BlockJob *job = bs->job;
 
-    assert(bs->job == job);
-    job->cb(job->opaque, ret);
     bs->job = NULL;
     bdrv_op_unblock_all(bs, job->blocker);
     error_free(job->blocker);
     g_free(job);
 }
 
+void block_job_completed(BlockJob *job, int ret)
+{
+    BlockDriverState *bs = job->bs;
+
+    assert(bs->job == job);
+    job->cb(job->opaque, ret);
+    block_job_release(bs);
+}
+
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 {
     Error *local_err = NULL;
include/block/blockjob.h +8 -0
index 57d8ef1..dd9d5e6 100644
@@ -166,6 +166,14 @@ void block_job_sleep_ns(BlockJob *job, QEMUClockType type, int64_t ns);
 void block_job_yield(BlockJob *job);
 
 /**
+ * block_job_release:
+ * @bs: The block device.
+ *
+ * Release job resources when an error occurred or job completed.
+ */
+void block_job_release(BlockDriverState *bs);
+
+/**
  * block_job_completed:
  * @job: The job being completed.
  * @ret: The status code.
Signature · 1 line
2.4.3
#7 lore raw
In reply to Stefan Hajnoczi
Quoted 12 lines · Stefan Hajnoczi

The following changes since commit f6e3035f75e5c6a73485335765ae070304c7a110:

Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream-smm' into staging (2015-07-06 23:37:53 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 970311646a701eecb103eb28093e8924d2fa6861:

blockjob: add block_job_release function (2015-07-07 14:27:14 +0100)

Quoted 7 lines

----------------------------------------------------------------
Pull request

v2:
* Drop block/nfs patch since it exposes an unfinished QAPI interface [kwolf]

----------------------------------------------------------------

Applied, thanks.

-- PMM