From patchwork Tue Jul 24 21:23:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 142825 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp55824ljj; Tue, 24 Jul 2018 14:24:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcCEHngB8XW0K2gl0ZmzjzjBVfKv1lDHyMrnjR2Fnp7S3yIApqUde9BNSFzYXlqB5gZxso1 X-Received: by 2002:a37:f86:: with SMTP id 6-v6mr16453009qkp.48.1532467446841; Tue, 24 Jul 2018 14:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532467446; cv=none; d=google.com; s=arc-20160816; b=M09K6ppmn73ZZjQkwpPgfYSeo876e6OcOKb8qqC0KzpFYBai4mq/qq8Jguni0OZXcr MlypxSCUgVQH7ucAT3dRBcd6ALKe3IQQ2ObtzpZYzfv0jS7P/ZxfDQcyM6Nsxcn28BJn lBNRigp9Nj0+jWu4WimKyvNsKhqxhEUPhOq7O0wmGnNtRlO6uCd1GcCdUqaGD6HW8Po0 3PkyJQUTRJHr8OG05ATkmr8GxqstmQk1oxKVBQlS/8DWrNlnIEzFUSk8zkBW0u3YrJpm DtDl/fPvKK9KzhAfPyNGA94dxtF7zW1hMmc9t/z4FHOdu+HuC9jjcCwxJ+Q9HRUYq/iG GAMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:references :in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=JNk3ZgqSba/BXK510wlUACxzYSxOVgFMCOxWf6cEiqU=; b=DegQxDnEoTR+0QEWxsetm1KqlY0T280ShmWWm9F3Uzl+z8JDwxU7ThY06LYPhaBIkL xDg/EhqKZySzQZVSwXNRdIsc9/th2ppZzhmb1gYPDnAP89eGKrovJth9WLsG2oUWdr+Y JuwVqmCMb8FG8BDT7LoBEnMvzUg+tthXksa2G9KVo4zA1VkPxLKaxmywj49ihLJEPgPM XC7iIpsVyoHSeUDCRuXn/sI8gpWuunLggzNlfpES5YHVRGPRcVjsPL71loWBEz3Dm6T1 UsitL/sIkB+n1Re5RYCeqWWIODUrK/hAdbdN4yqihS/+Yatp9QYLhNKkDj13HypzqSUa WmTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id r13-v6si8108765qtm.243.2018.07.24.14.24.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Jul 2018 14:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA36FC0587F8; Tue, 24 Jul 2018 21:24:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A000816E27; Tue, 24 Jul 2018 21:24:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 38F524A469; Tue, 24 Jul 2018 21:24:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6OLNpmw018726 for ; Tue, 24 Jul 2018 17:23:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 894F92026E18; Tue, 24 Jul 2018 21:23:51 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.bos.redhat.com (wlan-196-187.bos.redhat.com [10.16.196.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DC602026D68; Tue, 24 Jul 2018 21:23:51 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 24 Jul 2018 17:23:43 -0400 Message-Id: <1a4c1a045146524152f4d06fe8740504cef38d8b.1532467269.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/7] conf: Clean up virDomainDefParseCaps X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 24 Jul 2018 21:24:05 +0000 (UTC) - Convert to 'cleanup' label naming - Use more than one 'tmp' string and do all freeing at the end - Make the code easier to follow Signed-off-by: Cole Robinson --- src/conf/domain_conf.c | 76 ++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 39 deletions(-) -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7eb5ffc718..5a90429cd6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19121,43 +19121,45 @@ virDomainDefParseCaps(virDomainDefPtr def, unsigned int flags) { int ret = -1; - int virtType; - char *tmp = NULL; + char *virttype = NULL; + char *arch = NULL; + char *ostype = NULL; + virCapsDomainDataPtr capsdata = NULL; - /* Find out what type of virtualization to use */ - if (!(tmp = virXMLPropString(ctxt->node, "type"))) { + virttype = virXPathString("string(./@type)", ctxt); + ostype = virXPathString("string(./os/type[1])", ctxt); + arch = virXPathString("string(./os/type[1]/@arch)", ctxt); + + def->os.bootloader = virXPathString("string(./bootloader)", ctxt); + def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); + def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt); + def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); + + if (!virttype) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain type attribute")); - goto error; + goto cleanup; } - - if ((virtType = virDomainVirtTypeFromString(tmp)) < 0) { + if ((def->virtType = virDomainVirtTypeFromString(virttype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid domain type %s"), tmp); - goto error; + _("invalid domain type %s"), virttype); + goto cleanup; } - def->virtType = virtType; - VIR_FREE(tmp); - - def->os.bootloader = virXPathString("string(./bootloader)", ctxt); - def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); - tmp = virXPathString("string(./os/type[1])", ctxt); - if (!tmp) { + if (!ostype) { if (def->os.bootloader) { def->os.type = VIR_DOMAIN_OSTYPE_XEN; } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("an os must be specified")); - goto error; + goto cleanup; } } else { - if ((def->os.type = virDomainOSTypeFromString(tmp)) < 0) { + if ((def->os.type = virDomainOSTypeFromString(ostype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown OS type '%s'"), tmp); - goto error; + _("unknown OS type '%s'"), ostype); + goto cleanup; } - VIR_FREE(tmp); } /* @@ -19170,17 +19172,11 @@ virDomainDefParseCaps(virDomainDefPtr def, def->os.type = VIR_DOMAIN_OSTYPE_XEN; } - tmp = virXPathString("string(./os/type[1]/@arch)", ctxt); - if (tmp && !(def->os.arch = virArchFromString(tmp))) { + if (arch && !(def->os.arch = virArchFromString(arch))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown architecture %s"), - tmp); - goto error; + _("Unknown architecture %s"), arch); + goto cleanup; } - VIR_FREE(tmp); - - def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt); - def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); if ((!def->os.arch || !def->os.machine) && !(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) { @@ -19191,26 +19187,28 @@ virDomainDefParseCaps(virDomainDefPtr def, * in numerous minor ways. */ bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) || !def->os.machine); - virCapsDomainDataPtr capsdata = NULL; - if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, - def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, + if (!(capsdata = virCapabilitiesDomainDataLookup(caps, + def->os.type, + def->os.arch, + use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, NULL, NULL))) - goto error; + goto cleanup; if (!def->os.arch) def->os.arch = capsdata->arch; if ((!def->os.machine && VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) { - VIR_FREE(capsdata); - goto error; + goto cleanup; } - VIR_FREE(capsdata); } ret = 0; - error: - VIR_FREE(tmp); + cleanup: + VIR_FREE(virttype); + VIR_FREE(ostype); + VIR_FREE(arch); + VIR_FREE(capsdata); return ret; }