--- src/util/virstoragefile.c | 38 ++++++++++++++++++++++++++++++++++++++ tests/virstoragetest.c | 9 +++++++++ 2 files changed, 47 insertions(+)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 4aa1a9b..9c7b5a4 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2685,6 +2685,43 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src, } +static int +virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src, + virJSONValuePtr json, + int opaque ATTRIBUTE_UNUSED) +{ + const char *path = virJSONValueObjectGetString(json, "file.path"); + const char *host = virJSONValueObjectGetString(json, "file.host"); + const char *port = virJSONValueObjectGetString(json, "file.port"); + + if (!host) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("missing host of SSH server in 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); @@ -2704,6 +2741,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = { {"iscsi", virStorageSourceParseBackingJSONiSCSI, 0}, {"nbd", virStorageSourceParseBackingJSONNbd, 0}, {"sheepdog", virStorageSourceParseBackingJSONSheepdog, 0}, + {"ssh", virStorageSourceParseBackingJSONSSH, 0}, }; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index fcb6750..3479cd8 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1394,6 +1394,15 @@ mymain(void) "<source protocol='nbd' name='blah'>\n" " <host name='example.org' port='6000'/>\n" "</source>\n"); + TEST_BACKING_PARSE(17, "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 */ -- 2.8.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list