[RFC PATCH 6/6] util: Added a backing store NFS parser

Ryan Gahagan rgahagan at cs.utexas.edu
Thu Dec 10 20:00:07 UTC 2020


Signed-off-by: Ryan Gahagan <rgahagan at cs.utexas.edu>
---
 src/util/virstoragefile.c | 42 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index cff6dabd9e..098ec80542 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3805,6 +3805,47 @@ virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src,
 }
 
 
+static int
+virStorageSourceParseBackingJSONNFS(virStorageSourcePtr src,
+                                    virJSONValuePtr json,
+                                    const char *jsonstr G_GNUC_UNUSED,
+                                    int opaque G_GNUC_UNUSED)
+{
+    const char *vdisk_id = virJSONValueObjectGetString(json, "vdisk-id");
+    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
+    int gotUID = virJSONValueObjectGetNumberInt(json, "user", (int *)(&src->nfs_uid));
+    int gotGID = virJSONValueObjectGetNumberInt(json, "group", (int *)(&src->nfs_gid));
+
+    if (!vdisk_id || !server) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing 'vdisk-id' or 'server' attribute in "
+                         "JSON backing definition for NFS volume"));
+        return -1;
+    }
+
+    if (gotUID < 0 || gotGID < 0) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing 'user' or 'group' attribute in "
+                         "JSON backing definition for NFS volume"));
+        return -1;
+    }
+
+    src->type = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_NFS;
+
+    src->path = g_strdup(vdisk_id);
+
+    src->hosts = g_new0(virStorageNetHostDef, 1);
+    src->nhosts = 1;
+
+    if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts,
+                                                          server) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 virStorageSourceParseBackingJSONNVMe(virStorageSourcePtr src,
                                      virJSONValuePtr json,
@@ -3864,6 +3905,7 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
     {"ssh", false, virStorageSourceParseBackingJSONSSH, 0},
     {"rbd", false, virStorageSourceParseBackingJSONRBD, 0},
     {"raw", true, virStorageSourceParseBackingJSONRaw, 0},
+    {"nfs", false, virStorageSourceParseBackingJSONNFS, 0},
     {"vxhs", false, virStorageSourceParseBackingJSONVxHS, 0},
     {"nvme", false, virStorageSourceParseBackingJSONNVMe, 0},
 };
-- 
2.29.0




More information about the libvir-list mailing list