summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-04-07 11:44:29 +0200
committerLennart Poettering <lennart@poettering.net>2021-04-23 16:55:29 +0200
commitd2194e15dbaf18e7d0755dadda52c122d4d681cb (patch)
tree6430235ec2db69ec776f063290f82c69de220e0f /src/fstab-generator
parent6f47e45c67ad6a6b1a86ad631cd985c7301fed61 (diff)
downloadsystemd-d2194e15dbaf18e7d0755dadda52c122d4d681cb.tar.gz
fstab-generator: clean up mount point flags handling
Let's rename MountpointsFlags → MountPointFlags. In most of our codebase we name things mount_point/MountPoint rather than mountpoint/Mountpoint, do so here too. Also, prefix the enum values with "MOUNT_". The fact the enum values weren#t prefixed was pretty unique in our codebase, and pretty surprising. Let's fix that. This is just refactoring, no actual change in behaviour
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c87
1 files changed, 48 insertions, 39 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 110a9bd1ba..c0ded48d97 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -29,14 +29,14 @@
#include "virt.h"
#include "volatile-util.h"
-typedef enum MountpointFlags {
- NOAUTO = 1 << 0,
- NOFAIL = 1 << 1,
- AUTOMOUNT = 1 << 2,
- MAKEFS = 1 << 3,
- GROWFS = 1 << 4,
- RWONLY = 1 << 5,
-} MountpointFlags;
+typedef enum MountPointFlags {
+ MOUNT_NOAUTO = 1 << 0,
+ MOUNT_NOFAIL = 1 << 1,
+ MOUNT_AUTOMOUNT = 1 << 2,
+ MOUNT_MAKEFS = 1 << 3,
+ MOUNT_GROWFS = 1 << 4,
+ MOUNT_RW_ONLY = 1 << 5,
+} MountPointFlags;
static const char *arg_dest = NULL;
static const char *arg_dest_late = NULL;
@@ -91,7 +91,7 @@ static int write_what(FILE *f, const char *what) {
static int add_swap(
const char *what,
struct mntent *me,
- MountpointFlags flags) {
+ MountPointFlags flags) {
_cleanup_free_ char *name = NULL;
_cleanup_fclose_ FILE *f = NULL;
@@ -154,19 +154,19 @@ static int add_swap(
if (r < 0)
return r;
- if (flags & MAKEFS) {
+ if (flags & MOUNT_MAKEFS) {
r = generator_hook_up_mkswap(arg_dest, what);
if (r < 0)
return r;
}
- if (flags & GROWFS)
+ if (flags & MOUNT_GROWFS)
/* TODO: swap devices must be wiped and recreated */
log_warning("%s: growing swap devices is currently unsupported.", what);
- if (!(flags & NOAUTO)) {
+ if (!(flags & MOUNT_NOAUTO)) {
r = generator_add_symlink(arg_dest, SPECIAL_SWAP_TARGET,
- (flags & NOFAIL) ? "wants" : "requires", name);
+ (flags & MOUNT_NOFAIL) ? "wants" : "requires", name);
if (r < 0)
return r;
}
@@ -345,7 +345,7 @@ static int add_mount(
const char *fstype,
const char *opts,
int passno,
- MountpointFlags flags,
+ MountPointFlags flags,
const char *post,
const char *source) {
@@ -385,20 +385,20 @@ static int add_mount(
return r;
if (path_equal(where, "/")) {
- if (flags & NOAUTO)
- log_warning("Ignoring \"noauto\" for root device");
- if (flags & NOFAIL)
- log_warning("Ignoring \"nofail\" for root device");
- if (flags & AUTOMOUNT)
- log_warning("Ignoring automount option for root device");
+ if (flags & MOUNT_NOAUTO)
+ log_warning("Ignoring \"noauto\" option for root device");
+ if (flags & MOUNT_NOFAIL)
+ log_warning("Ignoring \"nofail\" option for root device");
+ if (flags & MOUNT_AUTOMOUNT)
+ log_warning("Ignoring \"automount\" option for root device");
if (!strv_isempty(wanted_by))
- log_warning("Ignoring \"x-systemd.wanted-by=\" for root device");
+ log_warning("Ignoring \"x-systemd.wanted-by=\" option for root device");
if (!strv_isempty(required_by))
- log_warning("Ignoring \"x-systemd.required-by=\" for root device");
+ log_warning("Ignoring \"x-systemd.required-by=\" option for root device");
required_by = strv_free(required_by);
wanted_by = strv_free(wanted_by);
- SET_FLAG(flags, NOAUTO | NOFAIL | AUTOMOUNT, false);
+ SET_FLAG(flags, MOUNT_NOAUTO | MOUNT_NOFAIL | MOUNT_AUTOMOUNT, false);
}
r = unit_name_from_path(where, ".mount", &name);
@@ -415,7 +415,7 @@ static int add_mount(
"SourcePath=%s\n",
source);
- if (STRPTR_IN_SET(fstype, "nfs", "nfs4") && !(flags & AUTOMOUNT) &&
+ if (STRPTR_IN_SET(fstype, "nfs", "nfs4") && !(flags & MOUNT_AUTOMOUNT) &&
fstab_test_yes_no_option(opts, "bg\0" "fg\0")) {
/* The default retry timeout that mount.nfs uses for 'bg' mounts
* is 10000 minutes, where as it uses 2 minutes for 'fg' mounts.
@@ -426,7 +426,7 @@ static int add_mount(
* By placing these options first, they can be overridden by
* settings in /etc/fstab. */
opts = strjoina("x-systemd.mount-timeout=infinity,retry=10000,nofail,", opts, ",fg");
- SET_FLAG(flags, NOFAIL, true);
+ SET_FLAG(flags, MOUNT_NOFAIL, true);
}
r = write_extra_dependencies(f, opts);
@@ -435,7 +435,7 @@ static int add_mount(
/* Order the mount unit we generate relative to the post unit, so that DefaultDependencies= on the
* target unit won't affect us. */
- if (post && !FLAGS_SET(flags, AUTOMOUNT) && !FLAGS_SET(flags, NOAUTO))
+ if (post && !FLAGS_SET(flags, MOUNT_AUTOMOUNT) && !FLAGS_SET(flags, MOUNT_NOAUTO))
fprintf(f, "Before=%s\n", post);
if (passno != 0) {
@@ -490,29 +490,29 @@ static int add_mount(
if (r < 0)
return r;
- if (flags & RWONLY)
+ if (flags & MOUNT_RW_ONLY)
fprintf(f, "ReadWriteOnly=yes\n");
r = fflush_and_check(f);
if (r < 0)
return log_error_errno(r, "Failed to write unit file %s: %m", name);
- if (flags & MAKEFS) {
+ if (flags & MOUNT_MAKEFS) {
r = generator_hook_up_mkfs(dest, what, where, fstype);
if (r < 0)
return r;
}
- if (flags & GROWFS) {
+ if (flags & MOUNT_GROWFS) {
r = generator_hook_up_growfs(dest, where, post);
if (r < 0)
return r;
}
- if (!FLAGS_SET(flags, AUTOMOUNT)) {
- if (!FLAGS_SET(flags, NOAUTO) && strv_isempty(wanted_by) && strv_isempty(required_by)) {
+ if (!FLAGS_SET(flags, MOUNT_AUTOMOUNT)) {
+ if (!FLAGS_SET(flags, MOUNT_NOAUTO) && strv_isempty(wanted_by) && strv_isempty(required_by)) {
r = generator_add_symlink(dest, post,
- (flags & NOFAIL) ? "wants" : "requires", name);
+ (flags & MOUNT_NOFAIL) ? "wants" : "requires", name);
if (r < 0)
return r;
} else {
@@ -562,7 +562,7 @@ static int add_mount(
return log_error_errno(r, "Failed to write unit file %s: %m", automount_name);
r = generator_add_symlink(dest, post,
- (flags & NOFAIL) ? "wants" : "requires", automount_name);
+ (flags & MOUNT_NOFAIL) ? "wants" : "requires", automount_name);
if (r < 0)
return r;
}
@@ -589,7 +589,8 @@ static int parse_fstab(bool initrd) {
while ((me = getmntent(f))) {
_cleanup_free_ char *where = NULL, *what = NULL, *canonical_where = NULL;
- bool makefs, growfs, noauto, nofail, rwonly;
+ bool makefs, growfs, noauto, nofail;
+ MountPointFlags flags;
int k;
if (initrd && !mount_in_initrd(me))
@@ -629,7 +630,6 @@ static int parse_fstab(bool initrd) {
makefs = fstab_test_option(me->mnt_opts, "x-systemd.makefs\0");
growfs = fstab_test_option(me->mnt_opts, "x-systemd.growfs\0");
- rwonly = fstab_test_option(me->mnt_opts, "x-systemd.rw-only\0");
noauto = fstab_test_yes_no_option(me->mnt_opts, "noauto\0" "auto\0");
nofail = fstab_test_yes_no_option(me->mnt_opts, "nofail\0" "fail\0");
@@ -638,16 +638,25 @@ static int parse_fstab(bool initrd) {
yes_no(makefs), yes_no(growfs),
yes_no(noauto), yes_no(nofail));
+ flags = makefs * MOUNT_MAKEFS |
+ growfs * MOUNT_GROWFS |
+ noauto * MOUNT_NOAUTO |
+ nofail * MOUNT_NOFAIL;
+
if (streq(me->mnt_type, "swap"))
- k = add_swap(what, me,
- makefs*MAKEFS | growfs*GROWFS | noauto*NOAUTO | nofail*NOFAIL);
+ k = add_swap(what, me, flags);
else {
- bool automount;
+ bool rw_only, automount;
const char *post;
+ rw_only = fstab_test_option(me->mnt_opts, "x-systemd.rw-only\0");
automount = fstab_test_option(me->mnt_opts,
"comment=systemd.automount\0"
"x-systemd.automount\0");
+
+ flags |= rw_only * MOUNT_RW_ONLY |
+ automount * MOUNT_AUTOMOUNT;
+
if (initrd)
post = SPECIAL_INITRD_FS_TARGET;
else if (mount_is_network(me))
@@ -662,7 +671,7 @@ static int parse_fstab(bool initrd) {
me->mnt_type,
me->mnt_opts,
me->mnt_passno,
- makefs*MAKEFS | growfs*GROWFS | noauto*NOAUTO | nofail*NOFAIL | automount*AUTOMOUNT | rwonly*RWONLY,
+ flags,
post,
fstab);
}