render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 35dd0575934117ccef069b751000fa8a1b7a67fd Mon Sep 17 00:00:00 2001
Message-Id: <35dd0575934117ccef069b751000fa8a1b7a67fd@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Wed, 26 Feb 2014 14:54:25 +0100
Subject: [PATCH] storage: improve directory support in gluster pool

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

Take advantage of the previous patch's addition of 'netdir' as
a distinct volume type, to expose rather than silently skip
directories embedded in a gluster pool.  Also serves as an XML
validation for the previous patch.

* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Don't skip directories.
* tests/storagevolxml2xmltest.c (mymain): Add test.
* tests/storagevolxml2xmlin/vol-gluster-dir.xml: New file.
* tests/storagevolxml2xmlout/vol-gluster-dir.xml: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 1458b2e963c65108f691f77ac10e6ff7d6805a39)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage/storage_backend_gluster.c          | 14 ++++++++++----
 tests/storagevolxml2xmlin/vol-gluster-dir.xml  | 12 ++++++++++++
 tests/storagevolxml2xmlout/vol-gluster-dir.xml | 17 +++++++++++++++++
 tests/storagevolxml2xmltest.c                  |  1 +
 4 files changed, 40 insertions(+), 4 deletions(-)
 create mode 100644 tests/storagevolxml2xmlin/vol-gluster-dir.xml
 create mode 100644 tests/storagevolxml2xmlout/vol-gluster-dir.xml

diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index d57427e..3f4e9f7 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -165,9 +165,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     /* Silently skip '.' and '..'.  */
     if (STREQ(name, ".") || STREQ(name, ".."))
         return 0;
-    /* FIXME: support directories.  For now, silently skip them.  */
-    if (S_ISDIR(st->st_mode))
-        return 0;
 
     if (VIR_ALLOC(vol) < 0)
         goto cleanup;
@@ -177,7 +174,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
                     vol->name) < 0)
         goto cleanup;
 
-    vol->type = VIR_STORAGE_VOL_NETWORK;
     tmp = state->uri->path;
     state->uri->path = vol->key;
     if (!(vol->target.path = virURIFormat(state->uri))) {
@@ -186,7 +182,17 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     }
     state->uri->path = tmp;
 
+    if (S_ISDIR(st->st_mode)) {
+        vol->type = VIR_STORAGE_VOL_NETDIR;
+        vol->target.format = VIR_STORAGE_FILE_DIR;
+        *volptr = vol;
+        vol = NULL;
+        ret = 0;
+        goto cleanup;
+    }
+
     /* FIXME - must open files to determine if they are non-raw */
+    vol->type = VIR_STORAGE_VOL_NETWORK;
     vol->target.format = VIR_STORAGE_FILE_RAW;
     vol->capacity = vol->allocation = st->st_size;
 
diff --git a/tests/storagevolxml2xmlin/vol-gluster-dir.xml b/tests/storagevolxml2xmlin/vol-gluster-dir.xml
new file mode 100644
index 0000000..208c2c2
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-gluster-dir.xml
@@ -0,0 +1,12 @@
+<volume type='netdir'>
+  <name>dir</name>
+  <key>vol/dir</key>
+  <source>
+  </source>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <target>
+    <format type='dir'/>
+    <path>gluster://example.com/vol/dir</path>
+  </target>
+</volume>
diff --git a/tests/storagevolxml2xmlout/vol-gluster-dir.xml b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
new file mode 100644
index 0000000..f188ceb
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
@@ -0,0 +1,17 @@
+<volume type='netdir'>
+  <name>dir</name>
+  <key>vol/dir</key>
+  <source>
+  </source>
+  <capacity unit='bytes'>0</capacity>
+  <allocation unit='bytes'>0</allocation>
+  <target>
+    <path>gluster://example.com/vol/dir</path>
+    <format type='dir'/>
+    <permissions>
+      <mode>0600</mode>
+      <owner>4294967295</owner>
+      <group>4294967295</group>
+    </permissions>
+  </target>
+</volume>
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index d62c29f..f502e42 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -121,6 +121,7 @@ mymain(void)
     DO_TEST("pool-logical", "vol-logical");
     DO_TEST("pool-logical", "vol-logical-backing");
     DO_TEST("pool-sheepdog", "vol-sheepdog");
+    DO_TEST("pool-gluster", "vol-gluster-dir");
 
     return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.9.0