]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
detach-dm: decouple from umount.[ch]
authorLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 08:54:03 +0000 (10:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 13:56:06 +0000 (15:56 +0200)
Let's also define our own little structure here with just the fields we
need.

src/shutdown/detach-dm.c

index 8a6408e4d205b243d8e8c122369d5b35265cbf5c..bfb591ede5fec2eaeb00709fbf8f08bfd457adf1 100644 (file)
 #include "errno-util.h"
 #include "fd-util.h"
 #include "sync-util.h"
-#include "umount.h"
 
-static int dm_list_get(MountPoint **head) {
+typedef struct DeviceMapper {
+        char *path;
+        dev_t devnum;
+        LIST_FIELDS(struct DeviceMapper, device_mapper);
+} DeviceMapper;
+
+static void device_mapper_free(DeviceMapper **head, DeviceMapper *m) {
+        assert(head);
+        assert(m);
+
+        LIST_REMOVE(device_mapper, *head, m);
+
+        free(m->path);
+        free(m);
+}
+
+static void device_mapper_list_free(DeviceMapper **head) {
+        assert(head);
+
+        while (*head)
+                device_mapper_free(head, *head);
+}
+
+static int dm_list_get(DeviceMapper **head) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
         sd_device *d;
         int r;
@@ -44,7 +66,7 @@ static int dm_list_get(MountPoint **head) {
         FOREACH_DEVICE(e, d) {
                 _cleanup_free_ char *p = NULL;
                 const char *dn;
-                MountPoint *m;
+                DeviceMapper *m;
                 dev_t devnum;
 
                 if (sd_device_get_devnum(d, &devnum) < 0 ||
@@ -55,22 +77,22 @@ static int dm_list_get(MountPoint **head) {
                 if (!p)
                         return -ENOMEM;
 
-                m = new(MountPoint, 1);
+                m = new(DeviceMapper, 1);
                 if (!m)
                         return -ENOMEM;
 
-                *m = (MountPoint) {
+                *m = (DeviceMapper) {
                         .path = TAKE_PTR(p),
                         .devnum = devnum,
                 };
 
-                LIST_PREPEND(mount_point, *head, m);
+                LIST_PREPEND(device_mapper, *head, m);
         }
 
         return 0;
 }
 
-static int delete_dm(MountPoint *m) {
+static int delete_dm(DeviceMapper *m) {
         _cleanup_close_ int fd = -EBADF;
         int r;
 
@@ -97,7 +119,7 @@ static int delete_dm(MountPoint *m) {
         }));
 }
 
-static int dm_points_list_detach(MountPoint **head, bool *changed, bool last_try) {
+static int dm_points_list_detach(DeviceMapper **head, bool *changed, bool last_try) {
         int n_failed = 0, r;
         dev_t rootdev = 0;
 
@@ -106,7 +128,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed, bool last_try
 
         (void) get_block_device("/", &rootdev);
 
-        LIST_FOREACH(mount_point, m, *head) {
+        LIST_FOREACH(device_mapper, m, *head) {
                 if (major(rootdev) != 0 && rootdev == m->devnum) {
                         n_failed ++;
                         continue;
@@ -121,14 +143,14 @@ static int dm_points_list_detach(MountPoint **head, bool *changed, bool last_try
                 }
 
                 *changed = true;
-                mount_point_free(head, m);
+                device_mapper_free(head, m);
         }
 
         return n_failed;
 }
 
 int dm_detach_all(bool *changed, bool last_try) {
-        _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, dm_list_head);
+        _cleanup_(device_mapper_list_free) LIST_HEAD(DeviceMapper, dm_list_head);
         int r;
 
         assert(changed);