1
0
mirror of https://github.com/systemd/systemd synced 2025-10-07 04:34:45 +02:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Luca Boccassi
1270e56526
Merge pull request #19179 from anitazha/buildandtest
test-oomd-util: fix running in mkosi
2021-04-02 17:56:13 +01:00
Viktor Mihajlovski
a496a238e8 udev: fix slot based network names on s390
The s390 PCI driver assigns the hotplug slot name from the
function_id attribute of the PCI device using a 8 char hexadecimal
format to match the underlying firmware/hypervisor notation.

Further, there's always a one-to-one mapping between a PCI
function and a hotplug slot, as individual functions can
hot plugged even for multi-function devices.

As the generic matching code will always try to parse the slot
name in /sys/bus/pci/slots as a positive decimal number, either
a wrong value might be produced for ID_NET_NAME_SLOT if
the slot name consists of decimal numbers only, or none at all
if a character in the range from 'a' to 'f' is encountered.

Additionally, the generic code assumes that two interfaces
share a hotplug slot, if they differ only in the function part
of the PCI address. E.g., for an interface with the PCI address
dddd:bb:aa.f, it will match the device to the first slot with
an address dddd:bb:aa. As more than one slot may have this address
for the s390 PCI driver, the wrong slot may be selected.

To resolve this we're adding a new naming schema version with the
flag NAMING_SLOT_FUNCTION_ID, which enables the correct matching
of hotplug slots if the device has an attribute named function_id.
The ID_NET_NAME_SLOT property will only be produced if there's
a file /sys/bus/pci/slots/<slotname> where <slotname> matches
the value of /sys/bus/pci/devices/.../function_id in 8 char
hex notation.

Fixes #19016
See also #19078
2021-04-02 18:08:23 +02:00
Anita Zhang
080ca0d830 test-oomd-util: fix running in mkosi
When this test is run in mkosi, the previously tested cgroup that we write
xattrs into and the root cgroup are the same.

Since the root cgroup is a live cgroup anyways (vs. the test cgroups which are
remade each time) let's generate the expected preference values from reading
the xattrs instead of assuming it will be NONE.
2021-04-01 21:23:24 -07:00
Anita Zhang
ea460d7964 meson: link with libm for math functions
Fixes this error I got building on F33:
  /usr/bin/ld: test-random-util.p/src_test_test-random-util.c.o: undefined
  reference to symbol 'sqrt@@GLIBC_2.2.5'
  /usr/bin/ld: /usr/lib64/libm.so.6: error adding symbols: DSO missing
  from command line
2021-04-01 18:45:48 -07:00
6 changed files with 51 additions and 3 deletions

View File

@ -369,6 +369,16 @@
property.</para></listitem> property.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><constant>v249</constant></term>
<listitem><para>PCI hotplug slot names for the s390 PCI driver are a hexadecimal representation
of the <filename>function_id</filename> device attribute. This attribute is now used to build the
<varname>ID_NET_NAME_SLOT</varname>. Before that, all slot names were parsed as decimal
numbers, which could either result in an incorrect value of the <varname>ID_NET_NAME_SLOT</varname>
property or none at all.</para></listitem>
</varlistentry>
</variablelist> </variablelist>
<para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this <para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this

View File

@ -88,9 +88,10 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
_cleanup_hashmap_free_ Hashmap *h1 = NULL, *h2 = NULL; _cleanup_hashmap_free_ Hashmap *h1 = NULL, *h2 = NULL;
_cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *ctx = NULL; _cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *ctx = NULL;
_cleanup_free_ char *cgroup = NULL; _cleanup_free_ char *cgroup = NULL;
ManagedOOMPreference root_pref;
OomdCGroupContext *c1, *c2; OomdCGroupContext *c1, *c2;
bool test_xattrs; bool test_xattrs;
int r; int root_xattrs, r;
if (geteuid() != 0) if (geteuid() != 0)
return (void) log_tests_skipped("not root"); return (void) log_tests_skipped("not root");
@ -140,10 +141,16 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
ctx = oomd_cgroup_context_free(ctx); ctx = oomd_cgroup_context_free(ctx);
/* Test the root cgroup */ /* Test the root cgroup */
/* Root cgroup is live and not made on demand like the cgroup the test runs in. It can have varying
* xattrs set already so let's read in the booleans first to get the final preference value. */
root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_omit");
root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_OMIT : MANAGED_OOM_PREFERENCE_NONE;
root_xattrs = cg_get_xattr_bool(SYSTEMD_CGROUP_CONTROLLER, "", "user.oomd_avoid");
root_pref = root_xattrs > 0 ? MANAGED_OOM_PREFERENCE_AVOID : MANAGED_OOM_PREFERENCE_NONE;
assert_se(oomd_cgroup_context_acquire("", &ctx) == 0); assert_se(oomd_cgroup_context_acquire("", &ctx) == 0);
assert_se(streq(ctx->path, "/")); assert_se(streq(ctx->path, "/"));
assert_se(ctx->current_memory_usage > 0); assert_se(ctx->current_memory_usage > 0);
assert_se(ctx->preference == MANAGED_OOM_PREFERENCE_NONE); assert_se(ctx->preference == root_pref);
/* Test hashmap inserts */ /* Test hashmap inserts */
assert_se(h1 = hashmap_new(&oomd_cgroup_ctx_hash_ops)); assert_se(h1 = hashmap_new(&oomd_cgroup_ctx_hash_ops));

