]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Add JSON backing volume parser for 'ssh' protocol
authorPeter Krempa <pkrempa@redhat.com>
Fri, 15 Jul 2016 13:12:10 +0000 (15:12 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 27 Jul 2016 11:24:20 +0000 (13:24 +0200)
src/util/virstoragefile.c
tests/virstoragetest.c

index 3e22b0c848a61024ba36b2de02484182ffe78591..fa12b28e3dfabcae4f2952c1644a87313061cc69 100644 (file)
@@ -2772,6 +2772,43 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
 }
 
 
+static int
+virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
+                                    virJSONValuePtr json,
+                                    int opaque ATTRIBUTE_UNUSED)
+{
+    const char *path = virJSONValueObjectGetString(json, "path");
+    const char *host = virJSONValueObjectGetString(json, "host");
+    const char *port = virJSONValueObjectGetString(json, "port");
+
+    if (!host || !path) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing host or path of SSH JSON backing "
+                         "volume definition"));
+        return -1;
+    }
+
+    src->type = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_SSH;
+
+    if (VIR_STRDUP(src->path, path) < 0)
+        return -1;
+
+    if (VIR_ALLOC_N(src->hosts, 1) < 0)
+        return -1;
+    src->nhosts = 1;
+
+    src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+    if (VIR_STRDUP(src->hosts[0].name, host) < 0)
+        return -1;
+
+    if (VIR_STRDUP(src->hosts[0].port, port) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 struct virStorageSourceJSONDriverParser {
     const char *drvname;
     int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
@@ -2791,6 +2828,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
     {"iscsi", virStorageSourceParseBackingJSONiSCSI, 0},
     {"nbd", virStorageSourceParseBackingJSONNbd, 0},
     {"sheepdog", virStorageSourceParseBackingJSONSheepdog, 0},
+    {"ssh", virStorageSourceParseBackingJSONSSH, 0},
 };
 
 
index 4ddcac06cd0f9362d8b7019bd95b083fc0d9015a..3b19f59fa5f118eedb1f67d77afd7fb027246592 100644 (file)
@@ -1467,6 +1467,25 @@ mymain(void)
                        "<source protocol='nbd' name='blah'>\n"
                        "  <host name='example.org' port='6000'/>\n"
                        "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
+                                       "\"host\":\"example.org\","
+                                       "\"port\":\"6000\","
+                                       "\"path\":\"blah\","
+                                       "\"user\":\"user\""
+                                      "}"
+                            "}",
+                       "<source protocol='ssh' name='blah'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
+    TEST_BACKING_PARSE("json:{\"file.driver\":\"ssh\","
+                             "\"file.host\":\"example.org\","
+                             "\"file.port\":\"6000\","
+                             "\"file.path\":\"blah\","
+                             "\"file.user\":\"user\""
+                            "}",
+                       "<source protocol='ssh' name='blah'>\n"
+                       "  <host name='example.org' port='6000'/>\n"
+                       "</source>\n");
 
  cleanup:
     /* Final cleanup */