[libvirt] [PATCHv4 4/8] storage: add network-dir as new storage volume type

Eric Blake eblake at redhat.com
Sat Nov 23 03:20:26 UTC 2013


In the 'directory' and 'netfs' storage pools, a user can see
both 'file' and 'dir' storage volume types, to know when they
can descend into a subdirectory.  But in a network-based storage
pool, such as the upcoming 'gluster' pool, we use 'network'
instead of 'file', and did not have any counterpart for a
directory until this patch.  Adding a new volume type
'network-dir' is better than reusing 'dir', because it makes
it clear that the only way to access 'network' volumes within
that container is through the network mounting (leaving 'dir'
for something accessible in the local file system).

* include/libvirt/libvirt.h.in (virStorageVolType): Expand enum.
* src/qemu/qemu_command.c (qemuBuildVolumeString): Fix client.
* src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Likewise.
* tools/virsh-volume.c (vshVolumeTypeToString): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemVolDelete): Likewise.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 include/libvirt/libvirt.h.in     | 2 ++
 src/conf/storage_conf.c          | 2 +-
 src/qemu/qemu_command.c          | 6 ++++--
 src/qemu/qemu_conf.c             | 4 +++-
 src/storage/storage_backend_fs.c | 5 +++--
 tools/virsh-volume.c             | 5 ++++-
 6 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 146a59b..5e8cba6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2951,6 +2951,8 @@ typedef enum {
     VIR_STORAGE_VOL_BLOCK = 1,    /* Block based volumes */
     VIR_STORAGE_VOL_DIR = 2,      /* Directory-passthrough based volume */
     VIR_STORAGE_VOL_NETWORK = 3,  /* Network volumes like RBD (RADOS Block Device) */
+    VIR_STORAGE_VOL_NETWORK_DIR = 4, /* Network accessible directory that can
+                                      * contain other network volumes */

 #ifdef VIR_ENUM_SENTINELS
     VIR_STORAGE_VOL_LAST
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index add2ae1..493a874 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -53,7 +53,7 @@

 VIR_ENUM_IMPL(virStorageVol,
               VIR_STORAGE_VOL_LAST,
-              "file", "block", "dir", "network")
+              "file", "block", "dir", "network", "network-dir")

 VIR_ENUM_IMPL(virStoragePool,
               VIR_STORAGE_POOL_LAST,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8dc7e43..711adcb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3782,7 +3782,7 @@ qemuBuildVolumeString(virConnectPtr conn,
 {
     int ret = -1;

-    switch (disk->srcpool->voltype) {
+    switch ((virStorageVolType) disk->srcpool->voltype) {
     case VIR_STORAGE_VOL_DIR:
         if (!disk->readonly) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -3825,10 +3825,12 @@ qemuBuildVolumeString(virConnectPtr conn,
         }
         break;
     case VIR_STORAGE_VOL_NETWORK:
+    case VIR_STORAGE_VOL_NETWORK_DIR:
+    case VIR_STORAGE_VOL_LAST:
         /* Keep the compiler quiet, qemuTranslateDiskSourcePool already
          * reported the unsupported error.
          */
-        break;
+        goto cleanup;
     }

     ret = 0;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 5803850..3c1e248 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1332,7 +1332,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
         goto cleanup;
     }

-    switch (info.type) {
+    switch ((virStorageVolType) info.type) {
     case VIR_STORAGE_VOL_FILE:
     case VIR_STORAGE_VOL_DIR:
         if (!(def->src = virStorageVolGetPath(vol)))
@@ -1377,6 +1377,8 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,

         break;
     case VIR_STORAGE_VOL_NETWORK:
+    case VIR_STORAGE_VOL_NETWORK_DIR:
+    case VIR_STORAGE_VOL_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Using network volume as disk source is not supported"));
         goto cleanup;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 510a3d6..2af6faf 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1137,7 +1137,7 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
 {
     virCheckFlags(0, -1);

-    switch (vol->type) {
+    switch ((virStorageVolType) vol->type) {
     case VIR_STORAGE_VOL_FILE:
         if (unlink(vol->target.path) < 0) {
             /* Silently ignore failures where the vol has already gone away */
@@ -1159,7 +1159,8 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
         break;
     case VIR_STORAGE_VOL_BLOCK:
     case VIR_STORAGE_VOL_NETWORK:
-    default:
+    case VIR_STORAGE_VOL_NETWORK_DIR:
+    case VIR_STORAGE_VOL_LAST:
         virReportError(VIR_ERR_NO_SUPPORT,
                        _("removing block or network volumes is not supported: %s"),
                        vol->target.path);
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index cbdb3f0..66d9922 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -947,7 +947,7 @@ out:
 static const char *
 vshVolumeTypeToString(int type)
 {
-    switch (type) {
+    switch ((virStorageVolType) type) {
     case VIR_STORAGE_VOL_FILE:
         return N_("file");

@@ -960,6 +960,9 @@ vshVolumeTypeToString(int type)
     case VIR_STORAGE_VOL_NETWORK:
         return N_("network");

+    case VIR_STORAGE_VOL_NETWORK_DIR:
+        return N_("net-dir");
+
     case VIR_STORAGE_VOL_LAST:
         break;
     }
-- 
1.8.3.1




More information about the libvir-list mailing list