From d8870cdd422a23cb1c783b029aed7372fadf71cd Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 26 Jul 2013 14:50:52 +0200 Subject: [PATCH] Adds a new --force-device option to allow to fix with disk with same device ID. --- snapraid.1 | 11 ++++++++++- snapraid.c | 7 ++++++- snapraid.d | 11 ++++++++++- snapraid.txt | 11 ++++++++++- state.c | 18 ++++++++++++------ state.h | 1 + 6 files changed, 49 insertions(+), 10 deletions(-) diff --git a/snapraid.1 b/snapraid.1 index 89e8644a..f322d91f 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -18,7 +18,7 @@ snapraid [\(hyc, \(hy\(hyconf CONFIG] .PD 0 .PP .PD - [\(hyZ, \(hy\(hyforce\(hyzero] [\(hyE, \(hy\(hyforce\(hyempty] [\(hyU, \(hy\(hyforce\(hyuuid] + [\(hyZ, \(hy\(hyforce\(hyzero] [\(hyE, \(hy\(hyforce\(hyempty] [\(hyU, \(hy\(hyforce\(hyuuid] [\(hyD, \(hy\(hyforce\(hydevice] .PD 0 .PP .PD @@ -559,6 +559,15 @@ the normal case of replacing disks. This option can be used only with the \(a"sync\(a", \(a"check\(a" or \(a"fix\(a" command. .TP +.B \(hyD, \(hy\(hyforce\(hydevice +Forces the insecure operation of fixing with disks on the same +physical device. +If SnapRAID detects that two disks have the same device ID, +it stops proceeding, because it\(cqs not a supported configuration. +But it could happen what you want to temporarely restore a lost +disk in the free space left in an already used disk. and this +option will allow you to continue anyway. +.TP .B \(hys, \(hy\(hystart BLKSTART Starts the processing from the specified block number. It could be useful to easy retry to check diff --git a/snapraid.c b/snapraid.c index b5bb8559..30543d93 100644 --- a/snapraid.c +++ b/snapraid.c @@ -69,6 +69,7 @@ void usage(void) printf(" " SWITCH_GETOPT_LONG("-Z, --force-zero ", "-Z") " Force synching of files that get zero size\n"); printf(" " SWITCH_GETOPT_LONG("-E, --force-empty ", "-E") " Force synching of disks that get empty\n"); printf(" " SWITCH_GETOPT_LONG("-U, --force-uuid ", "-U") " Force commands on disks with uuid changed\n"); + printf(" " SWITCH_GETOPT_LONG("-D, --force-device ", "-D") " Force commands on disks with same device id\n"); printf(" " SWITCH_GETOPT_LONG("-s, --start BLKSTART ", "-s") " Start from the specified block number\n"); printf(" " SWITCH_GETOPT_LONG("-t, --count BLKCOUNT ", "-t") " Count of block to process\n"); printf(" " SWITCH_GETOPT_LONG("-v, --verbose ", "-v") " Verbose\n"); @@ -107,6 +108,7 @@ struct option long_options[] = { { "force-zero", 0, 0, 'Z' }, { "force-empty", 0, 0, 'E' }, { "force-uuid", 0, 0, 'U' }, + { "force-device", 0, 0, 'D' }, { "find-by-name", 0, 0, 'N' }, { "audit-only", 0, 0, 'a' }, { "speed-test", 0, 0, 'T' }, @@ -166,7 +168,7 @@ struct option long_options[] = { }; #endif -#define OPTIONS "c:f:d:ms:t:i:l:ZEUNaTvhVG" +#define OPTIONS "c:f:d:ms:t:i:l:ZEUDNaTvhVG" volatile int global_interrupt = 0; @@ -293,6 +295,9 @@ int main(int argc, char* argv[]) case 'U' : opt.force_uuid = 1; break; + case 'D' : + opt.force_device = 1; + break; case 'N' : opt.force_by_name = 1; break; diff --git a/snapraid.d b/snapraid.d index 8bed941d..2b923b9e 100644 --- a/snapraid.d +++ b/snapraid.d @@ -6,7 +6,7 @@ Synopsis : [-f, --filter PATTERN] [-d, --filter-disk NAME] [-m, --filter-missing] : [-a, --audit-only] [-i, --import DIR] : [-N, --find-by-name] - : [-Z, --force-zero] [-E, --force-empty] [-U, --force-uuid] + : [-Z, --force-zero] [-E, --force-empty] [-U, --force-uuid] [-D, --force-device] : [-s, --start BLKSTART] [-t, --count BLKCOUNT] : [-v, --verbose] [-l, --log FILE] : sync|status|scrub|diff|dup|pool|check|fix|rehash @@ -419,6 +419,15 @@ Options This option can be used only with the "sync", "check" or "fix" command. + -D, --force-device + Forces the insecure operation of fixing with disks on the same + physical device. + If SnapRAID detects that two disks have the same device ID, + it stops proceeding, because it's not a supported configuration. + But it could happen what you want to temporarely restore a lost + disk in the free space left in an already used disk. and this + option will allow you to continue anyway. + -s, --start BLKSTART Starts the processing from the specified block number. It could be useful to easy retry to check diff --git a/snapraid.txt b/snapraid.txt index f6c671c1..a9e30bb9 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -10,7 +10,7 @@ snapraid [-c, --conf CONFIG] [-f, --filter PATTERN] [-d, --filter-disk NAME] [-m, --filter-missing] [-a, --audit-only] [-i, --import DIR] [-N, --find-by-name] - [-Z, --force-zero] [-E, --force-empty] [-U, --force-uuid] + [-Z, --force-zero] [-E, --force-empty] [-U, --force-uuid] [-D, --force-device] [-s, --start BLKSTART] [-t, --count BLKCOUNT] [-v, --verbose] [-l, --log FILE] sync|status|scrub|diff|dup|pool|check|fix|rehash @@ -460,6 +460,15 @@ SnapRAID provides the following options: This option can be used only with the "sync", "check" or "fix" command. + -D, --force-device + Forces the insecure operation of fixing with disks on the same + physical device. + If SnapRAID detects that two disks have the same device ID, + it stops proceeding, because it's not a supported configuration. + But it could happen what you want to temporarely restore a lost + disk in the free space left in an already used disk. and this + option will allow you to continue anyway. + -s, --start BLKSTART Starts the processing from the specified block number. It could be useful to easy retry to check diff --git a/state.c b/state.c index bd38a5de..660d16c8 100644 --- a/state.c +++ b/state.c @@ -112,14 +112,20 @@ static void state_config_check(struct snapraid_state* state, const char* path) } #endif - for(j=i->next;j!=0;j=j->next) { - struct snapraid_disk* other = j->data; - if (disk->device == other->device) { - fprintf(stderr, "Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); + if (!state->opt.force_device) { + for(j=i->next;j!=0;j=j->next) { + struct snapraid_disk* other = j->data; + if (disk->device == other->device) { + fprintf(stderr, "Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", disk->device); + fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", disk->device); #endif - exit(EXIT_FAILURE); + /* in "fix" we allow to continue anyway */ + if (strcmp(state->command, "fix") == 0) { + fprintf(stderr, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + } + exit(EXIT_FAILURE); + } } } diff --git a/state.h b/state.h index c3ffe115..5d67b91a 100644 --- a/state.h +++ b/state.h @@ -41,6 +41,7 @@ struct snapraid_option { int force_zero; /**< Forced dangerous operations of synching files now with zero size. */ int force_empty; /**< Forced dangerous operations of synching disks now empty. */ int force_uuid; /**< Forced dangerous operations of synching disks with uuid changed. */ + int force_device; /**< Forced dangerous operations of using disks with save device id. */ int force_by_name; /**< Forced dangerous operations of synching a rewritten disk. */ int expect_unrecoverable; /**< Expect presence of unrecoverable error in checking or fixing. */ int expect_recoverable; /**< Expect presence of recoverable error in checking. */