render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From b3704c6f2dba4017787ded2b7f90bd08d56cead7 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <b3704c6f2dba4017787ded2b7f90bd08d56cead7@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Tue, 2 Aug 2016 13:41:56 +0200
6ae9ed
Subject: [PATCH] util: storage: Add JSON backing volume parser for 'ssh'
6ae9ed
 protocol
6ae9ed
6ae9ed
(cherry picked from commit bc225b1b5fe3e02eac76f12792aac16d00a7de1d)
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1134878 [JSON backing]
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
6ae9ed
---
6ae9ed
 src/util/virstoragefile.c | 38 ++++++++++++++++++++++++++++++++++++++
6ae9ed
 tests/virstoragetest.c    | 19 +++++++++++++++++++
6ae9ed
 2 files changed, 57 insertions(+)
6ae9ed
6ae9ed
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
6ae9ed
index c0172af..1612e66 100644
6ae9ed
--- a/src/util/virstoragefile.c
6ae9ed
+++ b/src/util/virstoragefile.c
6ae9ed
@@ -2781,6 +2781,43 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
+static int
6ae9ed
+virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
6ae9ed
+                                    virJSONValuePtr json,
6ae9ed
+                                    int opaque ATTRIBUTE_UNUSED)
6ae9ed
+{
6ae9ed
+    const char *path = virJSONValueObjectGetString(json, "path");
6ae9ed
+    const char *host = virJSONValueObjectGetString(json, "host");
6ae9ed
+    const char *port = virJSONValueObjectGetString(json, "port");
6ae9ed
+
6ae9ed
+    if (!host || !path) {
6ae9ed
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
6ae9ed
+                       _("missing host or path of SSH JSON backing "
6ae9ed
+                         "volume definition"));
6ae9ed
+        return -1;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    src->type = VIR_STORAGE_TYPE_NETWORK;
6ae9ed
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_SSH;
6ae9ed
+
6ae9ed
+    if (VIR_STRDUP(src->path, path) < 0)
6ae9ed
+        return -1;
6ae9ed
+
6ae9ed
+    if (VIR_ALLOC_N(src->hosts, 1) < 0)
6ae9ed
+        return -1;
6ae9ed
+    src->nhosts = 1;
6ae9ed
+
6ae9ed
+    src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
6ae9ed
+    if (VIR_STRDUP(src->hosts[0].name, host) < 0)
6ae9ed
+        return -1;
6ae9ed
+
6ae9ed
+    if (VIR_STRDUP(src->hosts[0].port, port) < 0)
6ae9ed
+        return -1;
6ae9ed
+
6ae9ed
+    return 0;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
 struct virStorageSourceJSONDriverParser {
6ae9ed
     const char *drvname;
6ae9ed
     int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
6ae9ed
@@ -2800,6 +2837,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
6ae9ed
     {"iscsi", virStorageSourceParseBackingJSONiSCSI, 0},
6ae9ed
     {"nbd", virStorageSourceParseBackingJSONNbd, 0},
6ae9ed
     {"sheepdog", virStorageSourceParseBackingJSONSheepdog, 0},
6ae9ed
+    {"ssh", virStorageSourceParseBackingJSONSSH, 0},
6ae9ed
 };
6ae9ed
 
6ae9ed
 
6ae9ed
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
6ae9ed
index 4ddcac0..3b19f59 100644
6ae9ed
--- a/tests/virstoragetest.c
6ae9ed
+++ b/tests/virstoragetest.c
6ae9ed
@@ -1467,6 +1467,25 @@ mymain(void)
6ae9ed
                        "<source protocol='nbd' name='blah'>\n"
6ae9ed
                        "  <host name='example.org' port='6000'/>\n"
6ae9ed
                        "</source>\n");
6ae9ed
+    TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"ssh\","
6ae9ed
+                                       "\"host\":\"example.org\","
6ae9ed
+                                       "\"port\":\"6000\","
6ae9ed
+                                       "\"path\":\"blah\","
6ae9ed
+                                       "\"user\":\"user\""
6ae9ed
+                                      "}"
6ae9ed
+                            "}",
6ae9ed
+                       "<source protocol='ssh' name='blah'>\n"
6ae9ed
+                       "  <host name='example.org' port='6000'/>\n"
6ae9ed
+                       "</source>\n");
6ae9ed
+    TEST_BACKING_PARSE("json:{\"file.driver\":\"ssh\","
6ae9ed
+                             "\"file.host\":\"example.org\","
6ae9ed
+                             "\"file.port\":\"6000\","
6ae9ed
+                             "\"file.path\":\"blah\","
6ae9ed
+                             "\"file.user\":\"user\""
6ae9ed
+                            "}",
6ae9ed
+                       "<source protocol='ssh' name='blah'>\n"
6ae9ed
+                       "  <host name='example.org' port='6000'/>\n"
6ae9ed
+                       "</source>\n");
6ae9ed
 
6ae9ed
  cleanup:
6ae9ed
     /* Final cleanup */
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed