From adbf4f25c2a22ac69157ab0ed0009ef4a1a4f863 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 18 Jan 2016 22:36:06 +0100 Subject: [PATCH] Allow 'smart' without a configuration file --- HISTORY | 2 ++ cmdline/device.c | 9 ++++++--- cmdline/mingw.c | 4 ++-- cmdline/portable.h | 2 +- cmdline/snapraid.c | 7 +++++++ cmdline/state.c | 10 +++++++++- cmdline/state.h | 1 + cmdline/unix.c | 6 ++++-- 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index 3e3a9dca..f15fe6b5 100644 --- a/HISTORY +++ b/HISTORY @@ -15,6 +15,8 @@ SnapRAID HISTORY having verified all the hashes. This allows recovering of moved files in case a silent error is found during the hash verification check. + * Allows to run the 'smart' command without a configuration file. + In such case it operates on all the disks of the machine. * In the configuration file 'data' is now a synonymous of 'disk'. * Adds the 'touch' command intended to arbitrarely set all the zero subsecond timestamps. This improves the SnapRAID capabilities to diff --git a/cmdline/device.c b/cmdline/device.c index 3a94274c..b3a2ea09 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -984,10 +984,13 @@ void state_device(struct snapraid_state* state, int operation) tommy_list_insert_tail(&high, &entry->node, entry); } - if (state->opt.fake_device) + if (state->opt.fake_device) { ret = devtest(&low, operation); - else - ret = devquery(&high, &low, operation); + } else { + int others = operation == DEVICE_SMART; + + ret = devquery(&high, &low, operation, others); + } if (ret != 0) { const char* ope = 0; diff --git a/cmdline/mingw.c b/cmdline/mingw.c index f9d651d6..3139772c 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -2433,7 +2433,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) return 0; } -int devquery(tommy_list* high, tommy_list* low, int operation) +int devquery(tommy_list* high, tommy_list* low, int operation, int others) { tommy_node* i; void* (*func)(void* arg) = 0; @@ -2478,7 +2478,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) } /* add other devices */ - if (operation == DEVICE_SMART) { + if (others) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ log_fatal("Failed to list other devices.\n"); diff --git a/cmdline/portable.h b/cmdline/portable.h index 18867f89..2540d3d4 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -446,7 +446,7 @@ typedef struct devinfo_struct devinfo_t; * * The passed "low" device list must be already initialized. */ -int devquery(tommy_list* high, tommy_list* low, int operation); +int devquery(tommy_list* high, tommy_list* low, int operation, int others); #endif diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index d42bfa23..f40d9025 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1030,6 +1030,13 @@ int main(int argc, char* argv[]) break; } + switch (operation) { + case OPERATION_SMART : + /* allow to run without configuration file */ + opt.auto_conf = 1; + break; + } + /* open the log file */ log_open(log_file); diff --git a/cmdline/state.c b/cmdline/state.c index 7723f6d4..395bf10d 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -525,12 +525,20 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* store current command */ state->command = command; - log_tag("conf:%s\n", path); + log_tag("conf:file:%s\n", path); f = sopen_read(path); if (!f) { /* LCOV_EXCL_START */ if (errno == ENOENT) { + if (state->opt.auto_conf) { + log_tag("conf:missing:\n"); + /* mark that we are without a configuration file */ + state->no_conf = 1; + state->level = 0; + return; + } + log_fatal("No configuration file found at '%s'\n", path); } else if (errno == EACCES) { log_fatal("You do not have rights to access the configuration file '%s'\n", path); diff --git a/cmdline/state.h b/cmdline/state.h index 382e67df..be97124c 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -114,6 +114,7 @@ struct snapraid_option { int match_first_uuid; /**< Force the matching of the first UUID. */ int force_parity_update; /**< Force parity update even if data is not changed. */ unsigned io_cache; /**< Number of IO buffers to use. 0 for default. */ + int auto_conf; /**< Allow to run without configuration file. */ }; /** diff --git a/cmdline/unix.c b/cmdline/unix.c index 9be8c232..d71243b6 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -1054,7 +1054,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) return 0; } -int devquery(tommy_list* high, tommy_list* low, int operation) +int devquery(tommy_list* high, tommy_list* low, int operation, int others) { tommy_node* i; void* (*func)(void* arg) = 0; @@ -1118,7 +1118,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) #if HAVE_LINUX_DEVICE /* add other devices */ - if (operation == DEVICE_SMART) { + if (others) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ log_fatal("Failed to list other devices.\n"); @@ -1126,6 +1126,8 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* LCOV_EXCL_STOP */ } } +#else + (void)others; #endif switch (operation) {