Skip to contentSkip to conversation

allow RAID5 to grow to RAID6 with a backup_file

PATCH Superseded Nigel Croxon 2 participants 2 messages May 4, 2020 – May 5, 2020 MD RAID

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 allow RAID5 to grow to RAID6 with a backup_file

This problem came in, as the user did not specify a full path with the backup_file option when growing an RAID5 array to RAID6. When the full path is specified, the symbolic link is created properly (/run/mdadm/backup_file-mdX). But the code did not support the symbolic link when looking for the backup_file. Added two checks for symlink.

This addresses https://www.spinics.net/lists/raid/msg48910.html
and numerous customer reported problems.

---
 Grow.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
Grow.c +20 -1
index 764374f..6dce71c 100644
@@ -1135,6 +1135,16 @@ int reshape_open_backup_file(char *backup_file,
 	unsigned int dev;
 	int i;
 
+	if (lstat(backup_file, &stb) != -1) {
+		switch (stb.st_mode & S_IFMT) {
+		case S_IFLNK:
+			return 1;
+			break;
+		default:
+			break;
+		}
+	}
+
 	*fdlist = open(backup_file, O_RDWR|O_CREAT|(restart ? O_TRUNC : O_EXCL),
 		       S_IRUSR | S_IWUSR);
 	*offsets = 8 * 512;
@@ -5236,8 +5246,17 @@ char *locate_backup(char *name)
 	char *fl = make_backup(name);
 	struct stat stb;
 
-	if (stat(fl, &stb) == 0 && S_ISREG(stb.st_mode))
+	lstat(fl, &stb);
+	switch (stb.st_mode & S_IFMT) {
+	case S_IFLNK:
 		return fl;
+		break;
+	case S_IFREG:
+		return fl;
+		break;
+	default:
+		break;
+	}
 
 	free(fl);
 	return NULL;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 20 lines · Nigel Croxon

This problem came in, as the user did not specify a full path with the backup_file option when growing an RAID5 array to RAID6. When the full path is specified, the symbolic link is created properly (/run/mdadm/backup_file-mdX). But the code did not support the symbolic link when looking for the backup_file. Added two checks for symlink.

This addresses https://www.spinics.net/lists/raid/msg48910.html
and numerous customer reported problems.

---
 Grow.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
Grow.c +0 -0
index 764374f..6dce71c 100644

Grow.c int reshape_open_backup_file(char *backup_file, · line 1142

Quoted 8 lines
Grow.c +5 -0
@@ -1135,6 +1135,16 @@ int reshape_open_backup_file(char *backup_file,
 	unsigned int dev;
 	int i;
 
+	if (lstat(backup_file, &stb) != -1) {
+		switch (stb.st_mode & S_IFMT) {
+		case S_IFLNK:
+			return 1;
+			break;

It doesn't make sense to have a break after a return here.

Grow.c char *locate_backup(char *name) · line 5239

Quoted 13 lines
Grow.c +5 -1
+		default:
+			break;
+		}
+	}
+
 	*fdlist = open(backup_file, O_RDWR|O_CREAT|(restart ? O_TRUNC : O_EXCL),
 		       S_IRUSR | S_IWUSR);
 	*offsets = 8 * 512;
@@ -5236,8 +5246,17 @@ char *locate_backup(char *name)
 	char *fl = make_backup(name);
 	struct stat stb;
 
-	if (stat(fl, &stb) == 0 && S_ISREG(stb.st_mode))> +	lstat(fl, &stb);

You ditched the error check for lstat here. You cannot count on the contents of stb being valid in this case.

Grow.c char *locate_backup(char *name) · line 5256

Quoted 7 lines
Grow.c +6 -0
+	switch (stb.st_mode & S_IFMT) {
+	case S_IFLNK:
 		return fl;
+		break;
+	case S_IFREG:
+		return fl;
+		break;

Same with the break statements here.

Mind fixing this up and submitting a v2.

Thanks,
Jes

Quoted 7 lines
Grow.c +3 -0
+	default:
+		break;
+	}
 
 	free(fl);
 	return NULL;