Take advantage of the previous patch's addition of 'network-dir'
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.
---
src/storage/storage_backend_gluster.c | 14 ++++++++++----
tests/storagevolxml2xmlin/vol-gluster-dir.xml | 13 +++++++++++++
tests/storagevolxml2xmlout/vol-gluster-dir.xml | 18 ++++++++++++++++++
tests/storagevolxml2xmltest.c | 1 +
4 files changed, 42 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 120cf0f..89abb57 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_NETWORK_DIR;
+ 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..bd20a6a
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-gluster-dir.xml
@@ -0,0 +1,13 @@
+<volume>
+ <name>dir</name>
+ <key>/vol/dir</key>
+ <source>
+ </source>
+ <type>network-dir</type>
+ <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..29e6d1a
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
@@ -0,0 +1,18 @@
+<volume>
+ <name>dir</name>
+ <key>/vol/dir</key>
+ <source>
+ </source>
+ <type>network-dir</type>
+ <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 e1db465..fdcdea1 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.8.3.1