1
0
mirror of https://github.com/systemd/systemd synced 2026-03-26 00:34:53 +01:00

Compare commits

..

12 Commits

Author SHA1 Message Date
Tom Yan
c918b70a4d network: default LinkLocalAddresssing= to no for link stacked with a passthru mode MACVLAN/MACVTAP
For similar reason to the case of a bridge slave: we don't want any IP configuration for it.
2021-08-26 06:11:41 +09:00
Yu Watanabe
cacf882ff3
Merge pull request #20541 from yuwata/udev-coalesce-follow-up
udev: follow-ups for coalesce feature support
2021-08-26 06:05:29 +09:00
Yu Watanabe
d11ff2a4f1
Merge pull request #20515 from yuwata/pid1-mount-apivfs-no
pid1: make find_executable() work with MountAPIVFS=no
2021-08-26 06:05:03 +09:00
Yu Watanabe
ebab417cfb
Merge pull request #20531 from DaanDeMeyer/fix-17433
core: Check unit start rate limiting earlier
2021-08-26 06:04:40 +09:00
Yu Watanabe
ee7512404b udev/net: initialize coalesce tristate variables
Otherwise, 99-default.link may introduce something like the
following warnings:
----
Aug 26 03:23:59 systemd-udevd[519]: wlan0: Could not set coalesce settings, ignoring: Operation not supported
Aug 26 03:24:00 systemd-udevd[547]: wlp59s0: Could not set coalesce settings, ignoring: Operation not supported
----

Follow-up for 6c35ea5ef0231d519ff24d43a57a72cebab6a121.
2021-08-26 03:36:18 +09:00
Yu Watanabe
72328a5977 ethtool: move function
I'd like to locate all conf parsers at end of file.
2021-08-26 03:32:39 +09:00
Yu Watanabe
42867dfeef test-execute: add a testcase for MountAPIVFS=no 2021-08-26 02:54:37 +09:00
Daan De Meyer
9727f2427f core: Check unit start rate limiting earlier
Fixes #17433. Currently, if any of the validations we do before we
check start rate limiting fail, we can still enter a busy loop as
no rate limiting gets applied. A common occurence of this scenario
is path units triggering a service that fails a condition check.

To fix the issue, we simply move up start rate limiting checks to
be the first thing we do when starting a unit. To achieve this,
we add a new method to the unit vtable and implement it for the
relevant unit types so that we can do the start rate limit checks
earlier on.
2021-08-25 13:26:14 +01:00
Daan De Meyer
a243128d1f core: Remove circular include
service.h includes socket.h and socket.h includes service.h. Move
service.h include from socket.h to socket.c to remove the circular
dependency.
2021-08-24 16:19:03 +01:00
Yu Watanabe
aa2727517e test-execute: logs can_share flag 2021-08-24 02:04:24 +09:00
Yu Watanabe
93413acd3e path-util: make find_executable() work without /proc mounted
Follow-up for 888f65ace6296ed61285d31db846babf1c11885e.

Hopefully fixes #20514.
2021-08-24 02:04:24 +09:00
Yu Watanabe
ded8039abe path-util: split out common part in find_executable_full() 2021-08-24 02:04:24 +09:00
26 changed files with 600 additions and 246 deletions

View File

@ -427,7 +427,8 @@
has been unsuccessful for some time. (IPv4 link-local address autoconfiguration will usually
happen in parallel with repeated attempts to acquire a DHCPv4 lease).</para>
<para>Defaults to <option>no</option> when <varname>Bridge=yes</varname> is set, and
<para>Defaults to <option>no</option> when <varname>Bridge=</varname> is set or when the specified
<varname>MACVLAN=</varname>/<varname>MACVTAP=</varname> has <varname>Mode=passthru</varname>, or
<option>ipv6</option> otherwise.</para>
</listitem>
</varlistentry>

View File

