]> git.proxmox.com Git - mirror_qemu.git/commitdiff
block: Introduce "drained begin/end" API
authorFam Zheng <famz@redhat.com>
Fri, 23 Oct 2015 03:08:09 +0000 (11:08 +0800)
committerKevin Wolf <kwolf@redhat.com>
Fri, 23 Oct 2015 16:18:24 +0000 (18:18 +0200)
The semantics is that after bdrv_drained_begin(bs), bs will not get new external
requests until the matching bdrv_drained_end(bs).

Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/io.c
include/block/block.h
include/block/block_int.h

index 2fd7a1d764aa16a6c3792a0323ed0bbc33611b2d..5ac6256ad33b0dd46e82e97a8f0e6d9c7dde4d92 100644 (file)
@@ -2624,3 +2624,20 @@ void bdrv_flush_io_queue(BlockDriverState *bs)
     }
     bdrv_start_throttled_reqs(bs);
 }
+
+void bdrv_drained_begin(BlockDriverState *bs)
+{
+    if (!bs->quiesce_counter++) {
+        aio_disable_external(bdrv_get_aio_context(bs));
+    }
+    bdrv_drain(bs);
+}
+
+void bdrv_drained_end(BlockDriverState *bs)
+{
+    assert(bs->quiesce_counter > 0);
+    if (--bs->quiesce_counter > 0) {
+        return;
+    }
+    aio_enable_external(bdrv_get_aio_context(bs));
+}
index 77e91bdc79837f979101963ead8792c7070ec012..610db923d55f71c6ef64f62fdbd6d77c172acac3 100644 (file)
@@ -610,4 +610,23 @@ void bdrv_io_plug(BlockDriverState *bs);
 void bdrv_io_unplug(BlockDriverState *bs);
 void bdrv_flush_io_queue(BlockDriverState *bs);
 
+/**
+ * bdrv_drained_begin:
+ *
+ * Begin a quiesced section for exclusive access to the BDS, by disabling
+ * external request sources including NBD server and device model. Note that
+ * this doesn't block timers or coroutines from submitting more requests, which
+ * means block_job_pause is still necessary.
+ *
+ * This function can be recursive.
+ */
+void bdrv_drained_begin(BlockDriverState *bs);
+
+/**
+ * bdrv_drained_end:
+ *
+ * End a quiescent section started by bdrv_drained_begin().
+ */
+void bdrv_drained_end(BlockDriverState *bs);
+
 #endif
index 7b76eea2d9fb25dff65621ed8140c0657102338f..3ceeb5a940c4f20f539d9a5fd9bf9f11fd16c776 100644 (file)
@@ -448,6 +448,8 @@ struct BlockDriverState {
     /* threshold limit for writes, in bytes. "High water mark". */
     uint64_t write_threshold_offset;
     NotifierWithReturn write_threshold_notifier;
+
+    int quiesce_counter;
 };
 
 struct BlockBackendRootState {