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.
This commit is contained in:
Lennart Poettering
2025-03-06 09:35:59 +01:00
parent e706cadce5
commit 87bffa1eae

View File

@@ -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;
}