[libvirt] [PATCH 16/16] conf: Move validation of domain title

Laine Stump laine at laine.org
Fri Mar 1 19:31:12 UTC 2013


On 02/20/2013 12:06 PM, Peter Krempa wrote:
> Use the helper to avoid doing this in the parser.
> ---
>  src/conf/domain_conf.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index da04b7b..0689eff 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2365,6 +2365,13 @@ static int
>  virDomainDefUpdateDefaultsInternal(virDomainDefPtr def,
>                                     virCapsPtr caps ATTRIBUTE_UNUSED)
>  {
> +    /* verify the domain title */
> +    if (def->title && strchr(def->title, '\n')) {
> +        virReportError(VIR_ERR_XML_ERROR, "%s",
> +                       _("Domain title can't contain newlines"));
> +        return -1;
> +    }
> +

This is a good example of something that isn't "updating defaults". (I
think your implication here is that this validation should be
hypervisor-specific, and so should end up being moved out into the
hypervisor's parse callback, which is true, but it doesn't fit with the
current named purpose of the function.)

>      /* Auto-add any implied controllers which aren't present */
>      if (virDomainDefAddImplicitControllers(def) < 0)
>          return -1;
> @@ -9314,12 +9321,6 @@ virDomainDefParseXML(virCapsPtr caps,
>
>      /* Extract short description of domain (title) */
>      def->title = virXPathString("string(./title[1])", ctxt);
> -    if (def->title && strchr(def->title, '\n')) {
> -        virReportError(VIR_ERR_XML_ERROR, "%s",
> -                       _("Domain title can't contain newlines"));
> -        goto error;
> -    }
> -
>      /* Extract documentation if present */
>      def->description = virXPathString("string(./description[1])", ctxt);
>




More information about the libvir-list mailing list