Move restore backup code to function

Reshape backup should be able to be restored during reshape continuation
also. To reuse already existing code it is moved to function.

Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
Adam Kwolek 2011-09-21 12:17:30 +10:00 committed by NeilBrown
parent 910e9fa7f9
commit 3f54bd62dc
3 changed files with 70 additions and 37 deletions

View File

@ -1555,44 +1555,10 @@ int assemble_container_content(struct supertype *st, int mdfd,
if (content->reshape_active) {
int spare = content->array.raid_disks + expansion;
int i;
int *fdlist = malloc(sizeof(int) *
(working + expansion
+ content->array.raid_disks));
for (i=0; i<spare; i++)
fdlist[i] = -1;
for (dev = content->devs; dev; dev = dev->next) {
char buf[20];
int fd;
sprintf(buf, "%d:%d",
dev->disk.major,
dev->disk.minor);
fd = dev_open(buf, O_RDWR);
if (dev->disk.raid_disk >= 0)
fdlist[dev->disk.raid_disk] = fd;
else
fdlist[spare++] = fd;
}
if (st->ss->external && st->ss->recover_backup)
err = st->ss->recover_backup(st, content);
else
err = Grow_restart(st, content, fdlist, spare,
backup_file, verbose > 0);
while (spare > 0) {
spare--;
if (fdlist[spare] >= 0)
close(fdlist[spare]);
}
free(fdlist);
if (err) {
fprintf(stderr, Name ": Failed to restore critical"
" section for reshape - sorry.\n");
if (!backup_file)
fprintf(stderr, Name ": Possibly you need"
" to specify a --backup-file\n");
if (restore_backup(st, content,
working,
spare, backup_file, verbose) == 1)
return 1;
}
err = Grow_continue(mdfd, st, content, backup_file);
} else switch(content->array.level) {

61
Grow.c
View File

@ -35,6 +35,67 @@
#define offsetof(t,f) ((size_t)&(((t*)0)->f))
#endif
int restore_backup(struct supertype *st,
struct mdinfo *content,
int working_disks,
int next_spare,
char *backup_file,
int verbose)
{
int i;
int *fdlist;
struct mdinfo *dev;
int err;
int disk_count = next_spare + working_disks;
dprintf("Called restore_backup()\n");
fdlist = malloc(sizeof(int) * disk_count);
if (fdlist == NULL) {
fprintf(stderr,
Name ": cannot allocate memory for disk list\n");
return 1;
}
for (i = 0; i < next_spare; i++)
fdlist[i] = -1;
for (dev = content->devs; dev; dev = dev->next) {
char buf[22];
int fd;
sprintf(buf, "%d:%d",
dev->disk.major,
dev->disk.minor);
fd = dev_open(buf, O_RDWR);
if (dev->disk.raid_disk >= 0)
fdlist[dev->disk.raid_disk] = fd;
else
fdlist[next_spare++] = fd;
}
if (st->ss->external && st->ss->recover_backup)
err = st->ss->recover_backup(st, content);
else
err = Grow_restart(st, content, fdlist, next_spare,
backup_file, verbose > 0);
while (next_spare > 0) {
disk_count--;
if (fdlist[disk_count] >= 0)
close(fdlist[disk_count]);
}
free(fdlist);
if (err) {
fprintf(stderr, Name ": Failed to restore critical"
" section for reshape - sorry.\n");
if (!backup_file)
fprintf(stderr, Name ": Possibly you need"
" to specify a --backup-file\n");
return 1;
}
dprintf("restore_backup() returns status OK.\n");
return 0;
}
int Grow_Add_device(char *devname, int fd, char *newdev)
{
/* Add a device to an active array.

View File

@ -1025,6 +1025,12 @@ extern int Grow_restart(struct supertype *st, struct mdinfo *info,
int *fdlist, int cnt, char *backup_file, int verbose);
extern int Grow_continue(int mdfd, struct supertype *st,
struct mdinfo *info, char *backup_file);
extern int restore_backup(struct supertype *st,
struct mdinfo *content,
int working_disks,
int spares,
char *backup_file,
int verbose);
extern int Assemble(struct supertype *st, char *mddev,
struct mddev_ident *ident,