From: Lennart Poettering Date: Thu, 22 Apr 2021 09:31:14 +0000 (+0200) Subject: dissect-image: prefer PARTN= uevent property over "partition" sysfs attr X-Git-Tag: v249-rc1~362 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c1737506f3b8346fab544fedf80e9c3c2268f20f;p=thirdparty%2Fsystemd.git dissect-image: prefer PARTN= uevent property over "partition" sysfs attr The kernel will send us a PARTN= uevent proprty with partition add events, let's use it instead of going for the "partition" sysfs attr. It's less racy that way and there are reports the sysfs attr shows up after the device, which makes it evern worse. --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 53b613702e1..63a81d42ad8 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -139,7 +139,11 @@ static int enumerator_for_parent(sd_device *d, sd_device_enumerator **ret) { return 0; } -static int device_is_partition(sd_device *d, sd_device *expected_parent, blkid_partition pp) { +static int device_is_partition( + sd_device *d, + sd_device *expected_parent, + blkid_partition pp) { + const char *v, *parent_syspath, *expected_parent_syspath; blkid_loff_t bsize, bstart; uint64_t size, start; @@ -174,9 +178,16 @@ static int device_is_partition(sd_device *d, sd_device *expected_parent, blkid_p if (!path_equal(parent_syspath, expected_parent_syspath)) return false; /* Has a different parent than what we need, not interesting to us */ - r = sd_device_get_sysattr_value(d, "partition", &v); + /* On kernel uevents the partition number we may find in the PARTN= field. Let's use that preferably, + * since it's cheaper and more importantly: the sysfs attribute "partition" appear to become + * available late, hence let's use the property instead, which is available at the moment we see the + * uevent. */ + r = sd_device_get_property_value(d, "PARTN", &v); + if (r == -ENOENT) + r = sd_device_get_sysattr_value(d, "partition", &v); if (r < 0) return r; + r = safe_atoi(v, &partno); if (r < 0) return r;