Blame SOURCES/0086-mdadm-Grow-prevent-md-s-fd-from-being-occupied-durin.patch

e95a18
From 77b72fa828132a35c8b2e08d3fb07eea80b11895 Mon Sep 17 00:00:00 2001
e95a18
From: allenpeng <allenpeng@synology.com>
e95a18
Date: Fri, 12 Jun 2020 17:00:39 +0800
e95a18
Subject: [PATCH 086/108] mdadm/Grow: prevent md's fd from being occupied
e95a18
 during delayed time
e95a18
e95a18
If we start reshaping on md which shares sub-devices with another
e95a18
resyncing md, it may be forced to wait for others to complete. mdadm
e95a18
occupies the md's fd during this time, which causes the md can not be
e95a18
stopped and the filesystem can not be mounted on the md. We can close
e95a18
md's fd earlier to solve this problem.
e95a18
e95a18
Reproducible Steps:
e95a18
e95a18
1. create two partitions on sda, sdb, sdc, sdd
e95a18
2. create raid1 with sda1, sdb1
e95a18
mdadm -C /dev/md1 --assume-clean -l1 -n2 /dev/sda1 /dev/sdb1
e95a18
3. create raid5 with sda2, sdb2, sdc2
e95a18
mdadm -C /dev/md2 --assume-clean -l5 -n3 /dev/sda2 /dev/sdb2 /dev/sdc2
e95a18
4. start resync at md1
e95a18
echo repair > /sys/block/md1/md/sync_action
e95a18
5. reshape raid5 to raid6
e95a18
mdadm -a /dev/md2 /dev/sdd2
e95a18
mdadm --grow /dev/md2 -n4 -l6 --backup-file=/root/md2-backup
e95a18
e95a18
Now mdadm is occupying the fd of md2, causing md2 unable to be stopped
e95a18
e95a18
6.Try to stop md2, an error message shows
e95a18
mdadm -S /dev/md2
e95a18
mdadm: Cannot get exclusive access to /dev/md3:Perhaps a running process,
e95a18
mounted filesystem or active volume group?
e95a18
e95a18
Reviewed-by: Alex Wu <alexwu@synology.com>
e95a18
Reviewed-by: BingJing Chang <bingjingc@synology.com>
e95a18
Reviewed-by: Danny Shih <dannyshih@synology.com>
e95a18
Signed-off-by: ChangSyun Peng <allenpeng@synology.com>
e95a18
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
e95a18
---
e95a18
 Grow.c | 2 +-
e95a18
 1 file changed, 1 insertion(+), 1 deletion(-)
e95a18
e95a18
diff --git a/Grow.c b/Grow.c
e95a18
index 764374f..57db7d4 100644
e95a18
--- a/Grow.c
e95a18
+++ b/Grow.c
e95a18
@@ -3517,6 +3517,7 @@ started:
e95a18
 			return 0;
e95a18
 		}
e95a18
 
e95a18
+	close(fd);
e95a18
 	/* Now we just need to kick off the reshape and watch, while
e95a18
 	 * handling backups of the data...
e95a18
 	 * This is all done by a forked background process.
e95a18
@@ -3569,7 +3570,6 @@ started:
e95a18
 			mdstat_wait(30 - (delayed-1) * 25);
e95a18
 	} while (delayed);
e95a18
 	mdstat_close();
e95a18
-	close(fd);
e95a18
 	if (check_env("MDADM_GROW_VERIFY"))
e95a18
 		fd = open(devname, O_RDONLY | O_DIRECT);
e95a18
 	else
e95a18
-- 
e95a18
2.7.5
e95a18