From: Yu Watanabe Date: Fri, 12 May 2023 07:08:32 +0000 (+0900) Subject: fstab-generator: call add_swap() earlier X-Git-Tag: v254-rc1~372^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=256604ccddd41a16de329ff792c5f49d6750e510;p=thirdparty%2Fsystemd.git fstab-generator: call add_swap() earlier As 'where' field will be ignored for swap entry. --- diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 149bd5daf69..042cce1ffaf 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -131,6 +131,11 @@ static int add_swap( return true; } + log_debug("Found swap entry what=%s makefs=%s growfs=%s pcrfs=%s noauto=%s nofail=%s", + what, + yes_no(flags & MOUNT_MAKEFS), yes_no(flags & MOUNT_GROWFS), yes_no(flags & MOUNT_PCRFS), + yes_no(flags & MOUNT_NOAUTO), yes_no(flags & MOUNT_NOFAIL)); + r = unit_name_from_path(what, ".swap", &name); if (r < 0) return log_error_errno(r, "Failed to generate unit name: %m"); @@ -702,16 +707,18 @@ static int parse_fstab_one( _cleanup_free_ char *what = NULL, *where = NULL, *canonical_where = NULL; MountPointFlags flags; + bool is_swap; int r; assert(what_original); - assert(where_original); assert(fstype); assert(options); if (initrd && !mount_in_initrd(where_original, options)) return 0; + is_swap = streq_ptr(fstype, "swap"); + what = fstab_node_to_udev_node(what_original); if (!what) return log_oom(); @@ -723,6 +730,13 @@ static int parse_fstab_one( return 0; } + flags = fstab_options_to_flags(options, is_swap); + + if (is_swap) + return add_swap(source, what, options, flags); + + assert(where_original); /* 'where' is not necessary for swap entry. */ + where = strdup(where_original); if (!where) return log_oom(); @@ -757,16 +771,11 @@ static int parse_fstab_one( log_debug("Canonicalized what=%s where=%s to %s", what, where, canonical_where); } - flags = fstab_options_to_flags(options, streq_ptr(fstype, "swap")); - log_debug("Found entry what=%s where=%s type=%s makefs=%s growfs=%s pcrfs=%s noauto=%s nofail=%s", what, where, strna(fstype), yes_no(flags & MOUNT_MAKEFS), yes_no(flags & MOUNT_GROWFS), yes_no(flags & MOUNT_PCRFS), yes_no(flags & MOUNT_NOAUTO), yes_no(flags & MOUNT_NOFAIL)); - if (streq_ptr(fstype, "swap")) - return add_swap(source, what, options, flags); - bool is_sysroot = in_initrd() && path_equal(where, "/sysroot"); /* See comment from add_sysroot_usr_mount() about the need for extra indirection in case /usr needs * to be mounted in order for the root fs to be synthesized based on configuration included in /usr/,