diff mbox

[v2,06/22] block: Add bdrv_close_all() notifiers

Message ID 1423507124-29809-7-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Feb. 9, 2015, 6:38 p.m. UTC
This adds a list of notifiers to be invoked on bdrv_close_all().

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block.c               | 10 ++++++++++
 include/block/block.h |  2 ++
 2 files changed, 12 insertions(+)
diff mbox

Patch

diff --git a/block.c b/block.c
index 6ad80fe..143c7cc 100644
--- a/block.c
+++ b/block.c
@@ -104,6 +104,9 @@  static void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
 /* If non-zero, use only whitelisted block drivers */
 static int use_bdrv_whitelist;
 
+static NotifierList close_all_notifiers =
+    NOTIFIER_LIST_INITIALIZER(close_all_notifiers);
+
 #ifdef _WIN32
 static int is_windows_drive_prefix(const char *filename)
 {
@@ -1907,6 +1910,8 @@  void bdrv_close_all(void)
 {
     BlockDriverState *bs;
 
+    notifier_list_notify(&close_all_notifiers, NULL);
+
     QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
         AioContext *aio_context = bdrv_get_aio_context(bs);
 
@@ -1916,6 +1921,11 @@  void bdrv_close_all(void)
     }
 }
 
+void bdrv_add_close_all_notifier(Notifier *notifier)
+{
+    notifier_list_add(&close_all_notifiers, notifier);
+}
+
 /* Check if any requests are in-flight (including throttled requests) */
 static bool bdrv_requests_pending(BlockDriverState *bs)
 {
diff --git a/include/block/block.h b/include/block/block.h
index 0708a48..79efccb 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -543,4 +543,6 @@  void bdrv_io_plug(BlockDriverState *bs);
 void bdrv_io_unplug(BlockDriverState *bs);
 void bdrv_flush_io_queue(BlockDriverState *bs);
 
+void bdrv_add_close_all_notifier(Notifier *notifier);
+
 #endif