Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
md/dm-mpath: check whether all pgpaths have same uuid in multipath_ctr()
When we make IO stress test on multipath device, there will
be a metadata err because of wrong path. In the test, we
concurrent execute 'iscsi device login|logout' and
'multipath -r' command with IO stress on multipath device.
In some case, systemd-udevd may have not time to process
uevents of iscsi device logout|login, and then 'multipath -r'
command triggers multipathd daemon calls ioctl to load table
with incorrect old device info from systemd-udevd.
Then, one iscsi path may be incorrectly attached to another
multipath which has different uuid. Finally, the metadata err
occurs when umounting filesystem to down write metadata on
the iscsi device which is actually not owned by the multipath
device.

So we need to check whether all pgpaths of one multipath have
the same uuid, if not, we should throw a error.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: lixiaokeng <lixiaokeng@huawei.com>
Signed-off-by: linfeilong <linfeilong@huawei.com>
Signed-off-by: Wubo <wubo40@huawei.com>
  • Loading branch information
ZhiqiangLiu26 authored and intel-lab-lkp committed Mar 20, 2021
1 parent 88cc16b commit f8f908f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions drivers/md/dm-mpath.c
Expand Up @@ -24,6 +24,7 @@
#include <linux/workqueue.h>
#include <linux/delay.h>
#include <scsi/scsi_dh.h>
#include <linux/dm-ioctl.h>
#include <linux/atomic.h>
#include <linux/blk-mq.h>

Expand Down Expand Up @@ -1169,6 +1170,45 @@ static int parse_features(struct dm_arg_set *as, struct multipath *m)
return r;
}

#define SCSI_VPD_LUN_ID_PREFIX_LEN 4
#define MPATH_UUID_PREFIX_LEN 7
static int check_pg_uuid(struct priority_group *pg, char *md_uuid)
{
char pgpath_uuid[DM_UUID_LEN] = {0};
struct request_queue *q;
struct pgpath *pgpath;
struct scsi_device *sdev;
ssize_t count;
int r = 0;

list_for_each_entry(pgpath, &pg->pgpaths, list) {
q = bdev_get_queue(pgpath->path.dev->bdev);
sdev = scsi_device_from_queue(q);
if (!sdev) {
r = -EINVAL;
goto out;
}

count = scsi_vpd_lun_id(sdev, pgpath_uuid, DM_UUID_LEN);
if (count <= SCSI_VPD_LUN_ID_PREFIX_LEN) {
r = -EINVAL;
put_device(&sdev->sdev_gendev);
goto out;
}

if (strcmp(md_uuid + MPATH_UUID_PREFIX_LEN,
pgpath_uuid + SCSI_VPD_LUN_ID_PREFIX_LEN)) {
r = -EINVAL;
put_device(&sdev->sdev_gendev);
goto out;
}
put_device(&sdev->sdev_gendev);
}

out:
return r;
}

static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
{
/* target arguments */
Expand All @@ -1183,6 +1223,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
unsigned pg_count = 0;
unsigned next_pg_num;
unsigned long flags;
char md_uuid[DM_UUID_LEN] = {0};

as.argc = argc;
as.argv = argv;
Expand Down Expand Up @@ -1220,6 +1261,11 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
goto bad;
}

if (dm_copy_name_and_uuid(dm_table_get_md(ti->table), NULL, md_uuid)) {
r = -ENXIO;
goto bad;
}

/* parse the priority groups */
while (as.argc) {
struct priority_group *pg;
Expand All @@ -1231,6 +1277,12 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv)
goto bad;
}

if (check_pg_uuid(pg, md_uuid)) {
ti->error = "uuid of pgpaths mismatch";
r = -EINVAL;
goto bad;
}

nr_valid_paths += pg->nr_pgpaths;
atomic_set(&m->nr_valid_paths, nr_valid_paths);

Expand Down
1 change: 1 addition & 0 deletions drivers/scsi/scsi_lib.c
Expand Up @@ -1953,6 +1953,7 @@ struct scsi_device *scsi_device_from_queue(struct request_queue *q)

return sdev;
}
EXPORT_SYMBOL(scsi_device_from_queue);

/**
* scsi_block_requests - Utility function used by low-level drivers to prevent
Expand Down

0 comments on commit f8f908f

Please sign in to comment.