diff options
author | NeilBrown <neilb@suse.de> | 2010-12-01 01:58:32 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-03-10 07:19:20 +0100 |
commit | 48b1fc9ddbd1c4f6a5d0cb43d0290ea75dbdbc5f (patch) | |
tree | e750a86b4f95420f8cc3224a0438c1f3da6b1687 | |
parent | Create/grow: improve checks on number of devices. (diff) | |
download | mdadm-48b1fc9ddbd1c4f6a5d0cb43d0290ea75dbdbc5f.tar.xz mdadm-48b1fc9ddbd1c4f6a5d0cb43d0290ea75dbdbc5f.zip |
Grow: disallow placing backup file on array being reshaped.
the tests here aren't perfect, but they could catch some cases.
Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r-- | Grow.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1051,6 +1051,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, } else { /* need to check backup file is large enough */ char buf[512]; + struct stat stb; + unsigned int dev; fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL, S_IRUSR | S_IWUSR); offsets[d] = 8 * 512; @@ -1060,6 +1062,22 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, rv = 1; break; } + /* Guard against backup file being on array device. + * If array is partitioned or if LVM etc is in the + * way this will not notice, but it is better than + * nothing. + */ + fstat(fdlist[d], &stb); + dev = stb.st_dev; + fstat(fd, &stb); + if (stb.st_rdev == dev) { + fprintf(stderr, Name ": backup file must NOT be" + " on the array being reshaped.\n"); + rv = 1; + close(fdlist[d]); + break; + } + memset(buf, 0, 512); for (i=0; i < (signed)blocks + 8 ; i++) { if (write(fdlist[d], buf, 512) != 512) { |