Re: [PATCH v2 06/25] src/xenxs:Refactor code parsing disk config

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Kiarie wrote:
> From: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>
>
> Introduce function
>  xenParseXMDisk(virConfPtr conf,......);
> which parses XM disk config instead
>
> signed-off-by: David Kiarie<davidkiarie4@xxxxxxxxx>
> ---
>  src/xenxs/xen_xm.c | 302 ++++++++++++++++++++++++++++-------------------------
>  1 file changed, 157 insertions(+), 145 deletions(-)
>
> diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
> index 66d7b44..2c36c1b 100644
> --- a/src/xenxs/xen_xm.c
> +++ b/src/xenxs/xen_xm.c
> @@ -507,126 +507,15 @@ int xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr def)
>  }
>  
>  
> -virDomainDefPtr
> -xenParseXM(virConfPtr conf, int xendConfigVersion,
> -                       virCapsPtr caps)
> +static
> +int xenParseXMDisk(virConfPtr conf, virDomainDefPtr def,
> +                   int xendConfigVersion)
>   

libvirt style is to have function return type and name on separate
lines, e.g.

static int
xenParseXMDisk(...)

>  {
> -    const char *str;
> -    int hvm = 0;
> -    int val;
> -    virConfValuePtr list;
> -    virDomainDefPtr def = NULL;
> +    const char *str = NULL;
>      virDomainDiskDefPtr disk = NULL;
> -    virDomainNetDefPtr net = NULL;
> -    virDomainGraphicsDefPtr graphics = NULL;
> -    size_t i;
> -    const char *defaultMachine;
> -    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;
> -    if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
> -        goto cleanup;
> -
> -
> -    if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
> -        STREQ(str, "hvm"))
> -        hvm = 1;
> -
> -    if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
> -        goto cleanup;
> -
> -    def->os.arch =
> -        virCapabilitiesDefaultGuestArch(caps,
> -                                        def->os.type,
> -                                        virDomainVirtTypeToString(def->virtType));
> -    if (!def->os.arch) {
> -        virReportError(VIR_ERR_INTERNAL_ERROR,
> -                       _("no supported architecture for os type '%s'"),
> -                       def->os.type);
> -        goto cleanup;
> -    }
> -
> -    defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
> -                                                        def->os.type,
> -                                                        def->os.arch,
> -                                                        virDomainVirtTypeToString(def->virtType));
> -    if (defaultMachine != NULL) {
> -        if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
> -            goto cleanup;
> -    }
> -
> -    if (hvm) {
> -        const char *boot;
> -        if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
> -            goto cleanup;
> -
> -        if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
> -            goto cleanup;
> -
> -        for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
> -            switch (*boot) {
> -            case 'a':
> -                def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
> -                break;
> -            case 'd':
> -                def->os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
> -                break;
> -            case 'n':
> -                def->os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
> -                break;
> -            case 'c':
> -            default:
> -                def->os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
> -                break;
> -            }
> -            def->os.nBootDevs++;
> -        }
> -    } else {
> -        const char *extra, *root;
> -
> -        if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
> -            goto cleanup;
> -        if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
> -            goto cleanup;
> -
> -        if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
> -            goto cleanup;
> -        if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
> -            goto cleanup;
> -        if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
> -            goto cleanup;
> -        if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
> -            goto cleanup;
> -
> -        if (root) {
> -            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
> -                goto cleanup;
> -        } else {
> -            if (VIR_STRDUP(def->os.cmdline, extra) < 0)
> -                goto cleanup;
> -        }
> -    }
> -
> -    if (xenParseXMMem(conf, def) < 0)
> -        goto cleanup;
> -    if (xenParseXMEventsActions(conf, def) < 0)
> -        goto cleanup;
> -    if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
> -        goto cleanup;
> -    if (xenParseXMCPUFeatures(conf, def) < 0)
> -        goto cleanup;
> -    if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
> -        goto cleanup;
> +    int hvm = STREQ(def->os.type, "hvm");
> +    virConfValuePtr list = virConfGetValue(conf, "disk");
>  
> -    list = virConfGetValue(conf, "disk");
>      if (list && list->type == VIR_CONF_LIST) {
>          list = list->list;
>          while (list) {
> @@ -638,9 +527,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>              if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
>                  goto skipdisk;
>              head = list->str;
> -
>   

Spurious whitespace change.

>              if (!(disk = virDomainDiskDefNew()))
> -                goto cleanup;
> +                return -1;
>  
>              /*
>               * Disks have 3 components, SOURCE,DEST-DEVICE,MODE
> @@ -653,38 +541,39 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>              /* Extract the source file path*/
>              if (!(offset = strchr(head, ',')))
>                  goto skipdisk;
> -
>   

More whitespace change, again removing a blank line.

>              if (offset == head) {
>                  /* No source file given, eg CDROM with no media */
>                  ignore_value(virDomainDiskSetSource(disk, NULL));
>              } else {
>                  if (VIR_STRNDUP(tmp, head, offset - head) < 0)
> -                    goto cleanup;
> +                    return -1;
> +
>   

But here you are adding a blank line.  I think these types of changes
are fine as long as you are consistent and in the end the code is more
readable.

Regards,
Jim

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]