From bc9e5a4c67f5fff536d122118e16a53dfb592acd Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Mon, 30 Mar 2020 10:39:21 +0200 Subject: [PATCH] fstab-util: introduce fstab_is_extrinsic() --- src/core/mount.c | 26 +++++++------------------- src/shared/fstab-util.c | 24 ++++++++++++++++++++++++ src/shared/fstab-util.h | 1 + 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 1c4aefd734f..4be4c1781a4 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -400,32 +400,20 @@ static bool mount_is_extrinsic(Mount *m) { MountParameters *p; assert(m); - /* Returns true for all units that are "magic" and should be excluded from the usual start-up and shutdown - * dependencies. We call them "extrinsic" here, as they are generally mounted outside of the systemd dependency - * logic. We shouldn't attempt to manage them ourselves but it's fine if the user operates on them with us. */ + /* Returns true for all units that are "magic" and should be excluded from the usual + * start-up and shutdown dependencies. We call them "extrinsic" here, as they are generally + * mounted outside of the systemd dependency logic. We shouldn't attempt to manage them + * ourselves but it's fine if the user operates on them with us. */ - if (!MANAGER_IS_SYSTEM(UNIT(m)->manager)) /* We only automatically manage mounts if we are in system mode */ + /* We only automatically manage mounts if we are in system mode */ + if (!MANAGER_IS_SYSTEM(UNIT(m)->manager)) return true; if (UNIT(m)->perpetual) /* All perpetual units never change state */ return true; - if (PATH_IN_SET(m->where, /* Don't bother with the OS data itself */ - "/", /* (strictly speaking redundant: should already be covered by the perpetual flag check above) */ - "/usr", - "/etc")) - return true; - - if (PATH_STARTSWITH_SET(m->where, - "/run/initramfs", /* This should stay around from before we boot until after we shutdown */ - "/proc", /* All of this is API VFS */ - "/sys", /* … dito … */ - "/dev")) /* … dito … */ - return true; - - /* If this is an initrd mount, and we are not in the initrd, then leave this around forever, too. */ p = get_mount_parameters(m); - if (p && fstab_test_option(p->options, "x-initrd.mount\0") && !in_initrd()) + if (p && fstab_is_extrinsic(m->where, p->options)) return true; return false; diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 86a57e6b2ce..b19127be09a 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -35,6 +35,30 @@ int fstab_has_fstype(const char *fstype) { return false; } +bool fstab_is_extrinsic(const char *mount, const char *opts) { + + /* Don't bother with the OS data itself */ + if (PATH_IN_SET(mount, + "/", + "/usr", + "/etc")) + return true; + + if (PATH_STARTSWITH_SET(mount, + "/run/initramfs", /* This should stay around from before we boot until after we shutdown */ + "/proc", /* All of this is API VFS */ + "/sys", /* … dito … */ + "/dev")) /* … dito … */ + return true; + + /* If this is an initrd mount, and we are not in the initrd, then leave + * this around forever, too. */ + if (opts && fstab_test_option(opts, "x-initrd.mount\0") && !in_initrd()) + return true; + + return false; +} + int fstab_is_mount_point(const char *mount) { _cleanup_endmntent_ FILE *f = NULL; struct mntent *m; diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index f575ed0bb29..a73575e95c8 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -6,6 +6,7 @@ #include "macro.h" +bool fstab_is_extrinsic(const char *mount, const char *opts); int fstab_is_mount_point(const char *mount); int fstab_has_fstype(const char *fstype);