From nobody Mon Feb 9 08:56:23 2026 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; 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 1536136612122215.9098339663791; Wed, 5 Sep 2018 01:36:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68B5E8666B; Wed, 5 Sep 2018 08:36:50 +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 2BF37308BDA0; Wed, 5 Sep 2018 08:36:50 +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 9D4C64A460; Wed, 5 Sep 2018 08:36:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w858aiRT028456 for ; Wed, 5 Sep 2018 04:36:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7AA321719E; Wed, 5 Sep 2018 08:36:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6FEF45F726 for ; Wed, 5 Sep 2018 08:36:39 +0000 (UTC) Received: from m97134.mail.qiye.163.com (m97134.mail.qiye.163.com [220.181.97.134]) by mx1.redhat.com (Postfix) with ESMTP id 70CE780F6D for ; Wed, 5 Sep 2018 08:36:35 +0000 (UTC) Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp5 (Coremail) with SMTP id huCowABnV2uQlY9bWTyvAQ--.779S6; Wed, 05 Sep 2018 16:36:33 +0800 (CST) From: Shi Lei To: libvir-list@redhat.com Date: Wed, 5 Sep 2018 16:36:30 +0800 Message-Id: <20180905083630.32034-5-shi_lei@massclouds.com> In-Reply-To: <20180905083630.32034-1-shi_lei@massclouds.com> References: <20180905083630.32034-1-shi_lei@massclouds.com> X-CM-TRANSID: huCowABnV2uQlY9bWTyvAQ--.779S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxGry5Cr4fJrW5tw47ZF1UZFb_yoW5Cr4Upa 47Ka47Wr4rJr1q9ayxZr4UCF1Fqr1fXFyfGrWUKw1xWa1UZrn2qa4xKFy8KFZ5CFZ5uFyF 9a1q9ayrJFWxCaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrwIgUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbieRG4T1qrhIG3jwAAsT X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 212 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 05 Sep 2018 08:36:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 05 Sep 2018 08:36:38 +0000 (UTC) for IP:'220.181.97.134' DOMAIN:'m97134.mail.qiye.163.com' HELO:'m97134.mail.qiye.163.com' FROM:'shi_lei@massclouds.com' RCPT:'' X-RedHat-Spam-Score: -0.01 (RCVD_IN_DNSWL_NONE) 220.181.97.134 m97134.mail.qiye.163.com 220.181.97.134 m97134.mail.qiye.163.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCHv2 4/4] Remove virNetDevPutExtraHeader and replace with nlmsg_append 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 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 05 Sep 2018 08:36:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch replaces virNetDevPutExtraHeader with nlmsg_append directly. Signed-off-by: Shi Lei --- src/util/virnetdev.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 892a147..a7bc8e0 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3155,28 +3155,6 @@ virNetDevGetEthtoolFeatures(virBitmapPtr bitmap, =20 =20 # if HAVE_DECL_DEVLINK_CMD_ESWITCH_GET -/** - * virNetDevPutExtraHeader - * reserve and prepare room for an extra header - * This function sets to zero the room that is required to put the extra - * header after the initial Netlink header. This function also increases - * the nlmsg_len field. - * - * @nlh: pointer to Netlink header - * @size: size of the extra header that we want to put - * - * Returns pointer to the start of the extended header - */ -static void * -virNetDevPutExtraHeader(struct nlmsghdr *nlh, - size_t size) -{ - char *ptr =3D (char *)nlh + nlh->nlmsg_len; - size_t len =3D NLMSG_ALIGN(size); - nlh->nlmsg_len +=3D len; - return ptr; -} - =20 /** * virNetDevGetFamilyId: @@ -3191,7 +3169,11 @@ virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg =3D NULL; struct nlmsghdr *resp =3D NULL; - struct genlmsghdr* gmsgh =3D NULL; + struct genlmsghdr gmsgh =3D { + .cmd =3D CTRL_CMD_GETFAMILY, + .version =3D DEVLINK_GENL_VERSION, + .reserved =3D 0, + }; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; uint32_t family_id =3D 0; @@ -3202,12 +3184,9 @@ virNetDevGetFamilyId(const char *family_name) goto cleanup; } =20 - if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) + if (nlmsg_append(nl_msg, &gmsgh, sizeof(gmsgh), NLMSG_ALIGNTO) < 0) goto cleanup; =20 - gmsgh->cmd =3D CTRL_CMD_GETFAMILY; - gmsgh->version =3D DEVLINK_GENL_VERSION; - if (nla_put_string(nl_msg, CTRL_ATTR_FAMILY_NAME, family_name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); @@ -3254,7 +3233,11 @@ virNetDevSwitchdevFeature(const char *ifname, unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; virPCIDevicePtr pci_device_ptr =3D NULL; - struct genlmsghdr* gmsgh =3D NULL; + struct genlmsghdr gmsgh =3D { + .cmd =3D DEVLINK_CMD_ESWITCH_GET, + .version =3D DEVLINK_GENL_VERSION, + .reserved =3D 0, + }; const char *pci_name; char *pfname =3D NULL; int is_vf =3D -1; @@ -3284,12 +3267,9 @@ virNetDevSwitchdevFeature(const char *ifname, goto cleanup; } =20 - if (!(gmsgh =3D virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(stru= ct genlmsghdr)))) + if (nlmsg_append(nl_msg, &gmsgh, sizeof(gmsgh), NLMSG_ALIGNTO) < 0) goto cleanup; =20 - gmsgh->cmd =3D DEVLINK_CMD_ESWITCH_GET; - gmsgh->version =3D DEVLINK_GENL_VERSION; - pci_name =3D virPCIDeviceGetName(pci_device_ptr); =20 if (nla_put(nl_msg, DEVLINK_ATTR_BUS_NAME, strlen("pci")+1, "pci") < 0= || --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list