From: Lennart Poettering Date: Thu, 6 Mar 2025 08:35:59 +0000 (+0100) Subject: gpt-auto-generator: move around in_initrd() tests X-Git-Tag: v258-rc1~1168^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=87bffa1eae1023c2ee72c50270e40a44bbe97cba;p=thirdparty%2Fsystemd.git gpt-auto-generator: move around in_initrd() tests The partition enumeration only runs on the main system, and we test that early, hence no point in repeating this in functions further down the call chain. But let's keep it in place as assert()s, just in case. Also, move the top-level in_initrd() into add_mounts(), so that the tests are nicely encapsulated in the code they protect. --- diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index c6727523f00..0f7d089d1cf 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -485,11 +485,7 @@ static int add_partition_xbootldr(DissectedPartition *p) { int r; assert(p); - - if (in_initrd()) { - log_debug("In initrd, ignoring the XBOOTLDR partition."); - return 0; - } + assert(!in_initrd()); r = path_is_busy("/boot"); if (r < 0) @@ -526,11 +522,7 @@ static int add_partition_esp(DissectedPartition *p, bool has_xbootldr) { int r; assert(p); - - if (in_initrd()) { - log_debug("In initrd, ignoring the ESP."); - return 0; - } + assert(!in_initrd()); /* Check if there's an existing fstab entry for ESP. If so, we just skip the gpt-auto logic. */ r = fstab_has_node(p->node); @@ -908,6 +900,9 @@ static int add_mounts(void) { dev_t devno; int r; + if (in_initrd()) + return 0; + r = blockdev_get_root(LOG_ERR, &devno); if (r < 0) return r; @@ -1011,10 +1006,9 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) return 0; } - r = add_root_mount(); - - if (!in_initrd()) - RET_GATHER(r, add_mounts()); + r = 0; + RET_GATHER(r, add_root_mount()); + RET_GATHER(r, add_mounts()); return r; }