From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nigel Croxon Subject: [PATCH V2] allow RAID5 to grow to RAID6 with a backup_file Date: Tue, 5 May 2020 14:35:45 -0400 Message-ID: <20200505183545.26291-1-ncroxon@redhat.com> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Return-path: Sender: linux-raid-owner@vger.kernel.org To: jes@trained-monkey.org, linux-raid@vger.kernel.org List-Id: linux-raid.ids 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. V2: - Removed unneeded break; in both case-statements - Returned the error checking on call to lstat Signed-off-by: Nigel Croxon --- Grow.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Grow.c b/Grow.c index 764374f..53245d7 100644 --- a/Grow.c +++ b/Grow.c @@ -1135,6 +1135,15 @@ int reshape_open_backup_file(char *backup_file, unsigned int dev; int i; =20 + if (lstat(backup_file, &stb) !=3D -1) { + switch (stb.st_mode & S_IFMT) { + case S_IFLNK: + return 1; + default: + break; + } + } + *fdlist =3D open(backup_file, O_RDWR|O_CREAT|(restart ? O_TRUNC : O_EXC= L), S_IRUSR | S_IWUSR); *offsets =3D 8 * 512; @@ -5236,8 +5245,16 @@ char *locate_backup(char *name) char *fl =3D make_backup(name); struct stat stb; =20 - if (stat(fl, &stb) =3D=3D 0 && S_ISREG(stb.st_mode)) - return fl; + if (lstat(fl, &stb) =3D=3D 0) { + switch (stb.st_mode & S_IFMT) { + case S_IFLNK: + return fl; + case S_IFREG: + return fl; + default: + break; + } + } =20 free(fl); return NULL; --=20 2.20.1