summaryrefslogtreecommitdiff
path: root/src/fstab-generator
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-10-28 14:24:46 +0100
committerLennart Poettering <lennart@poettering.net>2014-10-28 14:31:25 +0100
commit47cb901e38cd7092576fc8e76cc4a14f39bf719d (patch)
tree7ca11b696f63e7ce2467139c455c89a47487101d /src/fstab-generator
parent33488f19793dc0a86fdee27266c5319b5b78d695 (diff)
swap: replace Discard= setting by a more generic Options= setting
For now, it's systemd itself that parses the options string, but as soon as util-linux' swapon can take the option string directly with -o we should pass it on unmodified.
Diffstat (limited to 'src/fstab-generator')
-rw-r--r--src/fstab-generator/fstab-generator.c56
1 files changed, 8 insertions, 48 deletions
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 32a8f9bd51..e257c121e5 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -47,7 +47,6 @@ static char *arg_usr_what = NULL;
static char *arg_usr_fstype = NULL;
static char *arg_usr_options = NULL;
-
static int mount_find_pri(struct mntent *me, int *ret) {
char *end, *opt;
unsigned long r;
@@ -60,7 +59,6 @@ static int mount_find_pri(struct mntent *me, int *ret) {
return 0;
opt += strlen("pri");
-
if (*opt != '=')
return -EINVAL;
@@ -76,43 +74,9 @@ static int mount_find_pri(struct mntent *me, int *ret) {
return 1;
}
-static int mount_find_discard(struct mntent *me, char **ret) {
- char *opt, *ans;
- size_t len;
-
- assert(me);
- assert(ret);
-
- opt = hasmntopt(me, "discard");
- if (!opt)
- return 0;
-
- opt += strlen("discard");
-
- if (*opt == ',' || *opt == '\0')
- ans = strdup("all");
- else {
- if (*opt != '=')
- return -EINVAL;
-
- len = strcspn(opt + 1, ",");
- if (len == 0)
- return -EINVAL;
-
- ans = strndup(opt + 1, len);
- }
-
- if (!ans)
- return -ENOMEM;
-
- *ret = ans;
- return 1;
-}
-
static int add_swap(const char *what, struct mntent *me) {
_cleanup_free_ char *name = NULL, *unit = NULL, *lnk = NULL;
_cleanup_fclose_ FILE *f = NULL;
- _cleanup_free_ char *discard = NULL;
bool noauto;
int r, pri = -1;
@@ -131,12 +95,6 @@ static int add_swap(const char *what, struct mntent *me) {
return r;
}
- r = mount_find_discard(me, &discard);
- if (r < 0) {
- log_error("Failed to parse discard");
- return r;
- }
-
noauto = !!hasmntopt(me, "noauto");
name = unit_name_from_path(what, ".swap");
@@ -165,16 +123,18 @@ static int add_swap(const char *what, struct mntent *me) {
"What=%s\n",
what);
+ /* Note that we currently pass the priority field twice, once
+ * in Priority=, and once in Options= */
if (pri >= 0)
fprintf(f, "Priority=%i\n", pri);
- if (discard)
- fprintf(f, "Discard=%s\n", discard);
+ if (!isempty(me->mnt_opts) && !streq(me->mnt_opts, "defaults"))
+ fprintf(f, "Options=%s\n", me->mnt_opts);
- fflush(f);
- if (ferror(f)) {
- log_error("Failed to write unit file %s: %m", unit);
- return -errno;
+ r = fflush_and_check(f);
+ if (r < 0) {
+ log_error("Failed to write unit file %s: %s", unit, strerror(-r));
+ return r;
}
/* use what as where, to have a nicer error message */