network,udev: move TransmitQueues=/ReceiveQueues= from .network to .link

As the settings are mostly hardware setup, and merely see from network
layer.

See also discussions in
https://github.com/systemd/systemd/pull/18170#issuecomment-758807497
https://github.com/orgs/systemd/teams/systemd/discussions/1
This commit is contained in:
Yu Watanabe 2021-01-20 15:50:01 +09:00
parent 1f8dc96c06
commit face9fcc16
13 changed files with 99 additions and 123 deletions

View file

@ -409,6 +409,20 @@
be ignored.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>TransmitQueues=</varname></term>
<listitem>
<para>Specifies the device's number of transmit queues. An integer in the range 1…4096.
When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>ReceiveQueues=</varname></term>
<listitem>
<para>Specifies the device's number of receive queues. An integer in the range 1…4096.
When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>TransmitQueueLength=</varname></term>
<listitem>

View file

@ -215,20 +215,6 @@
integer in the range 0…4294967294. Defaults to unset.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>TransmitQueues=</varname></term>
<listitem>
<para>Specifies the devices's number of transmit queues. An integer in the range 1…4096.
When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>ReceiveQueues=</varname></term>
<listitem>
<para>Specifies the devices's number of receive queues. An integer in the range 1…4096.
When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>RequiredForOnline=</varname></term>
<listitem>

View file

