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

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