X Tutup
Skip to content

Commit 83cdc87

Browse files
committed
mount: let pid1 alone handle the default dependencies for mount units
fstab-generator was also handling the default ordering dependencies for mount units setup in initrd. To do that it was turning the defaults dependencies off completely and ordered the mount unit against either local-fs.target or initrd-fs.target or initrd-root-fs.target itself. But it had the bad side effect to also remove all other default dependencies as well. Thus if an initrd mount was using _netdev, the network dependencies were missing. In general fstab-generator shouldn't use DefaultDependecies=no because it can handle only a small set of the default dependencies the rest are dealt by pid1. So this patch makes pid1 handle all default dependencies.
1 parent 457d659 commit 83cdc87

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/core/mount.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static bool mount_is_extrinsic(Mount *m) {
428428
}
429429

430430
static int mount_add_default_dependencies(Mount *m) {
431-
const char *after, *before;
431+
const char *after, *before, *e;
432432
UnitDependencyMask mask;
433433
MountParameters *p;
434434
bool nofail;
@@ -452,7 +452,16 @@ static int mount_add_default_dependencies(Mount *m) {
452452
mask = m->from_fragment ? UNIT_DEPENDENCY_FILE : UNIT_DEPENDENCY_MOUNTINFO_DEFAULT;
453453
nofail = m->from_fragment ? fstab_test_yes_no_option(m->parameters_fragment.options, "nofail\0" "fail\0") : false;
454454

455-
if (mount_is_network(p)) {
455+
e = path_startswith(m->where, "/sysroot");
456+
if (e && in_initrd()) {
457+
/* All mounts under /sysroot need to happen later, at initrd-fs.target time. IOW,
458+
* it's not technically part of the basic initrd filesystem itself, and so
459+
* shouldn't inherit the default Before=local-fs.target dependency. */
460+
461+
after = NULL;
462+
before = isempty(e) ? SPECIAL_INITRD_ROOT_FS_TARGET : SPECIAL_INITRD_FS_TARGET;
463+
464+
} else if (mount_is_network(p)) {
456465
/* We order ourselves after network.target. This is
457466
* primarily useful at shutdown: services that take
458467
* down the network should order themselves before
@@ -487,9 +496,11 @@ static int mount_add_default_dependencies(Mount *m) {
487496
return r;
488497
}
489498

490-
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, true, mask);
491-
if (r < 0)
492-
return r;
499+
if (after) {
500+
r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, true, mask);
501+
if (r < 0)
502+
return r;
503+
}
493504

494505
r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, true, mask);
495506
if (r < 0)

src/fstab-generator/fstab-generator.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ static int add_mount(
391391
"SourcePath=%s\n",
392392
source);
393393

394-
/* All mounts under /sysroot need to happen later, at initrd-fs.target time. IOW, it's not
395-
* technically part of the basic initrd filesystem itself, and so shouldn't inherit the default
396-
* Before=local-fs.target dependency. */
397-
if (in_initrd() && path_startswith(where, "/sysroot"))
398-
fprintf(f, "DefaultDependencies=no\n");
399-
400394
if (STRPTR_IN_SET(fstype, "nfs", "nfs4") && !(flags & AUTOMOUNT) &&
401395
fstab_test_yes_no_option(opts, "bg\0" "fg\0")) {
402396
/* The default retry timeout that mount.nfs uses for 'bg' mounts
@@ -411,9 +405,6 @@ static int add_mount(
411405
SET_FLAG(flags, NOFAIL, true);
412406
}
413407

414-
if (!(flags & NOFAIL) && !(flags & AUTOMOUNT))
415-
fprintf(f, "Before=%s\n", post);
416-
417408
if (!(flags & AUTOMOUNT) && opts) {
418409
r = write_after(f, opts);
419410
if (r < 0)

0 commit comments

Comments
 (0)
X Tutup