From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18A3A389
	for <dm-devel@lists.linux.dev>; Fri, 17 May 2024 00:41:32 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1715906494; cv=none; b=rOC+YSBJZz8F09BpBbSET2UtQoCAHQX6NW27/NX9djwl8cRvXw2rmOUOqUPG5R5RIIcoY7b6AFNUMfNRAEa54z2sKlBEs1Lchaj/9gPhBur3KA0rWnswGA7P21XlM5+75JhmdyoPr/MAN/c7N0fTBj6l+9Vdr/3CsYdf+1PW+SI=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1715906494; c=relaxed/simple;
	bh=LyHpouuKOXnX3t6QWjD9I1UFI51AazKIZHcUISIrKxs=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=g5wZPiZOYpZi0UzD3Wl4kAMIcZhMqzwr+fqr2ZniXsLscwsViS9rXkxj2Ynkr5bDsrFUbTrLmslLqrbGhFVbFs+D9VsIReyVxTMyllIzD9wsF4kK4xUCxGPdNjnuDXMmU854H5TV+7PoAFYrFleeiE38mwLqidWQbM782/bc6aQ=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CRalRczY; arc=none smtp.client-ip=170.10.133.124
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CRalRczY"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1715906491;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=0fXk/IX7Wo++TGM1QeYRMV1+4eolS0l8dg4qOBrNK/Q=;
	b=CRalRczYOfQBtkriUpuIR7V5Btptr51/dAl2TRcRvmEIN3C3vEvwAdLUJLvZPcqHtQGoB1
	7jdSugppAgEmWQ6GhzEF9oJ3aSUP1Fcyqki/Bxb+arnF0Xzv5qULmrpvFbf9rr0ASCcoQt
	tQIs29N4c8nZiC5Z975hTPzJTeD+Cyw=
Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])
 by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,
 cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-70CvIGbfM4CrSzilFwdwiA-1; Thu,
 16 May 2024 20:41:29 -0400
X-MC-Unique: 70CvIGbfM4CrSzilFwdwiA-1
Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ED5A380670C;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 89293202696B;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1])
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 44H0fTwa139630
	(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);
	Thu, 16 May 2024 20:41:29 -0400
Received: (from bmarzins@localhost)
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 44H0fTlk139629;
	Thu, 16 May 2024 20:41:29 -0400
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>, Mike Snitzer <snitzer@kernel.org>
Cc: dm-devel@lists.linux.dev
Subject: [PATCH 1/2] dm: factor out helper function from dm_get_device
Date: Thu, 16 May 2024 20:41:28 -0400
Message-ID: <20240517004129.139615-2-bmarzins@redhat.com>
In-Reply-To: <20240517004129.139615-1-bmarzins@redhat.com>
References: <20240517004129.139615-1-bmarzins@redhat.com>
Precedence: bulk
X-Mailing-List: dm-devel@lists.linux.dev
List-Id: <dm-devel.lists.linux.dev>
List-Subscribe: <mailto:dm-devel+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:dm-devel+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="US-ASCII"; x-default=true

Factor out a helper function, dm_devt_from_path(), from dm_get_device()
for use in dm targets.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 drivers/md/dm-table.c         | 33 ++++++++++++++++++++++++---------
 include/linux/device-mapper.h |  5 +++++
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index d124e37dfb00..41b58e0c6876 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -329,23 +329,15 @@ static int upgrade_mode(struct dm_dev_internal *dd, blk_mode_t new_mode,
 }
 
 /*
- * Add a device to the list, or just increment the usage count if
- * it's already present.
- *
  * Note: the __ref annotation is because this function can call the __init
  * marked early_lookup_bdev when called during early boot code from dm-init.c.
  */
