[libvirt] [PATCH] storage sheepdog: allow to specify redundancy level

Vasiliy Tolstov v.tolstov at selfip.ru
Tue Nov 17 10:27:54 UTC 2015


Signed-off-by: Vasiliy Tolstov <v.tolstov at selfip.ru>
---
 docs/schemas/storagevol.rng                |  3 ++
 src/conf/storage_conf.c                    |  2 +
 src/storage/storage_backend_sheepdog.c     | 38 +++++++++--------
 src/util/virstoragefile.c                  |  4 +-
 src/util/virstoragefile.h                  |  2 +
 tests/storagebackendsheepdogtest.c         | 68 +++++++++++++++---------------
 tests/storagevolxml2xmlin/vol-sheepdog.xml |  1 +
 7 files changed, 66 insertions(+), 52 deletions(-)

diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..068993f 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -55,6 +55,9 @@
         <element name='allocation'>
           <ref name='scaledInteger'/>
         </element>
+        <element name='redundancy'>
+          <ref name='string'/>
+        </element>
       </optional>
     </interleave>
   </define>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9b8abea..d37c93a 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1345,6 +1345,8 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
         ret->target.allocation = ret->target.capacity;
     }
 
+    ret->target.redundancy = virXPathString("string(./redundancy)", ctxt);
+
     ret->target.path = virXPathString("string(./target/path)", ctxt);
     if (options->formatFromString) {
         char *format = virXPathString("string(./target/format/@type)", ctxt);
diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c
index 1200813..565cfd0 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -275,6 +275,10 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "create", vol->name, NULL);
     virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
+
+    if(NULL != vol->target.redundancy)
+        virCommandAddArgFormat(cmd, "-c %s", vol->target.redundancy);
+
     virStorageBackendSheepdogAddHostArg(cmd, pool);
     if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
@@ -291,18 +295,19 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
                                       char *output)
 {
     /* fields:
-     * current/clone/snapshot, name, id, size, used, shared, creation time, vdi id, [tag]
+     * current/clone/snapshot, name, id, size, used, shared, creation time, vdi id, redundancy, [tag], size shift
      *
      * example output:
-     * s test 1 10 0 0 1336556634 7c2b25
-     * s test 2 10 0 0 1336557203 7c2b26
-     * = test 3 10 0 0 1336557216 7c2b27
+     * s test 1 10 0 0 1336556634 7c2b25 1 tt 22
+     * s test 2 10 0 0 1336557203 7c2b26 2 zz 22
+     * = test 3 10 0 0 1336557216 7c2b27 3 xx 22
      */
 
-    int id;
+    char **args;
     const char *p, *next;
 
     vol->target.allocation = vol->target.capacity = 0;
+    vol->target.redundancy = NULL;
 
     p = output;
     do {
@@ -327,24 +332,21 @@ virStorageBackendSheepdogParseVdiList(virStorageVolDefPtr vol,
                 ++p;
             ++p;
         }
+    }
+    args = virStringSplit(p, " ", 9);
 
-        if (virStrToLong_i(p, &end, 10, &id) < 0)
-            return -1;
-
-        p = end + 1;
-
-        if (virStrToLong_ull(p, &end, 10, &vol->target.capacity) < 0)
-            return -1;
+    if (virStrToLong_ull(args[1], strlen(args[1]), 10, &vol->target.capacity) < 0)
+        return -1;
 
-        p = end + 1;
+    if (virStrToLong_ull(args[2], strlen(args[2]), 10, &vol->target.allocation) < 0)
+        return -1;
 
-        if (virStrToLong_ull(p, &end, 10, &vol->target.allocation) < 0)
-            return -1;
+    if (VIR_STRNDUP(vol->target.redundancy, args[5], strlen(args[2])) < 0)
+        return -1;
 
-        return 0;
-    } while ((p = next));
+    virStringFreeList(args);
 
-    return -1;
+    return 0;
 }
 
 static int
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 2aa1d90..9cdc90d 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1846,7 +1846,8 @@ virStorageSourceCopy(const virStorageSource *src,
         VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
         VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
         VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
-        VIR_STRDUP(ret->compat, src->compat) < 0)
+        VIR_STRDUP(ret->compat, src->compat) < 0 ||
+        VIR_STRDUP(ret->redundancy, src->redundancy) < 0)
         goto error;
 
     if (src->nhosts) {
@@ -2040,6 +2041,7 @@ virStorageSourceClear(virStorageSourcePtr def)
     VIR_FREE(def->volume);
     VIR_FREE(def->snapshot);
     VIR_FREE(def->configFile);
+    VIR_FREE(def->redundancy);
     virStorageSourcePoolDefFree(def->srcpool);
     VIR_FREE(def->driverName);
     virBitmapFree(def->features);
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index b98fe25..c37cfc2 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -282,6 +282,8 @@ struct _virStorageSource {
     /* Name of the child backing store recorded in metadata of the
      * current file.  */
     char *backingStoreRaw;
+    /* redundancy level, may be used by sheepdog or ceph */
+    char *redundancy;
 };
 
 
diff --git a/tests/storagebackendsheepdogtest.c b/tests/storagebackendsheepdogtest.c
index 2b0f4db..c037ebe 100644
--- a/tests/storagebackendsheepdogtest.c
+++ b/tests/storagebackendsheepdogtest.c
@@ -42,6 +42,7 @@ typedef struct {
     int expected_return;
     uint64_t expected_capacity;
     uint64_t expected_allocation;
+    const char *expected_redundancy;
 } collie_test;
 
 struct testNodeInfoParserData {
@@ -119,7 +120,8 @@ test_vdi_list_parser(const void *opaque)
     }
 
     if (vol->target.capacity == test.expected_capacity &&
-        vol->target.allocation == test.expected_allocation)
+        vol->target.allocation == test.expected_allocation &&
+		!strcmp(vol->target.redundancy, test.expected_redundancy))
         ret = 0;
 
  cleanup:
