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.
This commit is contained in:
Lennart Poettering
2014-10-28 14:31:25 +01:00
parent 33488f1979
commit 47cb901e38
6 changed files with 102 additions and 76 deletions
+8 -48
View File
@@ -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 */