@ -630,9 +630,52 @@ static int check_x_access(const char *path, int *ret_fd) {
return r;
r = access_fd(fd, X_OK);
if (r == -ENOSYS) {
/* /proc is not mounted. Fallback to access(). */
if (access(path, X_OK) < 0)
return -errno;
} else if (r < 0)
return r;
if (ret_fd)
*ret_fd = TAKE_FD(fd);
return 0;
}
static int find_executable_impl(const char *name, const char *root, char **ret_filename, int *ret_fd) {
_cleanup_close_ int fd = -1;
_cleanup_free_ char *path_name = NULL;
int r;
assert(name);
/* Function chase_symlinks() is invoked only when root is not NULL, as using it regardless of
* root value would alter the behavior of existing callers for example: /bin/sleep would become
* /usr/bin/sleep when find_executables is called. Hence, this function should be invoked when
* needed to avoid unforeseen regression or other complicated changes. */
if (root) {
r = chase_symlinks(name,
root,
CHASE_PREFIX_ROOT,
&path_name,
/* ret_fd= */ NULL); /* prefix root to name in case full paths are not specified */
if (r < 0)
return r;
name = path_name;
}
r = check_x_access(name, ret_fd ? &fd : NULL);
if (r < 0)
return r;
if (ret_filename) {
r = path_make_absolute_cwd(name, ret_filename);
if (r < 0)
return r;
}
if (ret_fd)
*ret_fd = TAKE_FD(fd);
@ -645,43 +688,8 @@ int find_executable_full(const char *name, const char *root, bool use_path_envva
assert(name);
if (is_path(name)) {
_cleanup_close_ int fd = -1;
_cleanup_free_ char *path_name = NULL;
/* Function chase_symlinks() is invoked only when root is not NULL,
* as using it regardless of root value would alter the behavior
* of existing callers for example: /bin/sleep would become
* /usr/bin/sleep when find_executables is called. Hence, this function
* should be invoked when needed to avoid unforeseen regression or other
* complicated changes. */
if (root) {
r = chase_symlinks(name,
root,
CHASE_PREFIX_ROOT,
&path_name,
/* ret_fd= */ NULL); /* prefix root to name in case full paths are not specified */
if (r < 0)
return r;
name = path_name;
}
r = check_x_access(name, ret_fd ? &fd : NULL);
if (r < 0)
return r;
if (ret_filename) {
r = path_make_absolute_cwd(name, ret_filename);
if (r < 0)
return r;
}
if (ret_fd)
*ret_fd = TAKE_FD(fd);
return 0;
}
if (is_path(name))
return find_executable_impl(name, root, ret_filename, ret_fd);
if (use_path_envvar)
/* Plain getenv, not secure_getenv, because we want to actually allow the user to pick the
@ -695,7 +703,6 @@ int find_executable_full(const char *name, const char *root, bool use_path_envva
/* Resolve a single-component name to a full path */
for (;;) {
_cleanup_free_ char *element = NULL;
_cleanup_close_ int fd = -1;
r = extract_first_word(&p, &element, ":", EXTRACT_RELAX|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0)
@ -709,24 +716,7 @@ int find_executable_full(const char *name, const char *root, bool use_path_envva
if (!path_extend(&element, name))
return -ENOMEM;
if (root) {
char *path_name;
r = chase_symlinks(element,
root,
CHASE_PREFIX_ROOT,
&path_name,
/* ret_fd= */ NULL);
if (r < 0) {
if (r != -EACCES)
last_error = r;
continue;
}
free_and_replace(element, path_name);
}
r = check_x_access(element, ret_fd ? &fd : NULL);
r = find_executable_impl(element, root, ret_filename, ret_fd);
if (r < 0) {
/* PATH entries which we don't have access to are ignored, as per tradition. */
if (r != -EACCES)
@ -735,11 +725,6 @@ int find_executable_full(const char *name, const char *root, bool use_path_envva
}
/* Found it! */
if (ret_filename)
*ret_filename = path_simplify(TAKE_PTR(element));
if (ret_fd)
*ret_fd = TAKE_FD(fd);
return 0;
}

View File

@ -813,12 +813,6 @@ static int automount_start(Unit *u) {
if (r < 0)
return r;
r = unit_test_start_limit(u);
if (r < 0) {
automount_enter_dead(a, AUTOMOUNT_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -1064,6 +1058,21 @@ static bool automount_supported(void) {
return supported;
}
static int automount_test_start_limit(Unit *u) {
Automount *a = AUTOMOUNT(u);
int r;
assert(a);
r = unit_test_start_limit(u);
if (r < 0) {
automount_enter_dead(a, AUTOMOUNT_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const automount_result_table[_AUTOMOUNT_RESULT_MAX] = {
[AUTOMOUNT_SUCCESS] = "success",
[AUTOMOUNT_FAILURE_RESOURCES] = "resources",
@ -1126,4 +1135,6 @@ const UnitVTable automount_vtable = {
[JOB_FAILED] = "Failed to unset automount %s.",
},
},
.test_start_limit = automount_test_start_limit,
};

View File

@ -1167,12 +1167,6 @@ static int mount_start(Unit *u) {
assert(IN_SET(m->state, MOUNT_DEAD, MOUNT_FAILED));
r = unit_test_start_limit(u);
if (r < 0) {
mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -2138,6 +2132,21 @@ static int mount_can_clean(Unit *u, ExecCleanMask *ret) {
return exec_context_get_clean_mask(&m->exec_context, ret);
}
static int mount_test_start_limit(Unit *u) {
Mount *m = MOUNT(u);
int r;
assert(m);
r = unit_test_start_limit(u);
if (r < 0) {
mount_enter_dead(m, MOUNT_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const mount_exec_command_table[_MOUNT_EXEC_COMMAND_MAX] = {
[MOUNT_EXEC_MOUNT] = "ExecMount",
[MOUNT_EXEC_UNMOUNT] = "ExecUnmount",
@ -2235,4 +2244,6 @@ const UnitVTable mount_vtable = {
[JOB_TIMEOUT] = "Timed out unmounting %s.",
},
},
.test_start_limit = mount_test_start_limit,
};

View File

@ -590,12 +590,6 @@ static int path_start(Unit *u) {
if (r < 0)
return r;
r = unit_test_start_limit(u);
if (r < 0) {
path_enter_dead(p, PATH_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -812,6 +806,21 @@ static void path_reset_failed(Unit *u) {
p->result = PATH_SUCCESS;
}
static int path_test_start_limit(Unit *u) {
Path *p = PATH(u);
int r;
assert(p);
r = unit_test_start_limit(u);
if (r < 0) {
path_enter_dead(p, PATH_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const path_type_table[_PATH_TYPE_MAX] = {
[PATH_EXISTS] = "PathExists",
[PATH_EXISTS_GLOB] = "PathExistsGlob",
@ -866,4 +875,6 @@ const UnitVTable path_vtable = {
.reset_failed = path_reset_failed,
.bus_set_property = bus_path_set_property,
.test_start_limit = path_test_start_limit,
};

View File

@ -2436,13 +2436,6 @@ static int service_start(Unit *u) {
assert(IN_SET(s->state, SERVICE_DEAD, SERVICE_FAILED));
/* Make sure we don't enter a busy loop of some kind. */
r = unit_test_start_limit(u);
if (r < 0) {
service_enter_dead(s, SERVICE_FAILURE_START_LIMIT_HIT, false);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -4445,6 +4438,22 @@ static const char *service_finished_job(Unit *u, JobType t, JobResult result) {
return NULL;
}
static int service_test_start_limit(Unit *u) {
Service *s = SERVICE(u);
int r;
assert(s);
/* Make sure we don't enter a busy loop of some kind. */
r = unit_test_start_limit(u);
if (r < 0) {
service_enter_dead(s, SERVICE_FAILURE_START_LIMIT_HIT, false);
return r;
}
return 0;
}
static const char* const service_restart_table[_SERVICE_RESTART_MAX] = {
[SERVICE_RESTART_NO] = "no",
[SERVICE_RESTART_ON_SUCCESS] = "on-success",
@ -4608,4 +4617,6 @@ const UnitVTable service_vtable = {
},
.finished_job = service_finished_job,
},
.test_start_limit = service_test_start_limit,
};

View File

@ -34,6 +34,7 @@
#include "process-util.h"
#include "selinux-util.h"
#include "serialize.h"
#include "service.h"
#include "signal-util.h"
#include "smack-util.h"
#include "socket.h"
@ -2512,12 +2513,6 @@ static int socket_start(Unit *u) {
assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED));
r = unit_test_start_limit(u);
if (r < 0) {
socket_enter_dead(s, SOCKET_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -3424,6 +3419,21 @@ static int socket_can_clean(Unit *u, ExecCleanMask *ret) {
return exec_context_get_clean_mask(&s->exec_context, ret);
}
static int socket_test_start_limit(Unit *u) {
Socket *s = SOCKET(u);
int r;
assert(s);
r = unit_test_start_limit(u);
if (r < 0) {
socket_enter_dead(s, SOCKET_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const socket_exec_command_table[_SOCKET_EXEC_COMMAND_MAX] = {
[SOCKET_EXEC_START_PRE] = "ExecStartPre",
[SOCKET_EXEC_START_CHOWN] = "ExecStartChown",
@ -3550,4 +3560,6 @@ const UnitVTable socket_vtable = {
[JOB_TIMEOUT] = "Timed out stopping %s.",
},
},
.test_start_limit = socket_test_start_limit,
};

View File

@ -5,7 +5,6 @@ typedef struct Socket Socket;
typedef struct SocketPeer SocketPeer;
#include "mount.h"
#include "service.h"
#include "socket-util.h"
#include "unit.h"

View File

@ -932,12 +932,6 @@ static int swap_start(Unit *u) {
if (UNIT(other)->job && UNIT(other)->job->state == JOB_RUNNING)
return -EAGAIN;
r = unit_test_start_limit(u);
if (r < 0) {
swap_enter_dead(s, SWAP_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -1588,6 +1582,21 @@ static int swap_can_clean(Unit *u, ExecCleanMask *ret) {
return exec_context_get_clean_mask(&s->exec_context, ret);
}
static int swap_test_start_limit(Unit *u) {
Swap *s = SWAP(u);
int r;
assert(s);
r = unit_test_start_limit(u);
if (r < 0) {
swap_enter_dead(s, SWAP_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const swap_exec_command_table[_SWAP_EXEC_COMMAND_MAX] = {
[SWAP_EXEC_ACTIVATE] = "ExecActivate",
[SWAP_EXEC_DEACTIVATE] = "ExecDeactivate",
@ -1683,4 +1692,6 @@ const UnitVTable swap_vtable = {
[JOB_TIMEOUT] = "Timed out deactivating swap %s.",
},
},
.test_start_limit = swap_test_start_limit,
};

View File

@ -627,12 +627,6 @@ static int timer_start(Unit *u) {
if (r < 0)
return r;
r = unit_test_start_limit(u);
if (r < 0) {
timer_enter_dead(t, TIMER_FAILURE_START_LIMIT_HIT);
return r;
}
r = unit_acquire_invocation_id(u);
if (r < 0)
return r;
@ -890,6 +884,21 @@ static int timer_can_clean(Unit *u, ExecCleanMask *ret) {
return 0;
}
static int timer_test_start_limit(Unit *u) {
Timer *t = TIMER(u);
int r;
assert(t);
r = unit_test_start_limit(u);
if (r < 0) {
timer_enter_dead(t, TIMER_FAILURE_START_LIMIT_HIT);
return r;
}
return 0;
}
static const char* const timer_base_table[_TIMER_BASE_MAX] = {
[TIMER_ACTIVE] = "OnActiveSec",
[TIMER_BOOT] = "OnBootSec",
@ -949,4 +958,6 @@ const UnitVTable timer_vtable = {
.timezone_change = timer_timezone_change,
.bus_set_property = bus_timer_set_property,
.test_start_limit = timer_test_start_limit,
};

View File

@ -1857,6 +1857,13 @@ int unit_start(Unit *u) {
assert(u);
/* Check start rate limiting early so that failure conditions don't cause us to enter a busy loop. */
if (UNIT_VTABLE(u)->test_start_limit) {
int r = UNIT_VTABLE(u)->test_start_limit(u);
if (r < 0)
return r;
}
/* If this is already started, then this will succeed. Note that this will even succeed if this unit
* is not startable by the user. This is relied on to detect when we need to wait for units and when
* waiting is finished. */

View File

@ -658,6 +658,10 @@ typedef struct UnitVTable {
* of this type will immediately fail. */
bool (*supported)(void);
/* If this function is set, it's invoked first as part of starting a unit to allow start rate
* limiting checks to occur before we do anything else. */
int (*test_start_limit)(Unit *u);
/* The strings to print in status messages */
UnitStatusMessageFormats status_message_formats;

View File

@ -13,6 +13,7 @@
#include "hostname-util.h"
#include "in-addr-util.h"
#include "net-condition.h"
#include "netdev/macvlan.h"
#include "networkd-address-label.h"
#include "networkd-address.h"
#include "networkd-bridge-fdb.h"
@ -170,8 +171,33 @@ int network_verify(Network *network) {
network->routes_by_section = hashmap_free_with_destructor(network->routes_by_section, route_free);
}
if (network->link_local < 0)
network->link_local = network->bridge ? ADDRESS_FAMILY_NO : ADDRESS_FAMILY_IPV6;
if (network->link_local < 0) {
network->link_local = ADDRESS_FAMILY_IPV6;
if (network->bridge)
network->link_local = ADDRESS_FAMILY_NO;
else {
NetDev *netdev;
HASHMAP_FOREACH(netdev, network->stacked_netdevs) {
MacVlan *m;
if (netdev->kind == NETDEV_KIND_MACVLAN)
m = MACVLAN(netdev);
else if (netdev->kind == NETDEV_KIND_MACVTAP)
m = MACVTAP(netdev);
else
continue;
if (m->mode == NETDEV_MACVLAN_MODE_PASSTHRU)
network->link_local = ADDRESS_FAMILY_NO;
/* There won't be a passthru MACVLAN/MACVTAP if there's already one in another mode */
break;
}
}
}
if (network->ipv6ll_address_gen_mode == IPV6_LINK_LOCAL_ADDRESSS_GEN_MODE_NONE)
SET_FLAG(network->link_local, ADDRESS_FAMILY_IPV6, false);

View File

@ -932,6 +932,131 @@ int ethtool_set_flow_control(int *fd, const char *ifname, int rx, int tx, int au
return 0;
}
int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce) {
struct ethtool_coalesce ecmd = {
.cmd = ETHTOOL_GCOALESCE,
};
struct ifreq ifr = {
.ifr_data = (void*) &ecmd,
};
bool need_update = false;
int r;
assert(ethtool_fd);
assert(ifname);
assert(coalesce);
if (coalesce->use_adaptive_rx_coalesce < 0 &&
coalesce->use_adaptive_tx_coalesce < 0 &&
!coalesce->rx_coalesce_usecs.set &&
!coalesce->rx_max_coalesced_frames.set &&
!coalesce->rx_coalesce_usecs_irq.set &&
!coalesce->rx_max_coalesced_frames_irq.set &&
!coalesce->tx_coalesce_usecs.set &&
!coalesce->tx_max_coalesced_frames.set &&
!coalesce->tx_coalesce_usecs_irq.set &&
!coalesce->tx_max_coalesced_frames_irq.set &&
!coalesce->stats_block_coalesce_usecs.set &&
!coalesce->pkt_rate_low.set &&
!coalesce->rx_coalesce_usecs_low.set &&
!coalesce->rx_max_coalesced_frames_low.set &&
!coalesce->tx_coalesce_usecs_low.set &&
!coalesce->tx_max_coalesced_frames_low.set &&
!coalesce->pkt_rate_high.set &&
!coalesce->rx_coalesce_usecs_high.set &&
!coalesce->rx_max_coalesced_frames_high.set &&
!coalesce->tx_coalesce_usecs_high.set &&
!coalesce->tx_max_coalesced_frames_high.set &&
!coalesce->rate_sample_interval.set)
return 0;
r = ethtool_connect(ethtool_fd);
if (r < 0)
return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (coalesce->use_adaptive_rx_coalesce >= 0)
UPDATE(ecmd.use_adaptive_rx_coalesce, (uint32_t) coalesce->use_adaptive_rx_coalesce, need_update);
if (coalesce->use_adaptive_tx_coalesce >= 0)
UPDATE(ecmd.use_adaptive_tx_coalesce, (uint32_t) coalesce->use_adaptive_tx_coalesce, need_update);
if (coalesce->rx_coalesce_usecs.set)
UPDATE(ecmd.rx_coalesce_usecs, coalesce->rx_coalesce_usecs.value, need_update);
if (coalesce->rx_max_coalesced_frames.set)
UPDATE(ecmd.rx_max_coalesced_frames, coalesce->rx_max_coalesced_frames.value, need_update);
if (coalesce->rx_coalesce_usecs_irq.set)
UPDATE(ecmd.rx_coalesce_usecs_irq, coalesce->rx_coalesce_usecs_irq.value, need_update);
if (coalesce->rx_max_coalesced_frames_irq.set)
UPDATE(ecmd.rx_max_coalesced_frames_irq, coalesce->rx_max_coalesced_frames_irq.value, need_update);
if (coalesce->tx_coalesce_usecs.set)
UPDATE(ecmd.tx_coalesce_usecs, coalesce->tx_coalesce_usecs.value, need_update);
if (coalesce->tx_max_coalesced_frames.set)
UPDATE(ecmd.tx_max_coalesced_frames, coalesce->tx_max_coalesced_frames.value, need_update);
if (coalesce->tx_coalesce_usecs_irq.set)
UPDATE(ecmd.tx_coalesce_usecs_irq, coalesce->tx_coalesce_usecs_irq.value, need_update);
if (coalesce->tx_max_coalesced_frames_irq.set)
UPDATE(ecmd.tx_max_coalesced_frames_irq, coalesce->tx_max_coalesced_frames_irq.value, need_update);
if (coalesce->stats_block_coalesce_usecs.set)
UPDATE(ecmd.stats_block_coalesce_usecs, coalesce->stats_block_coalesce_usecs.value, need_update);
if (coalesce->pkt_rate_low.set)
UPDATE(ecmd.pkt_rate_low, coalesce->pkt_rate_low.value, need_update);
if (coalesce->rx_coalesce_usecs_low.set)
UPDATE(ecmd.rx_coalesce_usecs_low, coalesce->rx_coalesce_usecs_low.value, need_update);
if (coalesce->rx_max_coalesced_frames_low.set)
UPDATE(ecmd.rx_max_coalesced_frames_low, coalesce->rx_max_coalesced_frames_low.value, need_update);
if (coalesce->tx_coalesce_usecs_low.set)
UPDATE(ecmd.tx_coalesce_usecs_low, coalesce->tx_coalesce_usecs_low.value, need_update);
if (coalesce->tx_max_coalesced_frames_low.set)
UPDATE(ecmd.tx_max_coalesced_frames_low, coalesce->tx_max_coalesced_frames_low.value, need_update);
if (coalesce->pkt_rate_high.set)
UPDATE(ecmd.pkt_rate_high, coalesce->pkt_rate_high.value, need_update);
if (coalesce->rx_coalesce_usecs_high.set)
UPDATE(ecmd.rx_coalesce_usecs_high, coalesce->rx_coalesce_usecs_high.value, need_update);
if (coalesce->rx_max_coalesced_frames_high.set)
UPDATE(ecmd.rx_max_coalesced_frames_high, coalesce->rx_max_coalesced_frames_high.value, need_update);
if (coalesce->tx_coalesce_usecs_high.set)
UPDATE(ecmd.tx_coalesce_usecs_high, coalesce->tx_coalesce_usecs_high.value, need_update);
if (coalesce->tx_max_coalesced_frames_high.set)
UPDATE(ecmd.tx_max_coalesced_frames_high, coalesce->tx_max_coalesced_frames_high.value, need_update);
if (coalesce->rate_sample_interval.set)
UPDATE(ecmd.rate_sample_interval, DIV_ROUND_UP(coalesce->rate_sample_interval.value, USEC_PER_SEC), need_update);
if (!need_update)
return 0;
ecmd.cmd = ETHTOOL_SCOALESCE;
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
return 0;
}
int config_parse_advertise(
const char *unit,
const char *filename,
@ -1182,128 +1307,3 @@ int config_parse_coalesce_sec(
return 0;
}
int ethtool_set_nic_coalesce_settings(int *ethtool_fd, const char *ifname, const netdev_coalesce_param *coalesce) {
struct ethtool_coalesce ecmd = {
.cmd = ETHTOOL_GCOALESCE,
};
struct ifreq ifr = {
.ifr_data = (void*) &ecmd,
};
bool need_update = false;
int r;
assert(ethtool_fd);
assert(ifname);
assert(coalesce);
if (coalesce->use_adaptive_rx_coalesce < 0 &&
coalesce->use_adaptive_tx_coalesce < 0 &&
!coalesce->rx_coalesce_usecs.set &&
!coalesce->rx_max_coalesced_frames.set &&
!coalesce->rx_coalesce_usecs_irq.set &&
!coalesce->rx_max_coalesced_frames_irq.set &&
!coalesce->tx_coalesce_usecs.set &&
!coalesce->tx_max_coalesced_frames.set &&
!coalesce->tx_coalesce_usecs_irq.set &&
!coalesce->tx_max_coalesced_frames_irq.set &&
!coalesce->stats_block_coalesce_usecs.set &&
!coalesce->pkt_rate_low.set &&
!coalesce->rx_coalesce_usecs_low.set &&
!coalesce->rx_max_coalesced_frames_low.set &&
!coalesce->tx_coalesce_usecs_low.set &&
!coalesce->tx_max_coalesced_frames_low.set &&
!coalesce->pkt_rate_high.set &&
!coalesce->rx_coalesce_usecs_high.set &&
!coalesce->rx_max_coalesced_frames_high.set &&
!coalesce->tx_coalesce_usecs_high.set &&
!coalesce->tx_max_coalesced_frames_high.set &&
!coalesce->rate_sample_interval.set)
return 0;
r = ethtool_connect(ethtool_fd);
if (r < 0)
return r;
strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
if (coalesce->use_adaptive_rx_coalesce >= 0)
UPDATE(ecmd.use_adaptive_rx_coalesce, (uint32_t) coalesce->use_adaptive_rx_coalesce, need_update);
if (coalesce->use_adaptive_tx_coalesce >= 0)
UPDATE(ecmd.use_adaptive_tx_coalesce, (uint32_t) coalesce->use_adaptive_tx_coalesce, need_update);
if (coalesce->rx_coalesce_usecs.set)
UPDATE(ecmd.rx_coalesce_usecs, coalesce->rx_coalesce_usecs.value, need_update);
if (coalesce->rx_max_coalesced_frames.set)
UPDATE(ecmd.rx_max_coalesced_frames, coalesce->rx_max_coalesced_frames.value, need_update);
if (coalesce->rx_coalesce_usecs_irq.set)
UPDATE(ecmd.rx_coalesce_usecs_irq, coalesce->rx_coalesce_usecs_irq.value, need_update);
if (coalesce->rx_max_coalesced_frames_irq.set)
UPDATE(ecmd.rx_max_coalesced_frames_irq, coalesce->rx_max_coalesced_frames_irq.value, need_update);
if (coalesce->tx_coalesce_usecs.set)
UPDATE(ecmd.tx_coalesce_usecs, coalesce->tx_coalesce_usecs.value, need_update);
if (coalesce->tx_max_coalesced_frames.set)
UPDATE(ecmd.tx_max_coalesced_frames, coalesce->tx_max_coalesced_frames.value, need_update);
if (coalesce->tx_coalesce_usecs_irq.set)
UPDATE(ecmd.tx_coalesce_usecs_irq, coalesce->tx_coalesce_usecs_irq.value, need_update);
if (coalesce->tx_max_coalesced_frames_irq.set)
UPDATE(ecmd.tx_max_coalesced_frames_irq, coalesce->tx_max_coalesced_frames_irq.value, need_update);
if (coalesce->stats_block_coalesce_usecs.set)
UPDATE(ecmd.stats_block_coalesce_usecs, coalesce->stats_block_coalesce_usecs.value, need_update);
if (coalesce->pkt_rate_low.set)
UPDATE(ecmd.pkt_rate_low, coalesce->pkt_rate_low.value, need_update);
if (coalesce->rx_coalesce_usecs_low.set)
UPDATE(ecmd.rx_coalesce_usecs_low, coalesce->rx_coalesce_usecs_low.value, need_update);
if (coalesce->rx_max_coalesced_frames_low.set)
UPDATE(ecmd.rx_max_coalesced_frames_low, coalesce->rx_max_coalesced_frames_low.value, need_update);
if (coalesce->tx_coalesce_usecs_low.set)
UPDATE(ecmd.tx_coalesce_usecs_low, coalesce->tx_coalesce_usecs_low.value, need_update);
if (coalesce->tx_max_coalesced_frames_low.set)
UPDATE(ecmd.tx_max_coalesced_frames_low, coalesce->tx_max_coalesced_frames_low.value, need_update);
if (coalesce->pkt_rate_high.set)
UPDATE(ecmd.pkt_rate_high, coalesce->pkt_rate_high.value, need_update);
if (coalesce->rx_coalesce_usecs_high.set)
UPDATE(ecmd.rx_coalesce_usecs_high, coalesce->rx_coalesce_usecs_high.value, need_update);
if (coalesce->rx_max_coalesced_frames_high.set)
UPDATE(ecmd.rx_max_coalesced_frames_high, coalesce->rx_max_coalesced_frames_high.value, need_update);
if (coalesce->tx_coalesce_usecs_high.set)
UPDATE(ecmd.tx_coalesce_usecs_high, coalesce->tx_coalesce_usecs_high.value, need_update);
if (coalesce->tx_max_coalesced_frames_high.set)
UPDATE(ecmd.tx_max_coalesced_frames_high, coalesce->tx_max_coalesced_frames_high.value, need_update);
if (coalesce->rate_sample_interval.set)
UPDATE(ecmd.rate_sample_interval, DIV_ROUND_UP(coalesce->rate_sample_interval.value, USEC_PER_SEC), need_update);
if (!need_update)
return 0;
ecmd.cmd = ETHTOOL_SCOALESCE;
r = ioctl(*ethtool_fd, SIOCETHTOOL, &ifr);
if (r < 0)
return -errno;
return 0;
}

View File

@ -4,9 +4,13 @@
#include <sys/prctl.h>
#include <sys/types.h>
#include "sd-event.h"
#include "capability-util.h"
#include "cpu-set-util.h"
#include "dropin.h"
#include "errno-list.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "macro.h"
@ -14,11 +18,14 @@
#include "missing_prctl.h"
#include "mkdir.h"
#include "path-util.h"
#include "process-util.h"
#include "rm-rf.h"
#if HAVE_SECCOMP
#include "seccomp-util.h"
#endif
#include "service.h"
#include "signal-util.h"
#include "static-destruct.h"
#include "stat-util.h"
#include "tests.h"
#include "unit.h"
@ -26,8 +33,11 @@
#include "util.h"
#include "virt.h"
static char *user_runtime_unit_dir = NULL;
static bool can_unshare;
STATIC_DESTRUCTOR_REGISTER(user_runtime_unit_dir, freep);
typedef void (*test_function_t)(Manager *m);
static int cld_dumped_to_killed(int code) {
@ -79,16 +89,15 @@ static void check_main_result(const char *file, unsigned line, const char *func,
exec_status_dump(&service->main_exec_status, stdout, "\t");
if (cld_dumped_to_killed(service->main_exec_status.code) != cld_dumped_to_killed(code_expected)) {
log_error("%s:%u:%s %s: exit code %d, expected %d",
file, line, func,
unit->id,
log_error("%s:%u:%s %s: can_unshare=%s: exit code %d, expected %d",
file, line, func, unit->id, yes_no(can_unshare),
service->main_exec_status.code, code_expected);
abort();
}
if (service->main_exec_status.status != status_expected) {
log_error("%s:%u:%s: %s: exit status %d, expected %d",
file, line, func, unit->id,
log_error("%s:%u:%s: %s: can_unshare=%s: exit status %d, expected %d",
file, line, func, unit->id, yes_no(can_unshare),
service->main_exec_status.status, status_expected);
abort();
}
@ -106,9 +115,8 @@ static void check_service_result(const char *file, unsigned line, const char *fu
service = SERVICE(unit);
if (service->result != result_expected) {
log_error("%s:%u:%s: %s: service end result %s, expected %s",
file, line, func,
unit->id,
log_error("%s:%u:%s: %s: can_unshare=%s: service end result %s, expected %s",
file, line, func, unit->id, yes_no(can_unshare),
service_result_to_string(service->result),
service_result_to_string(result_expected));
abort();
@ -408,6 +416,190 @@ static void test_exec_inaccessiblepaths(Manager *m) {
test(m, "exec-inaccessiblepaths-mount-propagation.service", can_unshare ? 0 : EXIT_FAILURE, CLD_EXITED);
}
static int on_spawn_io(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
char **result = userdata;
char buf[4096];
ssize_t l;
assert(s);
assert(fd >= 0);
l = read(fd, buf, sizeof(buf) - 1);
if (l < 0) {
if (errno == EAGAIN)
goto reenable;
return 0;
}
if (l == 0)
return 0;
buf[l] = '\0';
if (result)
assert_se(strextend(result, buf));
else
log_error("ldd: %s", buf);
reenable:
/* Re-enable the event source if we did not encounter EOF */
assert_se(sd_event_source_set_enabled(s, SD_EVENT_ONESHOT) >= 0);
return 0;
}
static int on_spawn_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
pid_t *pid = userdata;
assert(pid);
(void) kill(*pid, SIGKILL);
return 1;
}
static int on_spawn_sigchld(sd_event_source *s, const siginfo_t *si, void *userdata) {
int ret = -EIO;
assert(si);
if (si->si_code == CLD_EXITED)
ret = si->si_status;
sd_event_exit(sd_event_source_get_event(s), ret);
return 1;
}
static int find_libraries(const char *exec, char ***ret) {
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *sigchld_source = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *stdout_source = NULL;
_cleanup_(sd_event_source_unrefp) sd_event_source *stderr_source = NULL;
_cleanup_close_pair_ int outpipe[2] = {-1, -1}, errpipe[2] = {-1, -1};
_cleanup_strv_free_ char **libraries = NULL;
_cleanup_free_ char *result = NULL;
pid_t pid;
int r;
assert(exec);
assert(ret);
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0);
assert_se(pipe2(outpipe, O_NONBLOCK|O_CLOEXEC) == 0);
assert_se(pipe2(errpipe, O_NONBLOCK|O_CLOEXEC) == 0);
r = safe_fork("(spawn-ldd)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid);
assert_se(r >= 0);
if (r == 0) {
if (rearrange_stdio(-1, outpipe[1], errpipe[1]) < 0)
_exit(EXIT_FAILURE);
(void) close_all_fds(NULL, 0);
execlp("ldd", "ldd", exec, NULL);
_exit(EXIT_FAILURE);
}
outpipe[1] = safe_close(outpipe[1]);
errpipe[1] = safe_close(errpipe[1]);
assert_se(sd_event_new(&e) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, CLOCK_MONOTONIC,
10 * USEC_PER_SEC, USEC_PER_SEC, on_spawn_timeout, &pid) >= 0);
assert_se(sd_event_add_io(e, &stdout_source, outpipe[0], EPOLLIN, on_spawn_io, &result) >= 0);
assert_se(sd_event_source_set_enabled(stdout_source, SD_EVENT_ONESHOT) >= 0);
assert_se(sd_event_add_io(e, &stderr_source, errpipe[0], EPOLLIN, on_spawn_io, NULL) >= 0);
assert_se(sd_event_source_set_enabled(stderr_source, SD_EVENT_ONESHOT) >= 0);
assert_se(sd_event_add_child(e, &sigchld_source, pid, WEXITED, on_spawn_sigchld, NULL) >= 0);
/* SIGCHLD should be processed after IO is complete */
assert_se(sd_event_source_set_priority(sigchld_source, SD_EVENT_PRIORITY_NORMAL + 1) >= 0);
assert_se(sd_event_loop(e) >= 0);
_cleanup_strv_free_ char **v = NULL;
assert_se(strv_split_newlines_full(&v, result, 0) >= 0);
char **q;
STRV_FOREACH(q, v) {
_cleanup_free_ char *word = NULL;
const char *p = *q;
r = extract_first_word(&p, &word, NULL, 0);
assert_se(r >= 0);
if (r == 0)
continue;
if (path_is_absolute(word)) {
assert_se(strv_consume(&libraries, TAKE_PTR(word)) >= 0);
continue;
}
word = mfree(word);
r = extract_first_word(&p, &word, NULL, 0);
assert_se(r >= 0);
if (r == 0)
continue;
if (!streq_ptr(word, "=>"))
continue;
word = mfree(word);
r = extract_first_word(&p, &word, NULL, 0);
assert_se(r >= 0);
if (r == 0)
continue;
if (path_is_absolute(word)) {
assert_se(strv_consume(&libraries, TAKE_PTR(word)) >= 0);
continue;
}
}
*ret = TAKE_PTR(libraries);
return 0;
}
static void test_exec_mount_apivfs(Manager *m) {
_cleanup_free_ char *fullpath_touch = NULL, *fullpath_test = NULL, *data = NULL;
_cleanup_strv_free_ char **libraries = NULL, **libraries_test = NULL;
int r;
assert(user_runtime_unit_dir);
r = find_executable("touch", &fullpath_touch);
if (r < 0) {
log_notice_errno(r, "Skipping %s, could not find 'touch' command: %m", __func__);
return;
}
r = find_executable("test", &fullpath_test);
if (r < 0) {
log_notice_errno(r, "Skipping %s, could not find 'test' command: %m", __func__);
return;
}
assert_se(find_libraries(fullpath_touch, &libraries) >= 0);
assert_se(find_libraries(fullpath_test, &libraries_test) >= 0);
assert_se(strv_extend_strv(&libraries, libraries_test, true) >= 0);
assert_se(strextend(&data, "[Service]\n"));
assert_se(strextend(&data, "ExecStart=", fullpath_touch, " /aaa\n"));
assert_se(strextend(&data, "ExecStart=", fullpath_test, " -f /aaa\n"));
assert_se(strextend(&data, "BindReadOnlyPaths=", fullpath_touch, "\n"));
assert_se(strextend(&data, "BindReadOnlyPaths=", fullpath_test, "\n"));
char **p;
STRV_FOREACH(p, libraries)
assert_se(strextend(&data, "BindReadOnlyPaths=", *p, "\n"));
assert_se(write_drop_in(user_runtime_unit_dir, "exec-mount-apivfs-no.service", 10, "bind-mount", data) >= 0);
assert_se(mkdir_p("/tmp/test-exec-mount-apivfs-no/root", 0755) >= 0);
test(m, "exec-mount-apivfs-no.service", can_unshare ? 0 : EXIT_NAMESPACE, CLD_EXITED);
(void) rm_rf("/tmp/test-exec-mount-apivfs-no/root", REMOVE_ROOT|REMOVE_PHYSICAL);
}
static void test_exec_noexecpaths(Manager *m) {
test(m, "exec-noexecpaths-simple.service", can_unshare ? 0 : EXIT_FAILURE, CLD_EXITED);
@ -871,6 +1063,7 @@ int main(int argc, char *argv[]) {
entry(test_exec_ignoresigpipe),
entry(test_exec_inaccessiblepaths),
entry(test_exec_ioschedulingclass),
entry(test_exec_mount_apivfs),
entry(test_exec_noexecpaths),
entry(test_exec_oomscoreadjust),
entry(test_exec_passenvironment),
@ -931,10 +1124,12 @@ int main(int argc, char *argv[]) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
_cleanup_free_ char *unit_dir = NULL;
_cleanup_free_ char *unit_dir = NULL, *unit_paths = NULL;
assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0);
assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(user_runtime_unit_dir = path_join(runtime_dir, "systemd/user"));
assert_se(unit_paths = strjoin(unit_dir, ":", user_runtime_unit_dir));
assert_se(set_unit_path(unit_paths) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
* cases, otherwise (and if they are present in the environment),

View File

@ -142,6 +142,8 @@ int link_load_one(LinkConfigContext *ctx, const char *filename) {
.tx_flow_control = -1,
.autoneg_flow_control = -1,
.txqueuelen = UINT32_MAX,
.coalesce.use_adaptive_rx_coalesce = -1,
.coalesce.use_adaptive_tx_coalesce = -1,
};
for (i = 0; i < ELEMENTSOF(link->features); i++)

View File

@ -0,0 +1 @@
../TEST-01-BASIC/Makefile

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/17433"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
do_test "$@"

View File

@ -33,6 +33,8 @@ if install_tests
install_dir : testdata_dir)
install_subdir('testsuite-52.units',
install_dir : testdata_dir)
install_subdir('testsuite-63.units',
install_dir : testdata_dir)
testsuite08_dir = testdata_dir + '/testsuite-08.units'
install_data('testsuite-08.units/-.mount',

View File

@ -0,0 +1,15 @@
[Unit]
Description=Test for find_executable() with MountAPIVFS=no
[Service]
Type=oneshot
MountAPIVFS=false
PrivateDevices=false
PrivateMounts=true
PrivateTmp=false
PrivateUsers=false
ProtectControlGroups=false
ProtectKernelModules=false
ProtectKernelTunables=false
RootDirectory=/tmp/test-exec-mount-apivfs-no/root

View File

@ -148,6 +148,7 @@ BASICTOOLS=(
head
ionice
ip
ldd
ln
loadkeys
login

View File

@ -1155,7 +1155,8 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
f.write('[MACVTAP]\nMode=' + mode)
start_networkd()
self.wait_online(['macvtap99:degraded', 'test1:degraded'])
self.wait_online(['macvtap99:degraded',
'test1:carrier' if mode == 'passthru' else 'test1:degraded'])
output = check_output('ip -d link show macvtap99')
print(output)
@ -1172,7 +1173,8 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
f.write('[MACVLAN]\nMode=' + mode)
start_networkd()
self.wait_online(['macvlan99:degraded', 'test1:degraded'])
self.wait_online(['macvlan99:degraded',
'test1:carrier' if mode == 'passthru' else 'test1:degraded'])
output = check_output('ip -d link show test1')
print(output)
@ -1191,7 +1193,8 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
self.assertEqual(rc, 0)
time.sleep(1)
self.wait_online(['macvlan99:degraded', 'test1:degraded'])
self.wait_online(['macvlan99:degraded',
'test1:carrier' if mode == 'passthru' else 'test1:degraded'])
output = check_output('ip -d link show test1')
print(output)

View File

@ -1,6 +1,9 @@
[Unit]
Requires=test10.socket
ConditionPathExistsGlob=/tmp/nonexistent
# Make sure we hit the socket trigger limit in the test and not the service start limit.
StartLimitInterval=1000
StartLimitBurst=1000
[Service]
ExecStart=true

View File

@ -0,0 +1,2 @@
[Path]
PathExists=/tmp/test63

View File

@ -0,0 +1,5 @@
[Unit]
ConditionPathExists=!/tmp/nonexistent
[Service]
ExecStart=true

View File

@ -0,0 +1,16 @@
[Unit]
Description=TEST-63-ISSUE-17433
[Service]
ExecStartPre=rm -f /failed /testok
Type=oneshot
ExecStart=rm -f /tmp/nonexistent
ExecStart=systemctl start test63.path
ExecStart=touch /tmp/test63
# Make sure systemd has sufficient time to hit the start limit for test63.service.
ExecStart=sleep 2
ExecStart=sh -x -c 'test "$(systemctl show test63.service -P ActiveState)" = failed'
ExecStart=sh -x -c 'test "$(systemctl show test63.service -P Result)" = start-limit-hit'
ExecStart=sh -x -c 'test "$(systemctl show test63.path -P ActiveState)" = failed'
ExecStart=sh -x -c 'test "$(systemctl show test63.path -P Result)" = unit-start-limit-hit'
ExecStart=sh -x -c 'echo OK >/testok'