summaryrefslogtreecommitdiff
path: root/src/core/swap.c
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2014-09-24 14:29:05 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-09-29 11:08:12 -0400
commit86b23b07c96b185126bfbf217227dad362a20c25 (patch)
tree897437332588d77a7f2e27d1a3dc486ecbdd562f /src/core/swap.c
parent70f1b2ddc6b94d3fa5539eb8503887b465f7fcc7 (diff)
swap: introduce Discard property
Process possible "discard" values from /etc/fstab.
Diffstat (limited to 'src/core/swap.c')
-rw-r--r--src/core/swap.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/core/swap.c b/src/core/swap.c
index b88a914f72..2e12824049 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -152,6 +152,9 @@ static void swap_done(Unit *u) {
free(s->parameters_fragment.what);
s->parameters_fragment.what = NULL;
+ free(s->parameters_fragment.discard);
+ s->parameters_fragment.discard = NULL;
+
s->exec_runtime = exec_runtime_unref(s->exec_runtime);
exec_command_done_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX);
s->control_command = NULL;
@@ -602,10 +605,12 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
fprintf(f,
"%sPriority: %i\n"
"%sNoAuto: %s\n"
- "%sNoFail: %s\n",
+ "%sNoFail: %s\n"
+ "%sDiscard: %s\n",
prefix, p->priority,
prefix, yes_no(p->noauto),
- prefix, yes_no(p->nofail));
+ prefix, yes_no(p->nofail),
+ prefix, p->discard);
if (s->control_pid > 0)
fprintf(f,
@@ -734,36 +739,46 @@ fail:
static void swap_enter_activating(Swap *s) {
int r, priority;
+ char *discard;
assert(s);
s->control_command_id = SWAP_EXEC_ACTIVATE;
s->control_command = s->exec_command + SWAP_EXEC_ACTIVATE;
- if (s->from_fragment)
+ if (s->from_fragment) {
priority = s->parameters_fragment.priority;
- else
+ discard = s->parameters_fragment.discard;
+ } else {
priority = -1;
+ discard = NULL;
+ }
+
+ r = exec_command_set(s->control_command, "/sbin/swapon", NULL);
+ if (r < 0)
+ goto fail;
if (priority >= 0) {
char p[DECIMAL_STR_MAX(int)];
sprintf(p, "%i", priority);
+ r = exec_command_append(s->control_command, "-p", p, NULL);
+ if (r < 0)
+ goto fail;
+ }
- r = exec_command_set(
- s->control_command,
- "/sbin/swapon",
- "-p",
- p,
- s->what,
- NULL);
- } else
- r = exec_command_set(
- s->control_command,
- "/sbin/swapon",
- s->what,
- NULL);
+ if (discard && !streq(discard, "none")) {
+ const char *discard_arg = "--discard";
+
+ if (!streq(discard, "all"))
+ discard_arg = strappenda("--discard=", discard);
+
+ r = exec_command_append(s->control_command, discard_arg, NULL);
+ if (r < 0)
+ goto fail;
+ }
+ r = exec_command_append(s->control_command, s->what, NULL);
if (r < 0)
goto fail;