From nobody Sun May 19 20:13:03 2024 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 1536308101865169.9457978483183; Fri, 7 Sep 2018 01:15:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D698D307D85A; Fri, 7 Sep 2018 08:14:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 182245C2E3; Fri, 7 Sep 2018 08:14:58 +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 E6EF0180005A; Fri, 7 Sep 2018 08:14:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w878Etj3019864 for ; Fri, 7 Sep 2018 04:14:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E7CAC5BCC; Fri, 7 Sep 2018 08:14:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25F0E9A30A for ; Fri, 7 Sep 2018 08:14:53 +0000 (UTC) Received: from m97139.mail.qiye.163.com (m97139.mail.qiye.163.com [220.181.97.139]) by mx1.redhat.com (Postfix) with ESMTP id E7999307D857 for ; Fri, 7 Sep 2018 08:14:49 +0000 (UTC) Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp10 (Coremail) with SMTP id vOCowAA3+kx4M5Jb96BfAA--.240S2; Fri, 07 Sep 2018 16:14:48 +0800 (CST) From: Shi Lei To: libvir-list@redhat.com Date: Fri, 7 Sep 2018 16:14:46 +0800 Message-Id: <20180907081446.19262-1-shi_lei@massclouds.com> X-CM-TRANSID: vOCowAA3+kx4M5Jb96BfAA--.240S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGry5Cry8ZF13CFyfCw1ftFb_yoW5Cry5pa 47Ka47urWrJr1j9ayxZr4UCF1Fvr1fXFyfGrWUKr1xWa1UZrn2qa4xKFy8KFWrAFZ5ZFyF 9a1q9ayrAFWxCaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U6EEUUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbifBi6T1rpNfRRNQAAsH 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.48]); Fri, 07 Sep 2018 08:14:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Sep 2018 08:14:50 +0000 (UTC) for IP:'220.181.97.139' DOMAIN:'m97139.mail.qiye.163.com' HELO:'m97139.mail.qiye.163.com' FROM:'shi_lei@massclouds.com' RCPT:'' X-RedHat-Spam-Score: -0.01 (RCVD_IN_DNSWL_NONE) 220.181.97.139 m97139.mail.qiye.163.com 220.181.97.139 m97139.mail.qiye.163.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: netlink: 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.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 07 Sep 2018 08:15:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch removes virNetDevPutExtraHeader and replaces it with nlmsg_append directly. Signed-off-by: Shi Lei Reviewed-by: Erik Skultety --- 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 c4dd354..5d4ad24 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3163,28 +3163,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: @@ -3199,7 +3177,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; @@ -3210,12 +3192,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")); @@ -3262,7 +3241,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; @@ -3292,12 +3275,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