summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-06-27 20:28:56 +0200
committerGitHub <noreply@github.com>2017-06-27 20:28:56 +0200
commit9af868392bb8ceb50afc6b5028786dc266888dea (patch)
tree2d70523e6a066a16f961252bdf552428ec1b2674 /src
parentMerge pull request #6067 from ssahani/networkctl (diff)
parentgpt-auto-generator: disable gpt auto logic for swaps if at least one is defin... (diff)
downloadsystemd-9af868392bb8ceb50afc6b5028786dc266888dea.tar.xz
systemd-9af868392bb8ceb50afc6b5028786dc266888dea.zip
Merge pull request #5976 from fbuihuu/swap-fix
Swap fix
Diffstat (limited to '')
-rw-r--r--src/core/swap.c72
-rw-r--r--src/gpt-auto-generator/gpt-auto-generator.c14
-rw-r--r--src/shared/fstab-util.c33
-rw-r--r--src/shared/fstab-util.h3
4 files changed, 80 insertions, 42 deletions
diff --git a/src/core/swap.c b/src/core/swap.c
index e9468e105c..4c3a74ce00 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -487,13 +487,14 @@ static void swap_set_state(Swap *s, SwapState state) {
old_state = s->state;
s->state = state;
- if (state != SWAP_ACTIVATING &&
- state != SWAP_ACTIVATING_SIGTERM &&
- state != SWAP_ACTIVATING_SIGKILL &&
- state != SWAP_ACTIVATING_DONE &&
- state != SWAP_DEACTIVATING &&
- state != SWAP_DEACTIVATING_SIGTERM &&
- state != SWAP_DEACTIVATING_SIGKILL) {
+ if (!IN_SET(state,
+ SWAP_ACTIVATING,
+ SWAP_ACTIVATING_SIGTERM,
+ SWAP_ACTIVATING_SIGKILL,
+ SWAP_ACTIVATING_DONE,
+ SWAP_DEACTIVATING,
+ SWAP_DEACTIVATING_SIGTERM,
+ SWAP_DEACTIVATING_SIGKILL)) {
s->timer_event_source = sd_event_source_unref(s->timer_event_source);
swap_unwatch_control_pid(s);
s->control_command = NULL;
@@ -695,20 +696,19 @@ static void swap_enter_active(Swap *s, SwapResult f) {
static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) {
int r;
+ KillOperation kop;
assert(s);
if (s->result == SWAP_SUCCESS)
s->result = f;
- r = unit_kill_context(
- UNIT(s),
- &s->kill_context,
- (state != SWAP_ACTIVATING_SIGTERM && state != SWAP_DEACTIVATING_SIGTERM) ?
- KILL_KILL : KILL_TERMINATE,
- -1,
- s->control_pid,
- false);
+ if (IN_SET(state, SWAP_ACTIVATING_SIGTERM, SWAP_DEACTIVATING_SIGTERM))
+ kop = KILL_TERMINATE;
+ else
+ kop = KILL_KILL;
+
+ r = unit_kill_context(UNIT(s), &s->kill_context, kop, -1, s->control_pid, false);
if (r < 0)
goto fail;
@@ -829,17 +829,18 @@ static int swap_start(Unit *u) {
/* We cannot fulfill this request right now, try again later
* please! */
- if (s->state == SWAP_DEACTIVATING ||
- s->state == SWAP_DEACTIVATING_SIGTERM ||
- s->state == SWAP_DEACTIVATING_SIGKILL ||
- s->state == SWAP_ACTIVATING_SIGTERM ||
- s->state == SWAP_ACTIVATING_SIGKILL)
+ if (IN_SET(s->state,
+ SWAP_DEACTIVATING,
+ SWAP_DEACTIVATING_SIGTERM,
+ SWAP_DEACTIVATING_SIGKILL,
+ SWAP_ACTIVATING_SIGTERM,
+ SWAP_ACTIVATING_SIGKILL))
return -EAGAIN;
if (s->state == SWAP_ACTIVATING)
return 0;
- assert(s->state == SWAP_DEAD || s->state == SWAP_FAILED);
+ assert(IN_SET(s->state, SWAP_DEAD, SWAP_FAILED));
if (detect_container() > 0)
return -EPERM;
@@ -873,16 +874,15 @@ static int swap_stop(Unit *u) {
assert(s);
- if (s->state == SWAP_DEACTIVATING ||
- s->state == SWAP_DEACTIVATING_SIGTERM ||
- s->state == SWAP_DEACTIVATING_SIGKILL ||
- s->state == SWAP_ACTIVATING_SIGTERM ||
- s->state == SWAP_ACTIVATING_SIGKILL)
+ if (IN_SET(s->state,
+ SWAP_DEACTIVATING,
+ SWAP_DEACTIVATING_SIGTERM,
+ SWAP_DEACTIVATING_SIGKILL,
+ SWAP_ACTIVATING_SIGTERM,
+ SWAP_ACTIVATING_SIGKILL))
return 0;
- assert(s->state == SWAP_ACTIVATING ||
- s->state == SWAP_ACTIVATING_DONE ||
- s->state == SWAP_ACTIVE);
+ assert(IN_SET(s->state, SWAP_ACTIVATING, SWAP_ACTIVATING_DONE, SWAP_ACTIVE));
if (detect_container() > 0)
return -EPERM;
@@ -1340,7 +1340,7 @@ int swap_process_device_new(Manager *m, struct udev_device *dev) {
struct udev_list_entry *item = NULL, *first = NULL;
_cleanup_free_ char *e = NULL;
const char *dn;
- Swap *s;
+ Unit *u;
int r = 0;
assert(m);
@@ -1354,9 +1354,9 @@ int swap_process_device_new(Manager *m, struct udev_device *dev) {
if (r < 0)
return r;
- s = hashmap_get(m->units, e);
- if (s)
- r = swap_set_devnode(s, dn);
+ u = manager_get_unit(m, e);
+ if (u)
+ r = swap_set_devnode(SWAP(u), dn);
first = udev_device_get_devlinks_list_entry(dev);
udev_list_entry_foreach(item, first) {
@@ -1367,9 +1367,9 @@ int swap_process_device_new(Manager *m, struct udev_device *dev) {
if (q < 0)
return q;
- s = hashmap_get(m->units, n);
- if (s) {
- q = swap_set_devnode(s, dn);
+ u = manager_get_unit(m, n);
+ if (u) {
+ q = swap_set_devnode(SWAP(u), dn);
if (q < 0)
r = q;
}
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c
index 3578e2513c..c5319169b3 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -305,6 +305,15 @@ static int add_swap(const char *path) {
assert(path);
+ /* Disable the swap auto logic if at least one swap is defined in /etc/fstab, see #6192. */
+ r = fstab_has_fstype("swap");
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse fstab: %m");
+ if (r == 0) {
+ log_debug("swap specified in fstab, ignoring.");
+ return 0;
+ }
+
log_debug("Adding swap: %s", path);
r = unit_name_from_path(path, ".swap", &name);
@@ -435,7 +444,10 @@ static int add_esp(DissectedPartition *p) {
esp = access("/efi/", F_OK) >= 0 ? "/efi" : "/boot";
/* We create an .automount which is not overridden by the .mount from the fstab generator. */
- if (fstab_is_mount_point(esp)) {
+ r = fstab_is_mount_point(esp);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse fstab: %m");
+ if (r == 0) {
log_debug("%s specified in fstab, ignoring.", esp);
return 0;
}
diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c
index c3106f1ae9..ec2e868ca8 100644
--- a/src/shared/fstab-util.c
+++ b/src/shared/fstab-util.c
@@ -34,18 +34,43 @@
#include "strv.h"
#include "util.h"
-bool fstab_is_mount_point(const char *mount) {
+int fstab_has_fstype(const char *fstype) {
_cleanup_endmntent_ FILE *f = NULL;
struct mntent *m;
f = setmntent("/etc/fstab", "re");
if (!f)
- return false;
+ return errno == ENOENT ? false : -errno;
- while ((m = getmntent(f)))
- if (path_equal(m->mnt_dir, mount))
+ for (;;) {
+ errno = 0;
+ m = getmntent(f);
+ if (!m)
+ return errno != 0 ? -errno : false;
+
+ if (streq(m->mnt_type, fstype))
return true;
+ }
+ return false;
+}
+
+int fstab_is_mount_point(const char *mount) {
+ _cleanup_endmntent_ FILE *f = NULL;
+ struct mntent *m;
+ f = setmntent("/etc/fstab", "re");
+ if (!f)
+ return errno == ENOENT ? false : -errno;
+
+ for (;;) {
+ errno = 0;
+ m = getmntent(f);
+ if (!m)
+ return errno != 0 ? -errno : false;
+
+ if (path_equal(m->mnt_dir, mount))
+ return true;
+ }
return false;
}
diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h
index 679f6902f7..bbf0441351 100644
--- a/src/shared/fstab-util.h
+++ b/src/shared/fstab-util.h
@@ -24,7 +24,8 @@
#include "macro.h"
-bool fstab_is_mount_point(const char *mount);
+int fstab_is_mount_point(const char *mount);
+int fstab_has_fstype(const char *fstype);
int fstab_filter_options(const char *opts, const char *names, const char **namefound, char **value, char **filtered);