Defer pending snapshot promotion until parity sync

This commit is contained in:
Andrea Mazzoleni 2026-08-12 14:53:58 +02:00
parent 554adc9048
commit 6cab8e3909
48 changed files with 352 additions and 145 deletions

View file

@ -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

View file

@ -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;
@ -678,6 +682,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);
}
/****************************************************************************/

View file

@ -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);
}

View file

@ -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,45 @@ 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;
/* 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,19 +6016,13 @@ 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;
}
msg_progress("Created disk %s pending snapshot...\n", disk->name);
/* setup the snapshot in use */
if (state_snapshot_dir(&disk->fss, SNAPSHOT_PENDING, disk->mount_point + root_len, disk) != 0) {
log_error(errno, "Error stating pending snapshot '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
return -1;
}
}
return 0;

View file

@ -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

View file

@ -1691,8 +1691,13 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
exit(EXIT_SUCCESS);
}
/* skip degenerated cases of empty parity, or skipping all */
if (blockstart < blockmax) {
/* 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 (blockstart < blockmax) {
ret = state_sync_process(state, parity_handle, blockstart, blockmax);
if (ret == -1) {
/* LCOV_EXCL_START */