1
0
mirror of https://github.com/systemd/systemd synced 2025-11-06 18:34:46 +01:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Lennart Poettering
fbbe240b21
Merge pull request #14605 from aerusso/pulls/x-systemd-wantedby-requiredby
Implemented x-systemd.{required,wanted}-by= options
2020-01-21 19:21:49 +01:00
Andreas Rammhold
a15e1a5df0 man: fix typo in systemd.netdev Xfrm example
The first section header in that example should probably be `[NetDev]` and not `[Xfrm]`.
2020-01-21 18:57:57 +01:00
Yu Watanabe
5029912157 network,udev: use uint64_t for bit rate
Fixes #14620.
2020-01-21 16:51:19 +01:00
Antonio Russo
be02c1cf42 Implemented x-systemd.{required,wanted}-by= options
Teaches systemd-fstab-generator these two unit options,
creating appropriate dependencies on the generated .mount
units.  When used, they override any other automatically
generated dependencies, such as local-fs.target, and are
NOT suppressed by noauto.  The new options are ignored for
/, in the same way that noauto is ignored.

Fixes: #14380
Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
2020-01-21 06:54:34 -07:00
Antonio Russo
81248e7f3e Documentation update for x-systemd.{before,after}
A minor clarification in the manual page is made.

Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
2020-01-20 21:05:08 -07:00
16 changed files with 86 additions and 49 deletions

View File

@ -211,9 +211,9 @@
<term><option>x-systemd.before=</option></term>
<term><option>x-systemd.after=</option></term>
<listitem><para>Configures a <varname>Before=</varname>
dependency or <varname>After=</varname> between the created
mount unit and another systemd unit, such as a mount unit.
<listitem><para>In the created mount unit, configures a
<varname>Before=</varname> or <varname>After=</varname>
dependency on another systemd unit, such as a mount unit.
The argument should be a unit name or an absolute path
to a mount point. This option may be specified more than once.
This option is particularly useful for mount point declarations
@ -226,6 +226,21 @@
for details.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>x-systemd.wanted-by=</option></term>
<term><option>x-systemd.required-by=</option></term>
<listitem><para>In the created mount unit, configures a
<varname>WantedBy=</varname> or <varname>RequiredBy=</varname>
dependency on another unit. This option may be
specified more than once. If this is specified, the normal
automatic dependencies on the created mount unit, e.g.,
<filename>local-fs.target</filename>, are not automatically
created. See <varname>WantedBy=</varname> and <varname>RequiredBy=</varname> in
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>x-systemd.requires-mounts-for=</option></term>

View File

@ -2112,7 +2112,7 @@ Endpoint=wireguard.example.com:51820</programlisting>
<example>
<title>/etc/systemd/network/27-xfrm.netdev</title>
<programlisting>[Xfrm]
<programlisting>[NetDev]
Name=xfrm0
Kind=xfrm

View File

