From 87e6497665ff4d425a3497206c924e8457331b59 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 9 Nov 2014 19:51:58 +0100 Subject: [PATCH] Checks parity UUID before proceding. --- HISTORY | 2 ++ cmdline/state.c | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index b5ecbdb2..cd82bd61 100644 --- a/HISTORY +++ b/HISTORY @@ -19,6 +19,8 @@ SnapRAID HISTORY * Prints the time spent waiting for each disk also in 'scrub'. * The CPU usage, speed and ETA estimations are now based on the last 100 seconds rather than from the start. + * Keeps track of the UUID of the parity disks to check them before + operating. * Windows binary built with gcc 4.8.1 using the MXE cross compiler 2.23. 6.3 2014/7 diff --git a/cmdline/state.c b/cmdline/state.c index 156ebe50..2d9121fa 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -1026,6 +1026,7 @@ static void state_map(struct snapraid_state* state) if (state->no_conf) return; + /* counter for the number of UUID mismatches */ uuid_mismatch = 0; /* checks if mapping match the disk uuid */ @@ -1088,11 +1089,21 @@ static void state_map(struct snapraid_state* state) continue; } - /* update the uuid in the mapping */ - /* at now we don't enforce uuid for parity */ - /* as the user is expected to have a different file name */ - /* for each parity file */ - pathcpy(state->parity[l].uuid, sizeof(state->parity[l].uuid), uuid); + /* if the uuid is changed */ + if (strcmp(uuid, state->parity[l].uuid) != 0) { + /* if the previous uuid is available */ + if (state->parity[l].uuid[0] != 0) { + /* count the number of uuid change */ + ++uuid_mismatch; + fprintf(stderr, "UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid); + } + + /* update the uuid */ + pathcpy(state->parity[l].uuid, sizeof(state->parity[l].uuid), uuid); + + /* write the new state with the new uuid */ + state->need_write = 1; + } } }