From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
dietmar@proxmox.com, imain@redhat.com,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
xiawenc@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v6 02/12] block: add bdrv_add_before_write_notifier()
Date: Mon, 24 Jun 2013 17:13:10 +0200 [thread overview]
Message-ID: <1372086800-4720-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1372086800-4720-1-git-send-email-stefanha@redhat.com>
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.
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block.c | 23 ++++++++++++-----------
include/block/block_int.h | 23 ++++++++++++++++++++++-
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/block.c b/block.c
index b88ad2f..de16817 100644
--- a/block.c
+++ b/block.c
@@ -305,6 +305,7 @@ BlockDriverState *bdrv_new(const char *device_name)
}
bdrv_iostatus_disable(bs);
notifier_list_init(&bs->close_notifiers);
+ notifier_with_return_list_init(&bs->before_write_notifiers);
return bs;
}
@@ -1840,16 +1841,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
*
@@ -2620,7 +2611,11 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
- if (flags & BDRV_REQ_ZERO_WRITE) {
+ ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req);
+
+ if (ret < 0) {
+ /* Do nothing, write notifier decided to fail this request */
+ } else if (flags & BDRV_REQ_ZERO_WRITE) {
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors);
} else {
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
@@ -4581,3 +4576,9 @@ 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,
+ NotifierWithReturn *notifier)
+{
+ notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
+}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index ba52247..2d00955 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -59,7 +59,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];
@@ -248,6 +257,9 @@ struct BlockDriverState {
NotifierList close_notifiers;
+ /* Callback before write request is processed */
+ NotifierWithReturnList before_write_notifiers;
+
/* number of in-flight copy-on-read requests */
unsigned int copy_on_read_in_flight;
@@ -299,6 +311,15 @@ 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,
+ NotifierWithReturn *notifier);
+
+/**
* bdrv_get_aio_context:
*
* Returns: the currently bound #AioContext
--
1.8.1.4
next prev parent reply other threads:[~2013-06-24 15:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 15:13 [Qemu-devel] [PATCH v6 00/12] block: drive-backup live backup command Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 01/12] notify: add NotiferWithReturn so notifier list can abort Stefan Hajnoczi
2013-06-24 15:13 ` Stefan Hajnoczi [this message]
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 03/12] block: add basic backup support to block driver Stefan Hajnoczi
2013-06-25 13:00 ` Kevin Wolf
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 04/12] blockdev: drop redundant proto_drv check Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 05/12] blockdev: use bdrv_getlength() in qmp_drive_mirror() Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 06/12] block: add drive-backup QMP command Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 07/12] blockdev: rename BlkTransactionStates to singular Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 08/12] blockdev: allow BdrvActionOps->commit() to be NULL Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 09/12] blockdev: add DriveBackup transaction Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 10/12] blockdev: add Abort transaction Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 11/12] qemu-iotests: extract wait_until_completed() into iotests.py Stefan Hajnoczi
2013-06-24 15:13 ` [Qemu-devel] [PATCH v6 12/12] qemu-iotests: add 055 drive-backup test case Stefan Hajnoczi
2013-06-25 13:16 ` [Qemu-devel] [PATCH v6 00/12] block: drive-backup live backup command Kevin Wolf
2013-06-25 14:59 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372086800-4720-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=dietmar@proxmox.com \
--cc=famz@redhat.com \
--cc=imain@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xiawenc@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).