]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
detach-loopback: also decouple from umount.h
authorLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 09:02:16 +0000 (11:02 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 13:56:06 +0000 (15:56 +0200)
Let's introduce LoopbackDevice as replacement for MountPoint, with just
the fields we actually need.

src/shutdown/detach-loopback.c
src/shutdown/test-umount.c
src/shutdown/umount.c
src/shutdown/umount.h

index 49150077d60939a23edaf419a894538bf38b3ed3..ceac74223c75e2901f751b7ef0ad32ee764844bc 100644 (file)
 #include "detach-loopback.h"
 #include "device-util.h"
 #include "fd-util.h"
-#include "umount.h"
 
-static int loopback_list_get(MountPoint **head) {
+typedef struct LoopbackDevice {
+        char *path;
+        dev_t devnum;
+        LIST_FIELDS(struct LoopbackDevice, loopback_device);
+} LoopbackDevice;
+
+static void loopback_device_free(LoopbackDevice **head, LoopbackDevice *m) {
+        assert(head);
+        assert(m);
+
+        LIST_REMOVE(loopback_device, *head, m);
+
+        free(m->path);
+        free(m);
+}
+
+static void loopback_device_list_free(LoopbackDevice **head) {
+        assert(head);
+
+        while (*head)
+                loopback_device_free(head, *head);
+}
+
+static int loopback_list_get(LoopbackDevice **head) {
         _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
         sd_device *d;
         int r;
@@ -50,7 +72,7 @@ static int loopback_list_get(MountPoint **head) {
         FOREACH_DEVICE(e, d) {
                 _cleanup_free_ char *p = NULL;
                 const char *dn;
-                MountPoint *lb;
+                LoopbackDevice *lb;
                 dev_t devnum;
 
                 if (sd_device_get_devnum(d, &devnum) < 0 ||
@@ -61,16 +83,16 @@ static int loopback_list_get(MountPoint **head) {
                 if (!p)
                         return -ENOMEM;
 
-                lb = new(MountPoint, 1);
+                lb = new(LoopbackDevice, 1);
                 if (!lb)
                         return -ENOMEM;
 
-                *lb = (MountPoint) {
+                *lb = (LoopbackDevice) {
                         .path = TAKE_PTR(p),
                         .devnum = devnum,
                 };
 
-                LIST_PREPEND(mount_point, *head, lb);
+                LIST_PREPEND(loopback_device, *head, lb);
         }
 
         return 0;
@@ -151,7 +173,7 @@ static int delete_loopback(const char *device) {
         return -EBUSY; /* Nothing changed, the device is still attached, hence it apparently is still busy */
 }
 
-static int loopback_points_list_detach(MountPoint **head, bool *changed, bool last_try) {
+static int loopback_points_list_detach(LoopbackDevice **head, bool *changed, bool last_try) {
         int n_failed = 0, r;
         dev_t rootdev = 0;
 
@@ -160,7 +182,7 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed, bool la
 
         (void) get_block_device("/", &rootdev);
 
-        LIST_FOREACH(mount_point, m, *head) {
+        LIST_FOREACH(loopback_device, m, *head) {
                 if (major(rootdev) != 0 && rootdev == m->devnum) {
                         n_failed++;
                         continue;
@@ -176,14 +198,14 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed, bool la
                 if (r > 0)
                         *changed = true;
 
-                mount_point_free(head, m);
+                loopback_device_free(head, m);
         }
 
         return n_failed;
 }
 
 int loopback_detach_all(bool *changed, bool last_try) {
-        _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, loopback_list_head);
+        _cleanup_(loopback_device_list_free) LIST_HEAD(LoopbackDevice, loopback_list_head);
         int r;
 
         assert(changed);
index d74cd878c63a61b8cb462be836c8dbf1d4427c54..93da2e0fc34a415419249330871c12c903d869b7 100644 (file)
@@ -24,12 +24,11 @@ static void test_mount_points_list_one(const char *fname) {
         assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
 
         LIST_FOREACH(mount_point, m, mp_list_head)
-                log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
+                log_debug("path=%s o=%s f=0x%lx try-ro=%s",
                           m->path,
                           strempty(m->remount_options),
                           m->remount_flags,
-                          yes_no(m->try_remount_ro),
-                          major(m->devnum), minor(m->devnum));
+                          yes_no(m->try_remount_ro));
 }
 
 TEST(mount_points_list) {
index 05f7b5b513f74ed6dd27dc41ccd8f86711129939..6cbe2befa290d7452153038918e5d80c66bed2bb 100644 (file)
@@ -29,7 +29,7 @@
 #include "umount.h"
 #include "virt.h"
 
-void mount_point_free(MountPoint **head, MountPoint *m) {
+static void mount_point_free(MountPoint **head, MountPoint *m) {
         assert(head);
         assert(m);
 
index eeda7f8ad9733c2f727fc9e19844f05ddf173f8d..f8f9ae8038094c0737ede634938e12b92b0a5e27 100644 (file)
@@ -5,6 +5,8 @@
   Copyright © 2010 ProFUSION embedded systems
 ***/
 
+#include <stdbool.h>
+
 #include "list.h"
 
 int umount_all(bool *changed, bool last_try);
@@ -17,10 +19,8 @@ typedef struct MountPoint {
         bool try_remount_ro;
         bool umount_lazily;
         bool leaf;
-        dev_t devnum;
         LIST_FIELDS(struct MountPoint, mount_point);
 } MountPoint;
 
 int mount_points_list_get(const char *mountinfo, MountPoint **head);
-void mount_point_free(MountPoint **head, MountPoint *m);
 void mount_points_list_free(MountPoint **head);