diff options
author | Tony Hutter <[email protected]> | 2023-12-21 10:53:16 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2023-12-21 10:53:16 -0800 |
commit | a9520e6e5961d9fc58d71b97652773d0f5fee1ff (patch) | |
tree | 05592b2a5e896114942dda1f6e7770cd9fc1405c /lib/libzutil/zutil_pool.c | |
parent | 6930ecbb75e17f6d6cc7686211d4f3b34852795b (diff) |
zpool: Add slot power control, print power status
Add `zpool` flags to control the slot power to drives. This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.
The new `--power` flag is added to `zpool offline|online|clear`:
zpool offline --power <pool> <device> Turn off device slot power
zpool online --power <pool> <device> Turn on device slot power
zpool clear --power <pool> [device] Turn on device slot power
If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '--power'
option is automatically implied for `zpool online` and `zpool clear`
and does not need to be passed.
zpool status also gets a --power option to print the slot power status.
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Mart Frauenlob <[email protected]>
Signed-off-by: Tony Hutter <[email protected]>
Closes #15662
Diffstat (limited to 'lib/libzutil/zutil_pool.c')
-rw-r--r-- | lib/libzutil/zutil_pool.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/libzutil/zutil_pool.c b/lib/libzutil/zutil_pool.c index 288a0033c..86460de3f 100644 --- a/lib/libzutil/zutil_pool.c +++ b/lib/libzutil/zutil_pool.c @@ -28,6 +28,7 @@ #include <string.h> #include <sys/nvpair.h> #include <sys/fs/zfs.h> +#include <math.h> #include <libzutil.h> @@ -144,3 +145,33 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, *leftover = bytes_read; return (0); } + +/* + * Floating point sleep(). Allows you to pass in a floating point value for + * seconds. + */ +void +fsleep(float sec) +{ + struct timespec req; + req.tv_sec = floor(sec); + req.tv_nsec = (sec - (float)req.tv_sec) * NANOSEC; + nanosleep(&req, NULL); +} + +/* + * Get environment variable 'env' and return it as an integer. + * If 'env' is not set, then return 'default_val' instead. + */ +int +zpool_getenv_int(const char *env, int default_val) +{ + char *str; + int val; + str = getenv(env); + if ((str == NULL) || sscanf(str, "%d", &val) != 1 || + val < 0) { + val = default_val; + } + return (val); +} |