From 1458b2e963c65108f691f77ac10e6ff7d6805a39 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 20 Nov 2013 13:17:55 -0700 Subject: [PATCH] storage: improve directory support in gluster pool 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 --- 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 d57427e6c5..3f4e9f7ff6 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 0000000000..208c2c241b --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-gluster-dir.xml @@ -0,0 +1,12 @@ + + dir + vol/dir + + + 0 + 0 + + + gluster://example.com/vol/dir + + diff --git a/tests/storagevolxml2xmlout/vol-gluster-dir.xml b/tests/storagevolxml2xmlout/vol-gluster-dir.xml new file mode 100644 index 0000000000..f188cebd85 --- /dev/null +++ b/tests/storagevolxml2xmlout/vol-gluster-dir.xml @@ -0,0 +1,17 @@ + + dir + vol/dir + + + 0 + 0 + + gluster://example.com/vol/dir + + + 0600 + 4294967295 + 4294967295 + + + diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c index e1db4653f0..fdcdea1253 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; }