diff options
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/cmd/zfs/zfs_main.c | 14 | ||||
-rw-r--r-- | usr/src/cmd/zpool/zpool_main.c | 10 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs.h | 5 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_pool.c | 50 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/mapfile-vers | 1 | ||||
-rw-r--r-- | usr/src/uts/common/fs/zfs/zfs_ioctl.c | 18 |
6 files changed, 48 insertions, 50 deletions
diff --git a/usr/src/cmd/zfs/zfs_main.c b/usr/src/cmd/zfs/zfs_main.c index cab179c5d7..b7fffb2973 100644 --- a/usr/src/cmd/zfs/zfs_main.c +++ b/usr/src/cmd/zfs/zfs_main.c @@ -57,8 +57,7 @@ libzfs_handle_t *g_zfs; static FILE *mnttab_file; -static int first_argc; -static char **first_argv; +static char history_str[HIS_MAX_RECORD_LEN]; static int zfs_do_clone(int argc, char **argv); static int zfs_do_create(int argc, char **argv); @@ -1299,7 +1298,7 @@ same_pool(zfs_handle_t *zhp, const char *name) if (len1 != len2) return (B_FALSE); - return (strncmp(name, zhname, len1) != 0); + return (strncmp(name, zhname, len1) == 0); } static int @@ -1355,8 +1354,7 @@ upgrade_set_callback(zfs_handle_t *zhp, void *data) * be doing ioctls to different pools. We need * to log this history once to each pool. */ - zpool_stage_history(g_zfs, first_argc, first_argv, - B_TRUE); + verify(zpool_stage_history(g_zfs, history_str) == 0); } if (zfs_prop_set(zhp, "version", verstr) == 0) cb->cb_numupgraded++; @@ -3816,16 +3814,14 @@ main(int argc, char **argv) opterr = 0; - first_argc = argc; - first_argv = argv; - if ((g_zfs = libzfs_init()) == NULL) { (void) fprintf(stderr, gettext("internal error: failed to " "initialize ZFS library\n")); return (1); } - zpool_stage_history(g_zfs, argc, argv, B_TRUE); + zpool_set_history_str("zfs", argc, argv, history_str); + verify(zpool_stage_history(g_zfs, history_str) == 0); libzfs_print_on_error(g_zfs, B_TRUE); diff --git a/usr/src/cmd/zpool/zpool_main.c b/usr/src/cmd/zpool/zpool_main.c index 03f52f0f6f..5120c2e518 100644 --- a/usr/src/cmd/zpool/zpool_main.c +++ b/usr/src/cmd/zpool/zpool_main.c @@ -169,6 +169,7 @@ static zpool_command_t command_table[] = { #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0])) zpool_command_t *current_command; +static char history_str[HIS_MAX_RECORD_LEN]; static const char * get_usage(zpool_help_t idx) { @@ -3788,18 +3789,15 @@ main(int argc, char **argv) cmdname = argv[1]; - /* Handle special case of pool create for staging history */ - if (strcmp(cmdname, "create") != 0) - zpool_stage_history(g_zfs, argc, argv, B_FALSE); - else - zpool_stage_history(g_zfs, argc, argv, B_FALSE); - /* * Special case '-?' */ if (strcmp(cmdname, "-?") == 0) usage(B_TRUE); + zpool_set_history_str("zpool", argc, argv, history_str); + verify(zpool_stage_history(g_zfs, history_str) == 0); + /* * Run the appropriate command. */ diff --git a/usr/src/lib/libzfs/common/libzfs.h b/usr/src/lib/libzfs/common/libzfs.h index 4e10b10bb4..867a06662a 100644 --- a/usr/src/lib/libzfs/common/libzfs.h +++ b/usr/src/lib/libzfs/common/libzfs.h @@ -296,8 +296,9 @@ struct zfs_cmd; extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *); extern int zpool_upgrade(zpool_handle_t *); extern int zpool_get_history(zpool_handle_t *, nvlist_t **); -extern void zpool_stage_history(libzfs_handle_t *, int, char **, - boolean_t zfs_cmd); +extern void zpool_set_history_str(const char *subcommand, int argc, + char **argv, char *history_str); +extern int zpool_stage_history(libzfs_handle_t *, const char *); extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, size_t len); extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c index 524406a3c8..eb586c1398 100644 --- a/usr/src/lib/libzfs/common/libzfs_pool.c +++ b/usr/src/lib/libzfs/common/libzfs_pool.c @@ -1794,37 +1794,41 @@ zpool_upgrade(zpool_handle_t *zhp) return (0); } -/* - * Log command history. - * - * 'zfs_cmd' is B_TRUE if we are logging a command for 'zfs'; B_FALSE - * otherwise ('zpool'). 'argc' and 'argv' are used to construct the - * command string. - */ void -zpool_stage_history(libzfs_handle_t *hdl, int argc, char **argv, - boolean_t zfs_cmd) +zpool_set_history_str(const char *subcommand, int argc, char **argv, + char *history_str) { - char *cmd_buf; int i; + (void) strlcpy(history_str, subcommand, HIS_MAX_RECORD_LEN); + for (i = 1; i < argc; i++) { + if (strlen(history_str) + 1 + strlen(argv[i]) > + HIS_MAX_RECORD_LEN) + break; + (void) strlcat(history_str, " ", HIS_MAX_RECORD_LEN); + (void) strlcat(history_str, argv[i], HIS_MAX_RECORD_LEN); + } +} + +/* + * Stage command history for logging. + */ +int +zpool_stage_history(libzfs_handle_t *hdl, const char *history_str) +{ + if (history_str == NULL) + return (EINVAL); + + if (strlen(history_str) > HIS_MAX_RECORD_LEN) + return (EINVAL); + if (hdl->libzfs_log_str != NULL) free(hdl->libzfs_log_str); - if ((hdl->libzfs_log_str = zfs_alloc(hdl, HIS_MAX_RECORD_LEN)) == NULL) - return; - - cmd_buf = hdl->libzfs_log_str; + if ((hdl->libzfs_log_str = strdup(history_str)) == NULL) + return (no_memory(hdl)); - /* construct the command string */ - (void) strlcpy(cmd_buf, zfs_cmd ? "zfs" : "zpool", - HIS_MAX_RECORD_LEN); - for (i = 1; i < argc; i++) { - if (strlen(cmd_buf) + 1 + strlen(argv[i]) > HIS_MAX_RECORD_LEN) - break; - (void) strlcat(cmd_buf, " ", HIS_MAX_RECORD_LEN); - (void) strlcat(cmd_buf, argv[i], HIS_MAX_RECORD_LEN); - } + return (0); } /* diff --git a/usr/src/lib/libzfs/common/mapfile-vers b/usr/src/lib/libzfs/common/mapfile-vers index 2ab83ae2e9..ee9bf4ab30 100644 --- a/usr/src/lib/libzfs/common/mapfile-vers +++ b/usr/src/lib/libzfs/common/mapfile-vers @@ -152,6 +152,7 @@ SUNWprivate_1.1 { zpool_refresh_stats; zpool_remove_zvol_links; zpool_scrub; + zpool_set_history_str; zpool_set_prop; zpool_stage_history; zpool_unmount_datasets; diff --git a/usr/src/uts/common/fs/zfs/zfs_ioctl.c b/usr/src/uts/common/fs/zfs/zfs_ioctl.c index 5316673d80..23de0b2146 100644 --- a/usr/src/uts/common/fs/zfs/zfs_ioctl.c +++ b/usr/src/uts/common/fs/zfs/zfs_ioctl.c @@ -678,19 +678,17 @@ zfs_ioc_pool_create(zfs_cmd_t *zc) nvlist_t *config; char *buf; - if ((buf = history_str_get(zc)) == NULL) - return (EINVAL); - - if ((error = get_nvlist(zc, &config)) != 0) { - history_str_free(buf); + if ((error = get_nvlist(zc, &config)) != 0) return (error); - } + + buf = history_str_get(zc); error = spa_create(zc->zc_name, config, zc->zc_value[0] == '\0' ? NULL : zc->zc_value, buf); + if (buf != NULL) + history_str_free(buf); nvlist_free(config); - history_str_free(buf); return (error); } @@ -2113,9 +2111,9 @@ zfs_ioc_share(zfs_cmd_t *zc) } /* - * pool destroy and pool export don't log the history as part of zfsdev_ioctl, - * but rather zfs_ioc_pool_create, and zfs_ioc_pool_export do the loggin - * of those commands. + * pool create, destroy, and export don't log the history as part of + * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export + * do the logging of those commands. */ static zfs_ioc_vec_t zfs_ioc_vec[] = { { zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE }, |