2020-09-22 18:01:38 +08:00
|
|
|
From 56635fe00f44f8c83ba059432d42c093be4e9ed8 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
|
|
Date: Sun, 19 Apr 2020 08:26:04 +0200
|
|
|
|
|
Subject: [PATCH 6/8] virNetDevGetFamilyId: Change signature
|
|
|
|
|
MIME-Version: 1.0
|
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
|
|
Introduced in v3.8.0-rc1~96, the virNetDevGetFamilyId() gets
|
|
|
|
|
netlink family ID for passed family name (even though it's used
|
|
|
|
|
only for getting "devlink" ID). Nevertheless, the function
|
|
|
|
|
returns 0 on an error or if no family ID was found. This makes it
|
|
|
|
|
harder for a caller to distinguish these two. Change the retval
|
|
|
|
|
so that a negative value is returned upon error, zero is no ID
|
|
|
|
|
found (but no error encountered) and a positive value is returned
|
|
|
|
|
on successful translation.
|
|
|
|
|
|
|
|
|
|
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
|
|
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
2020-09-22 23:06:28 +08:00
|
|
|
(cherry-picked from commit ca616274)
|
2020-09-22 18:01:38 +08:00
|
|
|
Signed-off-by: AlexChen <alex.chen@huawei.com>
|
|
|
|
|
---
|
|
|
|
|
src/util/virnetdev.c | 23 +++++++++++++++--------
|
|
|
|
|
1 file changed, 15 insertions(+), 8 deletions(-)
|
|
|
|
|
|
|
|
|
|
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
|
|
|
|
|
index b465bdac2e..3431aaf6a9 100644
|
|
|
|
|
--- a/src/util/virnetdev.c
|
|
|
|
|
+++ b/src/util/virnetdev.c
|
|
|
|
|
@@ -3057,11 +3057,15 @@ virNetDevGetEthtoolFeatures(virBitmapPtr bitmap,
|
|
|
|
|
* This function supplies the devlink family id
|
|
|
|
|
*
|
|
|
|
|
* @family_name: the name of the family to query
|
|
|
|
|
+ * @family_id: family ID
|
|
|
|
|
*
|
|
|
|
|
- * Returns family id or 0 on failure.
|
|
|
|
|
+ * Returns: 0 if no family was found,
|
|
|
|
|
+ * 1 if family was found (@family_id is set),
|
|
|
|
|
+ * -1 otherwise
|
|
|
|
|
*/
|
|
|
|
|
-static uint32_t
|
|
|
|
|
-virNetDevGetFamilyId(const char *family_name)
|
|
|
|
|
+static int
|
|
|
|
|
+virNetDevGetFamilyId(const char *family_name,
|
|
|
|
|
+ uint32_t *family_id)
|
|
|
|
|
{
|
|
|
|
|
struct nl_msg *nl_msg = NULL;
|
|
|
|
|
struct nlmsghdr *resp = NULL;
|
|
|
|
|
@@ -3072,7 +3076,7 @@ virNetDevGetFamilyId(const char *family_name)
|
|
|
|
|
};
|
|
|
|
|
struct nlattr *tb[CTRL_ATTR_MAX + 1] = {NULL, };
|
|
|
|
|
unsigned int recvbuflen;
|
|
|
|
|
- uint32_t family_id = 0;
|
|
|
|
|
+ int ret = -1;
|
|
|
|
|
|
|
|
|
|
if (!(nl_msg = nlmsg_alloc_simple(GENL_ID_CTRL,
|
|
|
|
|
NLM_F_REQUEST | NLM_F_ACK))) {
|
|
|
|
|
@@ -3098,15 +3102,18 @@ virNetDevGetFamilyId(const char *family_name)
|
|
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- if (tb[CTRL_ATTR_FAMILY_ID] == NULL)
|
|
|
|
|
+ if (tb[CTRL_ATTR_FAMILY_ID] == NULL) {
|
|
|
|
|
+ ret = 0;
|
|
|
|
|
goto cleanup;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- family_id = *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]);
|
|
|
|
|
+ *family_id = *(uint32_t *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID]);
|
|
|
|
|
+ ret = 1;
|
|
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
|
nlmsg_free(nl_msg);
|
|
|
|
|
VIR_FREE(resp);
|
|
|
|
|
- return family_id;
|
|
|
|
|
+ return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -3140,7 +3147,7 @@ virNetDevSwitchdevFeature(const char *ifname,
|
|
|
|
|
int ret = -1;
|
|
|
|
|
uint32_t family_id;
|
|
|
|
|
|
|
|
|
|
- if ((family_id = virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <= 0)
|
|
|
|
|
+ if (virNetDevGetFamilyId(DEVLINK_GENL_NAME, &family_id) <= 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
if ((is_vf = virNetDevIsVirtualFunction(ifname)) < 0)
|
|
|
|
|
--
|
|
|
|
|
2.23.0
|
|
|
|
|
|