-int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
-		  struct dm_dev **result)
+int __ref dm_devt_from_path(const char *path, dev_t *dev_p)
 {
 	int r;
 	dev_t dev;
 	unsigned int major, minor;
 	char dummy;
-	struct dm_dev_internal *dd;
-	struct dm_table *t = ti->table;
-
-	BUG_ON(!t);
 
 	if (sscanf(path, "%u:%u%c", &major, &minor, &dummy) == 2) {
 		/* Extract the major/minor numbers */
@@ -361,6 +353,29 @@ int __ref dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
 		if (r)
 			return r;
 	}
+	*dev_p = dev;
+	return 0;
+}
+EXPORT_SYMBOL(dm_devt_from_path);
+
+/*
+ * Add a device to the list, or just increment the usage count if
+ * it's already present.
+ */
+int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
+		  struct dm_dev **result)
+{
+	int r;
+	dev_t dev;
+	struct dm_dev_internal *dd;
+	struct dm_table *t = ti->table;
+
+	BUG_ON(!t);
+
+	r = dm_devt_from_path(path, &dev);
+	if (r)
+		return r;
+
 	if (dev == disk_devt(t->md->disk))
 		return -EINVAL;
 
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 82b2195efaca..b4c7c4fa2de6 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -179,6 +179,11 @@ int dm_get_device(struct dm_target *ti, const char *path, blk_mode_t mode,
 		  struct dm_dev **result);
 void dm_put_device(struct dm_target *ti, struct dm_dev *d);
 
+/*
+ * Helper function for getting devices
+ */
+int dm_devt_from_path(const char *path, dev_t *dev_p);
+
 /*
  * Information about a target type
  */
-- 
2.45.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72D7E38F
	for <dm-devel@lists.linux.dev>; Fri, 17 May 2024 00:41:34 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1715906495; cv=none; b=f/dqlBQSzvUI+fRHEdRlRSCeRZ2HClfSXvQre7VhSFUBwVtz7GVDA53ceNWZX/dvn/qcucKBm4XYf3O2aqXt07Mx49r3Av+ad6Eb5BXHRKRwj/6SZoAf2IVERa//d91AAramVud83uRr9HkZT2Bk/0NrP48v5plFSlWgeEHml3k=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1715906495; c=relaxed/simple;
	bh=ct30iUcaE98wJOSKUXpwNtUeXWIs4PQY870FIMSSiuI=;
	h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=aMI2oZ7/PLzujE9F/B6SlbNI7J/9HlBuwL1QwWo1ug3mde6gs/xpr1DRpvnLiSJfBZFuikO3mLOfFOdbqt+smxsbDix98ZpVoDLEronfn8J5IcF9Jb8wCyKWMwzHSdWqHcQ/Bl1ZgoBJ8S9X8SYtpO7DEcFkMlYJkaDya5/xgtU=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=YJ5gQocP; arc=none smtp.client-ip=170.10.133.124
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YJ5gQocP"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1715906493;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=I2LxHqr8sNqYfNAdl5l0jBFo3YkVt/8DexLUOpd503U=;
	b=YJ5gQocP2oboF+NjXEOY0zkYUlnVXJH9Eab9GB/wDTaccb1qsP9UbDvzrAROBtpibzbszA
	p/juGakVLO83Z5QBiZwB4rcdtUbyBzLkhHG3mZkRuokPgSEO+WHyCPC+oskQMaxn/BRFz+
	2DGEx95AaP7Xu0Mgo+91f4bWCnSpIEc=
Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com
 [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-590-7me5V8DkNfq-xHWcOw6heA-1; Thu, 16 May 2024 20:41:29 -0400
X-MC-Unique: 7me5V8DkNfq-xHWcOw6heA-1
Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E1D5801211;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id 6206A40C6CB7;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1])
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 44H0fTET139626
	(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);
	Thu, 16 May 2024 20:41:29 -0400
Received: (from bmarzins@localhost)
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 44H0fTCw139625;
	Thu, 16 May 2024 20:41:29 -0400
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>, Mike Snitzer <snitzer@kernel.org>
Cc: dm-devel@lists.linux.dev
Subject: [PATCH 0/2] dm: mpath dm_get_device fix
Date: Thu, 16 May 2024 20:41:27 -0400
Message-ID: <20240517004129.139615-1-bmarzins@redhat.com>
Precedence: bulk
X-Mailing-List: dm-devel@lists.linux.dev
List-Id: <dm-devel.lists.linux.dev>
List-Subscribe: <mailto:dm-devel+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:dm-devel+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="US-ASCII"; x-default=true

