mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
network: sriov: use request queue to configure SR-IOV virtual functions
This commit is contained in:
parent
bee8fc36f4
commit
cb8453cc51
@ -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;
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
link_ref(link);
|
||||
link->sr_iov_messages++;
|
||||
|
||||
return 0;
|
||||
return request_call_netlink_async(link->manager->rtnl, m, req);
|
||||
}
|
||||
|
||||
int link_configure_sr_iov(Link *link) {
|
||||
static int sr_iov_process_request(Request *req, Link *link, SRIOV *sr_iov) {
|
||||
int r;
|
||||
|
||||
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_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;
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
typedef struct Link Link;
|
||||
|
||||
int link_configure_sr_iov(Link *link);
|
||||
int link_request_sr_iov_vfs(Link *link);
|
||||
|
Loading…
Reference in New Issue
Block a user