qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 05/13] nbd: register named exports


From: Paolo Bonzini
Subject: [Qemu-devel] [RFC PATCH 05/13] nbd: register named exports
Date: Mon, 27 Aug 2012 17:00:18 +0200

Add an API to register and find named exports.

Signed-off-by: Paolo Bonzini <address@hidden>
---
 nbd.c | 38 ++++++++++++++++++++++++++++++++++++++
 nbd.h |  3 +++
 2 file modificati, 41 inserzioni(+)

diff --git a/nbd.c b/nbd.c
index f6eaea3..1249548 100644
--- a/nbd.c
+++ b/nbd.c
@@ -90,13 +90,17 @@ struct NBDRequest {
 
 struct NBDExport {
     BlockDriverState *bs;
+    char *name;
     off_t dev_offset;
     off_t size;
     uint32_t nbdflags;
     QTAILQ_HEAD(, NBDClient) clients;
     QSIMPLEQ_HEAD(, NBDRequest) requests;
+    QTAILQ_ENTRY(NBDExport) next;
 };
 
+static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
+
 struct NBDClient {
     int refcount;
     void (*close)(NBDClient *client);
@@ -724,6 +728,27 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
dev_offset,
     return exp;
 }
 
+NBDExport *nbd_export_find(const char *name)
+{
+    NBDExport *exp;
+    QTAILQ_FOREACH(exp, &exports, next) {
+        if (strcmp(name, exp->name) == 0) {
+            return exp;
+        }
+    }
+
+    return NULL;
+}
+
+void nbd_export_set_name(NBDExport *exp, const char *name)
+{
+    assert(exp->name == NULL);
+    assert(!nbd_export_find(name));
+
+    exp->name = g_strdup(name);
+    QTAILQ_INSERT_TAIL(&exports, exp, next);
+}
+
 void nbd_export_close(NBDExport *exp)
 {
     while (!QTAILQ_EMPTY(&exp->clients)) {
@@ -738,10 +763,23 @@ void nbd_export_close(NBDExport *exp)
         g_free(first);
     }
 
+    if (exp->name) {
+        QTAILQ_REMOVE(&exports, exp, next);
+        g_free(exp->name);
+    }
+
     bdrv_close(exp->bs);
     g_free(exp);
 }
 
+void nbd_export_close_all(void)
+{
+    while (!QTAILQ_EMPTY(&exports)) {
+        NBDExport *export = QTAILQ_FIRST(&exports);
+        nbd_export_close(export);
+    }
+}
+
 static int nbd_can_read(void *opaque);
 static void nbd_read(void *opaque);
 static void nbd_restart_write(void *opaque);
diff --git a/nbd.h b/nbd.h
index 6305d68..88ca324 100644
--- a/nbd.h
+++ b/nbd.h
@@ -80,7 +80,10 @@ typedef struct NBDClient NBDClient;
 
 NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
                           off_t size, uint32_t nbdflags);
+NBDExport *nbd_export_find(const char *name);
+void nbd_export_set_name(NBDExport *exp, const char *name);
 void nbd_export_close(NBDExport *exp);
+void nbd_export_close_all(void);
 
 NBDClient *nbd_client_new(NBDExport *exp, int csock,
                           void (*close)(NBDClient *));
-- 
1.7.11.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]