#include "detach-swap.h"
#include "libmount-util.h"
-int swap_list_get(const char *swaps, MountPoint **head) {
+static void swap_device_free(SwapDevice **head, SwapDevice *m) {
+ assert(head);
+ assert(m);
+
+ LIST_REMOVE(swap_device, *head, m);
+
+ free(m->path);
+ free(m);
+}
+
+void swap_devices_list_free(SwapDevice **head) {
+ assert(head);
+
+ while (*head)
+ swap_device_free(head, *head);
+}
+
+int swap_list_get(const char *swaps, SwapDevice **head) {
_cleanup_(mnt_free_tablep) struct libmnt_table *t = NULL;
_cleanup_(mnt_free_iterp) struct libmnt_iter *i = NULL;
int r;
for (;;) {
struct libmnt_fs *fs;
- _cleanup_free_ MountPoint *swap = NULL;
+ _cleanup_free_ SwapDevice *swap = NULL;
const char *source;
r = mnt_table_next_fs(t, i, &fs);
if (!source)
continue;
- swap = new0(MountPoint, 1);
+ swap = new0(SwapDevice, 1);
if (!swap)
return log_oom();
if (!swap->path)
return log_oom();
- LIST_PREPEND(mount_point, *head, TAKE_PTR(swap));
+ LIST_PREPEND(swap_device, *head, TAKE_PTR(swap));
}
return 0;
}
-static int swap_points_list_off(MountPoint **head, bool *changed) {
+static int swap_points_list_off(SwapDevice **head, bool *changed) {
int n_failed = 0;
assert(head);
assert(changed);
- LIST_FOREACH(mount_point, m, *head) {
+ LIST_FOREACH(swap_device, m, *head) {
log_info("Deactivating swap %s.", m->path);
if (swapoff(m->path) < 0) {
log_warning_errno(errno, "Could not deactivate swap %s: %m", m->path);
}
*changed = true;
- mount_point_free(head, m);
+ swap_device_free(head, m);
}
return n_failed;
}
int swapoff_all(bool *changed) {
- _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, swap_list_head);
+ _cleanup_(swap_devices_list_free) LIST_HEAD(SwapDevice, swap_list_head);
int r;
assert(changed);
#include <stdbool.h>
-#include "umount.h"
+#include "list.h"
int swapoff_all(bool *changed);
-int swap_list_get(const char *swaps, MountPoint **head);
+/* This is exported just for testing */
+typedef struct SwapDevice {
+ char *path;
+ LIST_FIELDS(struct SwapDevice, swap_device);
+} SwapDevice;
+
+int swap_list_get(const char *swaps, SwapDevice **head);
+void swap_devices_list_free(SwapDevice **head);
}
static void test_swap_list_one(const char *fname) {
- _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
+ _cleanup_(swap_devices_list_free) LIST_HEAD(SwapDevice, sd_list_head);
_cleanup_free_ char *testdata_fname = NULL;
int r;
fname = testdata_fname;
}
- LIST_HEAD_INIT(mp_list_head);
- r = swap_list_get(fname, &mp_list_head);
+ LIST_HEAD_INIT(sd_list_head);
+ r = swap_list_get(fname, &sd_list_head);
if (ERRNO_IS_PRIVILEGE(r))
return;
assert_se(r >= 0);
- LIST_FOREACH(mount_point, m, mp_list_head)
- log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
- m->path,
- strempty(m->remount_options),
- m->remount_flags,
- yes_no(m->try_remount_ro),
- major(m->devnum), minor(m->devnum));
+ LIST_FOREACH(swap_device, m, sd_list_head)
+ log_debug("path=%s", m->path);
}
TEST(swap_list) {