[libvirt] [PREPOST 01/17] src/xenxs:Introduce function

Jim Fehlig jfehlig at suse.com
Thu Jul 10 21:58:05 UTC 2014


David Kiarie wrote:
> From: Kiarie Kahurani <davidkiarie4 at gmail.com>
>
> Introduce function xenParseXMGeneral(virConfPtr conf, ...);
> This function parses the xm general options such as uuid and name
>
> signed-off-by: David Kiarie <davidkiarie4 at gmail.com>
> ---
>  src/xenxs/xen_xm.c | 65 +++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 37 insertions(+), 28 deletions(-)
>
> diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
> index 25a042d..1953a85 100644
> --- a/src/xenxs/xen_xm.c
> +++ b/src/xenxs/xen_xm.c
> @@ -253,44 +253,25 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid)
>   * Turn a config record into a lump of XML describing the
>   * domain, suitable for later feeding for virDomainCreateXML
>   */
> -virDomainDefPtr
> -xenParseXM(virConfPtr conf, int xendConfigVersion,
> -                       virCapsPtr caps)
> +static int xenParseXMGeneral(virConfPtr conf, virDomainDefPtr def,
> +                      virCapsPtr caps)
>   

Eric already mentioned the indentation, but I'll mention the name bugs
me a bit :).  Other names that come to mind are xenParseXMBasic,
xenParseXMMetadata, and xenParseXMGeneralMeta.  I tend to prefer the
last one.

Regards,
Jim

>  {
> +
> +    const char *defaultMachine;
>      const char *str;
>      int hvm = 0;
> -    int val;
> -    virConfValuePtr list;
> -    virDomainDefPtr def = NULL;
> -    virDomainDiskDefPtr disk = NULL;
> -    virDomainNetDefPtr net = NULL;
> -    virDomainGraphicsDefPtr graphics = NULL;
> -    virDomainHostdevDefPtr hostdev = NULL;
> -    size_t i;
> -    const char *defaultMachine;
> -    int vmlocaltime = 0;
> -    unsigned long count;
> -    char *script = NULL;
> -    char *listenAddr = NULL;
> -
> -    if (VIR_ALLOC(def) < 0)
> -        return NULL;
> -
> -    def->virtType = VIR_DOMAIN_VIRT_XEN;
> -    def->id = -1;
>  
>      if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
> -        goto cleanup;
> +        return -1;
>      if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
> -        goto cleanup;
> -
> +        return -1;
>  
>      if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
>          STREQ(str, "hvm"))
>          hvm = 1;
>  
>      if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
> -        goto cleanup;
> +        return -1;
>  
>      def->os.arch =
>          virCapabilitiesDefaultGuestArch(caps,
> @@ -300,7 +281,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>          virReportError(VIR_ERR_INTERNAL_ERROR,
>                         _("no supported architecture for os type '%s'"),
>                         def->os.type);
> -        goto cleanup;
> +        return -1;
>      }
>  
>      defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
> @@ -309,9 +290,37 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>                                                          virDomainVirtTypeToString(def->virtType));
>      if (defaultMachine != NULL) {
>          if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
> -            goto cleanup;
> +            return -1;
>      }
> +    return 0;
> +}
> +virDomainDefPtr
> +xenParseXM(virConfPtr conf, int xendConfigVersion,
> +                       virCapsPtr caps)
> +{
> +    const char *str;
> +    int hvm = 0;
> +    int val;
> +    virConfValuePtr list;
> +    virDomainDefPtr def = NULL;
> +    virDomainDiskDefPtr disk = NULL;
> +    virDomainNetDefPtr net = NULL;
> +    virDomainGraphicsDefPtr graphics = NULL;
> +    virDomainHostdevDefPtr hostdev = NULL;
> +    size_t i;
> +    int vmlocaltime = 0;
> +    unsigned long count;
> +    char *script = NULL;
> +    char *listenAddr = NULL;
> +
> +    if (VIR_ALLOC(def) < 0)
> +        return NULL;
>  
> +    def->virtType = VIR_DOMAIN_VIRT_XEN;
> +    def->id = -1;
> +    if (xenParseXMGeneral(conf, def, caps) < 0)
> +        goto cleanup;
> +    hvm = (STREQ(def->os.type, "hvm"));
>      if (hvm) {
>          const char *boot;
>          if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
>   




More information about the libvir-list mailing list