summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-03-23 08:48:36 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-03-23 08:48:36 +0100
commitcb8453cc51a9d49e094e746af2e074669a71cc4a (patch)
treeb5ddc9f19d993ca7bb88f4b99e224bfef93b17d2 /src/network
parentsriov: introduce sr_iov_hash_func() and sr_iov_compare_func() (diff)
downloadsystemd-cb8453cc51a9d49e094e746af2e074669a71cc4a.tar.xz
systemd-cb8453cc51a9d49e094e746af2e074669a71cc4a.zip
network: sriov: use request queue to configure SR-IOV virtual functions
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-link.c2
-rw-r--r--src/network/networkd-queue.c1
-rw-r--r--src/network/networkd-queue.h1
-rw-r--r--src/network/networkd-sriov.c70
-rw-r--r--src/network/networkd-sriov.h2
5 files changed, 45 insertions, 31 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a122ea84fe..4312c6c7bb 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1045,7 +1045,7 @@ static int link_configure(Link *link) {
return link_request_to_activate(link);
}
- r = link_configure_sr_iov(link);
+ r = link_request_sr_iov_vfs(link);
if (r < 0)
return r;
diff --git a/src/network/networkd-queue.c b/src/network/networkd-queue.c
index 1463f610b2..cf2ffa0327 100644
--- a/src/network/networkd-queue.c
+++ b/src/network/networkd-queue.c
@@ -295,6 +295,7 @@ static const char *const request_type_table[_REQUEST_TYPE_MAX] = {
[REQUEST_TYPE_SET_LINK_MAC] = "MAC address",
[REQUEST_TYPE_SET_LINK_MASTER] = "master interface",
[REQUEST_TYPE_SET_LINK_MTU] = "MTU",
+ [REQUEST_TYPE_SRIOV] = "SR-IOV",
[REQUEST_TYPE_TC_QDISC] = "QDisc",
[REQUEST_TYPE_TC_CLASS] = "TClass",
[REQUEST_TYPE_UP_DOWN] = "bring link up or down",
diff --git a/src/network/networkd-queue.h b/src/network/networkd-queue.h
index d1110119cc..6db0005e61 100644
--- a/src/network/networkd-queue.h
+++ b/src/network/networkd-queue.h
@@ -44,6 +44,7 @@ typedef enum RequestType {
REQUEST_TYPE_SET_LINK_MAC, /* Setting MAC address. */
REQUEST_TYPE_SET_LINK_MASTER, /* Setting IFLA_MASTER. */
REQUEST_TYPE_SET_LINK_MTU, /* Setting MTU. */
+ REQUEST_TYPE_SRIOV,
REQUEST_TYPE_TC_CLASS,
REQUEST_TYPE_TC_QDISC,
REQUEST_TYPE_UP_DOWN,
diff --git a/src/network/networkd-sriov.c b/src/network/networkd-sriov.c
index cf138c7370..09980b4256 100644
--- a/src/network/networkd-sriov.c
+++ b/src/network/networkd-sriov.c
@@ -1,20 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright © 2020 VMware, Inc. */
-#include "netlink-util.h"
#include "networkd-link.h"
#include "networkd-manager.h"
+#include "networkd-queue.h"
#include "networkd-sriov.h"
-static int sr_iov_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
+static int sr_iov_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, SRIOV *sr_iov) {
int r;
+ assert(m);
assert(link);
- assert(link->sr_iov_messages > 0);
- link->sr_iov_messages--;
-
- if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
- return 1;
r = sd_netlink_message_get_errno(m);
if (r < 0 && r != -EEXIST) {
@@ -32,61 +28,77 @@ static int sr_iov_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
return 1;
}
-static int sr_iov_configure(Link *link, SRIOV *sr_iov) {
- _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
+static int sr_iov_configure(SRIOV *sr_iov, Link *link, Request *req) {
+ _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL;
int r;
+ assert(sr_iov);
assert(link);
assert(link->manager);
assert(link->manager->rtnl);
assert(link->ifindex > 0);
+ assert(req);
- log_link_debug(link, "Setting SR-IOV virtual function %"PRIu32, sr_iov->vf);
+ log_link_debug(link, "Setting SR-IOV virtual function %"PRIu32".", sr_iov->vf);
- r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
+ r = sd_rtnl_message_new_link(link->manager->rtnl, &m, RTM_SETLINK, link->ifindex);
if (r < 0)
return r;
- r = sr_iov_set_netlink_message(sr_iov, req);
+ r = sr_iov_set_netlink_message(sr_iov, m);
if (r < 0)
return r;
- r = netlink_call_async(link->manager->rtnl, NULL, req, sr_iov_handler,
- link_netlink_destroy_callback, link);
- if (r < 0)
- return r;
+ return request_call_netlink_async(link->manager->rtnl, m, req);
+}
- link_ref(link);
- link->sr_iov_messages++;
+static int sr_iov_process_request(Request *req, Link *link, SRIOV *sr_iov) {
+ int r;
- return 0;
+ assert(req);
+ assert(link);
+ assert(sr_iov);
+
+ if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+ return 0;
+
+ r = sr_iov_configure(sr_iov, link, req);
+ if (r < 0)
+ return log_link_warning_errno(link, r,
+ "Failed to configure SR-IOV virtual function %"PRIu32": %m",
+ sr_iov->vf);
+
+ return 1;
}
-int link_configure_sr_iov(Link *link) {
+int link_request_sr_iov_vfs(Link *link) {
SRIOV *sr_iov;
int r;
assert(link);
assert(link->network);
- if (link->sr_iov_messages != 0) {
- log_link_debug(link, "SR-IOV is configuring.");
- return 0;
- }
-
link->sr_iov_configured = false;
ORDERED_HASHMAP_FOREACH(sr_iov, link->network->sr_iov_by_section) {
- r = sr_iov_configure(link, sr_iov);
+ r = link_queue_request_safe(link, REQUEST_TYPE_SRIOV,
+ sr_iov, NULL,
+ sr_iov_hash_func,
+ sr_iov_compare_func,
+ sr_iov_process_request,
+ &link->sr_iov_messages,
+ sr_iov_handler,
+ NULL);
if (r < 0)
return log_link_warning_errno(link, r,
- "Failed to configure SR-IOV virtual function %"PRIu32": %m",
+ "Failed to request SR-IOV virtual function %"PRIu32": %m",
sr_iov->vf);
}
- if (link->sr_iov_messages == 0)
+ if (link->sr_iov_messages == 0) {
link->sr_iov_configured = true;
- else
+ link_check_ready(link);
+ } else
log_link_debug(link, "Configuring SR-IOV");
return 0;
diff --git a/src/network/networkd-sriov.h b/src/network/networkd-sriov.h
index 4251fddf88..539fa06099 100644
--- a/src/network/networkd-sriov.h
+++ b/src/network/networkd-sriov.h
@@ -6,4 +6,4 @@
typedef struct Link Link;
-int link_configure_sr_iov(Link *link);
+int link_request_sr_iov_vfs(Link *link);