dm-mpath shouldn't be calling dm_get_device() in multipath_message().
If you run:

# dmsetup message <mpath_dev> 0 "fail_path <device_not_in_multipath>"

the dm_get_device() call in multipath_message() will add that incorrect
device to the devices list, fail to find a matching pgpath, and then
remove it.  multipath shouldn't be messing with the devices table
outside of its constructor and destructor.

To fix it, this patchset factors out a helper function from
dm_get_device() to turn the device path string into a dev_t.
multipath_message() calls that helper function and uses the dev_t to
find the correct pgpath instead.

Benjamin Marzinski (2):
  dm: factor out helper function from dm_get_device
  dm mpath: don't call dm_get_device in multipath_message

 drivers/md/dm-mpath.c         | 11 ++++-------
 drivers/md/dm-table.c         | 33 ++++++++++++++++++++++++---------
 include/linux/device-mapper.h |  5 +++++
 3 files changed, 33 insertions(+), 16 deletions(-)

-- 
2.45.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73219622
	for <dm-devel@lists.linux.dev>; Fri, 17 May 2024 00:41:34 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1715906496; cv=none; b=pcJjEUTrnzK0WvMdiTYDQw/P0sv46FOyNEMoN0e7jRtxTEP2SnIeslQYi1LekHWbi4sU46xIcMpr2xHxmAl/DjP9zVNrGg3ZyIPkqHoWl40H1k8rQMbZhFK1xe12PwunlAJoi7SFrKlxctWptfIhD2a4OMPZMBdiTO8EAtabmTQ=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1715906496; c=relaxed/simple;
	bh=LaHJ64k7Q3eC9qMLxiXcleKpirreeUXEoGzCE/33s28=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=OnbPLtxHEo5eKMDaEIR/hEGwyBqZN7QudOjgrsSy0QCyZPA9gA/Ww39ttPPf4xQwp7I8o3llLFlXHKRnzxouSji83X3jzaDGHOMMzWpIbG719LmAgS8ucbOKmX2Ykr9U2McNvr5gH/fhMut7GbBW0S17qfQfMtjEhwICapdXkM8=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dcnvyUEN; arc=none smtp.client-ip=170.10.133.124
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dcnvyUEN"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1715906493;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=tmhJ70e2wrskIjSUX2+CnkB7yvLwr+zBHMd3dwYbJSE=;
	b=dcnvyUENNQ20Ywbrco66WGI0yqN3rAsTioNMVxOP1KqpDMdh88CibCxAk60bfZShZXwqgT
	DmigkxTWRKERmCyZxoY0jSL8QnkBhUecChmOfSx4FujeKt+XMsm1FPQ0Uk17lF171WA+re
	DVbOliBzlmG5idD3WFLk0Vsg9EBpsf4=
Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com
 [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-210-jxu1m_PFPTCGJkn5QMjC1Q-1; Thu, 16 May 2024 20:41:30 -0400
X-MC-Unique: jxu1m_PFPTCGJkn5QMjC1Q-1
Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8156101A551;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id B1E91491037;
	Fri, 17 May 2024 00:41:29 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1])
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 44H0fTN7139634
	(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);
	Thu, 16 May 2024 20:41:29 -0400
Received: (from bmarzins@localhost)
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 44H0fTP6139633;
	Thu, 16 May 2024 20:41:29 -0400
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>, Mike Snitzer <snitzer@kernel.org>
Cc: dm-devel@lists.linux.dev
Subject: [PATCH 2/2] dm mpath: don't call dm_get_device in multipath_message
Date: Thu, 16 May 2024 20:41:29 -0400
Message-ID: <20240517004129.139615-3-bmarzins@redhat.com>
In-Reply-To: <20240517004129.139615-1-bmarzins@redhat.com>
References: <20240517004129.139615-1-bmarzins@redhat.com>
Precedence: bulk
X-Mailing-List: dm-devel@lists.linux.dev
List-Id: <dm-devel.lists.linux.dev>
List-Subscribe: <mailto:dm-devel+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:dm-devel+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="US-ASCII"; x-default=true

