From 543658640af04140a5f8af99ad97718c9cda18cc Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 17 Mar 2011 15:57:11 +0100 Subject: [PATCH] Splits the force option in force-zero and force-empty --- scan.c | 12 +++++++----- snapraid.c | 23 +++++++++++++++-------- snapraid.d | 24 +++++++++++++++++------- snapraid.html | 34 +++++++++++++++++++++++++--------- snapraid.txt | 30 +++++++++++++++++++++--------- state.c | 5 +++-- state.h | 5 +++-- 7 files changed, 91 insertions(+), 42 deletions(-) diff --git a/scan.c b/scan.c index aa5ee5c5..f4bb007a 100644 --- a/scan.c +++ b/scan.c @@ -111,9 +111,11 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, /* do a safety check to ensure that the common ext4 case of zeroing */ /* the size of a file after a crash doesn't propagate to the backup */ if (file->size != 0 && st->st_size == 0) { - fprintf(stderr, "The file '%s' in disk '%s' at dir '%s' has zero size!\n", sub, disk->name, disk->dir); - fprintf(stderr, "If it's really what you want to do, use 'snapraid --force sync\n"); - exit(EXIT_FAILURE); + if (!state->force_zero) { + fprintf(stderr, "The file '%s' in disk '%s' at dir '%s' has now zero size!\n", sub, disk->name, disk->dir); + fprintf(stderr, "If it's really what you want to sync it, use 'snapraid --force-zero sync\n"); + exit(EXIT_FAILURE); + } } /* remove and reinsert it */ @@ -247,9 +249,9 @@ void state_scan(struct snapraid_state* state) /* if all the previous file were removed */ if (scan[i].count_equal == 0 && scan[i].count_remove != 0) { - if (!state->force) { + if (!state->force_empty) { fprintf(stderr, "All the file in disk '%s' at dir '%s' are missing!\n", disk->name, disk->dir); - fprintf(stderr, "If it's really what you want to do, use 'snapraid --force sync\n"); + fprintf(stderr, "If it's really what you want to sync it, use 'snapraid --force-empty sync\n"); exit(EXIT_FAILURE); } } diff --git a/snapraid.c b/snapraid.c index ce64c2b0..beab6a78 100644 --- a/snapraid.c +++ b/snapraid.c @@ -36,7 +36,8 @@ void usage(void) { printf("Options:\n"); printf(" " SWITCH_GETOPT_LONG("-c, --conf FILE ", "-c") " Configuration file (default /etc/" PACKAGE ".conf)\n"); printf(" " SWITCH_GETOPT_LONG("-s, --start BLK ", "-s") " Start from the specified block number\n"); - printf(" " SWITCH_GETOPT_LONG("-f, --force ", "-f") " Force dangerous operations\n"); + 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("-v, --verbose ", "-v") " Verbose\n"); printf(" " SWITCH_GETOPT_LONG("-h, --help ", "-h") " Help\n"); printf(" " SWITCH_GETOPT_LONG("-V, --version ", "-V") " Version\n"); @@ -46,7 +47,8 @@ void usage(void) { struct option long_options[] = { { "conf", 1, 0, 'c' }, { "start", 1, 0, 's' }, - { "force", 0, 0, 'f' }, + { "force-zero", 0, 0, 'Z' }, + { "force-empty", 0, 0, 'E' }, { "verbose", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, @@ -54,7 +56,7 @@ struct option long_options[] = { }; #endif -#define OPTIONS "c:s:fvhV" +#define OPTIONS "c:s:ZEvhV" volatile int global_interrupt = 0; @@ -75,7 +77,8 @@ int main(int argc, char* argv[]) { int c; int verbose; - int force; + int force_zero; + int force_empty; const char* conf; struct snapraid_state state; int operation; @@ -87,7 +90,8 @@ int main(int argc, char* argv[]) /* defaults */ conf = "/etc/" PACKAGE ".conf"; verbose = 0; - force = 0; + force_zero = 0; + force_empty = 0; blockstart = 0; opterr = 0; @@ -108,8 +112,11 @@ int main(int argc, char* argv[]) exit(EXIT_FAILURE); } break; - case 'f' : - force = 1; + case 'Z' : + force_zero = 1; + break; + case 'E' : + force_empty = 1; break; case 'v' : verbose = 1; @@ -144,7 +151,7 @@ int main(int argc, char* argv[]) state_init(&state); - state_config(&state, conf, verbose, force); + state_config(&state, conf, verbose, force_zero, force_empty); if (operation == OPERATION_SYNC) { state_read(&state); diff --git a/snapraid.d b/snapraid.d index 8a6a617a..676b4bab 100644 --- a/snapraid.d +++ b/snapraid.d @@ -3,7 +3,8 @@ Name{number} Synopsis :snapraid [-c, --conf CONFIG] [-s, --start BLOCK] - : [-f, --force] [-v, --verbose] [-e, --exclude PATTERN] + : [-Z, --force-zero] [-E, --force-empty] + : [-v, --verbose] [-e, --exclude PATTERN] : COMMAND :snapraid [-V, --version] [-h, --help] @@ -254,12 +255,21 @@ Options block number. It could be useful to easy retry to fix some specific block, in case of a damaged disk. - -f, --force - Forces insecure operations. If snapraid detects - an unsafe operation, it stops the execution asking you - to use this option to force the operation. - For example, it happens if all the files in a disk are - missing. + -Z, --force-zero + Forces the insecure operation of synching a file with zero + size that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when after a system crash, + some accessed files were zeroed. + + -E, --force-empty + Forces the insecure operation of synching an empty disk + that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when a data filesystem is not + mounted. -v, --verbose Prints more information in the processing. diff --git a/snapraid.html b/snapraid.html index 452145eb..19f66eb2 100644 --- a/snapraid.html +++ b/snapraid.html @@ -9,7 +9,8 @@ Synopsis
 snapraid [-c, --conf CONFIG] [-s, --start BLOCK]
-    [-f, --force] [-v, --verbose] [-e, --exclude PATTERN]
+    [-Z, --force-zero] [-E, --force-empty]
+    [-v, --verbose] [-e, --exclude PATTERN]
     COMMAND
 

@@ -191,6 +192,8 @@ parity FILE Defines the file to use to store the redundancy information. It must be placed in a disk dedicated for this porpose with as much free space as the biggest disk in the array. +Leaving the parity disk reserved for only this file, ensures that +it doesn't get fragmented, improving the performance. This option can be used only one time. @@ -200,8 +203,8 @@ content FILE Defines the file to use to store the content of the redundancy organization. -It must be placed in the same disk of the parity file, or in -another location, but not in a disk of the array. +It can be placed in the same disk of the parity file, or better +in another disk, but NOT in a disk of the array. This option can be used only one time. @@ -394,13 +397,26 @@ some specific block, in case of a damaged disk. +
--f, --force +-Z, --force-zero
-Forces insecure operations. If snapraid detects -an unsafe operation, it stops the execution asking you -to use this option to force the operation. -For example, it happens if all the files in a disk are -missing. +Forces the insecure operation of synching a file with zero +size that before was not empty. +If SnapRAID detects such condition, it stops proceeding +unless you specify this option. +This allows to easily detect when after a system crash, +some accessed files were zeroed. +
+ +
+-E, --force-empty +
+Forces the insecure operation of synching an empty disk +that before was not empty. +If SnapRAID detects such condition, it stops proceeding +unless you specify this option. +This allows to easily detect when a data filesystem is not +mounted.
diff --git a/snapraid.txt b/snapraid.txt index ed867f5f..bf60f065 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -7,7 +7,8 @@ ========== snapraid [-c, --conf CONFIG] [-s, --start BLOCK] - [-f, --force] [-v, --verbose] [-e, --exclude PATTERN] + [-Z, --force-zero] [-E, --force-empty] + [-v, --verbose] [-e, --exclude PATTERN] COMMAND snapraid [-V, --version] [-h, --help] @@ -145,13 +146,15 @@ it should contains the following options: Defines the file to use to store the redundancy information. It must be placed in a disk dedicated for this porpose with as much free space as the biggest disk in the array. + Leaving the parity disk reserved for only this file, ensures that + it doesn't get fragmented, improving the performance. This option can be used only one time. content FILE Defines the file to use to store the content of the redundancy organization. - It must be placed in the same disk of the parity file, or in - another location, but not in a disk of the array. + It can be placed in the same disk of the parity file, or better + in another disk, but NOT in a disk of the array. This option can be used only one time. disk NAME DIR @@ -277,12 +280,21 @@ For example: block number. It could be useful to easy retry to fix some specific block, in case of a damaged disk. - -f, --force - Forces insecure operations. If snapraid detects - an unsafe operation, it stops the execution asking you - to use this option to force the operation. - For example, it happens if all the files in a disk are - missing. + -Z, --force-zero + Forces the insecure operation of synching a file with zero + size that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when after a system crash, + some accessed files were zeroed. + + -E, --force-empty + Forces the insecure operation of synching an empty disk + that before was not empty. + If SnapRAID detects such condition, it stops proceeding + unless you specify this option. + This allows to easily detect when a data filesystem is not + mounted. -v, --verbose Prints more information in the processing. diff --git a/state.c b/state.c index 955be694..ac3fe13a 100644 --- a/state.c +++ b/state.c @@ -51,13 +51,14 @@ void state_done(struct snapraid_state* state) tommy_list_foreach(&state->excludelist, (tommy_foreach_func*)filter_free); } -void state_config(struct snapraid_state* state, const char* path, int verbose, int force) +void state_config(struct snapraid_state* state, const char* path, int verbose, int force_zero, int force_empty) { FILE* f; unsigned line; state->verbose = verbose; - state->force = force; + state->force_zero = force_zero; + state->force_empty = force_empty; f = fopen(path, "rt"); if (!f) { diff --git a/state.h b/state.h index 7208ddd4..3d16e0b5 100644 --- a/state.h +++ b/state.h @@ -28,7 +28,8 @@ extern volatile int global_interrupt; struct snapraid_state { int verbose; /**< Verbose output. */ - int force; /**< Forced dangerous operations. */ + int force_zero; /**< Forced dangerous operations of synching file now with zero size. */ + int force_empty; /**< Forced dangerous operations of synching disk now empty. */ uint32_t block_size; /**< Block size in bytes. */ char content[PATH_MAX]; /**< Path of the content file. */ char parity[PATH_MAX]; /**< Path of the parity file. */ @@ -49,7 +50,7 @@ void state_done(struct snapraid_state* state); /** * Read the configuration file. */ -void state_config(struct snapraid_state* state, const char* path, int verbose, int force); +void state_config(struct snapraid_state* state, const char* path, int verbose, int force_zero, int force_empty); /** * Read the state.