]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: switch over to rereadpt() rather than raw BLKRRPART
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Oct 2025 13:21:44 +0000 (15:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Oct 2025 20:56:01 +0000 (22:56 +0200)
Fixes: #38672
src/shared/blockdev-util.c
src/shared/blockdev-util.h
src/udev/udev-watch.c

index 4a9567ce5144eeea4af286f8beebe4be21d87c2f..d86238b84e6d3d5dbc97740a3b9b33e617af113e 100644 (file)
@@ -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;
 
index 6c60c89e0cdb4c79b0b9ebc344b5cd64d156b644..3a481dd396493a0b85834d86306e41bc800d03c4 100644 (file)
@@ -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);
index c8f555ef71a7411e8f68cbfa011b1734c068e6d6..c421063438cb0bd94efa59a6f6b76d27c4810003 100644 (file)
@@ -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);
         }