]> sourceware.org Git - lvm2.git/commitdiff
libdm: enhance mounted fs detection
authorZdenek Kabelac <zkabelac@redhat.com>
Tue, 20 Mar 2018 10:13:22 +0000 (11:13 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 23 Mar 2018 16:24:58 +0000 (17:24 +0100)
btrfs is using fake major:minor device numbers.
try to be smarter and detect used node via DM device name.

This shortens delays, where i.e. lvm2 is asked to deactivate
volume with mounted btrfs as such operation is not retryed
and user is informed about device being in use.

WHATS_NEW_DM
libdm/libdm-common.c

index 34c68332c8ddec505b31598d4bd9c668cd5ad18b..d3cdf7d94144866f332ab1cc8d846ce19018b3dc 100644 (file)
@@ -1,5 +1,6 @@
 Version 1.02.147 - 
 =====================================
+  Recognize also mounted btrfs through dm_device_has_mounted_fs().
   Add missing log_error() into dm_stats_populate() returning 0.
   Avoid calling dm_stats_populat() for DM devices without any stats regions.
   Support DM_DEBUG_WITH_LINE_NUMBERS envvar for debug msg with source:line.
index 99cf0c8a611df4cba957ebd02d838c823322c704..094e6185483b748fb4d28cf3bad58dd31352d2a1 100644 (file)
@@ -1742,6 +1742,10 @@ static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min,
 {
        char root[PATH_MAX + 1]; /* sscanf needs extra '\0' */
        char target[PATH_MAX + 1];
+       char *devmapper;
+       struct dm_task *dmt;
+       struct dm_info info;
+       unsigned i;
 
        /* TODO: maybe detect availability of  %ms  glib support ? */
        if (sscanf(line, "%*u %*u %u:%u %" DM_TO_STRING(PATH_MAX)
@@ -1751,6 +1755,32 @@ static int _mountinfo_parse_line(const char *line, unsigned *maj, unsigned *min,
                return 0;
        }
 
+       /* btrfs fakes device numbers, but there is still /dev/mapper name
+        * placed in mountinfo, so try to detect proper major:minor via this */
+       if (*maj == 0 && (devmapper = strstr(line, "/dev/mapper/"))) {
+               if (!(dmt = dm_task_create(DM_DEVICE_INFO))) {
+                       log_error("Mount info task creation failed.");
+                       return 0;
+               }
+               devmapper += 12; /* skip fixed prefix */
+               for (i = 0; devmapper[i] && devmapper[i] != ' ' && i < sizeof(root); ++i)
+                       root[i] = devmapper[i];
+               root[i] = 0;
+               _unmangle_mountinfo_string(root, buf);
+               buf[DM_NAME_LEN] = 0; /* cut away */
+
+               if (dm_task_set_name(dmt, buf) &&
+                   dm_task_no_open_count(dmt) &&
+                   dm_task_run(dmt) &&
+                   dm_task_get_info(dmt, &info)) {
+                       log_debug("Replacing mountinfo device (%u:%u) with matching DM device %s (%u:%u).",
+                                 *maj, *min, buf, info.major, info.minor);
+                       *maj = info.major;
+                       *min = info.minor;
+               }
+               dm_task_destroy(dmt);
+       }
+
        _unmangle_mountinfo_string(target, buf);
 
        return 1;
This page took 0.032787 seconds and 5 git commands to generate.