Blob Blame History Raw
From ec8647d704e0b7a3025f05a2a0391c69b5b5921a Mon Sep 17 00:00:00 2001
Message-Id: <ec8647d704e0b7a3025f05a2a0391c69b5b5921a@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Wed, 26 Feb 2014 14:54:24 +0100
Subject: [PATCH] storage: add network-dir as new storage volume type

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

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.
* docs/formatstorage.html.in: Document it.
* docs/schemasa/storagevol.rng (vol): Allow new value.
* src/conf/storage_conf.c (virStorageVol): Use new value.
* 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@redhat.com>
(cherry picked from commit ecd881b7a77873dc7ca752522f7401f88722f471)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 docs/formatstorage.html.in       | 2 +-
 docs/schemas/storagevol.rng      | 1 +
 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 ++++-
 8 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 015de1e..d85fe1c 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -292,7 +292,7 @@
       A storage volume will generally be either a file or a device
       node; <span class="since">since 1.2.0</span>, an optional
       output-only attribute <code>type</code> lists the actual type
-      (file, block, dir, or network), which is also available
+      (file, block, dir, network, or netdir), which is also available
       from <code>virStorageVolGetInfo()</code>.  The storage volume
       XML format is available <span class="since">since 0.4.1</span>
     </p>
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index f8081d9..8f07d8f 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -20,6 +20,7 @@
             <value>block</value>
             <value>dir</value>
             <value>network</value>
+            <value>netdir</value>
           </choice>
         </attribute>
       </optional>
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 91d89ec..4e98bcc 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2937,6 +2937,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_NETDIR = 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 0723ca9..e64b331 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", "netdir")
 
 VIR_ENUM_IMPL(virStoragePool,
               VIR_STORAGE_POOL_LAST,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d303d96..4305052 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3703,7 +3703,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",
@@ -3746,10 +3746,12 @@ qemuBuildVolumeString(virConnectPtr conn,
         }
         break;
     case VIR_STORAGE_VOL_NETWORK:
+    case VIR_STORAGE_VOL_NETDIR:
+    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 ba32959..ec5a895 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1301,7 +1301,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)))
@@ -1346,6 +1346,8 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
 
         break;
     case VIR_STORAGE_VOL_NETWORK:
+    case VIR_STORAGE_VOL_NETDIR:
+    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 8bbee92..0374ea1 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1121,7 +1121,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 */
@@ -1143,7 +1143,8 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
         break;
     case VIR_STORAGE_VOL_BLOCK:
     case VIR_STORAGE_VOL_NETWORK:
-    default:
+    case VIR_STORAGE_VOL_NETDIR:
+    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 f5303ba..00104a6 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -938,7 +938,7 @@ out:
 static const char *
 vshVolumeTypeToString(int type)
 {
-    switch (type) {
+    switch ((virStorageVolType) type) {
     case VIR_STORAGE_VOL_FILE:
         return N_("file");
 
@@ -951,6 +951,9 @@ vshVolumeTypeToString(int type)
     case VIR_STORAGE_VOL_NETWORK:
         return N_("network");
 
+    case VIR_STORAGE_VOL_NETDIR:
+        return N_("netdir");
+
     case VIR_STORAGE_VOL_LAST:
         break;
     }
-- 
1.9.0