]> sourceware.org Git - lvm2.git/commitdiff
dev-mpath: check uuid with device_get_uuid
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 29 May 2024 20:43:11 +0000 (22:43 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 3 Jun 2024 13:30:05 +0000 (15:30 +0200)
lib/device/dev-mpath.c

index 25ab94c354735786d9a650caeffb44a68795d80e..01fc4c89fd2a74f8ebdb85bdf5c608cd5620d682 100644 (file)
@@ -18,6 +18,7 @@
 #include "lib/commands/toolcontext.h"
 #include "lib/device/device_id.h"
 #include "lib/datastruct/str_list.h"
+#include "device_mapper/misc/dm-ioctl.h"
 #ifdef UDEV_SYNC_SUPPORT
 #include <libudev.h>
 #include "lib/device/dev-ext-udev-constants.h"
@@ -379,48 +380,6 @@ static const char *_get_sysfs_name_by_devt(const char *sysfs_dir, dev_t devno,
        return name;
 }
 
-static int _get_sysfs_string(const char *path, char *buffer, int max_size)
-{
-       FILE *fp;
-       int r = 0;
-
-       if (!(fp = fopen(path, "r"))) {
-               log_sys_error("fopen", path);
-               return 0;
-       }
-
-       if (!fgets(buffer, max_size, fp))
-               log_sys_error("fgets", path);
-       else
-               r = 1;
-
-       if (fclose(fp))
-               log_sys_error("fclose", path);
-
-       return r;
-}
-
-static int _get_sysfs_dm_mpath(struct dev_types *dt, const char *sysfs_dir, const char *holder_name)
-{
-       char path[PATH_MAX];
-       char buffer[128];
-
-       if (dm_snprintf(path, sizeof(path), "%sblock/%s/dm/uuid", sysfs_dir, holder_name) < 0) {
-               log_error("Sysfs path string is too long.");
-               return 0;
-       }
-
-       buffer[0] = '\0';
-
-       if (!_get_sysfs_string(path, buffer, sizeof(buffer)))
-               return_0;
-
-       if (!strncmp(buffer, MPATH_PREFIX, 6))
-               return 1;
-
-       return 0;
-}
-
 #ifdef UDEV_SYNC_SUPPORT
 static int _dev_is_mpath_component_udev(struct device *dev)
 {
@@ -462,6 +421,7 @@ static int _dev_is_mpath_component_sysfs(struct cmd_context *cmd, struct device
        char link_path[PATH_MAX];       /* some obscure, unpredictable sysfs path */
        char holders_path[PATH_MAX];    /* e.g. "/sys/block/sda/holders/" */
        char dm_dev_path[PATH_MAX];     /* e.g. "/dev/dm-1" */
+       char uuid[DM_UUID_LEN];
        char *holder_name;              /* e.g. "dm-1" */
        const char *sysfs_dir = dm_sysfs_dir();
        DIR *dr;
@@ -573,12 +533,10 @@ static int _dev_is_mpath_component_sysfs(struct cmd_context *cmd, struct device
                        /* no saved result for dm_dev_minor, so check the uuid for it */
                }
 
-               /*
-                * Returns 1 if /sys/block/<holder_name>/dm/uuid indicates that
-                * <holder_name> is a dm device with dm uuid prefix mpath-.
-                * When true, <holder_name> will be something like "dm-1".
-                */
-               if (_get_sysfs_dm_mpath(dt, sysfs_dir, holder_name)) {
+               /* Check whether holder's UUID uses MPATH prefix */
+               /* TODO: reuse/merge with dev_has_mpath_uuid() as this function also recognizes kpartx partition */
+               if (device_get_uuid(cmd, dm_dev_major, dm_dev_minor, uuid, sizeof(uuid)) &&
+                   !strncmp(uuid, MPATH_PREFIX, sizeof(MPATH_PREFIX) - 1)) {
                        log_debug_devs("dev_is_mpath_component %s holder %s %u:%u ignore mpath component",
                                        dev_name(dev), holder_name, dm_dev_major, dm_dev_minor);
 
This page took 0.084181 seconds and 5 git commands to generate.