diff options
author | Giuseppe Di Natale <[email protected]> | 2017-06-05 13:52:15 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-06-05 10:52:15 -0700 |
commit | 099700d9dff46309cdd16f4c4331daddb70d8570 (patch) | |
tree | 13383ee2af7cc69b0f790b3c3f70fbc61ae074fb /cmd/zpool/zpool_main.c | |
parent | 92aceb2a7ee8c9367fdc901fed933f6f258173e0 (diff) |
zpool iostat/status -c improvements
Users can now provide their own scripts to be run
with 'zpool iostat/status -c'. User scripts should be
placed in ~/.zpool.d to be included in zpool's
default search path.
Provide a script which can be used with
'zpool iostat|status -c' that will return the type of
device (hdd, sdd, file).
Provide a script to get various values from smartctl
when using 'zpool iostat/status -c'.
Allow users to define the ZPOOL_SCRIPTS_PATH
environment variable which can be used to override
the default 'zpool iostat/status -c' search path.
Allow the ZPOOL_SCRIPTS_ENABLED environment
variable to enable or disable 'zpool status/iostat -c'
functionality.
Use the new smart script to provide the serial command.
Install /etc/sudoers.d/zfs file which contains the sudoer
rule for smartctl as a sample.
Allow 'zpool iostat/status -c' tests to run in tree.
Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Giuseppe Di Natale <[email protected]>
Closes #6121
Closes #6153
Diffstat (limited to 'cmd/zpool/zpool_main.c')
-rw-r--r-- | cmd/zpool/zpool_main.c | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index f99145da9..5fccd754b 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -4190,25 +4190,22 @@ print_zpool_script_help(char *name, char *path) libzfs_free_str_array(lines, lines_cnt); } - /* - * Go though the list of all the zpool status/iostat -c scripts, run their + * Go though the zpool status/iostat -c scripts in the user's path, run their * help option (-h), and print out the results. */ static void -print_zpool_script_list(void) +print_zpool_dir_scripts(char *dirpath) { DIR *dir; struct dirent *ent; char fullpath[MAXPATHLEN]; struct stat dir_stat; - if ((dir = opendir(ZPOOL_SCRIPTS_DIR)) != NULL) { - printf("\n"); + if ((dir = opendir(dirpath)) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir(dir)) != NULL) { - sprintf(fullpath, "%s/%s", ZPOOL_SCRIPTS_DIR, - ent->d_name); + sprintf(fullpath, "%s/%s", dirpath, ent->d_name); /* Print the scripts */ if (stat(fullpath, &dir_stat) == 0) @@ -4217,15 +4214,34 @@ print_zpool_script_list(void) print_zpool_script_help(ent->d_name, fullpath); } - printf("\n"); closedir(dir); - } else { - fprintf(stderr, gettext("Can't open %s scripts dir\n"), - ZPOOL_SCRIPTS_DIR); } } /* + * Print out help text for all zpool status/iostat -c scripts. + */ +static void +print_zpool_script_list(char *subcommand) +{ + char *dir, *sp; + + printf(gettext("Available 'zpool %s -c' commands:\n"), subcommand); + + sp = zpool_get_cmd_search_path(); + if (sp == NULL) + return; + + dir = strtok(sp, ":"); + while (dir != NULL) { + print_zpool_dir_scripts(dir); + dir = strtok(NULL, ":"); + } + + free(sp); +} + +/* * zpool iostat [[-c [script1,script2,...]] [-lq]|[-rw]] [-ghHLpPvy] [-n name] * [-T d|u] [[ pool ...]|[pool vdev ...]|[vdev ...]] * [interval [count]] @@ -4285,6 +4301,15 @@ zpool_do_iostat(int argc, char **argv) gettext("Can't set -c flag twice\n")); exit(1); } + + if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL && + !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) { + fprintf(stderr, gettext( + "Can't run -c, disabled by " + "ZPOOL_SCRIPTS_ENABLED.\n")); + exit(1); + } + if ((getuid() <= 0 || geteuid() <= 0) && !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) { fprintf(stderr, gettext( @@ -4336,10 +4361,7 @@ zpool_do_iostat(int argc, char **argv) break; case '?': if (optopt == 'c') { - fprintf(stderr, gettext( - "Current scripts in %s:\n"), - ZPOOL_SCRIPTS_DIR); - print_zpool_script_list(); + print_zpool_script_list("iostat"); exit(0); } else { fprintf(stderr, @@ -6427,6 +6449,15 @@ zpool_do_status(int argc, char **argv) gettext("Can't set -c flag twice\n")); exit(1); } + + if (getenv("ZPOOL_SCRIPTS_ENABLED") != NULL && + !libzfs_envvar_is_set("ZPOOL_SCRIPTS_ENABLED")) { + fprintf(stderr, gettext( + "Can't run -c, disabled by " + "ZPOOL_SCRIPTS_ENABLED.\n")); + exit(1); + } + if ((getuid() <= 0 || geteuid() <= 0) && !libzfs_envvar_is_set("ZPOOL_SCRIPTS_AS_ROOT")) { fprintf(stderr, gettext( @@ -6459,10 +6490,7 @@ zpool_do_status(int argc, char **argv) break; case '?': if (optopt == 'c') { - fprintf(stderr, gettext( - "Current scripts in %s:\n"), - ZPOOL_SCRIPTS_DIR); - print_zpool_script_list(); + print_zpool_script_list("status"); exit(0); } else { fprintf(stderr, |