From: Yu Watanabe Date: Thu, 10 Oct 2024 01:36:46 +0000 (+0900) Subject: udev-node: drop workaround for by-diskseq symlinks X-Git-Tag: v257-rc1~247^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b364af59f0afb01132a497abeb57dd20a6f357b1;p=thirdparty%2Fsystemd.git udev-node: drop workaround for by-diskseq symlinks This effectively reverts 09373c1a50297079e6b0447ea97af4e9a60f77fa, as stack directories and lock files are removed by udev workers on unlocking. --- diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 589a56e5025..6d917c4dd22 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -448,85 +448,6 @@ static int node_get_current(const char *slink, int dirfd, char **ret_id, int *re return 0; } -static int link_update_diskseq(sd_device *dev, const char *slink, bool add) { - _cleanup_free_ char *buf = NULL; - const char *fname, *diskseq; - int r; - - assert(dev); - assert(slink); - - if (!device_in_subsystem(dev, "block")) - return 0; - - fname = path_startswith(slink, "/dev/disk/by-diskseq"); - if (isempty(fname)) - return 0; - - if (device_is_devtype(dev, "partition")) { - _cleanup_free_ char *suffix = NULL; - const char *partn, *p; - - /* Check if the symlink has an expected suffix "-part%n". See 60-persistent-storage.rules. */ - - r = sd_device_get_sysnum(dev, &partn); - if (r < 0) { - /* Cannot verify the symlink is owned by this device. Let's create the stack directory for the symlink. */ - log_device_debug_errno(dev, r, "Failed to get sysnum, but symlink '%s' is requested, ignoring: %m", slink); - return 0; - } - - suffix = strjoin("-part", partn); - if (!suffix) - return -ENOMEM; - - p = endswith(fname, suffix); - if (!p) { - log_device_debug(dev, "Unexpected by-diskseq symlink '%s' is requested, proceeding anyway.", slink); - return 0; - } - - buf = strndup(fname, p - fname); - if (!buf) - return -ENOMEM; - - fname = buf; - } - - /* Check if the diskseq part of the symlink is in digits. */ - if (!in_charset(fname, DIGITS)) { - log_device_debug(dev, "Unexpected by-diskseq symlink '%s' is requested, proceeding anyway.", slink); - return 0; /* unexpected by-diskseq symlink */ - } - - /* On removal, we cannot verify the diskseq. Skipping further check below. */ - if (!add) { - r = node_remove_symlink(dev, slink); - if (r < 0) - return r; - - return 1; /* done */ - } - - /* Check if the diskseq matches with the DISKSEQ property. */ - r = sd_device_get_property_value(dev, "DISKSEQ", &diskseq); - if (r < 0) { - log_device_debug_errno(dev, r, "Failed to get DISKSEQ property, but symlink '%s' is requested, ignoring: %m", slink); - return 0; - } - - if (!streq(fname, diskseq)) { - log_device_debug(dev, "Unexpected by-diskseq symlink '%s' is requested (DISKSEQ=%s), proceeding anyway.", slink, diskseq); - return 0; - } - - r = node_create_symlink(dev, /* devnode = */ NULL, slink); - if (r < 0) - return r; - - return 1; /* done */ -} - static int link_update(sd_device *dev, const char *slink, bool add) { /* On cleaning up, * 1. close the stack directory, @@ -542,10 +463,6 @@ static int link_update(sd_device *dev, const char *slink, bool add) { assert(dev); assert(slink); - r = link_update_diskseq(dev, slink, add); - if (r != 0) - return r; - r = stack_directory_open_and_lock(dev, slink, &dirpath, &dirfd, &lockfile); if (r < 0) return r; diff --git a/test/units/TEST-17-UDEV.diskseq.sh b/test/units/TEST-17-UDEV.diskseq.sh index 0cb717fbd0c..1aafbe9834c 100755 --- a/test/units/TEST-17-UDEV.diskseq.sh +++ b/test/units/TEST-17-UDEV.diskseq.sh @@ -43,15 +43,15 @@ systemctl daemon-reload udevadm settle -# If an initrd from the host is used, stack directories for by-diskseq symlinks -# may already exist. Save the number of the directories here. -NUM_DISKSEQ_EXPECTED=$(ls /run/udev/links | grep -c by-diskseq || :) +# Save the current number of the directories. +NUM_DISKSEQ=$(ls /run/udev/links/ | grep -c by-diskseq || :) systemctl start --no-block test-diskseq.service for _ in {0..100}; do sleep .1 - assert_eq "$(ls /run/udev/links | grep -c by-diskseq || :)" "$NUM_DISKSEQ_EXPECTED" + n=$(ls /run/udev/links/ | grep -c by-diskseq || :) + (( n <= NUM_DISKSEQ + 1 )) done exit 0