@ -4771,7 +4771,7 @@ void unit_dump_config_items(FILE *f) {
{ config_parse_unsigned, "UNSIGNED" },
{ config_parse_iec_size, "SIZE" },
{ config_parse_iec_uint64, "SIZE" },
{ config_parse_si_size, "SIZE" },
{ config_parse_si_uint64, "SIZE" },
{ config_parse_bool, "BOOLEAN" },
{ config_parse_string, "STRING" },
{ config_parse_path, "PATH" },

View File

@ -306,6 +306,7 @@ static int add_mount(
*automount_name = NULL,
*filtered = NULL,
*where_escaped = NULL;
_cleanup_strv_free_ char **wanted_by = NULL, **required_by = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
@ -327,6 +328,14 @@ static int add_mount(
mount_point_ignore(where))
return 0;
r = fstab_extract_values(opts, "x-systemd.wanted-by", &wanted_by);
if (r < 0)
return r;
r = fstab_extract_values(opts, "x-systemd.required-by", &required_by);
if (r < 0)
return r;
if (path_equal(where, "/")) {
if (flags & NOAUTO)
log_warning("Ignoring \"noauto\" for root device");
@ -334,7 +343,13 @@ static int add_mount(
log_warning("Ignoring \"nofail\" for root device");
if (flags & AUTOMOUNT)
log_warning("Ignoring automount option for root device");
if (!strv_isempty(wanted_by))
log_warning("Ignoring \"x-systemd.wanted-by=\" for root device");
if (!strv_isempty(required_by))
log_warning("Ignoring \"x-systemd.required-by=\" for root device");
required_by = strv_free(required_by);
wanted_by = strv_free(wanted_by);
SET_FLAG(flags, NOAUTO | NOFAIL | AUTOMOUNT, false);
}
@ -451,14 +466,28 @@ static int add_mount(
return r;
}
if (!(flags & NOAUTO) && !(flags & AUTOMOUNT)) {
r = generator_add_symlink(dest, post,
(flags & NOFAIL) ? "wants" : "requires", name);
if (r < 0)
return r;
}
if (!FLAGS_SET(flags, AUTOMOUNT)) {
if (!FLAGS_SET(flags, NOAUTO) && strv_isempty(wanted_by) && strv_isempty(required_by)) {
r = generator_add_symlink(dest, post,
(flags & NOFAIL) ? "wants" : "requires", name);
if (r < 0)
return r;
} else {
char **s;
if (flags & AUTOMOUNT) {
STRV_FOREACH(s, wanted_by) {
r = generator_add_symlink(dest, *s, "wants", name);
if (r < 0)
return r;
}
STRV_FOREACH(s, required_by) {
r = generator_add_symlink(dest, *s, "requires", name);
if (r < 0)
return r;
}
}
} else {
r = unit_name_from_path(where, ".automount", &automount_name);
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");

View File

@ -170,7 +170,7 @@ typedef struct LinkInfo {
/* ethtool info */
int autonegotiation;
size_t speed;
uint64_t speed;
Duplex duplex;
NetDevPort port;
@ -1495,7 +1495,7 @@ static int link_status_one(
r = table_add_many(table,
TABLE_EMPTY,
TABLE_STRING, "Speed:",
TABLE_BPS, (uint64_t) info->speed);
TABLE_BPS, info->speed);
if (r < 0)
return table_log_add_error(r);
}

View File

@ -101,7 +101,7 @@ static int link_set_can(Link *link) {
};
if (link->network->can_bitrate > UINT32_MAX) {
log_link_error(link, "bitrate (%zu) too big.", link->network->can_bitrate);
log_link_error(link, "bitrate (%" PRIu64 ") too big.", link->network->can_bitrate);
return -ERANGE;
}

View File

@ -245,7 +245,7 @@ IPv6Prefix.ValidLifetimeSec, config_parse_prefix_lifetime,
IPv6Prefix.PreferredLifetimeSec, config_parse_prefix_lifetime, 0, 0
IPv6RoutePrefix.Route, config_parse_route_prefix, 0, 0
IPv6RoutePrefix.LifetimeSec, config_parse_route_prefix_lifetime, 0, 0
CAN.BitRate, config_parse_si_size, 0, offsetof(Network, can_bitrate)
CAN.BitRate, config_parse_si_uint64, 0, offsetof(Network, can_bitrate)
CAN.SamplePoint, config_parse_permille, 0, offsetof(Network, can_sample_point)
CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us)
CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling)

View File

@ -194,7 +194,7 @@ struct Network {
uint32_t br_untagged_bitmap[BRIDGE_VLAN_BITMAP_LEN];
/* CAN support */
size_t can_bitrate;
uint64_t can_bitrate;
unsigned can_sample_point;
usec_t can_restart_us;
int can_triple_sampling;

View File

@ -555,7 +555,7 @@ int config_parse_iec_size(const char* unit,
return 0;
}
int config_parse_si_size(
int config_parse_si_uint64(
const char* unit,
const char *filename,
unsigned line,
@ -567,8 +567,7 @@ int config_parse_si_size(
void *data,
void *userdata) {
size_t *sz = data;
uint64_t v;
uint64_t *sz = data;
int r;
assert(filename);
@ -576,15 +575,12 @@ int config_parse_si_size(
assert(rvalue);
assert(data);
r = parse_size(rvalue, 1000, &v);
if (r >= 0 && (uint64_t) (size_t) v != v)
r = -ERANGE;
r = parse_size(rvalue, 1000, sz);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue);
return 0;
}
*sz = (size_t) v;
return 0;
}

View File

@ -118,7 +118,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_uint32);
CONFIG_PARSER_PROTOTYPE(config_parse_uint64);
CONFIG_PARSER_PROTOTYPE(config_parse_double);
CONFIG_PARSER_PROTOTYPE(config_parse_iec_size);
CONFIG_PARSER_PROTOTYPE(config_parse_si_size);
CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64);
CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64);
CONFIG_PARSER_PROTOTYPE(config_parse_bool);
CONFIG_PARSER_PROTOTYPE(config_parse_tristate);

View File

@ -177,7 +177,7 @@ int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret) {
}
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
int *ret_autonegotiation, size_t *ret_speed,
int *ret_autonegotiation, uint64_t *ret_speed,
Duplex *ret_duplex, NetDevPort *ret_port) {
struct ethtool_cmd ecmd = {
.cmd = ETHTOOL_GSET,
@ -734,7 +734,7 @@ int ethtool_set_glinksettings(
const char *ifname,
int autonegotiation,
uint32_t advertise[static N_ADVERTISE],
size_t speed,
uint64_t speed,
Duplex duplex,
NetDevPort port) {
_cleanup_free_ struct ethtool_link_usettings *u = NULL;

View File

@ -90,7 +90,7 @@ typedef struct netdev_ring_param {
int ethtool_get_driver(int *ethtool_fd, const char *ifname, char **ret);
int ethtool_get_link_info(int *ethtool_fd, const char *ifname,
int *ret_autonegotiation, size_t *ret_speed,
int *ret_autonegotiation, uint64_t *ret_speed,
Duplex *ret_duplex, NetDevPort *ret_port);
int ethtool_get_permanent_macaddr(int *ethtool_fd, const char *ifname, struct ether_addr *ret);
int ethtool_set_speed(int *ethtool_fd, const char *ifname, unsigned speed, Duplex duplex);
@ -99,7 +99,7 @@ int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, netdev_ring
int ethtool_set_features(int *ethtool_fd, const char *ifname, int *features);
int ethtool_set_glinksettings(int *ethtool_fd, const char *ifname,
int autonegotiation, uint32_t advertise[static N_ADVERTISE],
size_t speed, Duplex duplex, NetDevPort port);
uint64_t speed, Duplex duplex, NetDevPort port);
int ethtool_set_channels(int *ethtool_fd, const char *ifname, netdev_channels *channels);
const char *duplex_to_string(Duplex d) _const_;

View File

@ -38,11 +38,11 @@ static void test_config_parse_iec_size_one(const char *rvalue, size_t expected)
assert_se(expected == iec_size);
}
static void test_config_parse_si_size_one(const char *rvalue, size_t expected) {
size_t si_size = 0;
static void test_config_parse_si_uint64_one(const char *rvalue, uint64_t expected) {
uint64_t si_uint64 = 0;
assert_se(config_parse_si_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_size, NULL) >= 0);
assert_se(expected == si_size);
assert_se(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL) >= 0);
assert_se(expected == si_uint64);
}
static void test_config_parse_int_one(const char *rvalue, int expected) {
@ -125,17 +125,17 @@ static void test_config_parse_iec_size(void) {
test_config_parse_iec_size_one("garbage", 0);
}
static void test_config_parse_si_size(void) {
test_config_parse_si_size_one("1024", 1024);
test_config_parse_si_size_one("2K", 2000);
test_config_parse_si_size_one("10M", 10 * 1000 * 1000);
test_config_parse_si_size_one("1G", 1 * 1000 * 1000 * 1000);
test_config_parse_si_size_one("0G", 0);
test_config_parse_si_size_one("0", 0);
static void test_config_parse_si_uint64(void) {
test_config_parse_si_uint64_one("1024", 1024);
test_config_parse_si_uint64_one("2K", 2000);
test_config_parse_si_uint64_one("10M", 10 * 1000 * 1000);
test_config_parse_si_uint64_one("1G", 1 * 1000 * 1000 * 1000);
test_config_parse_si_uint64_one("0G", 0);
test_config_parse_si_uint64_one("0", 0);
test_config_parse_si_size_one("-982", 0);
test_config_parse_si_size_one("49874444198739873000000G", 0);
test_config_parse_si_size_one("garbage", 0);
test_config_parse_si_uint64_one("-982", 0);
test_config_parse_si_uint64_one("49874444198739873000000G", 0);
test_config_parse_si_uint64_one("garbage", 0);
}
static void test_config_parse_int(void) {
@ -391,7 +391,7 @@ int main(int argc, char **argv) {
test_config_parse_log_level();
test_config_parse_log_facility();
test_config_parse_iec_size();
test_config_parse_si_size();
test_config_parse_si_uint64();
test_config_parse_int();
test_config_parse_unsigned();
test_config_parse_strv();

View File

@ -40,7 +40,7 @@ Link.AlternativeName, config_parse_ifnames, 1,
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.MTUBytes, config_parse_mtu, AF_UNSPEC, offsetof(link_config, mtu)
Link.BitsPerSecond, config_parse_si_size, 0, offsetof(link_config, speed)
Link.BitsPerSecond, config_parse_si_uint64, 0, offsetof(link_config, speed)
Link.Duplex, config_parse_duplex, 0, offsetof(link_config, duplex)
Link.AutoNegotiation, config_parse_tristate, 0, offsetof(link_config, autonegotiation)
Link.WakeOnLan, config_parse_wol, 0, offsetof(link_config, wol)

View File

@ -160,9 +160,6 @@ int link_load_one(link_config_ctx *ctx, const char *filename) {
if (r < 0)
return r;
if (link->speed > UINT_MAX)
return -ERANGE;
if (set_isempty(link->match_mac) && set_isempty(link->match_permanent_mac) &&
strv_isempty(link->match_path) && strv_isempty(link->match_driver) && strv_isempty(link->match_type) &&
strv_isempty(link->match_name) && strv_isempty(link->match_property) && !link->conditions)

View File

@ -53,7 +53,7 @@ struct link_config {
char **alternative_names;
char *alias;
uint32_t mtu;
size_t speed;
uint64_t speed;
Duplex duplex;
int autonegotiation;
uint32_t advertise[N_ADVERTISE];