Signed-off-by: Ryan Gahagan <rgahagan(a)cs.utexas.edu>
---
src/qemu/qemu_block.c | 48 +++++++++++++++++++++++++++++++++++++++++-
src/qemu/qemu_domain.c | 39 ++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index b224a550f3..c0f47eedc0 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -674,6 +674,42 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src,
}
+static virJSONValuePtr
+qemuBlockStorageSourceGetNFSProps(virStorageSourcePtr src)
+{
+ g_autoptr(virJSONValue) server = NULL;
+ virJSONValuePtr ret = NULL;
+
+ if (src->nhosts != 1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("NFS protocol accepts only one host"));
+ return NULL;
+ }
+
+ if (!(server =
qemuBlockStorageSourceBuildJSONInetSocketAddress(&src->hosts[0])))
+ return NULL;
+
+ /* NFS disk specification example:
+ * { driver:"nfs",
+ * user: "0",
+ * group: "0",
+ * server: {type:"tcp", host:"1.2.3.4", port:9999}}
+ */
+ ignore_value(virJSONValueObjectCreate(&ret,
+ "a:server", &server, NULL));
+
+ if (src->nfs_uid != -1 &&
+ virJSONValueObjectAdd(ret, "i:user", src->nfs_uid, NULL) < 0)
+ return NULL;
+
+ if (src->nfs_gid != -1 &&
+ virJSONValueObjectAdd(ret, "i:group", src->nfs_gid, NULL) < 0)
+ return NULL;
+
+ return ret;
+}
+
+
static virJSONValuePtr
qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
bool onlytarget)
@@ -1181,6 +1217,11 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
break;
case VIR_STORAGE_NET_PROTOCOL_NFS:
+ driver = "nfs";
+ if (!(fileprops = qemuBlockStorageSourceGetNFSProps(src)))
+ return NULL;
+ break;
+
case VIR_STORAGE_NET_PROTOCOL_NONE:
case VIR_STORAGE_NET_PROTOCOL_LAST:
virReportEnumRangeError(virStorageNetProtocol, src->protocol);
@@ -2500,11 +2541,16 @@ qemuBlockStorageSourceCreateGetStorageProps(virStorageSourcePtr
src,
return -1;
break;
+ case VIR_STORAGE_NET_PROTOCOL_NFS:
+ driver = "nfs";
+ if (!(location = qemuBlockStorageSourceGetNFSProps(src)))
+ return -1;
+ break;
+
/* unsupported/impossible */
case VIR_STORAGE_NET_PROTOCOL_NBD:
case VIR_STORAGE_NET_PROTOCOL_ISCSI:
case VIR_STORAGE_NET_PROTOCOL_VXHS:
- case VIR_STORAGE_NET_PROTOCOL_NFS:
case VIR_STORAGE_NET_PROTOCOL_HTTP:
case VIR_STORAGE_NET_PROTOCOL_HTTPS:
case VIR_STORAGE_NET_PROTOCOL_FTP:
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 692bc925c6..65c751e1d9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9598,6 +9598,42 @@ qemuProcessPrepareStorageSourceTLSNBD(virStorageSourcePtr src,
}
+/* qemuPrepareStorageSourceNFS:
+ * @src: source for a disk
+ *
+ * If src is an NFS source, translate nfs_user and nfs_group
+ * into a uid and gid field. If these strings are empty (ie "")
+ * then provide the hypervisor default uid and gid.
+ */
+ static int
+ qemuDomainPrepareStorageSourceNFS(virStorageSourcePtr src)
+ {
+ if (virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK)
+ return 0;
+
+ if ((virStorageNetProtocol) src->protocol != VIR_STORAGE_NET_PROTOCOL_NFS)
+ return 0;
+
+ if (src->nfs_user) {
+ if (virGetUserID(src->nfs_user, &src->nfs_uid) < 0)
+ return -1;
+ } else {
+ /* -1 indicates default UID */
+ src->nfs_uid = -1;
+ }
+
+ if (src->nfs_group) {
+ if (virGetGroupID(src->nfs_group, &src->nfs_gid) < 0)
+ return -1;
+ } else {
+ /* -1 indicates default GID */
+ src->nfs_gid = -1;
+ }
+
+ return 0;
+}
+
+
/* qemuProcessPrepareStorageSourceTLS:
* @source: source for a disk
* @cfg: driver configuration
@@ -10409,6 +10445,9 @@ qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk,
priv) < 0)
return -1;
+ if (qemuDomainPrepareStorageSourceNFS(src) < 0)
+ return -1;
+
return 0;
}
--
2.29.0