Grow: open backup file for reshape as function
Move opening backup file to the function for future reuse during container reshape. Signed-off-by: Adam Kwolek <adam.kwolek@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
899aead007
commit
e6e9d47b76
101
Grow.c
101
Grow.c
|
@ -914,6 +914,61 @@ release:
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int reshape_open_backup_file(char *backup_file,
|
||||||
|
int fd,
|
||||||
|
char *devname,
|
||||||
|
long blocks,
|
||||||
|
int *fdlist,
|
||||||
|
unsigned long long *offsets)
|
||||||
|
{
|
||||||
|
/* Return 1 on success, 0 on any form of failure */
|
||||||
|
/* need to check backup file is large enough */
|
||||||
|
char buf[512];
|
||||||
|
struct stat stb;
|
||||||
|
unsigned int dev;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
*fdlist = open(backup_file, O_RDWR|O_CREAT|O_EXCL,
|
||||||
|
S_IRUSR | S_IWUSR);
|
||||||
|
*offsets = 8 * 512;
|
||||||
|
if (*fdlist < 0) {
|
||||||
|
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
|
||||||
|
devname, backup_file, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* 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, &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");
|
||||||
|
close(*fdlist);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(buf, 0, 512);
|
||||||
|
for (i=0; i < blocks + 1 ; i++) {
|
||||||
|
if (write(*fdlist, buf, 512) != 512) {
|
||||||
|
fprintf(stderr, Name ": %s: cannot create"
|
||||||
|
" backup file %s: %s\n",
|
||||||
|
devname, backup_file, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fsync(*fdlist) != 0) {
|
||||||
|
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
|
||||||
|
devname, backup_file, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long compute_backup_blocks(int nchunk, int ochunk,
|
unsigned long compute_backup_blocks(int nchunk, int ochunk,
|
||||||
unsigned int ndata, unsigned int odata)
|
unsigned int ndata, unsigned int odata)
|
||||||
{
|
{
|
||||||
|
@ -974,7 +1029,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
|
||||||
char alt_layout[40];
|
char alt_layout[40];
|
||||||
int *fdlist;
|
int *fdlist;
|
||||||
unsigned long long *offsets;
|
unsigned long long *offsets;
|
||||||
int d, i;
|
int d;
|
||||||
int nrdisks;
|
int nrdisks;
|
||||||
int err;
|
int err;
|
||||||
int frozen;
|
int frozen;
|
||||||
|
@ -1649,47 +1704,9 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* need to check backup file is large enough */
|
if (!reshape_open_backup_file(backup_file, fd, devname,
|
||||||
char buf[512];
|
(signed)blocks,
|
||||||
struct stat stb;
|
fdlist+d, offsets+d)) {
|
||||||
unsigned int dev;
|
|
||||||
fdlist[d] = open(backup_file, O_RDWR|O_CREAT|O_EXCL,
|
|
||||||
S_IRUSR | S_IWUSR);
|
|
||||||
offsets[d] = 8 * 512;
|
|
||||||
if (fdlist[d] < 0) {
|
|
||||||
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
|
|
||||||
devname, backup_file, strerror(errno));
|
|
||||||
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 + 1 ; i++) {
|
|
||||||
if (write(fdlist[d], buf, 512) != 512) {
|
|
||||||
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
|
|
||||||
devname, backup_file, strerror(errno));
|
|
||||||
rv = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fsync(fdlist[d]) != 0) {
|
|
||||||
fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n",
|
|
||||||
devname, backup_file, strerror(errno));
|
|
||||||
rv = 1;
|
rv = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
7
mdadm.h
7
mdadm.h
|
@ -486,7 +486,12 @@ extern int reshape_prepare_fdlist(char *devname,
|
||||||
extern void reshape_free_fdlist(int *fdlist,
|
extern void reshape_free_fdlist(int *fdlist,
|
||||||
unsigned long long *offsets,
|
unsigned long long *offsets,
|
||||||
int size);
|
int size);
|
||||||
|
extern int reshape_open_backup_file(char *backup,
|
||||||
|
int fd,
|
||||||
|
char *devname,
|
||||||
|
long blocks,
|
||||||
|
int *fdlist,
|
||||||
|
unsigned long long *offsets);
|
||||||
extern unsigned long compute_backup_blocks(int nchunk, int ochunk,
|
extern unsigned long compute_backup_blocks(int nchunk, int ochunk,
|
||||||
unsigned int ndata, unsigned int odata);
|
unsigned int ndata, unsigned int odata);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue