]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: move device_has_block_children() to blockdev-util.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 5 Sep 2022 20:01:34 +0000 (05:01 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Sep 2022 11:45:24 +0000 (20:45 +0900)
As the function is not only for loopback block device.

No actual code changes, just refactoring.

src/shared/blockdev-util.c
src/shared/blockdev-util.h
src/shared/loop-util.c

index 9f3c9053dd959aa4b4e202881f77ae03c5e9d2d4..66807c673d1f3c13bf54483895d354e72a6b0360 100644 (file)
@@ -621,3 +621,18 @@ int block_device_remove_all_partitions(sd_device *dev, int fd) {
 
         return k;
 }
+
+int block_device_has_partitions(sd_device *dev) {
+        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
+        int r;
+
+        assert(dev);
+
+        /* Checks if the specified device currently has partitions. */
+
+        r = partition_enumerator_new(dev, &e);
+        if (r < 0)
+                return r;
+
+        return !!sd_device_enumerator_get_device_first(e);
+}
index e63c447331ccbc4fbdbf4178ececcfea96995128..fb041bf619606e4282fc3be561be42e6726b57d8 100644 (file)
@@ -37,3 +37,4 @@ int block_device_add_partition(int fd, const char *name, int nr, uint64_t start,
 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 block_device_remove_all_partitions(sd_device *dev, int fd);
+int block_device_has_partitions(sd_device *dev);
index 56574ee7f20dc936ff9602ef13385ffd6ea62a84..b5c16b0b0ef1b134374bd4b04fb8aba988a05aa7 100644 (file)
@@ -70,53 +70,6 @@ static int get_current_uevent_seqnum(uint64_t *ret) {
         return 0;
 }
 
-static int device_has_block_children(sd_device *d) {
-        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
-        const char *main_ss, *main_dt;
-        int r;
-
-        assert(d);
-
-        /* Checks if the specified device currently has block device children (i.e. partition block
-         * devices). */
-
-        r = sd_device_get_subsystem(d, &main_ss);
-        if (r < 0)
-                return r;
-
-        if (!streq(main_ss, "block"))
-                return -EINVAL;
-
-        r = sd_device_get_devtype(d, &main_dt);
-        if (r < 0)
-                return r;
-
-        if (!streq(main_dt, "disk")) /* Refuse invocation on partition block device, insist on "whole" device */
-                return -EINVAL;
-
-        r = sd_device_enumerator_new(&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, d);
-        if (r < 0)
-                return r;
-
-        r = sd_device_enumerator_add_match_subsystem(e, "block", /* match = */ true);
-        if (r < 0)
-                return r;
-
-        r = sd_device_enumerator_add_match_property(e, "DEVTYPE", "partition");
-        if (r < 0)
-                return r;
-
-        return !!sd_device_enumerator_get_device_first(e);
-}
-
 static int open_lock_fd(int primary_fd, int operation) {
         int lock_fd;
 
@@ -168,7 +121,7 @@ static int loop_configure(
          * superficially is detached but still has partition block devices associated for it. Let's then
          * manually remove the partitions via BLKPG, and tell the caller we did that via EUCLEAN, so they try
          * again. */
-        r = device_has_block_children(dev);
+        r = block_device_has_partitions(dev);
         if (r < 0)
                 return r;
         if (r > 0) {