]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loop-util: use filter provided by sd_device_enumerator
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 27 Aug 2022 06:24:49 +0000 (15:24 +0900)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 27 Aug 2022 11:32:11 +0000 (11:32 +0000)
src/shared/loop-util.c

index a5ad914577071d7acb182779eafce2a648ddeed6..fa71086741dbd20029d481e4f1a453c5031f84a8 100644 (file)
@@ -73,7 +73,6 @@ static int get_current_uevent_seqnum(uint64_t *ret) {
 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;
-        sd_device *q;
         int r;
 
         assert(d);
@@ -107,35 +106,15 @@ static int device_has_block_children(sd_device *d) {
         if (r < 0)
                 return r;
 
-        FOREACH_DEVICE(e, q) {
-                const char *ss, *dt;
-
-                r = sd_device_get_subsystem(q, &ss);
-                if (r < 0) {
-                        log_device_debug_errno(q, r, "Failed to get subsystem of child, ignoring: %m");
-                        continue;
-                }
-
-                if (!streq(ss, "block")) {
-                        log_device_debug(q, "Skipping child that is not a block device (subsystem=%s).", ss);
-                        continue;
-                }
-
-                r = sd_device_get_devtype(q, &dt);
-                if (r < 0) {
-                        log_device_debug_errno(q, r, "Failed to get devtype of child, ignoring: %m");
-                        continue;
-                }
-
-                if (!streq(dt, "partition")) {
-                        log_device_debug(q, "Skipping non-partition child (devtype=%s).", dt);
-                        continue;
-                }
+        r = sd_device_enumerator_add_match_subsystem(e, "block", /* match = */ true);
+        if (r < 0)
+                return r;
 
-                return true; /* we have block device children */
-        }
+        r = sd_device_enumerator_add_match_property(e, "DEVTYPE", "partition");
+        if (r < 0)
+                return r;
 
-        return false;
+        return !!sd_device_enumerator_get_device_first(e);
 }
 
 static int loop_configure(