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

Peter Krempa pkrempa at redhat.com
Fri Dec 11 09:23:47 UTC 2020


On Thu, Dec 10, 2020 at 14:00:07 -0600, Ryan Gahagan wrote:
> 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");

I'm fairly sure that this is a 'vxhs' protocol property.

You'd probably notice it if you'd add tests in the same commit.

> +    virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
> +    int gotUID = virJSONValueObjectGetNumberInt(json, "user", (int *)(&src->nfs_uid));

You should not typecast the pointers here since it's not guaranteed that
the uid_t/gid_t type is the same as an integer. Additionally storing
this only in the nfs_uid field will actually not show up in the VM xml
once parsed. You actually need to populate the string variants with the
uid number with + prepended so that the XML conversion works.

> +    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"));

Our coding style mandates that error messages in new code should be on a
single line.

> +        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,




More information about the libvir-list mailing list