Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2110005pxf; Sat, 20 Mar 2021 04:56:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrA89hBoRIml9f8PxEDkyEsDP4muzwk5JqIMPOoomw3yXOtzanAJqjq6VRBmWANfkJ68Kr X-Received: by 2002:a05:6402:5211:: with SMTP id s17mr15225227edd.327.1616241409240; Sat, 20 Mar 2021 04:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616241409; cv=none; d=google.com; s=arc-20160816; b=Sfttumiebw1kRo6M575khOB2PFmpceSVxu0vJhrHpKHOabTczFk+Tbx30Xvi863Owq Di3oEwB5qpbWxvs4rIEwkzyEWk8za1QgX8QxyOl4LjjMW/U+kpQIxXunSYs6a+iStIam 9ip+WTwo6v1nr5tnFx3NPkw+LtyRIXGNZGopmIUFFHzwvnBORcd/iyvfBGoTn6waoSEI FwGtxix1OLfp26sO+XR1tpflQjgYmScq8HqTEDSa1Uh+r1WwftUb3yx9kZabQ8zZ/IDn E/9WCbFQTKn1+YzdatOcZO7XXPHTFdhY98FlpDb/rKndXt7qx9gw44IIsev5xZkUqg8w u/Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:cc:to; bh=q316lmLE9x4Nw5uvkog1EQWZz51tR8CH2WRHXeeiC4Q=; b=EnG7wNITUmG4aQQTnQYQXBRkxYwwlT4mG+IUkVEhjqlvTiY7sUdMyfz0sIBwT91aa1 C1hBmpcnhcf/5jN2YWBCzaq51zwzUftI8DDTdu/pSN8PPYrAFk7lAhYRPRX2seTFzCnz QheGP0qj27R9Ml9SsaPCcZxBFhwcXkgIi3OqkgiQCbpQThhb6RuYKFQfOSLxH95rS02K 83v3lc/hhsKZ4g7rC5pD5lJAUc98B+baahG0Ee8QEbZwqjQ0M8xHZFBff4cUjJkYqwe9 KIicyjpJdF8qbFcGjbmd2ehCBDyPDRbuEPl/grfGmjpiQdO4dNdzl1Nt1Pq2f98EmBFr Cq6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e13si6430910edz.432.2021.03.20.04.56.27; Sat, 20 Mar 2021 04:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229865AbhCTLza (ORCPT + 99 others); Sat, 20 Mar 2021 07:55:30 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14112 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbhCTLzS (ORCPT ); Sat, 20 Mar 2021 07:55:18 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F2XCS2qQyz16H17; Sat, 20 Mar 2021 15:17:40 +0800 (CST) Received: from [127.0.0.1] (10.174.176.117) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Sat, 20 Mar 2021 15:19:26 +0800 To: , , , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" CC: , , linfeilong , lixiaokeng , "wubo (T)" , From: Zhiqiang Liu Subject: [PATCH] md/dm-mpath: check whether all pgpaths have same uuid in multipath_ctr() Message-ID: Date: Sat, 20 Mar 2021 15:19:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.117] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhiqiang Liu 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 Signed-off-by: lixiaokeng Signed-off-by: linfeilong Signed-off-by: Wubo --- drivers/md/dm-mpath.c | 52 +++++++++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_lib.c | 1 + 2 files changed, 53 insertions(+) diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index bced42f082b0..f0b995784b53 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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 */ @@ -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; @@ -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; @@ -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); diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 7d52a11e1b61..fee82262a227 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -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 -- 2.19.1