diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-04-05 17:00:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-04-07 18:55:58 +0200 |
commit | 7ffc7f3fcc86260417a7b09bd40f9c517da371df (patch) | |
tree | d037daecc1f2eaa3cfb19a8f0441eab0720e14d8 /src | |
parent | loop-util: let's cut trailing whitespace, not trailing lines (diff) | |
download | systemd-7ffc7f3fcc86260417a7b09bd40f9c517da371df.tar.xz systemd-7ffc7f3fcc86260417a7b09bd40f9c517da371df.zip |
loop-util: slightly rework device_has_block_children()
Let's match by devtype, i.e. the official way to distinguish "whole"
block devices from partitions.
Also add debug logging for devices we thus ignore.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/loop-util.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 026adf070d..e5c7acb470 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -71,7 +71,7 @@ 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_sn, *main_ss; + const char *main_ss, *main_dt; sd_device *q; int r; @@ -80,15 +80,18 @@ static int device_has_block_children(sd_device *d) { /* Checks if the specified device currently has block device children (i.e. partition block * devices). */ - r = sd_device_get_sysname(d, &main_sn); + r = sd_device_get_subsystem(d, &main_ss); if (r < 0) return r; - r = sd_device_get_subsystem(d, &main_ss); + if (!streq(main_ss, "block")) + return -EINVAL; + + r = sd_device_get_devtype(d, &main_dt); if (r < 0) return r; - if (!streq(main_ss, "block")) + if (!streq(main_dt, "disk")) /* Refuse invocation on partition block device, insist on "whole" device */ return -EINVAL; r = sd_device_enumerator_new(&e); @@ -104,26 +107,34 @@ static int device_has_block_children(sd_device *d) { return r; FOREACH_DEVICE(e, q) { - const char *ss, *sn; + const char *ss, *dt; r = sd_device_get_subsystem(q, &ss); - if (r < 0) + if (r < 0) { + log_device_debug_errno(q, r, "Failed to get subsystem of child, ignoring: %m"); continue; + } - if (!streq(ss, "block")) + if (!streq(ss, "block")) { + log_device_debug(q, "Skipping child that is not a block device (subsystem=%s).", ss); continue; + } - r = sd_device_get_sysname(q, &sn); - if (r < 0) + 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(sn, main_sn)) + if (!streq(dt, "partition")) { + log_device_debug(q, "Skipping non-partition child (devtype=%s).", dt); continue; + } - return 1; /* we have block device children */ + return true; /* we have block device children */ } - return 0; + return false; } static int loop_configure( |