From 23b4cc5fa03fb2db43909c9d6c4b4d21bc423a08 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 21 May 2026 14:51:01 +0200 Subject: [PATCH] Make the devices commands to fail if unsupported in the platform --- cmdline/device.c | 4 +++- cmdline/snapraid.c | 30 +++++++++++++++++++++++++----- cmdline/state.h | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cmdline/device.c b/cmdline/device.c index 2ee0dc74..6a830fa0 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -1006,7 +1006,7 @@ int devtest(tommy_list* high, tommy_list* low, int operation) return 0; } -void state_device(struct snapraid_state* state, int operation, tommy_list* filterlist_disk) +int state_device(struct snapraid_state* state, int operation, tommy_list* filterlist_disk) { tommy_node* i; unsigned j; @@ -1150,5 +1150,7 @@ void state_device(struct snapraid_state* state, int operation, tommy_list* filte tommy_list_foreach(&high, free); tommy_list_foreach(&low, free); + + return ret; } diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 950b1a93..b8bb4fa9 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1951,18 +1951,38 @@ int snapraid_main(int argc, char* argv[]) state_write(&state); } else if (operation == OPERATION_SPINUP) { - state_device(&state, DEVICE_UP, &filterlist_disk); + ret = state_device(&state, DEVICE_UP, &filterlist_disk); +#if HAVE_CHECKER + if (ret < 0) + ret = 0; /* ignore errors in test environment */ +#endif } else if (operation == OPERATION_SPINDOWN) { - state_device(&state, DEVICE_DOWN, &filterlist_disk); + ret = state_device(&state, DEVICE_DOWN, &filterlist_disk); +#if HAVE_CHECKER + if (ret < 0) + ret = 0; /* ignore errors in test environment */ +#endif } else if (operation == OPERATION_DEVICES) { - state_device(&state, DEVICE_LIST, 0); + ret = state_device(&state, DEVICE_LIST, 0); +#if HAVE_CHECKER + if (ret < 0) + ret = 0; /* ignore errors in test environment */ +#endif } else if (operation == OPERATION_SMART) { - state_device(&state, DEVICE_SMART, 0); + ret = state_device(&state, DEVICE_SMART, 0); +#if HAVE_CHECKER + if (ret < 0) + ret = 0; /* ignore errors in test environment */ +#endif } else if (operation == OPERATION_PROBE) { /* probe also the content file */ state_probe(&state); - state_device(&state, DEVICE_PROBE, 0); + ret = state_device(&state, DEVICE_PROBE, 0); +#if HAVE_CHECKER + if (ret < 0) + ret = 0; /* ignore errors in test environment */ +#endif } else if (operation == OPERATION_STATUS) { state_read(&state); diff --git a/cmdline/state.h b/cmdline/state.h index e0859647..ebe80ced 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -250,7 +250,7 @@ void state_touch(struct snapraid_state* state); /** * Devices operations. */ -void state_device(struct snapraid_state* state, int operation, tommy_list* filterlist_disk); +int state_device(struct snapraid_state* state, int operation, tommy_list* filterlist_disk); /** * Sync the parity data.