]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount: make acquire_mount_where_for_loop_dev() take sd-device object
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Nov 2022 02:43:57 +0000 (11:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 24 Nov 2022 05:17:22 +0000 (14:17 +0900)
No functional change, just refactoring.

src/mount/mount-tool.c

index 95dcf1bab0610f45ba00e7ec7422b74b7f06d867..72570f6fa6b65ea7e9e9d3d26e876bf3e03c7e44 100644 (file)
@@ -1136,24 +1136,31 @@ static int acquire_mount_where(sd_device *d) {
         return 1;
 }
 
-static int acquire_mount_where_for_loop_dev(const char *loop_dev) {
+static int acquire_mount_where_for_loop_dev(sd_device *dev) {
         _cleanup_strv_free_ char **list = NULL;
+        const char *node;
         int r;
 
+        assert(dev);
+
         if (arg_mount_where)
                 return 0;
 
-        r = find_mount_points(loop_dev, &list);
+        r = sd_device_get_devname(dev, &node);
         if (r < 0)
                 return r;
-        else if (r == 0)
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                       "Can't find mount point of %s. It is expected that %s is already mounted on a place.",
-                                       loop_dev, loop_dev);
-        else if (r >= 2)
-                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                       "%s is mounted on %d places. It is expected that %s is mounted on a place.",
-                                       loop_dev, r, loop_dev);
+
+        r = find_mount_points(node, &list);
+        if (r < 0)
+                return r;
+        if (r == 0)
+                return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL),
+                                              "Can't find mount point of %s. It is expected that %s is already mounted on a place.",
+                                              node, node);
+        if (r >= 2)
+                return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL),
+                                              "%s is mounted on %d places. It is expected that %s is mounted on a place.",
+                                              node, r, node);
 
         arg_mount_where = strdup(list[0]);
         if (!arg_mount_where)
@@ -1288,7 +1295,7 @@ static int discover_loop_backing_file(void) {
         if (r < 0)
                 return r;
 
-        r = acquire_mount_where_for_loop_dev(loop_dev);
+        r = acquire_mount_where_for_loop_dev(d);
         if (r < 0)
                 return r;