View File

@ -13,6 +13,7 @@ static const NamingScheme naming_schemes[] = {
{ "v243", NAMING_V243 }, { "v243", NAMING_V243 },
{ "v245", NAMING_V245 }, { "v245", NAMING_V245 },
{ "v247", NAMING_V247 }, { "v247", NAMING_V247 },
{ "v249", NAMING_V249 },
/* … add more schemes here, as the logic to name devices is updated … */ /* … add more schemes here, as the logic to name devices is updated … */
}; };

View File

@ -32,6 +32,7 @@ typedef enum NamingSchemeFlags {
NAMING_LABEL_NOPREFIX = 1 << 7, /* Don't prepend ID_NET_LABEL_ONBOARD with interface type prefix */ NAMING_LABEL_NOPREFIX = 1 << 7, /* Don't prepend ID_NET_LABEL_ONBOARD with interface type prefix */
NAMING_NSPAWN_LONG_HASH = 1 << 8, /* Shorten nspawn interfaces by including 24bit hash, instead of simple truncation */ NAMING_NSPAWN_LONG_HASH = 1 << 8, /* Shorten nspawn interfaces by including 24bit hash, instead of simple truncation */
NAMING_BRIDGE_NO_SLOT = 1 << 9, /* Don't use PCI hotplug slot information if the corresponding device is a PCI bridge */ NAMING_BRIDGE_NO_SLOT = 1 << 9, /* Don't use PCI hotplug slot information if the corresponding device is a PCI bridge */
NAMING_SLOT_FUNCTION_ID = 1 << 10, /* Use function_id if present to identify PCI hotplug slots */
/* And now the masks that combine the features above */ /* And now the masks that combine the features above */
NAMING_V238 = 0, NAMING_V238 = 0,
@ -41,6 +42,7 @@ typedef enum NamingSchemeFlags {
NAMING_V243 = NAMING_V241 | NAMING_NETDEVSIM | NAMING_LABEL_NOPREFIX, NAMING_V243 = NAMING_V241 | NAMING_NETDEVSIM | NAMING_LABEL_NOPREFIX,
NAMING_V245 = NAMING_V243 | NAMING_NSPAWN_LONG_HASH, NAMING_V245 = NAMING_V243 | NAMING_NSPAWN_LONG_HASH,
NAMING_V247 = NAMING_V245 | NAMING_BRIDGE_NO_SLOT, NAMING_V247 = NAMING_V245 | NAMING_BRIDGE_NO_SLOT,
NAMING_V249 = NAMING_V247 | NAMING_SLOT_FUNCTION_ID,
_NAMING_SCHEME_FLAGS_INVALID = -EINVAL, _NAMING_SCHEME_FLAGS_INVALID = -EINVAL,
} NamingSchemeFlags; } NamingSchemeFlags;

View File

@ -158,7 +158,9 @@ tests += [
[['src/test/test-fstab-util.c']], [['src/test/test-fstab-util.c']],
[['src/test/test-random-util.c']], [['src/test/test-random-util.c'],
[],
[libm]],
[['src/test/test-format-table.c']], [['src/test/test-format-table.c']],

View File

@ -345,6 +345,32 @@ static int dev_pci_slot(sd_device *dev, struct netnames *names) {
if (sd_device_get_sysname(hotplug_slot_dev, &sysname) < 0) if (sd_device_get_sysname(hotplug_slot_dev, &sysname) < 0)
continue; continue;
/* The <sysname>/function_id attribute is unique to the s390 PCI driver.
If present, we know that the slot's directory name for this device is
/sys/bus/pci/XXXXXXXX/ where XXXXXXXX is the fixed length 8 hexadecimal
character string representation of function_id.
Therefore we can short cut here and just check for the existence of
the slot directory. As this directory has to exist, we're emitting a
debug message for the unlikely case it's not found.
Note that the domain part of doesn't belong to the slot name here
because there's a 1-to-1 relationship between PCI function and its hotplug
slot.
*/
if (naming_scheme_has(NAMING_SLOT_FUNCTION_ID) &&
sd_device_get_sysattr_value(hotplug_slot_dev, "function_id", &attr) >= 0) {
int function_id;
_cleanup_free_ char *str;
if (safe_atoi(attr, &function_id) >= 0 &&
asprintf(&str, "%s/%08x/", slots, function_id) >= 0 &&
access(str, R_OK) == 0) {
hotplug_slot = function_id;
domain = 0;
} else
log_debug("No matching slot for function_id (%s).", attr);
break;
}
FOREACH_DIRENT_ALL(dent, dir, break) { FOREACH_DIRENT_ALL(dent, dir, break) {
int i; int i;
char str[PATH_MAX]; char str[PATH_MAX];