[systemd-devel] [PATCH] Fix starting swap unit on symlink made it unstoppable

Olivier Brunel i.am.jack.mail at gmail.com
Sat Oct 13 05:24:15 PDT 2012


Starting a swap unit pointing to (What) a symlink (e.g. /dev/mapper/swap
or /dev/disk/by-uuid/...) would have said unit be marked active, follow
the one using the "actual" device (/dev/{dm-1,sda3}), but that new unit
would be seen as inactive.
Since all requests to stop swap units would follow/redirect to it,
and it is seen inactive, nothing would be done (swapoff never called).

This is because this unit would be treated twice in
swap_process_new_swap, the second call to swap_add_one causing it to
eventually be marked inactive.

Signed-off-by: Olivier Brunel <i.am.jack.mail at gmail.com>
---
The patch removes the call to udev_device_get_devnode, assuming that
device nodes (and not symlinks) are used under /proc/swaps, which
seems to be the case.

If that's not always true though, a strcmp(device, dn) would then fix
the issue, as well as a second one on the symlinks loop (to avoid
double calls to swap_add_one on the symink this time).


 src/core/swap.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/core/swap.c b/src/core/swap.c
index b4f53b7..9394a07 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -424,7 +424,6 @@ static int swap_process_new_swap(Manager *m, const char *device, int prio, bool
 
         if (stat(device, &st) >= 0 && S_ISBLK(st.st_mode)) {
                 struct udev_device *d;
-                const char *dn;
                 struct udev_list_entry *item = NULL, *first = NULL;
 
                 /* So this is a proper swap device. Create swap units
@@ -433,10 +432,6 @@ static int swap_process_new_swap(Manager *m, const char *device, int prio, bool
                 if (!(d = udev_device_new_from_devnum(m->udev, 'b', st.st_rdev)))
                         return -ENOMEM;
 
-                dn = udev_device_get_devnode(d);
-                if (dn)
-                        r = swap_add_one(m, dn, device, prio, false, false, set_flags);
-
                 /* Add additional units for all symlinks */
                 first = udev_device_get_devlinks_list_entry(d);
                 udev_list_entry_foreach(item, first) {
-- 
1.7.12.2



More information about the systemd-devel mailing list