public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] dm ioctl: fix erroneous EINVAL when signaled
@ 2024-07-17 18:56 Khazhismel Kumykov
  2024-07-17 19:44 ` Mikulas Patocka
  0 siblings, 1 reply; 9+ messages in thread
From: Khazhismel Kumykov @ 2024-07-17 18:56 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka
  Cc: dm-devel, linux-kernel, Khazhismel Kumykov

do_resume when loading a new map first calls dm_suspend, which could
silently fail. When we proceeded to dm_swap_table, we would bail out
with EINVAL. Instead, restore new_map and return ERESTARTSYS when
signaled.

Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
---
 drivers/md/dm-ioctl.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)


RFC as I am rather unfamiliar with the locking semantics here - whether
we do need to re-grab hash_lock to write to an hc we previously grabbed,
and whether the device becoming unhashed while we're in this function is
really something that needs to be checked. However, this patch does fix
the issue we were seeing - we'd get EINVAL when thread in ioctl was
signaled.


diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index c2c07bfa6471..b81650c6d096 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1181,8 +1181,22 @@ static int do_resume(struct dm_ioctl *param)
 			suspend_flags &= ~DM_SUSPEND_LOCKFS_FLAG;
 		if (param->flags & DM_NOFLUSH_FLAG)
 			suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG;
-		if (!dm_suspended_md(md))
-			dm_suspend(md, suspend_flags);
+		if (!dm_suspended_md(md)) {
+			r = dm_suspend(md, suspend_flags);
+			if (r == -EINTR)
+				r = -ERESTARTSYS;
+			if (r) {
+				down_write(&_hash_lock);
+				hc = dm_get_mdptr(md);
+				if (!hc)
+					r = -ENXIO;
+				else
+					hc->new_map = new_map;
+				up_write(&_hash_lock);
+				dm_put(md);
+				return r;
+			}
+		}
 
 		old_size = dm_get_size(md);
 		old_map = dm_swap_table(md, new_map);
-- 
2.45.2.993.g49e7a77208-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-07-23 17:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-17 18:56 [RFC PATCH] dm ioctl: fix erroneous EINVAL when signaled Khazhismel Kumykov
2024-07-17 19:44 ` Mikulas Patocka
2024-07-17 19:52   ` Khazhy Kumykov
2024-07-17 23:18     ` [RFC PATCH v2] " Khazhismel Kumykov
2024-07-18 14:25       ` Mike Snitzer
2024-07-23 12:51       ` Mikulas Patocka
2024-07-23 13:11         ` Zdenek Kabelac
2024-07-23 17:17           ` Khazhy Kumykov
2024-07-22  9:52     ` [RFC PATCH] " Zdenek Kabelac

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox