summaryrefslogtreecommitdiff
path: root/usr/src/lib/libzfs
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libzfs')
-rw-r--r--usr/src/lib/libzfs/common/libzfs.h5
-rw-r--r--usr/src/lib/libzfs/common/libzfs_pool.c50
-rw-r--r--usr/src/lib/libzfs/common/mapfile-vers1
3 files changed, 31 insertions, 25 deletions
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;