When mutipath_message is called with an action and a device, it needs to
find the pgpath that matches that device. dm_get_device() is not the
right function for this. dm_get_device() will look for a table_device
matching the requested path in use by either the live or inactive table.
If it doesn't find the device, dm_get_device() will open it and add it
to the table. Means that multipath_message will accept any block device,
add it to the table if not present, and then look through the pgpaths
to see if it finds a match. Afterwards it will remove the device if it
was not previously in the table devices list.

This is the only function that can modify the device list of a table
besides the constructors and destructors, and it can only do this when
it was passed an invalid message.  Instead, multipath_message() should
call dm_devt_from_path() to get the device dev_t, and match that against
its pgpaths.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 drivers/md/dm-mpath.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 05d1328d1811..a1d08a702709 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1420,8 +1420,7 @@ static int reinstate_path(struct pgpath *pgpath)
 /*
  * Fail or reinstate all paths that match the provided struct dm_dev.
  */
-static int action_dev(struct multipath *m, struct dm_dev *dev,
-		      action_fn action)
+static int action_dev(struct multipath *m, dev_t dev, action_fn action)
 {
 	int r = -EINVAL;
 	struct pgpath *pgpath;
@@ -1429,7 +1428,7 @@ static int action_dev(struct multipath *m, struct dm_dev *dev,
 
 	list_for_each_entry(pg, &m->priority_groups, list) {
 		list_for_each_entry(pgpath, &pg->pgpaths, list) {
-			if (pgpath->path.dev == dev)
+			if (pgpath->path.dev->bdev->bd_dev == dev)
 				r = action(pgpath);
 		}
 	}
@@ -1960,7 +1959,7 @@ static int multipath_message(struct dm_target *ti, unsigned int argc, char **arg
 			     char *result, unsigned int maxlen)
 {
 	int r = -EINVAL;
-	struct dm_dev *dev;
+	dev_t dev;
 	struct multipath *m = ti->private;
 	action_fn action;
 	unsigned long flags;
@@ -2009,7 +2008,7 @@ static int multipath_message(struct dm_target *ti, unsigned int argc, char **arg
 		goto out;
 	}
 
-	r = dm_get_device(ti, argv[1], dm_table_get_mode(ti->table), &dev);
+	r = dm_devt_from_path(argv[1], &dev);
 	if (r) {
 		DMWARN("message: error getting device %s",
 		       argv[1]);
@@ -2018,8 +2017,6 @@ static int multipath_message(struct dm_target *ti, unsigned int argc, char **arg
 
 	r = action_dev(m, dev, action);
 
-	dm_put_device(ti, dev);
-
 out:
 	mutex_unlock(&m->work_mutex);
 	return r;
-- 
2.45.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C20DA14B978
	for <dm-devel@lists.linux.dev>; Mon, 10 Jun 2024 18:12:23 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1718043145; cv=none; b=WUQJqDfq7CF+/zzfNNvTJUFgzq9OhOhjTsX8tZyyAQC/lJ48YNDLdsenERjpDsbcWfqH/s3WfFUp4W68WB0VVoAwiNRhqkKDwlNQUgKDDaphp8KxbC+V7iRTakNZdENqH+i7n541fTQx2o5AAOyXu0H1IWcaXdw8CCV0aWFaBx0=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1718043145; c=relaxed/simple;
	bh=Yz6mvzmZQk/n+4U8DiaqWskmTygh5Qeu7CQPPVEUwaI=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 In-Reply-To:Content-Type:Content-Disposition; b=Mxwv3dRWK6Izi4SlJ9iWsaX/n8v5j1dDt3GuHRxuM7yCNoXc/I5dL0NJMpEJ+l/BTRI6TiORyVOSAJddIw5wJbqjnou/aAdNjs07Up5Jd4dTq8tVPwx/SqDVeccBUm+0xrDpXZt1bdXsoYXJla/WmVMA94o6Bd1h+4UQS8/9N84=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OMn1Zfch; arc=none smtp.client-ip=170.10.129.124
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OMn1Zfch"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1718043142;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=fqNYuUqzAoWW3qERQEv/HP188IqWrnYU9Ao4+Zs2fbM=;
	b=OMn1ZfchptC3d/neiwp3jVCTIPboMiMfKCgQ9GKZUqbqfaDUyYzaCmCO0CLoUMyC5OMgB5
	+z99Yt2qYOk3fNUkSesoSVZ6NrcTNDnGPX5Xh8OxlfY3GGozNHzHxDyGF4ZXkZvvPR47hX
	o/coghXRTcs03gqIOMQI7CZXpPMvG9Y=
Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com
 (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by
 relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,
 cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-dAv8-BMJN5iob_lNjcmPUw-1; Mon,
 10 Jun 2024 14:12:21 -0400
X-MC-Unique: dAv8-BMJN5iob_lNjcmPUw-1
Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6691119560B4;
	Mon, 10 Jun 2024 18:12:20 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12])
	by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F36C31956089;
	Mon, 10 Jun 2024 18:12:19 +0000 (UTC)
Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1])
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 45AICIWM802730
	(version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);
	Mon, 10 Jun 2024 14:12:18 -0400
Received: (from bmarzins@localhost)
	by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 45AICION802729;
	Mon, 10 Jun 2024 14:12:18 -0400
Date: Mon, 10 Jun 2024 14:12:18 -0400
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>, Mike Snitzer <snitzer@kernel.org>
Cc: dm-devel@lists.linux.dev
Subject: Re: [PATCH 0/2] dm: mpath dm_get_device fix
Message-ID: <ZmdCAlEPN8Lmd5XQ@redhat.com>
References: <20240517004129.139615-1-bmarzins@redhat.com>
Precedence: bulk
X-Mailing-List: dm-devel@lists.linux.dev
List-Id: <dm-devel.lists.linux.dev>
List-Subscribe: <mailto:dm-devel+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:dm-devel+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
In-Reply-To: <20240517004129.139615-1-bmarzins@redhat.com>
X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, May 16, 2024 at 08:41:27PM -0400, Benjamin Marzinski wrote:

ping.

> dm-mpath shouldn't be calling dm_get_device() in multipath_message().
> If you run:
> 
> # dmsetup message <mpath_dev> 0 "fail_path <device_not_in_multipath>"
> 
> the dm_get_device() call in multipath_message() will add that incorrect
> device to the devices list, fail to find a matching pgpath, and then
> remove it.  multipath shouldn't be messing with the devices table
> outside of its constructor and destructor.
> 
> To fix it, this patchset factors out a helper function from
> dm_get_device() to turn the device path string into a dev_t.
> multipath_message() calls that helper function and uses the dev_t to
> find the correct pgpath instead.
> 
> Benjamin Marzinski (2):
>   dm: factor out helper function from dm_get_device
>   dm mpath: don't call dm_get_device in multipath_message
> 
>  drivers/md/dm-mpath.c         | 11 ++++-------
>  drivers/md/dm-table.c         | 33 ++++++++++++++++++++++++---------
>  include/linux/device-mapper.h |  5 +++++
>  3 files changed, 33 insertions(+), 16 deletions(-)
> 
> -- 
> 2.45.0
> 


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B60ED1B0123
	for <dm-devel@lists.linux.dev>; Thu,  4 Jul 2024 15:06:26 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1720105588; cv=none; b=Y0lXhzzp0erlPfRW3+VUSU2WvhpEKHbfNFQ5Nh6XzRRNvc9HCdO3tbPKbQAdtdLGhBu8JOJLqLw5OrH6Cax/qBp7tKnrsII1MRcO9R0jULJC+GRtsY3xQ7QdTRySVddhMGvrzVE+FOQTak0BOffGIdNfBCleyCz8RL7U2+yEh+Y=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1720105588; c=relaxed/simple;
	bh=86Gm5Is8mkPJBC1aXyNs0DKmxSaeY/KIbMV8xYZbvdY=;
	h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:
	 MIME-Version:Content-Type; b=bWFQ2/qFS8Z6zql41UllVFKyFO84vVgv/pba64C6xG6N9q/ybp0LoXOfFRlDb5EnrPj0AlSKssxkBBjFD0Dc5Oq5skqZB3z1+elwEhrIVY37pc5dbEHu+JJm/LHd3q6TGR1EW50VqXWVle2hYjxukzb5aOWvP3MlW5fgqGdSsww=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aM0UUMW6; arc=none smtp.client-ip=170.10.133.124
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aM0UUMW6"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1720105585;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 in-reply-to:in-reply-to:references:references;
	bh=dtE8aD6qVsajP0FmvCYMq8naOyw7sWRkPDwBD4QiAlw=;
	b=aM0UUMW6Q1fotsTX7Pi4uhpwlHXSNLF2tNKvL2pMfYzqk6iD3ylTNq29M16dyT8m0HW2RT
	zx/GXCrI/gCN4mecsKlZH8ZbUSxAtTokExF/i8FJ3PRpUY7RiLAnbIauXvFUgBRMsvw2CA
	RxjD+PU91M3u1DPlugddfEuYW0bo+I8=
Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com
 (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by
 relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,
 cipher=TLS_AES_256_GCM_SHA384) id us-mta-18-nV9naJy3NkWOml5eBGwT1Q-1; Thu,
 04 Jul 2024 11:06:22 -0400
X-MC-Unique: nV9naJy3NkWOml5eBGwT1Q-1
Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 89F3119560B0;
	Thu,  4 Jul 2024 15:06:21 +0000 (UTC)
Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21])
	by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0456A195605A;
	Thu,  4 Jul 2024 15:06:21 +0000 (UTC)
Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668)
	id E832030C1C14; Thu,  4 Jul 2024 15:06:19 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
	by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id E77D63FB52;
	Thu,  4 Jul 2024 17:06:19 +0200 (CEST)
Date: Thu, 4 Jul 2024 17:06:19 +0200 (CEST)
From: Mikulas Patocka <mpatocka@redhat.com>
To: Benjamin Marzinski <bmarzins@redhat.com>
cc: Mike Snitzer <snitzer@kernel.org>, dm-devel@lists.linux.dev
Subject: Re: [PATCH 0/2] dm: mpath dm_get_device fix
In-Reply-To: <ZmdCAlEPN8Lmd5XQ@redhat.com>
Message-ID: <29d56ec7-87c5-cbcf-a75c-fb2fcea91978@redhat.com>
References: <20240517004129.139615-1-bmarzins@redhat.com> <ZmdCAlEPN8Lmd5XQ@redhat.com>
Precedence: bulk
X-Mailing-List: dm-devel@lists.linux.dev
List-Id: <dm-devel.lists.linux.dev>
List-Subscribe: <mailto:dm-devel+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:dm-devel+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=US-ASCII



On Mon, 10 Jun 2024, Benjamin Marzinski wrote:

> On Thu, May 16, 2024 at 08:41:27PM -0400, Benjamin Marzinski wrote:
> 
> ping.

I staged these patches for 6.11.

Mikulas

> > dm-mpath shouldn't be calling dm_get_device() in multipath_message().
> > If you run:
> > 
> > # dmsetup message <mpath_dev> 0 "fail_path <device_not_in_multipath>"
> > 
> > the dm_get_device() call in multipath_message() will add that incorrect
> > device to the devices list, fail to find a matching pgpath, and then
> > remove it.  multipath shouldn't be messing with the devices table
> > outside of its constructor and destructor.
> > 
> > To fix it, this patchset factors out a helper function from
> > dm_get_device() to turn the device path string into a dev_t.
> > multipath_message() calls that helper function and uses the dev_t to
> > find the correct pgpath instead.
> > 
> > Benjamin Marzinski (2):
> >   dm: factor out helper function from dm_get_device
> >   dm mpath: don't call dm_get_device in multipath_message
> > 
> >  drivers/md/dm-mpath.c         | 11 ++++-------
> >  drivers/md/dm-table.c         | 33 ++++++++++++++++++++++++---------
> >  include/linux/device-mapper.h |  5 +++++
> >  3 files changed, 33 insertions(+), 16 deletions(-)
> > 
> > -- 
> > 2.45.0
> > 
> 


