mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-21 07:26:29 -05:00
Defer pending snapshot promotion until parity sync
This commit is contained in:
parent
950d4a0b10
commit
fbd9b9ea49
48 changed files with 1076 additions and 682 deletions
|
|
@ -61,6 +61,7 @@ int fsinfo(const char* path, int* has_persistent_inode, int* has_syncronized_har
|
|||
*/
|
||||
#define SNAPSHOT_PENDING "pending"
|
||||
#define SNAPSHOT_STABLE "stable"
|
||||
#define SNAPSHOT_SCAN "scan"
|
||||
|
||||
/*
|
||||
* Snapshots context
|
||||
|
|
|
|||
|
|
@ -487,6 +487,10 @@ int fssnapshot_mount(const char* dir, struct fssnapshot_struct* fss)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (windows_rebuild_link(fss, SNAPSHOT_SCAN) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fss->magic = magic;
|
||||
|
||||
return 0;
|
||||
|
|
@ -645,6 +649,8 @@ int fssnapshot_rename(const struct fssnapshot_struct* fss, const char* old_name,
|
|||
{
|
||||
char old_guid[PATH_MAX];
|
||||
char new_guid[PATH_MAX];
|
||||
char old_link[PATH_MAX];
|
||||
char new_link[PATH_MAX];
|
||||
|
||||
pathcpy(old_guid, sizeof(old_guid), fss->snapshot_dir);
|
||||
pathcat(old_guid, sizeof(old_guid), old_name);
|
||||
|
|
@ -652,15 +658,20 @@ int fssnapshot_rename(const struct fssnapshot_struct* fss, const char* old_name,
|
|||
pathcpy(new_guid, sizeof(new_guid), fss->snapshot_dir);
|
||||
pathcat(new_guid, sizeof(new_guid), new_name);
|
||||
pathcat(new_guid, sizeof(new_guid), SNAPSHOT_GUID);
|
||||
pathcpy(old_link, sizeof(old_link), fss->snapshot_dir);
|
||||
pathcat(old_link, sizeof(old_link), old_name);
|
||||
pathcpy(new_link, sizeof(new_link), fss->snapshot_dir);
|
||||
pathcat(new_link, sizeof(new_link), new_name);
|
||||
|
||||
if (windows_rename(old_guid, new_guid) != 0) {
|
||||
log_error(errno, "Error renaming '%s' to '%s'. %s.\n", old_guid, new_guid, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* the rename is the latest operation, and then we don't care about the links, we just remove both */
|
||||
windows_delete_link(fss, old_name);
|
||||
windows_delete_link(fss, new_name);
|
||||
if (windows_rename(old_link, new_link) != 0) {
|
||||
log_error(errno, "Error renaming '%s' to '%s'. %s.\n", old_link, new_link, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -678,6 +689,7 @@ void fssnapshot_unmount(const struct fssnapshot_struct* fss)
|
|||
*/
|
||||
windows_delete_link(fss, SNAPSHOT_PENDING);
|
||||
windows_delete_link(fss, SNAPSHOT_STABLE);
|
||||
windows_delete_link(fss, SNAPSHOT_SCAN);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -1806,7 +1806,7 @@ int snapraid_main(int argc, char* argv[])
|
|||
state_write(&state);
|
||||
}
|
||||
|
||||
ret = state_snapshot_new(&state);
|
||||
ret = state_snapshot_scan(&state);
|
||||
if (ret != 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5956,7 +5956,7 @@ static int state_snapshot_dir(struct fssnapshot_struct* fss, const char* name, c
|
|||
return 0;
|
||||
}
|
||||
|
||||
int state_snapshot_new(struct snapraid_state* state)
|
||||
int state_snapshot_scan(struct snapraid_state* state)
|
||||
{
|
||||
if (!state->snapshot)
|
||||
return 0;
|
||||
|
|
@ -5970,7 +5970,47 @@ int state_snapshot_new(struct snapraid_state* state)
|
|||
|
||||
size_t root_len = strlen(disk->fss.root_dir);
|
||||
|
||||
/* delete a potential previous pending snapshot */
|
||||
/* delete a potential previous scan snapshot */
|
||||
if (state_snapshot_dir(&disk->fss, SNAPSHOT_SCAN, 0, 0) == 0) {
|
||||
if (fssnapshot_delete(&disk->fss, SNAPSHOT_SCAN) != 0) {
|
||||
log_fatal(errno, "Failed to delete scan snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* create a new snapshot for scanning */
|
||||
if (fssnapshot_create(&disk->fss, SNAPSHOT_SCAN) != 0) {
|
||||
log_fatal(errno, "Failed to create scan snapshot '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg_progress("Created disk %s scan snapshot...\n", disk->name);
|
||||
|
||||
/* setup the snapshot in use */
|
||||
if (state_snapshot_dir(&disk->fss, SNAPSHOT_SCAN, disk->mount_point + root_len, disk) != 0) {
|
||||
log_error(errno, "Error stating scan snapshot '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int state_snapshot_pending(struct snapraid_state* state)
|
||||
{
|
||||
if (!state->snapshot)
|
||||
return 0;
|
||||
|
||||
for (tommy_node* i = state->disklist; i != 0; i = i->next) {
|
||||
struct snapraid_disk* disk = i->data;
|
||||
|
||||
/* check if it supports snapshot */
|
||||
if (disk->fss.magic == 0)
|
||||
continue;
|
||||
|
||||
size_t root_len = strlen(disk->fss.root_dir);
|
||||
|
||||
/* delete the pending snapshot only after the content state was saved */
|
||||
if (state_snapshot_dir(&disk->fss, SNAPSHOT_PENDING, 0, 0) == 0) {
|
||||
if (fssnapshot_delete(&disk->fss, SNAPSHOT_PENDING) != 0) {
|
||||
log_fatal(errno, "Failed to delete pending snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
|
|
@ -5978,9 +6018,9 @@ int state_snapshot_new(struct snapraid_state* state)
|
|||
}
|
||||
}
|
||||
|
||||
/* create a new snapshot */
|
||||
if (fssnapshot_create(&disk->fss, SNAPSHOT_PENDING) != 0) {
|
||||
log_fatal(errno, "Failed to create pending snapshot '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
/* make the scan snapshot available for recovery */
|
||||
if (fssnapshot_rename(&disk->fss, SNAPSHOT_SCAN, SNAPSHOT_PENDING) != 0) {
|
||||
log_fatal(errno, "Failed to rename scan snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -426,9 +426,14 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha
|
|||
void state_attr(struct snapraid_state* state, tommy_list* low);
|
||||
|
||||
/**
|
||||
* Create (or reuse existing) pending snapshots
|
||||
* Create (or reuse existing) scan snapshots
|
||||
*/
|
||||
int state_snapshot_new(struct snapraid_state* state);
|
||||
int state_snapshot_scan(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Promote scan snapshots to pending before starting parity processing.
|
||||
*/
|
||||
int state_snapshot_pending(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Make the pending snapshots as stable
|
||||
|
|
|
|||
|
|
@ -1686,13 +1686,16 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
|
|||
log_fatal(EUSER, "WARNING! Skipped state write for --test-skip-content-write option.\n");
|
||||
}
|
||||
|
||||
if (state->opt.kill_before_sync) {
|
||||
/* make the scanned state available for recovery before changing parity */
|
||||
if (state_snapshot_pending(state) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
++process_error;
|
||||
/* continue, as we are already exiting */
|
||||
/* LCOV_EXCL_STOP */
|
||||
} else if (state->opt.kill_before_sync) {
|
||||
log_fatal(EUSER, "WARNING! Killing due --test-kill-before-sync option.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* skip degenerated cases of empty parity, or skipping all */
|
||||
if (blockstart < blockmax) {
|
||||
} else if (blockstart < blockmax) {
|
||||
ret = state_sync_process(state, parity_handle, blockstart, blockmax);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue