]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevd: use partition enumerator at one more place
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 15:17:46 +0000 (00:17 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 9 Sep 2022 15:48:34 +0000 (00:48 +0900)
No functional changes, just refactoring.

src/shared/blockdev-util.c
src/shared/blockdev-util.h
src/udev/udevd.c

index 7ffb619ac6f6cf3fe3b355d1a08c70fa05ea9a40..87c19d708695bec0341113e68a707f5b189c1506 100644 (file)
@@ -509,7 +509,7 @@ int block_device_resize_partition(
         return RET_NERRNO(ioctl(fd, BLKPG, &ba));
 }
 
-static int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) {
+int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
         const char *s;
         int r;
index fb041bf619606e4282fc3be561be42e6726b57d8..8df76ff30eedfc0dc55b689f45c9f8ad298f77d4 100644 (file)
@@ -36,5 +36,6 @@ int path_get_whole_disk(const char *path, bool backing, dev_t *ret);
 int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size);
 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 block_device_has_partitions(sd_device *dev);
index b179dfac3702fd6dd6ce72fcde336a676673fdad..c034e6a3cfe7e03aca6c9030f913d30a0c8d5cb3 100644 (file)
@@ -28,6 +28,7 @@
 #include "sd-event.h"
 
 #include "alloc-util.h"
+#include "blockdev-util.h"
 #include "cgroup-setup.h"
 #include "cgroup-util.h"
 #include "cpu-set-util.h"
@@ -1399,7 +1400,7 @@ static int synthesize_change(sd_device *dev) {
             streq_ptr(devtype, "disk") &&
             !startswith(sysname, "dm-")) {
                 _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
-                bool part_table_read = false, has_partitions = false;
+                bool part_table_read = false;
                 sd_device *d;
                 int fd;
 
@@ -1418,50 +1419,20 @@ static int synthesize_change(sd_device *dev) {
                 }
 
                 /* search for partitions */
-                r = sd_device_enumerator_new(&e);
+                r = partition_enumerator_new(dev, &e);
                 if (r < 0)
                         return r;
 
-                r = sd_device_enumerator_allow_uninitialized(e);
-                if (r < 0)
-                        return r;
-
-                r = sd_device_enumerator_add_match_parent(e, dev);
-                if (r < 0)
-                        return r;
-
-                r = sd_device_enumerator_add_match_subsystem(e, "block", true);
-                if (r < 0)
-                        return r;
-
-                FOREACH_DEVICE(e, d) {
-                        const char *t;
-
-                        if (sd_device_get_devtype(d, &t) < 0 || !streq(t, "partition"))
-                                continue;
-
-                        has_partitions = true;
-                        break;
-                }
-
                 /* 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 && has_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. */
                 (void) synthesize_change_one(dev, dev);
-
-                FOREACH_DEVICE(e, d) {
-                        const char *t;
-
-                        if (sd_device_get_devtype(d, &t) < 0 || !streq(t, "partition"))
-                                continue;
-
+                FOREACH_DEVICE(e, d)
                         (void) synthesize_change_one(dev, d);
-                }
-
         } else
                 (void) synthesize_change_one(dev, dev);