@ -57,15 +57,25 @@ int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name) {
return 0;
}
int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac,
uint32_t txqueuelen, uint32_t mtu, uint32_t gso_max_size, size_t gso_max_segments) {
int rtnl_set_link_properties(
sd_netlink **rtnl,
int ifindex,
const char *alias,
const struct ether_addr *mac,
uint32_t txqueues,
uint32_t rxqueues,
uint32_t txqueuelen,
uint32_t mtu,
uint32_t gso_max_size,
size_t gso_max_segments) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *message = NULL;
int r;
assert(rtnl);
assert(ifindex > 0);
if (!alias && !mac && txqueuelen == UINT32_MAX && mtu == 0 && gso_max_size == 0 && gso_max_segments == 0)
if (!alias && !mac && txqueues == 0 && rxqueues == 0 && txqueuelen == UINT32_MAX && mtu == 0 &&
gso_max_size == 0 && gso_max_segments == 0)
return 0;
if (!*rtnl) {
@ -90,6 +100,18 @@ int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias,
return r;
}
if (txqueues > 0) {
r = sd_netlink_message_append_u32(message, IFLA_NUM_TX_QUEUES, txqueues);
if (r < 0)
return r;
}
if (rxqueues > 0) {
r = sd_netlink_message_append_u32(message, IFLA_NUM_RX_QUEUES, rxqueues);
if (r < 0)
return r;
}
if (txqueuelen < UINT32_MAX) {
r = sd_netlink_message_append_u32(message, IFLA_TXQLEN, txqueuelen);
if (r < 0)

View file

@ -70,8 +70,17 @@ static inline bool rtnl_message_type_is_mdb(uint16_t type) {
}
int rtnl_set_link_name(sd_netlink **rtnl, int ifindex, const char *name);
int rtnl_set_link_properties(sd_netlink **rtnl, int ifindex, const char *alias, const struct ether_addr *mac,
uint32_t txqueuelen, uint32_t mtu, uint32_t gso_max_size, size_t gso_max_segments);
int rtnl_set_link_properties(
sd_netlink **rtnl,
int ifindex,
const char *alias,
const struct ether_addr *mac,
uint32_t txqueues,
uint32_t rxqueues,
uint32_t txqueuelen,
uint32_t mtu,
uint32_t gso_max_size,
size_t gso_max_segments);
int rtnl_get_link_alternative_names(sd_netlink **rtnl, int ifindex, char ***ret);
int rtnl_set_link_alternative_names(sd_netlink **rtnl, int ifindex, char * const *alternative_names);
int rtnl_set_link_alternative_names_by_ifname(sd_netlink **rtnl, const char *ifname, char * const *alternative_names);

View file

@ -1479,61 +1479,6 @@ static int link_set_group(Link *link) {
return 0;
}
static int link_tx_rx_queues_hadler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
assert(link);
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
return 1;
r = sd_netlink_message_get_errno(m);
if (r < 0)
log_link_message_warning_errno(link, m, r, "Could not set transmit / receive queues for the interface");
return 1;
}
static int link_set_tx_rx_queues(Link *link) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r;
assert(link);
assert(link->network);
assert(link->manager);
assert(link->manager->rtnl);
if (link->network->txqueues == 0 && link->network->rxqueues == 0)
return 0;
log_link_debug(link, "Setting transmit / receive queues");
r = sd_rtnl_message_new_link(link->manager->rtnl, &req, RTM_SETLINK, link->ifindex);
if (r < 0)
return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
if (link->network->txqueues > 0) {
r = sd_netlink_message_append_u32(req, IFLA_NUM_TX_QUEUES, link->network->txqueues);
if (r < 0)
return log_link_error_errno(link, r, "Could not set link transmit queues: %m");
}
if (link->network->rxqueues > 0) {
r = sd_netlink_message_append_u32(req, IFLA_NUM_RX_QUEUES, link->network->rxqueues);
if (r < 0)
return log_link_error_errno(link, r, "Could not set link receive queues: %m");
}
r = netlink_call_async(link->manager->rtnl, NULL, req, link_tx_rx_queues_hadler,
link_netlink_destroy_callback, link);
if (r < 0)
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
link_ref(link);
return 0;
}
static int link_handle_bound_to_list(Link *link) {
Link *l;
int r;
@ -2111,10 +2056,6 @@ int link_configure(Link *link) {
if (r < 0)
return r;
r = link_set_tx_rx_queues(link);
if (r < 0)
return r;
r = ipv4ll_configure(link);
if (r < 0)
return r;

View file

@ -60,8 +60,6 @@ Match.Architecture, config_parse_net_condition,
Link.MACAddress, config_parse_hwaddr, 0, offsetof(Network, mac)
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(Network, mtu)
Link.Group, config_parse_uint32, 0, offsetof(Network, group)
Link.TransmitQueues, config_parse_rx_tx_queues, 0, offsetof(Network, txqueues)
Link.ReceiveQueues, config_parse_rx_tx_queues, 0, offsetof(Network, rxqueues)
Link.ARP, config_parse_tristate, 0, offsetof(Network, arp)
Link.Multicast, config_parse_tristate, 0, offsetof(Network, multicast)
Link.AllMulticast, config_parse_tristate, 0, offsetof(Network, allmulticast)

View file

@ -1198,40 +1198,6 @@ int config_parse_required_for_online(
return 0;
}
int config_parse_rx_tx_queues(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
uint32_t k, *v = data;
int r;
if (isempty(rvalue)) {
*v = 0;
return 0;
}
r = safe_atou32(rvalue, &k);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring assignment: %s.", lvalue, rvalue);
return 0;
}
if (k == 0 || k > 4096) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s=, ignoring assignment: %s.", lvalue, rvalue);
return 0;
}
*v = k;
return 0;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, KeepConfiguration,
"Failed to parse KeepConfiguration= setting");

View file

@ -95,8 +95,6 @@ struct Network {
struct ether_addr *mac;
uint32_t mtu;
uint32_t group;
uint32_t txqueues;
uint32_t rxqueues;
int arp;
int multicast;
int allmulticast;
@ -344,7 +342,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ntp);
CONFIG_PARSER_PROTOTYPE(config_parse_required_for_online);
CONFIG_PARSER_PROTOTYPE(config_parse_keep_configuration);
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_link_local_address_gen_mode);
CONFIG_PARSER_PROTOTYPE(config_parse_rx_tx_queues);
CONFIG_PARSER_PROTOTYPE(config_parse_activation_policy);
const struct ConfigPerfItem* network_network_gperf_lookup(const char *key, GPERF_LEN_TYPE length);