@@ -138,41 +140,41 @@ mymain(void)
     char *volxml = NULL;
 
     collie_test node_info_tests[] = {
-        {"", -1, 0, 0},
-        {"Total 15245667872 117571104 0% 20972341\n", 0, 15245667872, 117571104},
-        {"To", -1, 0, 0},
-        {"asdf\nasdf", -1, 0, 0},
-        {"Total ", -1, 0, 0},
-        {"Total 1", -1, 0, 0},
-        {"Total 1\n", -1, 0, 0},
-        {"Total 1 ", -1, 0, 0},
-        {"Total 1 2", -1, 0, 0},
-        {"Total 1 2 ", -1, 0, 0},
-        {"Total 1 2\n", 0, 1, 2},
-        {"Total 1 2 \n", 0, 1, 2},
-        {"Total a 2 \n", -1, 0, 0},
-        {"Total 1 b \n", -1, 0, 0},
-        {"Total a b \n", -1, 0, 0},
-        {"stuff\nTotal 1 2 \n", 0, 1, 2},
-        {"0 1 2 3\nTotal 1 2 \n", 0, 1, 2},
-        {NULL, 0, 0, 0}
+        {"", -1, 0, 0,"0"},
+        {"Total 15245667872 117571104 1 0% 20972341\n", 0, 15245667872, 117571104,"1"},
+        {"To", -1, 0, 0," "},
+        {"asdf\nasdf", -1, 0, 0," "},
+        {"Total ", -1, 0, 0, " "},
+        {"Total 1", -1, 0, 0, " "},
+        {"Total 1\n", -1, 0, 0," "},
+        {"Total 1 ", -1, 0, 0, " "},
+        {"Total 1 2", -1, 0, 0, " "},
+        {"Total 1 2 ", -1, 0, 0," "},
+        {"Total 1 2 1:1\n", 0, 1, 2,"1:1"},
+        {"Total 1 2 3:4\n", 0, 1, 2,"3:4"},
+        {"Total a 2 \n", -1, 0, 0," "},
+        {"Total 1 b \n", -1, 0, 0," "},
+        {"Total a b \n", -1, 0, 0,"sss"},
+        {"stuff\nTotal 1 2 1:2\n", 0, 1, 2,"1:2"},
+        {"0 1 2 3\nTotal 1 2 3\n", 0, 1, 2,"3"},
+        {NULL, 0, 0, 0, NULL}
     };
 
     collie_test vdi_list_tests[] = {
-        {"", -1, 0, 0},
-        {"= test 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
-        {"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
-        {"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
-        {"s test 1 10 20 0 1336556634 7c2b25\n= test 3 50 60 0 1336557216 7c2b27\n", 0, 50, 60},
-        {"=", -1, 0, 0},
-        {"= test", -1, 0, 0},
-        {"= test ", -1, 0, 0},
-        {"= test 1", -1, 0, 0},
-        {"= test 1 ", -1, 0, 0},
-        {"= test 1 2", -1, 0, 0},
-        {"= test 1 2 ", -1, 0, 0},
-        {"= test 1 2 3", -1, 0, 0},
-        {NULL, 0, 0, 0}
+        {"", -1, 0, 0,NULL},
+        {"= test 3 10 20 1 0 1336557216 7c2b27 1\n", 0, 10, 20, "1"},
+        {"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27 3:4\n", 0, 10, 20, "3:4"},
+        {"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27 1\n", 0, 10, 20, "1"},
+        {"s test 1 10 20 0 1336556634 7c2b25 2\n= test 3 50 60 0 1336557216 7c2b27 2:3\n", 0, 50, 60, "2:3"},
+        {"=", -1, 0, 0," "},
+        {"= test", -1, 0, 0," "},
+        {"= test ", -1, 0, 0," "},
+        {"= test 1", -1, 0, 0," "},
+        {"= test 1 ", -1, 0, 0," "},
+        {"= test 1 2", -1, 0, 0," "},
+        {"= test 1 2 ", -1, 0, 0," "},
+        {"= test 1 2 3", -1, 0, 0," "},
+        {NULL, 0, 0, 0,NULL}
     };
 
     collie_test *test = node_info_tests;
diff --git a/tests/storagevolxml2xmlin/vol-sheepdog.xml b/tests/storagevolxml2xmlin/vol-sheepdog.xml
index d6e920b..f88e6db 100644
--- a/tests/storagevolxml2xmlin/vol-sheepdog.xml
+++ b/tests/storagevolxml2xmlin/vol-sheepdog.xml
@@ -4,6 +4,7 @@
   </source>
   <capacity unit='bytes'>1024</capacity>
   <allocation unit='bytes'>0</allocation>
+  <redundancy unit='string'>3</redundancy>
   <target>
     <path>sheepdog:test2</path>
   </target>
-- 
2.5.0




More information about the libvir-list mailing list