pr_err(":%s has an active reshape - checking "
"if critical section needs to be restored\n",
chosen_name);
+ if (!c->backup_file)
+ c->backup_file = locate_backup(content->sys_name);
enable_fds(bestcnt/2);
for (i = 0; i < bestcnt/2; i++) {
int j = best[i*2];
int spare = content->array.raid_disks + expansion;
if (restore_backup(st, content,
working,
- spare, c->backup_file, c->verbose) == 1)
+ spare, &c->backup_file, c->verbose) == 1)
return 1;
err = sysfs_set_str(content, NULL,
struct mdinfo *content,
int working_disks,
int next_spare,
- char *backup_file,
+ char **backup_filep,
int verbose)
{
int i;
struct mdinfo *dev;
int err;
int disk_count = next_spare + working_disks;
+ char *backup_file = *backup_filep;
dprintf("Called restore_backup()\n");
fdlist = xmalloc(sizeof(int) * disk_count);
fdlist[next_spare++] = fd;
}
+ if (!backup_file) {
+ backup_file = locate_backup(content->sys_name);
+ *backup_filep = backup_file;
+ }
+
if (st->ss->external && st->ss->recover_backup)
err = st->ss->recover_backup(st, content);
else
long blocks,
int *fdlist,
unsigned long long *offsets,
+ char *sys_name,
int restart)
{
/* Return 1 on success, 0 on any form of failure */
return 0;
}
+ if (!restart && strncmp(backup_file, MAP_DIR, strlen(MAP_DIR)) != 0) {
+ char *bu = make_backup(sys_name);
+ symlink(backup_file, bu);
+ free(bu);
+ }
+
return 1;
}
devname);
goto release;
}
+
+ if (!backup_file)
+ backup_file = locate_backup(sra->sys_name);
+
goto started;
}
/* The container is frozen but the array may not be.
if (!reshape_open_backup_file(backup_file, fd, devname,
(signed)blocks,
fdlist+d, offsets+d,
+ sra->sys_name,
restart)) {
goto release;
}
free(fdlist);
free(offsets);
- if (backup_file && done)
+ if (backup_file && done) {
+ char *bul;
unlink(backup_file);
+ bul = make_backup(sra->sys_name);
+ if (bul) {
+ unlink(bul);
+ free(bul);
+ }
+ }
if (!done) {
abort_reshape(sra);
goto out;
return ret_val;
}
+
+char *make_backup(char *name)
+{
+ char *base = "backup_file-";
+ int len;
+ char *fname;
+
+ len = strlen(MAP_DIR) + 1 + strlen(base) + strlen(name)+1;
+ fname = xmalloc(len);
+ sprintf(fname, "%s/%s%s", MAP_DIR, base, name);
+ return fname;
+}
+
+char *locate_backup(char *name)
+{
+ char *fl = make_backup(name);
+ struct stat stb;
+
+ if (stat(fl, &stb) == 0 &&
+ S_ISREG(stb.st_mode))
+ return fl;
+
+ free(fl);
+ return NULL;
+}
long blocks,
int *fdlist,
unsigned long long *offsets,
+ char *sysfs_name,
int restart);
extern unsigned long compute_backup_blocks(int nchunk, int ochunk,
unsigned int ndata, unsigned int odata);
+extern char *locate_backup(char *name);
+extern char *make_backup(char *name);
extern int save_stripes(int *source, unsigned long long *offsets,
int raid_disks, int chunk_size, int level, int layout,
struct mdinfo *content,
int working_disks,
int spares,
- char *backup_file,
+ char **backup_filep,
int verbose);
extern int Grow_continue_command(char *devname, int fd,
char *backup_file, int verbose);