[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 1/8] block: add bdrv_add_before_write_notifier()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH v4 1/8] block: add bdrv_add_before_write_notifier() |
Date: |
Thu, 16 May 2013 10:36:12 +0200 |
The bdrv_add_before_write_notifier() function installs a callback that
is invoked before a write request is processed. This will be used to
implement copy-on-write point-in-time snapshots where we need to copy
out old data before overwriting it.
Note that BdrvTrackedRequest is moved to block_int.h since it is passed
to .notify() functions.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 18 ++++++++----------
include/block/block_int.h | 22 +++++++++++++++++++++-
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index 3f87489..591e312 100644
--- a/block.c
+++ b/block.c
@@ -308,6 +308,7 @@ BlockDriverState *bdrv_new(const char *device_name)
}
bdrv_iostatus_disable(bs);
notifier_list_init(&bs->close_notifiers);
+ notifier_list_init(&bs->before_write_notifiers);
return bs;
}
@@ -1839,16 +1840,6 @@ int bdrv_commit_all(void)
return 0;
}
-struct BdrvTrackedRequest {
- BlockDriverState *bs;
- int64_t sector_num;
- int nb_sectors;
- bool is_write;
- QLIST_ENTRY(BdrvTrackedRequest) list;
- Coroutine *co; /* owner, used for deadlock detection */
- CoQueue wait_queue; /* coroutines blocked on this request */
-};
-
/**
* Remove an active request from the tracked requests list
*
@@ -2619,6 +2610,8 @@ static int coroutine_fn
bdrv_co_do_writev(BlockDriverState *bs,
tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
+ notifier_list_notify(&bs->before_write_notifiers, &req);
+
if (flags & BDRV_REQ_ZERO_WRITE) {
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors);
} else {
@@ -4883,3 +4876,8 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs)
/* Currently BlockDriverState always uses the main loop AioContext */
return qemu_get_aio_context();
}
+
+void bdrv_add_before_write_notifier(BlockDriverState *bs, Notifier *notifier)
+{
+ notifier_list_add(&bs->before_write_notifiers, notifier);
+}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 6078dd3..a498fb0 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -58,7 +58,16 @@
#define BLOCK_OPT_LAZY_REFCOUNTS "lazy_refcounts"
#define BLOCK_OPT_ADAPTER_TYPE "adapter_type"
-typedef struct BdrvTrackedRequest BdrvTrackedRequest;
+typedef struct BdrvTrackedRequest {
+ BlockDriverState *bs;
+ int64_t sector_num;
+ int nb_sectors;
+ bool is_write;
+ QLIST_ENTRY(BdrvTrackedRequest) list;
+ Coroutine *co; /* owner, used for deadlock detection */
+ CoQueue wait_queue; /* coroutines blocked on this request */
+} BdrvTrackedRequest;
+
typedef struct BlockIOLimit {
int64_t bps[3];
@@ -247,6 +256,9 @@ struct BlockDriverState {
NotifierList close_notifiers;
+ /* Callback before write request is processed */
+ NotifierList before_write_notifiers;
+
/* number of in-flight copy-on-read requests */
unsigned int copy_on_read_in_flight;
@@ -298,6 +310,14 @@ void bdrv_set_io_limits(BlockDriverState *bs,
BlockIOLimit *io_limits);
/**
+ * bdrv_add_before_write_notifier:
+ *
+ * Register a callback that is invoked before write requests are processed but
+ * after any throttling or waiting for overlapping requests.
+ */
+void bdrv_add_before_write_notifier(BlockDriverState *bs, Notifier *notifier);
+
+/**
* bdrv_get_aio_context:
*
* Returns: the currently bound #AioContext
--
1.8.1.4
- [Qemu-devel] [PATCH v4 2/8] block: add basic backup support to block driver, (continued)
[Qemu-devel] [PATCH v4 5/8] blockdev: rename BlkTransactionStates to singular, Stefan Hajnoczi, 2013/05/16
[Qemu-devel] [PATCH v4 4/8] qemu-iotests: add 055 drive-backup test case, Stefan Hajnoczi, 2013/05/16
[Qemu-devel] [PATCH v4 1/8] block: add bdrv_add_before_write_notifier(),
Stefan Hajnoczi <=
[Qemu-devel] [PATCH v4 6/8] blockdev: add DriveBackup transaction, Stefan Hajnoczi, 2013/05/16
[Qemu-devel] [PATCH v4 8/8] qemu-iotests: test 'drive-backup' transaction in 055, Stefan Hajnoczi, 2013/05/16
Re: [Qemu-devel] [PATCH v4 0/8] block: drive-backup live backup command, Richard W.M. Jones, 2013/05/19
Re: [Qemu-devel] [PATCH v4 0/8] block: drive-backup live backup command, Kevin Wolf, 2013/05/22