Make snapshot replacement crash-safe using retiring snapshots
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-09-08 22:19:55 +02:00
parent 7ba5f63d2d
commit f11b649cf4
4 changed files with 228 additions and 38 deletions

View file

@ -6506,18 +6506,9 @@ int state_snapshot_pending(struct snapraid_state* state)
msg_progress("Creating disk %s pending snapshot...\n", disk->name);
/* delete the pending snapshot only after the content state was saved */
if (state_snapshot_dir(&disk->fss, SNAPSHOT_PENDING, 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));
error = -1;
continue;
}
}
/* 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));
/* publish the scan snapshot without dropping the previous recovery source first */
if (fssnapshot_replace(&disk->fss, SNAPSHOT_SCAN, SNAPSHOT_PENDING) != 0) {
log_fatal(errno, "Failed to replace pending snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
error = -1;
continue;
}
@ -6549,18 +6540,9 @@ int state_snapshot_commit(struct snapraid_state* state)
msg_progress("Committing disk %s stable snapshot...\n", disk->name);
/* delete a potential previous stable snapshot */
if (state_snapshot_dir(&disk->fss, SNAPSHOT_STABLE, 0) == 0) {
if (fssnapshot_delete(&disk->fss, SNAPSHOT_STABLE) != 0) {
log_fatal(errno, "Failed to delete stable snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
error = -1;
continue;
}
}
/* rename pending to stable */
if (fssnapshot_rename(&disk->fss, SNAPSHOT_PENDING, SNAPSHOT_STABLE) != 0) {
log_fatal(errno, "Failed to rename snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
/* publish pending without dropping the previous stable deallocation source first */
if (fssnapshot_replace(&disk->fss, SNAPSHOT_PENDING, SNAPSHOT_STABLE) != 0) {
log_fatal(errno, "Failed to replace stable snapshot in '%s'. %s.\n", disk->fss.snapshot_dir, strerror(errno));
error = -1;
continue;
}