View file

@ -41,6 +41,8 @@ Link.Name, config_parse_ifname, 0,
Link.AlternativeName, config_parse_ifnames, IFNAME_VALID_ALTERNATIVE, offsetof(link_config, alternative_names)
Link.AlternativeNamesPolicy, config_parse_alternative_names_policy, 0, offsetof(link_config, alternative_names_policy)
Link.Alias, config_parse_ifalias, 0, offsetof(link_config, alias)
Link.TransmitQueues, config_parse_rx_tx_queues, 0, offsetof(link_config, txqueues)
Link.ReceiveQueues, config_parse_rx_tx_queues, 0, offsetof(link_config, rxqueues)
Link.TransmitQueueLength, config_parse_txqueuelen, 0, offsetof(link_config, txqueuelen)
Link.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu)
Link.BitsPerSecond, config_parse_si_uint64, 0, offsetof(link_config, speed)

View file

@ -427,11 +427,15 @@ static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config
} else
mac = config->mac;
r = rtnl_set_link_properties(rtnl, ifindex, config->alias, mac, config->txqueuelen, config->mtu,
config->gso_max_size, config->gso_max_segments);
r = rtnl_set_link_properties(rtnl, ifindex, config->alias, mac,
config->txqueues, config->rxqueues, config->txqueuelen,
config->mtu, config->gso_max_size, config->gso_max_segments);
if (r < 0)
log_device_warning_errno(device, r, "Could not set Alias=, MACAddress=, TransmitQueueLength=, MTU=, "
"GenericSegmentOffloadMaxBytes= or GenericSegmentOffloadMaxSegments=, ignoring: %m");
log_device_warning_errno(device, r,
"Could not set Alias=, MACAddress=, "
"TransmitQueues=, ReceiveQueues=, TransmitQueueLength=, MTU=, "
"GenericSegmentOffloadMaxBytes= or GenericSegmentOffloadMaxSegments=, "
"ignoring: %m");
return 0;
}
@ -704,6 +708,40 @@ int config_parse_ifalias(
return 0;
}
int config_parse_rx_tx_queues(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
uint32_t k, *v = data;
int r;
if (isempty(rvalue)) {
*v = 0;
return 0;
}
r = safe_atou32(rvalue, &k);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring assignment: %s.", lvalue, rvalue);
return 0;
}
if (k == 0 || k > 4096) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid %s=, ignoring assignment: %s.", lvalue, rvalue);
return 0;
}
*v = k;
return 0;
}
int config_parse_txqueuelen(
const char *unit,
const char *filename,

View file

@ -46,6 +46,8 @@ struct link_config {
char *name;
char **alternative_names;
char *alias;
uint32_t txqueues;
uint32_t rxqueues;
uint32_t txqueuelen;
uint32_t mtu;
uint32_t gso_max_segments;
@ -91,6 +93,7 @@ MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_;
const struct ConfigPerfItem* link_config_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
CONFIG_PARSER_PROTOTYPE(config_parse_rx_tx_queues);
CONFIG_PARSER_PROTOTYPE(config_parse_txqueuelen);
CONFIG_PARSER_PROTOTYPE(config_parse_mac_address_policy);
CONFIG_PARSER_PROTOTYPE(config_parse_name_policy);

View file

@ -20,6 +20,8 @@ Name=
AlternativeNamesPolicy=
AlternativeName=
Alias=
TransmitQueues=
ReceiveQueues=
TransmitQueueLength=
MTUBytes=
BitsPerSecond=

View file

@ -40,8 +40,6 @@ Multicast=
MACAddress=
Group=
Promiscuous=
TransmitQueues=
ReceiveQueues=
[SR-IOV]
VirtualFunction=
MACSpoofCheck=