From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com,
berto@igalia.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v5 10/11] nbd-server: Use a separate BlockBackend
Date: Wed, 3 Aug 2016 13:21:33 +0200 [thread overview]
Message-ID: <1470223294-3870-11-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1470223294-3870-1-git-send-email-kwolf@redhat.com>
The builtin NBD server uses its own BlockBackend now instead of reusing
the monitor/guest device one.
This means that it has its own writethrough setting now. The builtin
NBD server always uses writeback caching now regardless of whether the
guest device has WCE enabled. qemu-nbd respects the cache mode given on
the command line.
We still need to keep a reference to the monitor BB because we put an
eject notifier on it, but we don't use it for any I/O.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
block.c | 2 ++
blockdev-nbd.c | 4 ++--
include/block/nbd.h | 3 ++-
nbd/server.c | 25 ++++++++++++++++++++-----
qemu-nbd.c | 4 ++--
5 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/block.c b/block.c
index 30d64e6..101f8c6 100644
--- a/block.c
+++ b/block.c
@@ -25,6 +25,7 @@
#include "trace.h"
#include "block/block_int.h"
#include "block/blockjob.h"
+#include "block/nbd.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "qapi/qmp/qerror.h"
@@ -2206,6 +2207,7 @@ static void bdrv_close(BlockDriverState *bs)
void bdrv_close_all(void)
{
block_job_cancel_sync_all();
+ nbd_export_close_all();
/* Drop references from requests still in flight, such as canceled block
* jobs whose AIO context has not been polled yet */
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 12cae0e..c437d32 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -176,8 +176,8 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
writable = false;
}
- exp = nbd_export_new(blk, 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY, NULL,
- errp);
+ exp = nbd_export_new(blk_bs(blk), 0, -1, writable ? 0 : NBD_FLAG_READ_ONLY,
+ NULL, false, blk, errp);
if (!exp) {
return;
}
diff --git a/include/block/nbd.h b/include/block/nbd.h
index cb91820..ebdba0d 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -103,8 +103,9 @@ int nbd_disconnect(int fd);
typedef struct NBDExport NBDExport;
typedef struct NBDClient NBDClient;
-NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
+NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
uint32_t nbdflags, void (*close)(NBDExport *),
+ bool writethrough, BlockBackend *on_eject_blk,
Error **errp);
void nbd_export_close(NBDExport *exp);
void nbd_export_get(NBDExport *exp);
diff --git a/nbd/server.c b/nbd/server.c
index 29e2099..207625e 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -69,6 +69,7 @@ struct NBDExport {
AioContext *ctx;
+ BlockBackend *eject_notifier_blk;
Notifier eject_notifier;
};
@@ -809,11 +810,18 @@ static void nbd_eject_notifier(Notifier *n, void *data)
nbd_export_close(exp);
}
-NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
+NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
uint32_t nbdflags, void (*close)(NBDExport *),
+ bool writethrough, BlockBackend *on_eject_blk,
Error **errp)
{
+ BlockBackend *blk;
NBDExport *exp = g_malloc0(sizeof(NBDExport));
+
+ blk = blk_new();
+ blk_insert_bs(blk, bs);
+ blk_set_enable_write_cache(blk, !writethrough);
+
exp->refcount = 1;
QTAILQ_INIT(&exp->clients);
exp->blk = blk;
@@ -829,11 +837,14 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
exp->close = close;
exp->ctx = blk_get_aio_context(blk);
- blk_ref(blk);
blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp);
- exp->eject_notifier.notify = nbd_eject_notifier;
- blk_add_remove_bs_notifier(blk, &exp->eject_notifier);
+ if (on_eject_blk) {
+ blk_ref(on_eject_blk);
+ exp->eject_notifier_blk = on_eject_blk;
+ exp->eject_notifier.notify = nbd_eject_notifier;
+ blk_add_remove_bs_notifier(on_eject_blk, &exp->eject_notifier);
+ }
/*
* NBD exports are used for non-shared storage migration. Make sure
@@ -846,6 +857,7 @@ NBDExport *nbd_export_new(BlockBackend *blk, off_t dev_offset, off_t size,
return exp;
fail:
+ blk_unref(blk);
g_free(exp);
return NULL;
}
@@ -916,7 +928,10 @@ void nbd_export_put(NBDExport *exp)
}
if (exp->blk) {
- notifier_remove(&exp->eject_notifier);
+ if (exp->eject_notifier_blk) {
+ notifier_remove(&exp->eject_notifier);
+ blk_unref(exp->eject_notifier_blk);
+ }
blk_remove_aio_context_notifier(exp->blk, blk_aio_attached,
blk_aio_detach, exp);
blk_unref(exp->blk);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 321f02b..9e6aaa9 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -910,8 +910,8 @@ int main(int argc, char **argv)
}
}
- exp = nbd_export_new(blk, dev_offset, fd_size, nbdflags, nbd_export_closed,
- &local_err);
+ exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags, nbd_export_closed,
+ writethrough, NULL, &local_err);
if (!exp) {
error_report_err(local_err);
exit(EXIT_FAILURE);
--
1.8.3.1
next prev parent reply other threads:[~2016-08-03 11:22 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-03 11:21 [Qemu-devel] [PATCH v5 00/11] block: Accept node-name in all node level QMP commands Kevin Wolf
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 01/11] block: Accept node-name for block-stream Kevin Wolf
2016-08-03 12:25 ` Alberto Garcia
2016-08-03 12:53 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 02/11] block: Accept node-name for block-commit Kevin Wolf
2016-08-03 12:32 ` Alberto Garcia
2016-08-03 12:54 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 03/11] block: Accept node-name for blockdev-backup Kevin Wolf
2016-08-03 12:58 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 04/11] block: Accept node-name for blockdev-mirror Kevin Wolf
2016-08-03 14:59 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 05/11] block: Accept node-name for blockdev-snapshot-delete-internal-sync Kevin Wolf
2016-08-03 15:06 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 06/11] block: Accept node-name for blockdev-snapshot-internal-sync Kevin Wolf
2016-08-03 15:07 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 07/11] block: Accept node-name for change-backing-file Kevin Wolf
2016-08-03 15:09 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 08/11] block: Accept node-name for drive-backup Kevin Wolf
2016-08-03 15:14 ` Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 09/11] block: Accept node-name for drive-mirror Kevin Wolf
2016-08-03 15:32 ` Max Reitz
2016-08-03 15:34 ` Max Reitz
2016-08-03 11:21 ` Kevin Wolf [this message]
2016-08-03 16:00 ` [Qemu-devel] [PATCH v5 10/11] nbd-server: Use a separate BlockBackend Max Reitz
2016-08-03 11:21 ` [Qemu-devel] [PATCH v5 11/11] nbd-server: Allow node name for nbd-server-add Kevin Wolf
2016-08-03 16:12 ` Max Reitz
2016-08-03 16:36 ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-08-08 13:14 ` [Qemu-devel] [PATCH v5 00/11] block: Accept node-name in all node level QMP commands Kevin Wolf
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=1470223294-3870-11-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=berto@igalia.com \
--cc=eblake@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).