[libvirt] [PATCHv1 05/13] Split out storage format 'compat' attribute sanity check

Peter Krempa pkrempa at redhat.com
Mon Apr 13 05:28:01 UTC 2015


On Fri, Apr 10, 2015 at 14:58:57 +0200, Ján Tomko wrote:
> For future reuse in the snapshot XML.
> ---
>  src/conf/storage_conf.c   | 16 ++--------------
>  src/util/virstoragefile.c | 29 +++++++++++++++++++++++++++++
>  src/util/virstoragefile.h |  1 +
>  3 files changed, 32 insertions(+), 14 deletions(-)
> 

...

> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 96be02e..c1246e7 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -2873,3 +2873,32 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
>      VIR_FREE(tmp);
>      return ret;
>  }
> +
> +
> +/*
> + * virStorageFileCheckCompat
> + */
> +bool
> +virStorageFileCheckCompat(const char *compat)
> +{
> +    char **version;
> +    unsigned int result;
> +    bool ret;
> +
> +    if (!compat)
> +        return true;
> +
> +    version = virStringSplit(compat, ".", 2);
> +    if (!version || !version[1] ||
> +        virStrToLong_ui(version[0], NULL, 10, &result) < 0 ||
> +        virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
> +        virReportError(VIR_ERR_XML_ERROR, "%s",
> +                       _("forbidden characters in 'compat' attribute"));
> +        goto cleanup;

Functions that set errors usually return an integer despite only
returning two possible values in total.


> +    }
> +    ret = true;
> +
> + cleanup:
> +    virStringFreeList(version);
> +    return ret;
> +}

ACK if you change the return type to 'int' or add a documentation
comment explaining when the error is set.

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150413/c106e66b/attachment-0001.sig>


More information about the libvir-list mailing list