From nobody Wed May 14 10:31:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527460162644781.4753883085534; Sun, 27 May 2018 15:29:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 508463157116; Sun, 27 May 2018 22:29:21 +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 1DF149420A; Sun, 27 May 2018 22:29:21 +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 B5C7A4CA89; Sun, 27 May 2018 22:29:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RMSnme015020 for ; Sun, 27 May 2018 18:28:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA83B17D25; Sun, 27 May 2018 22:28:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A34115DD6B for ; Sun, 27 May 2018 22:28:47 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 551BB19D2BB for ; Sun, 27 May 2018 22:28:36 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id i12-v6so17316638wrc.4 for ; Sun, 27 May 2018 15:28:36 -0700 (PDT) Received: from machado.local ([95.82.135.172]) by smtp.gmail.com with ESMTPSA id h81-v6sm23469897wmd.0.2018.05.27.15.28.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 27 May 2018 15:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fidencio-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OIa2uaM/OVZ5pXxcqRPqKOZQDp/vcFn4O6HXcdaxUH4=; b=WADrTKtsDCKJtU54NdJAfzRDoacJ87W58SoJF8HutJdZCC1Z8nghH75RfNe6a5NxL0 SaaIW9tiEQ945+4NJBYTDFLGa6fVOVN0WA+hY3FwsKuzEZwHaDrICgSCKcEVIv0V8C+y NbFqqA+9PTUyIiote8K3GWRANsaiDXMDhivqmxzIfxG5pgzxOhAnK02uodRC3gtP/Ka0 tFplFpCrbC1f9jAmPSFTHvn7zRS4aqR7Pyq5tfgfif7uJ3q48u81B2yJ+uqCap+5VTrg xM/jHtm7xVIg8Q6w6XthwTlMTz5rlFSHxbJkSLmxX+ypcoCaNcPR7t2Ac3sWZkoP+z4t Nf9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OIa2uaM/OVZ5pXxcqRPqKOZQDp/vcFn4O6HXcdaxUH4=; b=q4vL5ELHNHV3oVJxRFYgox2aWwmm384Ni0LfL9SKz+JvZL7KJ5sfo3Lpo5l+0z/Ayk Ts8AdIkO0fuKIJoWpDDkcCQdVT9uYOn5NwlKgbfPWvOjBWCKM5FrERp4s4/otpqP6JY0 SXHR9BEE/wyzvH54TDA/YnWT6Jt8/uos6pU25lygyc0YEPbdrOSDA1juyTDTgnjjqyCB v6YYwAt3UJp8SgL7GWd/0ru6SHCmu9+TBpcTqmux+fLkJoKorA4NzYEeWVBpfJx56Iut yJUdWPIxlkO/a4iSj2Ci4ihZFeYE8jyw1lkdsuEjgyBRz9JI+oTPSmulBe3Pp5NVn1Ep aMbw== X-Gm-Message-State: ALKqPwfNOpP2A14MDMT/XbzTSXKFuCUVNZ/sbUff6kBI/QMlmib3/laA k66zx0SUQE4Ktfr1AQTDuOJNcQe0 X-Google-Smtp-Source: AB8JxZrmrkDolFIDrozO5qasExxPd1zxo4m6cYes963AkZphjCU7c+mg99geVzXhEqCaGTdBfz7J9g== X-Received: by 2002:adf:e70d:: with SMTP id c13-v6mr9485736wrm.203.1527460114698; Sun, 27 May 2018 15:28:34 -0700 (PDT) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Mon, 28 May 2018 00:28:23 +0200 Message-Id: <20180527222826.18525-5-fabiano@fidencio.org> In-Reply-To: <20180527222826.18525-1-fabiano@fidencio.org> References: <20180527222826.18525-1-fabiano@fidencio.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 27 May 2018 22:28:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 27 May 2018 22:28:36 +0000 (UTC) for IP:'209.85.128.195' DOMAIN:'mail-wr0-f195.google.com' HELO:'mail-wr0-f195.google.com' FROM:'fabiano@fidencio.org' RCPT:'' X-RedHat-Spam-Score: -1.597 (DKIM_SIGNED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID) 209.85.128.195 mail-wr0-f195.google.com 209.85.128.195 mail-wr0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCHv3 4/7] xen_common: Split per-PCI logic from xenParsePCI() 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sun, 27 May 2018 22:29:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 xenParsePCI() does a lot of stuff and, in order to make things cleaner, let's split it in two new functions: - xenParsePCI(): it's a new function that keeps the old name. It's responsible for the whole per-PCI logic from the old xenParsePCI(); - xenParsePCIList(): it's basically the old xenParsePCI(), but now it just iterates over the list of PCIs, calling xenParsePCI() per each PCI. This patch is basically preparing the ground for the future when typesafe virConf acessors will be used. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/xenconfig/xen_common.c | 167 ++++++++++++++++++++++++-----------------= ---- 1 file changed, 89 insertions(+), 78 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index a2b0708ee3..fc7b0683b8 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -389,92 +389,103 @@ xenParseEventsActions(virConfPtr conf, virDomainDefP= tr def) } =20 =20 -static int -xenParsePCI(virConfPtr conf, virDomainDefPtr def) +static virDomainHostdevDefPtr +xenParsePCI(char *entry) { - virConfValuePtr list =3D virConfGetValue(conf, "pci"); virDomainHostdevDefPtr hostdev =3D NULL; + char domain[5]; + char bus[3]; + char slot[3]; + char func[2]; + char *key, *nextkey; + int domainID; + int busID; + int slotID; + int funcID; + + domain[0] =3D bus[0] =3D slot[0] =3D func[0] =3D '\0'; + + /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ + if (!(key =3D entry)) + return NULL; + if (!(nextkey =3D strchr(key, ':'))) + return NULL; + if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) =3D=3D NU= LL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Domain %s too big for destination"), key); + return NULL; + } =20 - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - char domain[5]; - char bus[3]; - char slot[3]; - char func[2]; - char *key, *nextkey; - int domainID; - int busID; - int slotID; - int funcID; - - domain[0] =3D bus[0] =3D slot[0] =3D func[0] =3D '\0'; + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, ':'))) + return NULL; + if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bus %s too big for destination"), key); + return NULL; + } =20 - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) - goto skippci; - /* pci=3D['0000:00:1b.0','0000:00:13.0'] */ - if (!(key =3D list->str)) - goto skippci; - if (!(nextkey =3D strchr(key, ':'))) - goto skippci; - if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) = =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Domain %s too big for destination"), key= ); - goto skippci; - } + key =3D nextkey + 1; + if (!(nextkey =3D strchr(key, '.'))) + return NULL; + if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Slot %s too big for destination"), key); + return NULL; + } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, ':'))) - goto skippci; - if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) =3D=3D = NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bus %s too big for destination"), key); - goto skippci; - } + key =3D nextkey + 1; + if (strlen(key) !=3D 1) + return NULL; + if (virStrncpy(func, key, 1, sizeof(func)) =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Function %s too big for destination"), key); + return NULL; + } =20 - key =3D nextkey + 1; - if (!(nextkey =3D strchr(key, '.'))) - goto skippci; - if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) =3D= =3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Slot %s too big for destination"), key); - goto skippci; - } + if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) + return NULL; + if (virStrToLong_i(bus, NULL, 16, &busID) < 0) + return NULL; + if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) + return NULL; + if (virStrToLong_i(func, NULL, 16, &funcID) < 0) + return NULL; =20 - key =3D nextkey + 1; - if (strlen(key) !=3D 1) - goto skippci; - if (virStrncpy(func, key, 1, sizeof(func)) =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Function %s too big for destination"), k= ey); - goto skippci; - } + if (!(hostdev =3D virDomainHostdevDefNew())) + return NULL; =20 - if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) - goto skippci; - if (virStrToLong_i(bus, NULL, 16, &busID) < 0) - goto skippci; - if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) - goto skippci; - if (virStrToLong_i(func, NULL, 16, &funcID) < 0) - goto skippci; - if (!(hostdev =3D virDomainHostdevDefNew())) - return -1; - - hostdev->managed =3D false; - hostdev->source.subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE= _PCI; - hostdev->source.subsys.u.pci.addr.domain =3D domainID; - hostdev->source.subsys.u.pci.addr.bus =3D busID; - hostdev->source.subsys.u.pci.addr.slot =3D slotID; - hostdev->source.subsys.u.pci.addr.function =3D funcID; - - if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev)= < 0) { - virDomainHostdevDefFree(hostdev); - return -1; - } + hostdev->managed =3D false; + hostdev->source.subsys.type =3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; + hostdev->source.subsys.u.pci.addr.domain =3D domainID; + hostdev->source.subsys.u.pci.addr.bus =3D busID; + hostdev->source.subsys.u.pci.addr.slot =3D slotID; + hostdev->source.subsys.u.pci.addr.function =3D funcID; =20 - skippci: - list =3D list->next; + return hostdev; +} + + +static int +xenParsePCIList(virConfPtr conf, virDomainDefPtr def) +{ + virConfValuePtr list =3D virConfGetValue(conf, "pci"); + + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; + + for (list =3D list->list; list; list =3D list->next) { + virDomainHostdevDefPtr hostdev; + + if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NULL)) + continue; + + if (!(hostdev =3D xenParsePCI(list->str))) + return -1; + + if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0= ) { + virDomainHostdevDefFree(hostdev); + return -1; } } =20 @@ -1126,7 +1137,7 @@ xenParseConfigCommon(virConfPtr conf, return -1; } =20 - if (xenParsePCI(conf, def) < 0) + if (xenParsePCIList(conf, def) < 0) return -1; =20 if (xenParseEmulatedDevices(conf, def) < 0) --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list