summaryrefslogtreecommitdiff
path: root/nbd.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-09-18 13:59:03 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2012-09-19 15:26:29 +0200
commit0ddf08db22a9ef6b122d8c4cfe5b25d2c2c51962 (patch)
treedcb0d20b2d886dc2111edb98228726d741b15333 /nbd.c
parent4b9441f6b3565ba6affa95141590cd2be4ae0cd9 (diff)
downloadqemu-0ddf08db22a9ef6b122d8c4cfe5b25d2c2c51962.tar.gz
qemu-0ddf08db22a9ef6b122d8c4cfe5b25d2c2c51962.tar.bz2
qemu-0ddf08db22a9ef6b122d8c4cfe5b25d2c2c51962.zip
nbd: add notification for closing an NBDExport
In order to exit cleanly from qemu-nbd, add a callback that triggers when an NBDExport is closed. In the case of qemu-nbd it will exit the main loop. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'nbd.c')
-rw-r--r--nbd.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/nbd.c b/nbd.c
index c39692b61f..2e9de70288 100644
--- a/nbd.c
+++ b/nbd.c
@@ -90,6 +90,8 @@ struct NBDRequest {
struct NBDExport {
int refcount;
+ void (*close)(NBDExport *exp);
+
BlockDriverState *bs;
off_t dev_offset;
off_t size;
@@ -723,7 +725,8 @@ static void nbd_request_put(NBDRequest *req)
}
NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
- off_t size, uint32_t nbdflags)
+ off_t size, uint32_t nbdflags,
+ void (*close)(NBDExport *))
{
NBDExport *exp = g_malloc0(sizeof(NBDExport));
QSIMPLEQ_INIT(&exp->requests);
@@ -733,6 +736,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
exp->dev_offset = dev_offset;
exp->nbdflags = nbdflags;
exp->size = size == -1 ? bdrv_getlength(bs) : size;
+ exp->close = close;
return exp;
}
@@ -761,6 +765,10 @@ void nbd_export_put(NBDExport *exp)
}
if (--exp->refcount == 0) {
+ if (exp->close) {
+ exp->close(exp);
+ }
+
while (!QSIMPLEQ_EMPTY(&exp->requests)) {
NBDRequest *first = QSIMPLEQ_FIRST(&exp->requests);
QSIMPLEQ_REMOVE_HEAD(&exp->requests, entry);