From: Lennart Poettering Date: Mon, 20 Oct 2025 13:21:44 +0000 (+0200) Subject: udev: switch over to rereadpt() rather than raw BLKRRPART X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa47d8ade18cc4a079fef5a1aaa37d763507104e;p=thirdparty%2Fsystemd.git udev: switch over to rereadpt() rather than raw BLKRRPART Fixes: #38672 --- diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index 4a9567ce514..d86238b84e6 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -804,27 +804,6 @@ int block_device_remove_all_partitions(sd_device *dev, int fd) { return k < 0 ? k : has_partitions; } - -int blockdev_reread_partition_table(sd_device *dev) { - _cleanup_close_ int fd = -EBADF; - - assert(dev); - - /* Try to re-read the partition table. This only succeeds if none of the devices is busy. */ - - fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); - if (fd < 0) - return fd; - - if (flock(fd, LOCK_EX|LOCK_NB) < 0) - return -errno; - - if (ioctl(fd, BLKRRPART, 0) < 0) - return -errno; - - return 0; -} - int blockdev_get_sector_size(int fd, uint32_t *ret) { int ssz = 0; diff --git a/src/shared/blockdev-util.h b/src/shared/blockdev-util.h index 6c60c89e0cd..3a481dd3964 100644 --- a/src/shared/blockdev-util.h +++ b/src/shared/blockdev-util.h @@ -51,7 +51,6 @@ int block_device_remove_partition(int fd, const char *name, int nr); int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size); int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret); int block_device_remove_all_partitions(sd_device *dev, int fd); -int blockdev_reread_partition_table(sd_device *dev); int blockdev_get_sector_size(int fd, uint32_t *ret); int blockdev_get_device_size(int fd, uint64_t *ret); diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index c8f555ef71a..c421063438c 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -22,6 +22,7 @@ #include "parse-util.h" #include "pidref.h" #include "process-util.h" +#include "reread-partition-table.h" #include "rm-rf.h" #include "set.h" #include "signal-util.h" @@ -161,36 +162,6 @@ static int synthesize_change_one(sd_device *dev, sd_device *target) { return 0; } -static int synthesize_change_all(sd_device *dev) { - int r; - - assert(dev); - - r = blockdev_reread_partition_table(dev); - if (r < 0) - log_device_debug_errno(dev, r, "Failed to re-read partition table, ignoring: %m"); - bool part_table_read = r >= 0; - - /* search for partitions */ - _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - r = partition_enumerator_new(dev, &e); - if (r < 0) - return log_device_debug_errno(dev, r, "Failed to initialize partition enumerator, ignoring: %m"); - - /* We have partitions and re-read the table, the kernel already sent out a "change" - * event for the disk, and "remove/add" for all partitions. */ - if (part_table_read && sd_device_enumerator_get_device_first(e)) - return 0; - - /* We have partitions but re-reading the partition table did not work, synthesize - * "change" for the disk and all partitions. */ - r = synthesize_change_one(dev, dev); - FOREACH_DEVICE(e, d) - RET_GATHER(r, synthesize_change_one(dev, d)); - - return r; -} - static int synthesize_change_child_handler(sd_event_source *s, const siginfo_t *si, void *userdata) { Manager *manager = ASSERT_PTR(userdata); assert(s); @@ -226,7 +197,7 @@ static int synthesize_change(Manager *manager, sd_device *dev) { return r; if (r == 0) { /* child */ - (void) synthesize_change_all(dev); + (void) reread_partition_table(dev, REREADPT_FORCE_UEVENT|REREADPT_BSD_LOCK); _exit(EXIT_SUCCESS); }