summaryrefslogtreecommitdiff
path: root/src/gpt-auto-generator/gpt-auto-generator.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-20 16:04:07 +0100
committerLennart Poettering <lennart@poettering.net>2016-12-21 19:09:31 +0100
commit78f0243a445882211058f995ee99ea9ae088b802 (patch)
tree8d5092168c1928a19777ff93b36d2e94b6a4d9bb /src/gpt-auto-generator/gpt-auto-generator.c
parent5f4bfe56f3a413584d9ee203b3c5a8ea8ca803d2 (diff)
gpt-auto-generator: enable auto-discovery logic also for verity root file systems
verity block devices have two backing devices: the data partition and the hash partition. Previously the gpt auto-discovery logic would refuse working on devices with multiple backing devices, losen this up a bit, to permit them as long as the backing devices are all located on the same physical media.
Diffstat (limited to 'src/gpt-auto-generator/gpt-auto-generator.c')
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 612a3fe777..f05544f3d4 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -664,8 +664,40 @@ static int get_block_device_harder(const char *path, dev_t *dev) {
if (!IN_SET(de->d_type, DT_LNK, DT_UNKNOWN))
continue;
- if (found) /* Don't try to support multiple backing block devices */
- goto fallback;
+ if (found) {
+ _cleanup_free_ char *u = NULL, *v = NULL, *a = NULL, *b = NULL;
+
+ /* We found a device backed by multiple other devices. We don't really support automatic
+ * discovery on such setups, with the exception of dm-verity partitions. In this case there are
+ * two backing devices: the data partitoin and the hash partition. We are fine with such
+ * setups, however, only if both partitions are on the same physical device. Hence, let's
+ * verify this. */
+
+ u = strjoin(p, "/", de->d_name, "/../dev");
+ if (!u)
+ return -ENOMEM;
+
+ v = strjoin(p, "/", found->d_name, "/../dev");
+ if (!v)
+ return -ENOMEM;
+
+ r = read_one_line_file(u, &a);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to read %s: %m", u);
+ goto fallback;
+ }
+
+ r = read_one_line_file(v, &b);
+ if (r < 0) {
+ log_debug_errno(r, "Failed to read %s: %m", v);
+ goto fallback;
+ }
+
+ /* Check if the parent device is the same. If not, then the two backing devices are on
+ * different physical devices, and we don't support that. */
+ if (!streq(a, b))
+ goto fallback;
+ }
found = de;
}