[RFC PATCH 5/6] qemu: added NFS JSON props methods

Peter Krempa pkrempa at redhat.com
Fri Dec 11 09:30:35 UTC 2020


On Thu, Dec 10, 2020 at 14:00:06 -0600, Ryan Gahagan wrote:
> Signed-off-by: Ryan Gahagan <rgahagan at cs.utexas.edu>
> ---
>  src/qemu/qemu_block.c  | 42 +++++++++++++++++++++++++++++++++++++++++-
>  src/qemu/qemu_domain.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 83 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
> index b224a550f3..f93f675262 100644
> --- a/src/qemu/qemu_block.c
> +++ b/src/qemu/qemu_block.c
> @@ -674,6 +674,36 @@ 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,
> +                                          "i:user", src->nfs_uid,
> +                                          "i:group", src->nfs_gid,
> +                                          "a:server", &server, NULL));

There's also virJSONValueObjectAdd, that might come in handy given my
comment below.

> +
> +    return ret;
> +}

[...]

> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index b5a4a22ed3..64ebfb5812 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -9589,6 +9589,45 @@ 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)
> + {
> +    int err = 0;
> +    if (virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK)
> +        return 0;
> +
> +    if ((virStorageNetProtocol) src->protocol != VIR_STORAGE_NET_PROTOCOL_NFS)
> +        return 0;
> +
> +    if (src->nfs_user) {
> +        err = virGetUserID(src->nfs_user, &src->nfs_uid);

You can return here directly if virGetUserID returns -1. No need for the
extra vriable.

> +    } else {
> +        /* TODO: Provide hypervisor default value */

The best bet is to actually avoid formatting the user/group members
formatting towards qemu.

Unfortunately 0 is a very valid uid, so you'll probably need to use -1
to signal that it's the default.

> +    if (err < 0)
> +        return -1;




More information about the libvir-list mailing list