4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 * Copyright (c) 2012 by Frederik Wessels. All rights reserved.
27 * Copyright (c) 2012 by Cyril Plisko. All rights reserved.
48 #include <sys/fs/zfs.h>
50 #include <sys/fm/util.h>
51 #include <sys/fm/protocol.h>
55 #include "zpool_util.h"
56 #include "zfs_comutil.h"
57 #include "zfeature_common.h"
59 #include "statcommon.h"
61 static int zpool_do_create(int, char **);
62 static int zpool_do_destroy(int, char **);
64 static int zpool_do_add(int, char **);
65 static int zpool_do_remove(int, char **);
66 static int zpool_do_labelclear(int, char **);
68 static int zpool_do_list(int, char **);
69 static int zpool_do_iostat(int, char **);
70 static int zpool_do_status(int, char **);
72 static int zpool_do_online(int, char **);
73 static int zpool_do_offline(int, char **);
74 static int zpool_do_clear(int, char **);
75 static int zpool_do_reopen(int, char **);
77 static int zpool_do_reguid(int, char **);
79 static int zpool_do_attach(int, char **);
80 static int zpool_do_detach(int, char **);
81 static int zpool_do_replace(int, char **);
82 static int zpool_do_split(int, char **);
84 static int zpool_do_scrub(int, char **);
86 static int zpool_do_import(int, char **);
87 static int zpool_do_export(int, char **);
89 static int zpool_do_upgrade(int, char **);
91 static int zpool_do_history(int, char **);
92 static int zpool_do_events(int, char **);
94 static int zpool_do_get(int, char **);
95 static int zpool_do_set(int, char **);
98 * These libumem hooks provide a reasonable set of defaults for the allocator's
99 * debugging facilities.
104 _umem_debug_init(void)
106 return ("default,verbose"); /* $UMEM_DEBUG setting */
110 _umem_logging_init(void)
112 return ("fail,contents"); /* $UMEM_LOGGING setting */
145 typedef struct zpool_command
{
147 int (*func
)(int, char **);
152 * Master command table. Each ZFS command has a name, associated function, and
153 * usage message. The usage messages need to be internationalized, so we have
154 * to have a function to return the usage message based on a command index.
156 * These commands are organized according to how they are displayed in the usage
157 * message. An empty command (one with a NULL name) indicates an empty line in
158 * the generic usage message.
160 static zpool_command_t command_table
[] = {
161 { "create", zpool_do_create
, HELP_CREATE
},
162 { "destroy", zpool_do_destroy
, HELP_DESTROY
},
164 { "add", zpool_do_add
, HELP_ADD
},
165 { "remove", zpool_do_remove
, HELP_REMOVE
},
167 { "labelclear", zpool_do_labelclear
, HELP_LABELCLEAR
},
169 { "list", zpool_do_list
, HELP_LIST
},
170 { "iostat", zpool_do_iostat
, HELP_IOSTAT
},
171 { "status", zpool_do_status
, HELP_STATUS
},
173 { "online", zpool_do_online
, HELP_ONLINE
},
174 { "offline", zpool_do_offline
, HELP_OFFLINE
},
175 { "clear", zpool_do_clear
, HELP_CLEAR
},
176 { "reopen", zpool_do_reopen
, HELP_REOPEN
},
178 { "attach", zpool_do_attach
, HELP_ATTACH
},
179 { "detach", zpool_do_detach
, HELP_DETACH
},
180 { "replace", zpool_do_replace
, HELP_REPLACE
},
181 { "split", zpool_do_split
, HELP_SPLIT
},
183 { "scrub", zpool_do_scrub
, HELP_SCRUB
},
185 { "import", zpool_do_import
, HELP_IMPORT
},
186 { "export", zpool_do_export
, HELP_EXPORT
},
187 { "upgrade", zpool_do_upgrade
, HELP_UPGRADE
},
188 { "reguid", zpool_do_reguid
, HELP_REGUID
},
190 { "history", zpool_do_history
, HELP_HISTORY
},
191 { "events", zpool_do_events
, HELP_EVENTS
},
193 { "get", zpool_do_get
, HELP_GET
},
194 { "set", zpool_do_set
, HELP_SET
},
197 #define NCOMMAND (sizeof (command_table) / sizeof (command_table[0]))
199 static zpool_command_t
*current_command
;
200 static char history_str
[HIS_MAX_RECORD_LEN
];
201 static boolean_t log_history
= B_TRUE
;
202 static uint_t timestamp_fmt
= NODATE
;
205 get_usage(zpool_help_t idx
) {
208 return (gettext("\tadd [-fn] [-o property=value] "
209 "<pool> <vdev> ...\n"));
211 return (gettext("\tattach [-f] [-o property=value] "
212 "<pool> <device> <new-device>\n"));
214 return (gettext("\tclear [-nF] <pool> [device]\n"));
216 return (gettext("\tcreate [-fnd] [-o property=value] ... \n"
217 "\t [-O file-system-property=value] ... \n"
218 "\t [-m mountpoint] [-R root] <pool> <vdev> ...\n"));
220 return (gettext("\tdestroy [-f] <pool>\n"));
222 return (gettext("\tdetach <pool> <device>\n"));
224 return (gettext("\texport [-f] <pool> ...\n"));
226 return (gettext("\thistory [-il] [<pool>] ...\n"));
228 return (gettext("\timport [-d dir] [-D]\n"
229 "\timport [-d dir | -c cachefile] [-F [-n]] <pool | id>\n"
230 "\timport [-o mntopts] [-o property=value] ... \n"
231 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
232 "[-R root] [-F [-n]] -a\n"
233 "\timport [-o mntopts] [-o property=value] ... \n"
234 "\t [-d dir | -c cachefile] [-D] [-f] [-m] [-N] "
235 "[-R root] [-F [-n]]\n"
236 "\t <pool | id> [newpool]\n"));
238 return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
240 case HELP_LABELCLEAR
:
241 return (gettext("\tlabelclear [-f] <vdev>\n"));
243 return (gettext("\tlist [-Hv] [-o property[,...]] "
244 "[-T d|u] [pool] ... [interval [count]]\n"));
246 return (gettext("\toffline [-t] <pool> <device> ...\n"));
248 return (gettext("\tonline <pool> <device> ...\n"));
250 return (gettext("\treplace [-f] <pool> <device> "
253 return (gettext("\tremove <pool> <device> ...\n"));
255 return (gettext("\treopen <pool>\n"));
257 return (gettext("\tscrub [-s] <pool> ...\n"));
259 return (gettext("\tstatus [-vxD] [-T d|u] [pool] ... [interval "
262 return (gettext("\tupgrade\n"
264 "\tupgrade [-V version] <-a | pool ...>\n"));
266 return (gettext("\tevents [-vHfc]\n"));
268 return (gettext("\tget [-p] <\"all\" | property[,...]> "
271 return (gettext("\tset <property=value> <pool> \n"));
273 return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
274 "\t [-o property=value] <pool> <newpool> "
275 "[<device> ...]\n"));
277 return (gettext("\treguid <pool>\n"));
286 * Callback routine that will print out a pool property value.
289 print_prop_cb(int prop
, void *cb
)
293 (void) fprintf(fp
, "\t%-15s ", zpool_prop_to_name(prop
));
295 if (zpool_prop_readonly(prop
))
296 (void) fprintf(fp
, " NO ");
298 (void) fprintf(fp
, " YES ");
300 if (zpool_prop_values(prop
) == NULL
)
301 (void) fprintf(fp
, "-\n");
303 (void) fprintf(fp
, "%s\n", zpool_prop_values(prop
));
309 * Display usage message. If we're inside a command, display only the usage for
310 * that command. Otherwise, iterate over the entire command table and display
311 * a complete usage message.
314 usage(boolean_t requested
)
316 FILE *fp
= requested
? stdout
: stderr
;
318 if (current_command
== NULL
) {
321 (void) fprintf(fp
, gettext("usage: zpool command args ...\n"));
323 gettext("where 'command' is one of the following:\n\n"));
325 for (i
= 0; i
< NCOMMAND
; i
++) {
326 if (command_table
[i
].name
== NULL
)
327 (void) fprintf(fp
, "\n");
329 (void) fprintf(fp
, "%s",
330 get_usage(command_table
[i
].usage
));
333 (void) fprintf(fp
, gettext("usage:\n"));
334 (void) fprintf(fp
, "%s", get_usage(current_command
->usage
));
337 if (current_command
!= NULL
&&
338 ((strcmp(current_command
->name
, "set") == 0) ||
339 (strcmp(current_command
->name
, "get") == 0) ||
340 (strcmp(current_command
->name
, "list") == 0))) {
343 gettext("\nthe following properties are supported:\n"));
345 (void) fprintf(fp
, "\n\t%-15s %s %s\n\n",
346 "PROPERTY", "EDIT", "VALUES");
348 /* Iterate over all properties */
349 (void) zprop_iter(print_prop_cb
, fp
, B_FALSE
, B_TRUE
,
352 (void) fprintf(fp
, "\t%-15s ", "feature@...");
353 (void) fprintf(fp
, "YES disabled | enabled | active\n");
355 (void) fprintf(fp
, gettext("\nThe feature@ properties must be "
356 "appended with a feature name.\nSee zpool-features(5).\n"));
360 * See comments at end of main().
362 if (getenv("ZFS_ABORT") != NULL
) {
363 (void) printf("dumping core by request\n");
367 exit(requested
? 0 : 2);
371 print_vdev_tree(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
, int indent
,
372 boolean_t print_logs
)
379 (void) printf("\t%*s%s\n", indent
, "", name
);
381 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
382 &child
, &children
) != 0)
385 for (c
= 0; c
< children
; c
++) {
386 uint64_t is_log
= B_FALSE
;
388 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
390 if ((is_log
&& !print_logs
) || (!is_log
&& print_logs
))
393 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
394 print_vdev_tree(zhp
, vname
, child
[c
], indent
+ 2,
401 prop_list_contains_feature(nvlist_t
*proplist
)
404 for (nvp
= nvlist_next_nvpair(proplist
, NULL
); NULL
!= nvp
;
405 nvp
= nvlist_next_nvpair(proplist
, nvp
)) {
406 if (zpool_prop_feature(nvpair_name(nvp
)))
413 * Add a property pair (name, string-value) into a property nvlist.
416 add_prop_list(const char *propname
, char *propval
, nvlist_t
**props
,
419 zpool_prop_t prop
= ZPROP_INVAL
;
425 if (*props
== NULL
&&
426 nvlist_alloc(props
, NV_UNIQUE_NAME
, 0) != 0) {
427 (void) fprintf(stderr
,
428 gettext("internal error: out of memory\n"));
435 const char *vname
= zpool_prop_to_name(ZPOOL_PROP_VERSION
);
437 if ((prop
= zpool_name_to_prop(propname
)) == ZPROP_INVAL
&&
438 !zpool_prop_feature(propname
)) {
439 (void) fprintf(stderr
, gettext("property '%s' is "
440 "not a valid pool property\n"), propname
);
445 * feature@ properties and version should not be specified
448 if ((prop
== ZPROP_INVAL
&& zpool_prop_feature(propname
) &&
449 nvlist_exists(proplist
, vname
)) ||
450 (prop
== ZPOOL_PROP_VERSION
&&
451 prop_list_contains_feature(proplist
))) {
452 (void) fprintf(stderr
, gettext("'feature@' and "
453 "'version' properties cannot be specified "
459 if (zpool_prop_feature(propname
))
462 normnm
= zpool_prop_to_name(prop
);
464 if ((fprop
= zfs_name_to_prop(propname
)) != ZPROP_INVAL
) {
465 normnm
= zfs_prop_to_name(fprop
);
471 if (nvlist_lookup_string(proplist
, normnm
, &strval
) == 0 &&
472 prop
!= ZPOOL_PROP_CACHEFILE
) {
473 (void) fprintf(stderr
, gettext("property '%s' "
474 "specified multiple times\n"), propname
);
478 if (nvlist_add_string(proplist
, normnm
, propval
) != 0) {
479 (void) fprintf(stderr
, gettext("internal "
480 "error: out of memory\n"));
488 * zpool add [-fn] [-o property=value] <pool> <vdev> ...
490 * -f Force addition of devices, even if they appear in use
491 * -n Do not add the devices, but display the resulting layout if
492 * they were to be added.
493 * -o Set property=value.
495 * Adds the given vdevs to 'pool'. As with create, the bulk of this work is
496 * handled by get_vdev_spec(), which constructs the nvlist needed to pass to
500 zpool_do_add(int argc
, char **argv
)
502 boolean_t force
= B_FALSE
;
503 boolean_t dryrun
= B_FALSE
;
510 nvlist_t
*props
= NULL
;
514 while ((c
= getopt(argc
, argv
, "fno:")) != -1) {
523 if ((propval
= strchr(optarg
, '=')) == NULL
) {
524 (void) fprintf(stderr
, gettext("missing "
525 "'=' for -o option\n"));
531 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
532 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
536 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
545 /* get pool name and check number of arguments */
547 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
551 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
560 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
563 if ((config
= zpool_get_config(zhp
, NULL
)) == NULL
) {
564 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
570 /* pass off to get_vdev_spec for processing */
571 nvroot
= make_root_vdev(zhp
, props
, force
, !force
, B_FALSE
, dryrun
,
573 if (nvroot
== NULL
) {
579 nvlist_t
*poolnvroot
;
581 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
584 (void) printf(gettext("would update '%s' to the following "
585 "configuration:\n"), zpool_get_name(zhp
));
587 /* print original main pool and new tree */
588 print_vdev_tree(zhp
, poolname
, poolnvroot
, 0, B_FALSE
);
589 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_FALSE
);
591 /* Do the same for the logs */
592 if (num_logs(poolnvroot
) > 0) {
593 print_vdev_tree(zhp
, "logs", poolnvroot
, 0, B_TRUE
);
594 print_vdev_tree(zhp
, NULL
, nvroot
, 0, B_TRUE
);
595 } else if (num_logs(nvroot
) > 0) {
596 print_vdev_tree(zhp
, "logs", nvroot
, 0, B_TRUE
);
601 ret
= (zpool_add(zhp
, nvroot
) != 0);
612 * zpool remove <pool> <vdev> ...
614 * Removes the given vdev from the pool. Currently, this supports removing
615 * spares, cache, and log devices from the pool.
618 zpool_do_remove(int argc
, char **argv
)
627 /* get pool name and check number of arguments */
629 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
633 (void) fprintf(stderr
, gettext("missing device\n"));
639 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
642 for (i
= 1; i
< argc
; i
++) {
643 if (zpool_vdev_remove(zhp
, argv
[i
]) != 0)
651 * zpool labelclear <vdev>
653 * Verifies that the vdev is not active and zeros out the label information
657 zpool_do_labelclear(int argc
, char **argv
)
660 int c
, fd
= -1, ret
= 0;
662 boolean_t inuse
= B_FALSE
;
663 boolean_t force
= B_FALSE
;
666 while ((c
= getopt(argc
, argv
, "f")) != -1) {
672 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
683 (void) fprintf(stderr
, gettext("missing vdev device name\n"));
688 if ((fd
= open(vdev
, O_RDWR
)) < 0) {
689 (void) fprintf(stderr
, gettext("Unable to open %s\n"), vdev
);
694 if (zpool_in_use(g_zfs
, fd
, &state
, &name
, &inuse
) != 0) {
698 (void) fprintf(stderr
,
699 gettext("Unable to determine pool state for %s\n"
700 "Use -f to force the clearing any label data\n"), vdev
);
708 case POOL_STATE_ACTIVE
:
709 case POOL_STATE_SPARE
:
710 case POOL_STATE_L2CACHE
:
711 (void) fprintf(stderr
,
712 gettext("labelclear operation failed.\n"
713 "\tVdev %s is a member (%s), of pool \"%s\".\n"
714 "\tTo remove label information from this device, "
715 "export or destroy\n\tthe pool, or remove %s from "
716 "the configuration of this pool\n\tand retry the "
717 "labelclear operation.\n"),
718 vdev
, zpool_pool_state_to_name(state
), name
, vdev
);
722 case POOL_STATE_EXPORTED
:
726 (void) fprintf(stderr
,
727 gettext("labelclear operation failed.\n\tVdev "
728 "%s is a member of the exported pool \"%s\".\n"
729 "\tUse \"zpool labelclear -f %s\" to force the "
730 "removal of label\n\tinformation.\n"),
735 case POOL_STATE_POTENTIALLY_ACTIVE
:
739 (void) fprintf(stderr
,
740 gettext("labelclear operation failed.\n"
741 "\tVdev %s is a member of the pool \"%s\".\n"
742 "\tThis pool is unknown to this system, but may "
743 "be active on\n\tanother system. Use "
744 "\'zpool labelclear -f %s\' to force the\n"
745 "\tremoval of label information.\n"),
750 case POOL_STATE_DESTROYED
:
751 /* inuse should never be set for a destroyed pool... */
757 if (zpool_clear_label(fd
) != 0) {
758 (void) fprintf(stderr
,
759 gettext("Label clear failed on vdev %s\n"), vdev
);
772 * zpool create [-fnd] [-o property=value] ...
773 * [-O file-system-property=value] ...
774 * [-R root] [-m mountpoint] <pool> <dev> ...
776 * -f Force creation, even if devices appear in use
777 * -n Do not create the pool, but display the resulting layout if it
778 * were to be created.
779 * -R Create a pool under an alternate root
780 * -m Set default mountpoint for the root dataset. By default it's
782 * -o Set property=value.
783 * -d Don't automatically enable all supported pool features
784 * (individual features can be enabled with -o).
785 * -O Set fsproperty=value in the pool's root file system
787 * Creates the named pool according to the given vdev specification. The
788 * bulk of the vdev processing is done in get_vdev_spec() in zpool_vdev.c. Once
789 * we get the nvlist back from get_vdev_spec(), we either print out the contents
790 * (if '-n' was specified), or pass it to libzfs to do the creation.
793 zpool_do_create(int argc
, char **argv
)
795 boolean_t force
= B_FALSE
;
796 boolean_t dryrun
= B_FALSE
;
797 boolean_t enable_all_pool_feat
= B_TRUE
;
799 nvlist_t
*nvroot
= NULL
;
802 char *altroot
= NULL
;
803 char *mountpoint
= NULL
;
804 nvlist_t
*fsprops
= NULL
;
805 nvlist_t
*props
= NULL
;
809 while ((c
= getopt(argc
, argv
, ":fndR:m:o:O:")) != -1) {
818 enable_all_pool_feat
= B_FALSE
;
822 if (add_prop_list(zpool_prop_to_name(
823 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
825 if (nvlist_lookup_string(props
,
826 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
829 if (add_prop_list(zpool_prop_to_name(
830 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
834 /* Equivalent to -O mountpoint=optarg */
838 if ((propval
= strchr(optarg
, '=')) == NULL
) {
839 (void) fprintf(stderr
, gettext("missing "
840 "'=' for -o option\n"));
846 if (add_prop_list(optarg
, propval
, &props
, B_TRUE
))
850 * If the user is creating a pool that doesn't support
851 * feature flags, don't enable any features.
853 if (zpool_name_to_prop(optarg
) == ZPOOL_PROP_VERSION
) {
857 ver
= strtoull(propval
, &end
, 10);
859 ver
< SPA_VERSION_FEATURES
) {
860 enable_all_pool_feat
= B_FALSE
;
865 if ((propval
= strchr(optarg
, '=')) == NULL
) {
866 (void) fprintf(stderr
, gettext("missing "
867 "'=' for -O option\n"));
874 * Mountpoints are checked and then added later.
875 * Uniquely among properties, they can be specified
876 * more than once, to avoid conflict with -m.
878 if (0 == strcmp(optarg
,
879 zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
))) {
880 mountpoint
= propval
;
881 } else if (add_prop_list(optarg
, propval
, &fsprops
,
887 (void) fprintf(stderr
, gettext("missing argument for "
888 "'%c' option\n"), optopt
);
891 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
900 /* get pool name and check number of arguments */
902 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
906 (void) fprintf(stderr
, gettext("missing vdev specification\n"));
913 * As a special case, check for use of '/' in the name, and direct the
914 * user to use 'zfs create' instead.
916 if (strchr(poolname
, '/') != NULL
) {
917 (void) fprintf(stderr
, gettext("cannot create '%s': invalid "
918 "character '/' in pool name\n"), poolname
);
919 (void) fprintf(stderr
, gettext("use 'zfs create' to "
920 "create a dataset\n"));
924 /* pass off to get_vdev_spec for bulk processing */
925 nvroot
= make_root_vdev(NULL
, props
, force
, !force
, B_FALSE
, dryrun
,
930 /* make_root_vdev() allows 0 toplevel children if there are spares */
931 if (!zfs_allocatable_devs(nvroot
)) {
932 (void) fprintf(stderr
, gettext("invalid vdev "
933 "specification: at least one toplevel vdev must be "
938 if (altroot
!= NULL
&& altroot
[0] != '/') {
939 (void) fprintf(stderr
, gettext("invalid alternate root '%s': "
940 "must be an absolute path\n"), altroot
);
945 * Check the validity of the mountpoint and direct the user to use the
946 * '-m' mountpoint option if it looks like its in use.
948 if (mountpoint
== NULL
||
949 (strcmp(mountpoint
, ZFS_MOUNTPOINT_LEGACY
) != 0 &&
950 strcmp(mountpoint
, ZFS_MOUNTPOINT_NONE
) != 0)) {
951 char buf
[MAXPATHLEN
];
954 if (mountpoint
&& mountpoint
[0] != '/') {
955 (void) fprintf(stderr
, gettext("invalid mountpoint "
956 "'%s': must be an absolute path, 'legacy', or "
957 "'none'\n"), mountpoint
);
961 if (mountpoint
== NULL
) {
963 (void) snprintf(buf
, sizeof (buf
), "%s/%s",
966 (void) snprintf(buf
, sizeof (buf
), "/%s",
970 (void) snprintf(buf
, sizeof (buf
), "%s%s",
971 altroot
, mountpoint
);
973 (void) snprintf(buf
, sizeof (buf
), "%s",
977 if ((dirp
= opendir(buf
)) == NULL
&& errno
!= ENOENT
) {
978 (void) fprintf(stderr
, gettext("mountpoint '%s' : "
979 "%s\n"), buf
, strerror(errno
));
980 (void) fprintf(stderr
, gettext("use '-m' "
981 "option to provide a different default\n"));
986 while (count
< 3 && readdir(dirp
) != NULL
)
988 (void) closedir(dirp
);
991 (void) fprintf(stderr
, gettext("mountpoint "
992 "'%s' exists and is not empty\n"), buf
);
993 (void) fprintf(stderr
, gettext("use '-m' "
994 "option to provide a "
995 "different default\n"));
1002 * Now that the mountpoint's validity has been checked, ensure that
1003 * the property is set appropriately prior to creating the pool.
1005 if (mountpoint
!= NULL
) {
1006 ret
= add_prop_list(zfs_prop_to_name(ZFS_PROP_MOUNTPOINT
),
1007 mountpoint
, &fsprops
, B_FALSE
);
1015 * For a dry run invocation, print out a basic message and run
1016 * through all the vdevs in the list and print out in an
1017 * appropriate hierarchy.
1019 (void) printf(gettext("would create '%s' with the "
1020 "following layout:\n\n"), poolname
);
1022 print_vdev_tree(NULL
, poolname
, nvroot
, 0, B_FALSE
);
1023 if (num_logs(nvroot
) > 0)
1024 print_vdev_tree(NULL
, "logs", nvroot
, 0, B_TRUE
);
1029 * Hand off to libzfs.
1031 if (enable_all_pool_feat
) {
1033 for (i
= 0; i
< SPA_FEATURES
; i
++) {
1034 char propname
[MAXPATHLEN
];
1035 zfeature_info_t
*feat
= &spa_feature_table
[i
];
1037 (void) snprintf(propname
, sizeof (propname
),
1038 "feature@%s", feat
->fi_uname
);
1041 * Skip feature if user specified it manually
1042 * on the command line.
1044 if (nvlist_exists(props
, propname
))
1047 ret
= add_prop_list(propname
,
1048 ZFS_FEATURE_ENABLED
, &props
, B_TRUE
);
1055 if (zpool_create(g_zfs
, poolname
,
1056 nvroot
, props
, fsprops
) == 0) {
1057 zfs_handle_t
*pool
= zfs_open(g_zfs
, poolname
,
1058 ZFS_TYPE_FILESYSTEM
);
1060 if (zfs_mount(pool
, NULL
, 0) == 0)
1061 ret
= zfs_shareall(pool
);
1064 } else if (libzfs_errno(g_zfs
) == EZFS_INVALIDNAME
) {
1065 (void) fprintf(stderr
, gettext("pool name may have "
1071 nvlist_free(nvroot
);
1072 nvlist_free(fsprops
);
1076 nvlist_free(fsprops
);
1083 * zpool destroy <pool>
1085 * -f Forcefully unmount any datasets
1087 * Destroy the given pool. Automatically unmounts any datasets in the pool.
1090 zpool_do_destroy(int argc
, char **argv
)
1092 boolean_t force
= B_FALSE
;
1095 zpool_handle_t
*zhp
;
1099 while ((c
= getopt(argc
, argv
, "f")) != -1) {
1105 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1114 /* check arguments */
1116 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1120 (void) fprintf(stderr
, gettext("too many arguments\n"));
1126 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
1128 * As a special case, check for use of '/' in the name, and
1129 * direct the user to use 'zfs destroy' instead.
1131 if (strchr(pool
, '/') != NULL
)
1132 (void) fprintf(stderr
, gettext("use 'zfs destroy' to "
1133 "destroy a dataset\n"));
1137 if (zpool_disable_datasets(zhp
, force
) != 0) {
1138 (void) fprintf(stderr
, gettext("could not destroy '%s': "
1139 "could not unmount datasets\n"), zpool_get_name(zhp
));
1143 /* The history must be logged as part of the export */
1144 log_history
= B_FALSE
;
1146 ret
= (zpool_destroy(zhp
, history_str
) != 0);
1154 * zpool export [-f] <pool> ...
1156 * -f Forcefully unmount datasets
1158 * Export the given pools. By default, the command will attempt to cleanly
1159 * unmount any active datasets within the pool. If the '-f' flag is specified,
1160 * then the datasets will be forcefully unmounted.
1163 zpool_do_export(int argc
, char **argv
)
1165 boolean_t force
= B_FALSE
;
1166 boolean_t hardforce
= B_FALSE
;
1168 zpool_handle_t
*zhp
;
1173 while ((c
= getopt(argc
, argv
, "fF")) != -1) {
1182 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
1191 /* check arguments */
1193 (void) fprintf(stderr
, gettext("missing pool argument\n"));
1198 for (i
= 0; i
< argc
; i
++) {
1199 if ((zhp
= zpool_open_canfail(g_zfs
, argv
[i
])) == NULL
) {
1204 if (zpool_disable_datasets(zhp
, force
) != 0) {
1210 /* The history must be logged as part of the export */
1211 log_history
= B_FALSE
;
1214 if (zpool_export_force(zhp
, history_str
) != 0)
1216 } else if (zpool_export(zhp
, force
, history_str
) != 0) {
1227 * Given a vdev configuration, determine the maximum width needed for the device
1231 max_width(zpool_handle_t
*zhp
, nvlist_t
*nv
, int depth
, int max
)
1233 char *name
= zpool_vdev_name(g_zfs
, zhp
, nv
, B_TRUE
);
1238 if (strlen(name
) + depth
> max
)
1239 max
= strlen(name
) + depth
;
1243 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1244 &child
, &children
) == 0) {
1245 for (c
= 0; c
< children
; c
++)
1246 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1251 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1252 &child
, &children
) == 0) {
1253 for (c
= 0; c
< children
; c
++)
1254 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1259 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1260 &child
, &children
) == 0) {
1261 for (c
= 0; c
< children
; c
++)
1262 if ((ret
= max_width(zhp
, child
[c
], depth
+ 2,
1271 typedef struct spare_cbdata
{
1273 zpool_handle_t
*cb_zhp
;
1277 find_vdev(nvlist_t
*nv
, uint64_t search
)
1283 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
, &guid
) == 0 &&
1287 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1288 &child
, &children
) == 0) {
1289 for (c
= 0; c
< children
; c
++)
1290 if (find_vdev(child
[c
], search
))
1298 find_spare(zpool_handle_t
*zhp
, void *data
)
1300 spare_cbdata_t
*cbp
= data
;
1301 nvlist_t
*config
, *nvroot
;
1303 config
= zpool_get_config(zhp
, NULL
);
1304 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1307 if (find_vdev(nvroot
, cbp
->cb_guid
)) {
1317 * Print out configuration state as requested by status_callback.
1320 print_status_config(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
1321 int namewidth
, int depth
, boolean_t isspare
)
1325 pool_scan_stat_t
*ps
= NULL
;
1327 char rbuf
[6], wbuf
[6], cbuf
[6];
1329 uint64_t notpresent
;
1333 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1334 &child
, &children
) != 0)
1337 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1338 (uint64_t **)&vs
, &c
) == 0);
1340 state
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1343 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1346 if (vs
->vs_aux
== VDEV_AUX_SPARED
)
1348 else if (vs
->vs_state
== VDEV_STATE_HEALTHY
)
1352 (void) printf("\t%*s%-*s %-8s", depth
, "", namewidth
- depth
,
1356 zfs_nicenum(vs
->vs_read_errors
, rbuf
, sizeof (rbuf
));
1357 zfs_nicenum(vs
->vs_write_errors
, wbuf
, sizeof (wbuf
));
1358 zfs_nicenum(vs
->vs_checksum_errors
, cbuf
, sizeof (cbuf
));
1359 (void) printf(" %5s %5s %5s", rbuf
, wbuf
, cbuf
);
1362 if (nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_NOT_PRESENT
,
1363 ¬present
) == 0) {
1365 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_PATH
, &path
) == 0);
1366 (void) printf(" was %s", path
);
1367 } else if (vs
->vs_aux
!= 0) {
1370 switch (vs
->vs_aux
) {
1371 case VDEV_AUX_OPEN_FAILED
:
1372 (void) printf(gettext("cannot open"));
1375 case VDEV_AUX_BAD_GUID_SUM
:
1376 (void) printf(gettext("missing device"));
1379 case VDEV_AUX_NO_REPLICAS
:
1380 (void) printf(gettext("insufficient replicas"));
1383 case VDEV_AUX_VERSION_NEWER
:
1384 (void) printf(gettext("newer version"));
1387 case VDEV_AUX_UNSUP_FEAT
:
1388 (void) printf(gettext("unsupported feature(s)"));
1391 case VDEV_AUX_SPARED
:
1392 verify(nvlist_lookup_uint64(nv
, ZPOOL_CONFIG_GUID
,
1394 if (zpool_iter(g_zfs
, find_spare
, &cb
) == 1) {
1395 if (strcmp(zpool_get_name(cb
.cb_zhp
),
1396 zpool_get_name(zhp
)) == 0)
1397 (void) printf(gettext("currently in "
1400 (void) printf(gettext("in use by "
1402 zpool_get_name(cb
.cb_zhp
));
1403 zpool_close(cb
.cb_zhp
);
1405 (void) printf(gettext("currently in use"));
1409 case VDEV_AUX_ERR_EXCEEDED
:
1410 (void) printf(gettext("too many errors"));
1413 case VDEV_AUX_IO_FAILURE
:
1414 (void) printf(gettext("experienced I/O failures"));
1417 case VDEV_AUX_BAD_LOG
:
1418 (void) printf(gettext("bad intent log"));
1421 case VDEV_AUX_EXTERNAL
:
1422 (void) printf(gettext("external device fault"));
1425 case VDEV_AUX_SPLIT_POOL
:
1426 (void) printf(gettext("split into new pool"));
1430 (void) printf(gettext("corrupted data"));
1435 (void) nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_SCAN_STATS
,
1436 (uint64_t **)&ps
, &c
);
1438 if (ps
&& ps
->pss_state
== DSS_SCANNING
&&
1439 vs
->vs_scan_processed
!= 0 && children
== 0) {
1440 (void) printf(gettext(" (%s)"),
1441 (ps
->pss_func
== POOL_SCAN_RESILVER
) ?
1442 "resilvering" : "repairing");
1445 (void) printf("\n");
1447 for (c
= 0; c
< children
; c
++) {
1448 uint64_t islog
= B_FALSE
, ishole
= B_FALSE
;
1450 /* Don't print logs or holes here */
1451 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1453 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_HOLE
,
1455 if (islog
|| ishole
)
1457 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1458 print_status_config(zhp
, vname
, child
[c
],
1459 namewidth
, depth
+ 2, isspare
);
1466 * Print the configuration of an exported pool. Iterate over all vdevs in the
1467 * pool, printing out the name and status for each one.
1470 print_import_config(const char *name
, nvlist_t
*nv
, int namewidth
, int depth
)
1477 verify(nvlist_lookup_string(nv
, ZPOOL_CONFIG_TYPE
, &type
) == 0);
1478 if (strcmp(type
, VDEV_TYPE_MISSING
) == 0 ||
1479 strcmp(type
, VDEV_TYPE_HOLE
) == 0)
1482 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
1483 (uint64_t **)&vs
, &c
) == 0);
1485 (void) printf("\t%*s%-*s", depth
, "", namewidth
- depth
, name
);
1486 (void) printf(" %s", zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
));
1488 if (vs
->vs_aux
!= 0) {
1491 switch (vs
->vs_aux
) {
1492 case VDEV_AUX_OPEN_FAILED
:
1493 (void) printf(gettext("cannot open"));
1496 case VDEV_AUX_BAD_GUID_SUM
:
1497 (void) printf(gettext("missing device"));
1500 case VDEV_AUX_NO_REPLICAS
:
1501 (void) printf(gettext("insufficient replicas"));
1504 case VDEV_AUX_VERSION_NEWER
:
1505 (void) printf(gettext("newer version"));
1508 case VDEV_AUX_UNSUP_FEAT
:
1509 (void) printf(gettext("unsupported feature(s)"));
1512 case VDEV_AUX_ERR_EXCEEDED
:
1513 (void) printf(gettext("too many errors"));
1517 (void) printf(gettext("corrupted data"));
1521 (void) printf("\n");
1523 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
1524 &child
, &children
) != 0)
1527 for (c
= 0; c
< children
; c
++) {
1528 uint64_t is_log
= B_FALSE
;
1530 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1535 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_TRUE
);
1536 print_import_config(vname
, child
[c
], namewidth
, depth
+ 2);
1540 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
1541 &child
, &children
) == 0) {
1542 (void) printf(gettext("\tcache\n"));
1543 for (c
= 0; c
< children
; c
++) {
1544 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1545 (void) printf("\t %s\n", vname
);
1550 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_SPARES
,
1551 &child
, &children
) == 0) {
1552 (void) printf(gettext("\tspares\n"));
1553 for (c
= 0; c
< children
; c
++) {
1554 vname
= zpool_vdev_name(g_zfs
, NULL
, child
[c
], B_FALSE
);
1555 (void) printf("\t %s\n", vname
);
1563 * Logs are recorded as top level vdevs in the main pool child array
1564 * but with "is_log" set to 1. We use either print_status_config() or
1565 * print_import_config() to print the top level logs then any log
1566 * children (eg mirrored slogs) are printed recursively - which
1567 * works because only the top level vdev is marked "is_log"
1570 print_logs(zpool_handle_t
*zhp
, nvlist_t
*nv
, int namewidth
, boolean_t verbose
)
1575 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
, &child
,
1579 (void) printf(gettext("\tlogs\n"));
1581 for (c
= 0; c
< children
; c
++) {
1582 uint64_t is_log
= B_FALSE
;
1585 (void) nvlist_lookup_uint64(child
[c
], ZPOOL_CONFIG_IS_LOG
,
1589 name
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_TRUE
);
1591 print_status_config(zhp
, name
, child
[c
], namewidth
,
1594 print_import_config(name
, child
[c
], namewidth
, 2);
1600 * Display the status for the given pool.
1603 show_import(nvlist_t
*config
)
1605 uint64_t pool_state
;
1617 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1619 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_GUID
,
1621 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
1623 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
1626 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
1627 (uint64_t **)&vs
, &vsc
) == 0);
1628 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
1630 reason
= zpool_import_status(config
, &msgid
);
1632 (void) printf(gettext(" pool: %s\n"), name
);
1633 (void) printf(gettext(" id: %llu\n"), (u_longlong_t
)guid
);
1634 (void) printf(gettext(" state: %s"), health
);
1635 if (pool_state
== POOL_STATE_DESTROYED
)
1636 (void) printf(gettext(" (DESTROYED)"));
1637 (void) printf("\n");
1640 case ZPOOL_STATUS_MISSING_DEV_R
:
1641 case ZPOOL_STATUS_MISSING_DEV_NR
:
1642 case ZPOOL_STATUS_BAD_GUID_SUM
:
1643 (void) printf(gettext(" status: One or more devices are "
1644 "missing from the system.\n"));
1647 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
1648 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
1649 (void) printf(gettext(" status: One or more devices contains "
1650 "corrupted data.\n"));
1653 case ZPOOL_STATUS_CORRUPT_DATA
:
1655 gettext(" status: The pool data is corrupted.\n"));
1658 case ZPOOL_STATUS_OFFLINE_DEV
:
1659 (void) printf(gettext(" status: One or more devices "
1660 "are offlined.\n"));
1663 case ZPOOL_STATUS_CORRUPT_POOL
:
1664 (void) printf(gettext(" status: The pool metadata is "
1668 case ZPOOL_STATUS_VERSION_OLDER
:
1669 (void) printf(gettext(" status: The pool is formatted using a "
1670 "legacy on-disk version.\n"));
1673 case ZPOOL_STATUS_VERSION_NEWER
:
1674 (void) printf(gettext(" status: The pool is formatted using an "
1675 "incompatible version.\n"));
1678 case ZPOOL_STATUS_FEAT_DISABLED
:
1679 (void) printf(gettext(" status: Some supported features are "
1680 "not enabled on the pool.\n"));
1683 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1684 (void) printf(gettext("status: The pool uses the following "
1685 "feature(s) not supported on this sytem:\n"));
1686 zpool_print_unsup_feat(config
);
1689 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1690 (void) printf(gettext("status: The pool can only be accessed "
1691 "in read-only mode on this system. It\n\tcannot be "
1692 "accessed in read-write mode because it uses the "
1693 "following\n\tfeature(s) not supported on this system:\n"));
1694 zpool_print_unsup_feat(config
);
1697 case ZPOOL_STATUS_HOSTID_MISMATCH
:
1698 (void) printf(gettext(" status: The pool was last accessed by "
1699 "another system.\n"));
1702 case ZPOOL_STATUS_FAULTED_DEV_R
:
1703 case ZPOOL_STATUS_FAULTED_DEV_NR
:
1704 (void) printf(gettext(" status: One or more devices are "
1708 case ZPOOL_STATUS_BAD_LOG
:
1709 (void) printf(gettext(" status: An intent log record cannot be "
1713 case ZPOOL_STATUS_RESILVERING
:
1714 (void) printf(gettext(" status: One or more devices were being "
1720 * No other status can be seen when importing pools.
1722 assert(reason
== ZPOOL_STATUS_OK
);
1726 * Print out an action according to the overall state of the pool.
1728 if (vs
->vs_state
== VDEV_STATE_HEALTHY
) {
1729 if (reason
== ZPOOL_STATUS_VERSION_OLDER
||
1730 reason
== ZPOOL_STATUS_FEAT_DISABLED
) {
1731 (void) printf(gettext(" action: The pool can be "
1732 "imported using its name or numeric identifier, "
1733 "though\n\tsome features will not be available "
1734 "without an explicit 'zpool upgrade'.\n"));
1735 } else if (reason
== ZPOOL_STATUS_HOSTID_MISMATCH
) {
1736 (void) printf(gettext(" action: The pool can be "
1737 "imported using its name or numeric "
1738 "identifier and\n\tthe '-f' flag.\n"));
1740 (void) printf(gettext(" action: The pool can be "
1741 "imported using its name or numeric "
1744 } else if (vs
->vs_state
== VDEV_STATE_DEGRADED
) {
1745 (void) printf(gettext(" action: The pool can be imported "
1746 "despite missing or damaged devices. The\n\tfault "
1747 "tolerance of the pool may be compromised if imported.\n"));
1750 case ZPOOL_STATUS_VERSION_NEWER
:
1751 (void) printf(gettext(" action: The pool cannot be "
1752 "imported. Access the pool on a system running "
1753 "newer\n\tsoftware, or recreate the pool from "
1756 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
1757 (void) printf(gettext("action: The pool cannot be "
1758 "imported. Access the pool on a system that "
1759 "supports\n\tthe required feature(s), or recreate "
1760 "the pool from backup.\n"));
1762 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
1763 (void) printf(gettext("action: The pool cannot be "
1764 "imported in read-write mode. Import the pool "
1766 "\t\"-o readonly=on\", access the pool on a system "
1767 "that supports the\n\trequired feature(s), or "
1768 "recreate the pool from backup.\n"));
1770 case ZPOOL_STATUS_MISSING_DEV_R
:
1771 case ZPOOL_STATUS_MISSING_DEV_NR
:
1772 case ZPOOL_STATUS_BAD_GUID_SUM
:
1773 (void) printf(gettext(" action: The pool cannot be "
1774 "imported. Attach the missing\n\tdevices and try "
1778 (void) printf(gettext(" action: The pool cannot be "
1779 "imported due to damaged devices or data.\n"));
1783 /* Print the comment attached to the pool. */
1784 if (nvlist_lookup_string(config
, ZPOOL_CONFIG_COMMENT
, &comment
) == 0)
1785 (void) printf(gettext("comment: %s\n"), comment
);
1788 * If the state is "closed" or "can't open", and the aux state
1789 * is "corrupt data":
1791 if (((vs
->vs_state
== VDEV_STATE_CLOSED
) ||
1792 (vs
->vs_state
== VDEV_STATE_CANT_OPEN
)) &&
1793 (vs
->vs_aux
== VDEV_AUX_CORRUPT_DATA
)) {
1794 if (pool_state
== POOL_STATE_DESTROYED
)
1795 (void) printf(gettext("\tThe pool was destroyed, "
1796 "but can be imported using the '-Df' flags.\n"));
1797 else if (pool_state
!= POOL_STATE_EXPORTED
)
1798 (void) printf(gettext("\tThe pool may be active on "
1799 "another system, but can be imported using\n\t"
1800 "the '-f' flag.\n"));
1804 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
1807 (void) printf(gettext(" config:\n\n"));
1809 namewidth
= max_width(NULL
, nvroot
, 0, 0);
1813 print_import_config(name
, nvroot
, namewidth
, 0);
1814 if (num_logs(nvroot
) > 0)
1815 print_logs(NULL
, nvroot
, namewidth
, B_FALSE
);
1817 if (reason
== ZPOOL_STATUS_BAD_GUID_SUM
) {
1818 (void) printf(gettext("\n\tAdditional devices are known to "
1819 "be part of this pool, though their\n\texact "
1820 "configuration cannot be determined.\n"));
1825 * Perform the import for the given configuration. This passes the heavy
1826 * lifting off to zpool_import_props(), and then mounts the datasets contained
1830 do_import(nvlist_t
*config
, const char *newname
, const char *mntopts
,
1831 nvlist_t
*props
, int flags
)
1833 zpool_handle_t
*zhp
;
1838 verify(nvlist_lookup_string(config
, ZPOOL_CONFIG_POOL_NAME
,
1841 verify(nvlist_lookup_uint64(config
,
1842 ZPOOL_CONFIG_POOL_STATE
, &state
) == 0);
1843 verify(nvlist_lookup_uint64(config
,
1844 ZPOOL_CONFIG_VERSION
, &version
) == 0);
1845 if (!SPA_VERSION_IS_SUPPORTED(version
)) {
1846 (void) fprintf(stderr
, gettext("cannot import '%s': pool "
1847 "is formatted using an unsupported ZFS version\n"), name
);
1849 } else if (state
!= POOL_STATE_EXPORTED
&&
1850 !(flags
& ZFS_IMPORT_ANY_HOST
)) {
1853 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_HOSTID
,
1855 unsigned long system_hostid
= gethostid() & 0xffffffff;
1857 if ((unsigned long)hostid
!= system_hostid
) {
1862 verify(nvlist_lookup_string(config
,
1863 ZPOOL_CONFIG_HOSTNAME
, &hostname
) == 0);
1864 verify(nvlist_lookup_uint64(config
,
1865 ZPOOL_CONFIG_TIMESTAMP
, ×tamp
) == 0);
1867 (void) fprintf(stderr
, gettext("cannot import "
1868 "'%s': pool may be in use from other "
1869 "system, it was last accessed by %s "
1870 "(hostid: 0x%lx) on %s"), name
, hostname
,
1871 (unsigned long)hostid
,
1872 asctime(localtime(&t
)));
1873 (void) fprintf(stderr
, gettext("use '-f' to "
1874 "import anyway\n"));
1878 (void) fprintf(stderr
, gettext("cannot import '%s': "
1879 "pool may be in use from other system\n"), name
);
1880 (void) fprintf(stderr
, gettext("use '-f' to import "
1886 if (zpool_import_props(g_zfs
, config
, newname
, props
, flags
) != 0)
1889 if (newname
!= NULL
)
1890 name
= (char *)newname
;
1892 if ((zhp
= zpool_open_canfail(g_zfs
, name
)) == NULL
)
1895 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
1896 !(flags
& ZFS_IMPORT_ONLY
) &&
1897 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
1907 * zpool import [-d dir] [-D]
1908 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1909 * [-d dir | -c cachefile] [-f] -a
1910 * import [-o mntopts] [-o prop=value] ... [-R root] [-D]
1911 * [-d dir | -c cachefile] [-f] [-n] [-F] <pool | id> [newpool]
1913 * -c Read pool information from a cachefile instead of searching
1916 * -d Scan in a specific directory, other than /dev/. More than
1917 * one directory can be specified using multiple '-d' options.
1919 * -D Scan for previously destroyed pools or import all or only
1920 * specified destroyed pools.
1922 * -R Temporarily import the pool, with all mountpoints relative to
1923 * the given root. The pool will remain exported when the machine
1926 * -V Import even in the presence of faulted vdevs. This is an
1927 * intentionally undocumented option for testing purposes, and
1928 * treats the pool configuration as complete, leaving any bad
1929 * vdevs in the FAULTED state. In other words, it does verbatim
1932 * -f Force import, even if it appears that the pool is active.
1934 * -F Attempt rewind if necessary.
1936 * -n See if rewind would work, but don't actually rewind.
1938 * -N Import the pool but don't mount datasets.
1940 * -T Specify a starting txg to use for import. This option is
1941 * intentionally undocumented option for testing purposes.
1943 * -a Import all pools found.
1945 * -o Set property=value and/or temporary mount options (without '=').
1947 * The import command scans for pools to import, and import pools based on pool
1948 * name and GUID. The pool can also be renamed as part of the import process.
1951 zpool_do_import(int argc
, char **argv
)
1953 char **searchdirs
= NULL
;
1954 char *env
, *envdup
= NULL
;
1958 nvlist_t
*pools
= NULL
;
1959 boolean_t do_all
= B_FALSE
;
1960 boolean_t do_destroyed
= B_FALSE
;
1961 char *mntopts
= NULL
;
1964 uint64_t searchguid
= 0;
1965 char *searchname
= NULL
;
1967 nvlist_t
*found_config
;
1968 nvlist_t
*policy
= NULL
;
1969 nvlist_t
*props
= NULL
;
1971 int flags
= ZFS_IMPORT_NORMAL
;
1972 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
1973 boolean_t dryrun
= B_FALSE
;
1974 boolean_t do_rewind
= B_FALSE
;
1975 boolean_t xtreme_rewind
= B_FALSE
;
1976 uint64_t pool_state
, txg
= -1ULL;
1977 char *cachefile
= NULL
;
1978 importargs_t idata
= { 0 };
1982 while ((c
= getopt(argc
, argv
, ":aCc:d:DEfFmnNo:rR:T:VX")) != -1) {
1991 if (searchdirs
== NULL
) {
1992 searchdirs
= safe_malloc(sizeof (char *));
1994 char **tmp
= safe_malloc((nsearch
+ 1) *
1996 bcopy(searchdirs
, tmp
, nsearch
*
2001 searchdirs
[nsearch
++] = optarg
;
2004 do_destroyed
= B_TRUE
;
2007 flags
|= ZFS_IMPORT_ANY_HOST
;
2013 flags
|= ZFS_IMPORT_MISSING_LOG
;
2019 flags
|= ZFS_IMPORT_ONLY
;
2022 if ((propval
= strchr(optarg
, '=')) != NULL
) {
2025 if (add_prop_list(optarg
, propval
,
2033 if (add_prop_list(zpool_prop_to_name(
2034 ZPOOL_PROP_ALTROOT
), optarg
, &props
, B_TRUE
))
2036 if (nvlist_lookup_string(props
,
2037 zpool_prop_to_name(ZPOOL_PROP_CACHEFILE
),
2040 if (add_prop_list(zpool_prop_to_name(
2041 ZPOOL_PROP_CACHEFILE
), "none", &props
, B_TRUE
))
2046 txg
= strtoull(optarg
, &endptr
, 10);
2047 if (errno
!= 0 || *endptr
!= '\0') {
2048 (void) fprintf(stderr
,
2049 gettext("invalid txg value\n"));
2052 rewind_policy
= ZPOOL_DO_REWIND
| ZPOOL_EXTREME_REWIND
;
2055 flags
|= ZFS_IMPORT_VERBATIM
;
2058 xtreme_rewind
= B_TRUE
;
2061 (void) fprintf(stderr
, gettext("missing argument for "
2062 "'%c' option\n"), optopt
);
2066 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2075 if (cachefile
&& nsearch
!= 0) {
2076 (void) fprintf(stderr
, gettext("-c is incompatible with -d\n"));
2080 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
2081 (void) fprintf(stderr
,
2082 gettext("-n or -X only meaningful with -F\n"));
2086 rewind_policy
= ZPOOL_TRY_REWIND
;
2088 rewind_policy
= ZPOOL_DO_REWIND
;
2090 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
2092 /* In the future, we can capture further policy and include it here */
2093 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
2094 nvlist_add_uint64(policy
, ZPOOL_REWIND_REQUEST_TXG
, txg
) != 0 ||
2095 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
2098 /* check argument count */
2101 (void) fprintf(stderr
, gettext("too many arguments\n"));
2106 (void) fprintf(stderr
, gettext("too many arguments\n"));
2111 * Check for the SYS_CONFIG privilege. We do this explicitly
2112 * here because otherwise any attempt to discover pools will
2115 if (argc
== 0 && !priv_ineffect(PRIV_SYS_CONFIG
)) {
2116 (void) fprintf(stderr
, gettext("cannot "
2117 "discover pools: permission denied\n"));
2118 if (searchdirs
!= NULL
)
2121 nvlist_free(policy
);
2127 * Depending on the arguments given, we do one of the following:
2129 * <none> Iterate through all pools and display information about
2132 * -a Iterate through all pools and try to import each one.
2134 * <id> Find the pool that corresponds to the given GUID/pool
2135 * name and import that one.
2137 * -D Above options applies only to destroyed pools.
2143 searchguid
= strtoull(argv
[0], &endptr
, 10);
2144 if (errno
!= 0 || *endptr
!= '\0')
2145 searchname
= argv
[0];
2146 found_config
= NULL
;
2149 * User specified a name or guid. Ensure it's unique.
2151 idata
.unique
= B_TRUE
;
2155 * Check the environment for the preferred search path.
2157 if ((searchdirs
== NULL
) && (env
= getenv("ZPOOL_IMPORT_PATH"))) {
2160 envdup
= strdup(env
);
2162 dir
= strtok(envdup
, ":");
2163 while (dir
!= NULL
) {
2164 if (searchdirs
== NULL
) {
2165 searchdirs
= safe_malloc(sizeof (char *));
2167 char **tmp
= safe_malloc((nsearch
+ 1) *
2169 bcopy(searchdirs
, tmp
, nsearch
*
2174 searchdirs
[nsearch
++] = dir
;
2175 dir
= strtok(NULL
, ":");
2179 idata
.path
= searchdirs
;
2180 idata
.paths
= nsearch
;
2181 idata
.poolname
= searchname
;
2182 idata
.guid
= searchguid
;
2183 idata
.cachefile
= cachefile
;
2185 pools
= zpool_search_import(g_zfs
, &idata
);
2187 if (pools
!= NULL
&& idata
.exists
&&
2188 (argc
== 1 || strcmp(argv
[0], argv
[1]) == 0)) {
2189 (void) fprintf(stderr
, gettext("cannot import '%s': "
2190 "a pool with that name already exists\n"),
2192 (void) fprintf(stderr
, gettext("use the form '%s "
2193 "<pool | id> <newpool>' to give it a new name\n"),
2196 } else if (pools
== NULL
&& idata
.exists
) {
2197 (void) fprintf(stderr
, gettext("cannot import '%s': "
2198 "a pool with that name is already created/imported,\n"),
2200 (void) fprintf(stderr
, gettext("and no additional pools "
2201 "with that name were found\n"));
2203 } else if (pools
== NULL
) {
2205 (void) fprintf(stderr
, gettext("cannot import '%s': "
2206 "no such pool available\n"), argv
[0]);
2212 if (searchdirs
!= NULL
)
2216 nvlist_free(policy
);
2221 * At this point we have a list of import candidate configs. Even if
2222 * we were searching by pool name or guid, we still need to
2223 * post-process the list to deal with pool state and possible
2229 while ((elem
= nvlist_next_nvpair(pools
, elem
)) != NULL
) {
2231 verify(nvpair_value_nvlist(elem
, &config
) == 0);
2233 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_POOL_STATE
,
2235 if (!do_destroyed
&& pool_state
== POOL_STATE_DESTROYED
)
2237 if (do_destroyed
&& pool_state
!= POOL_STATE_DESTROYED
)
2240 verify(nvlist_add_nvlist(config
, ZPOOL_REWIND_POLICY
,
2247 (void) printf("\n");
2250 err
|= do_import(config
, NULL
, mntopts
,
2253 show_import(config
);
2255 } else if (searchname
!= NULL
) {
2259 * We are searching for a pool based on name.
2261 verify(nvlist_lookup_string(config
,
2262 ZPOOL_CONFIG_POOL_NAME
, &name
) == 0);
2264 if (strcmp(name
, searchname
) == 0) {
2265 if (found_config
!= NULL
) {
2266 (void) fprintf(stderr
, gettext(
2267 "cannot import '%s': more than "
2268 "one matching pool\n"), searchname
);
2269 (void) fprintf(stderr
, gettext(
2270 "import by numeric ID instead\n"));
2273 found_config
= config
;
2279 * Search for a pool by guid.
2281 verify(nvlist_lookup_uint64(config
,
2282 ZPOOL_CONFIG_POOL_GUID
, &guid
) == 0);
2284 if (guid
== searchguid
)
2285 found_config
= config
;
2290 * If we were searching for a specific pool, verify that we found a
2291 * pool, and then do the import.
2293 if (argc
!= 0 && err
== 0) {
2294 if (found_config
== NULL
) {
2295 (void) fprintf(stderr
, gettext("cannot import '%s': "
2296 "no such pool available\n"), argv
[0]);
2299 err
|= do_import(found_config
, argc
== 1 ? NULL
:
2300 argv
[1], mntopts
, props
, flags
);
2305 * If we were just looking for pools, report an error if none were
2308 if (argc
== 0 && first
)
2309 (void) fprintf(stderr
,
2310 gettext("no pools available to import\n"));
2315 nvlist_free(policy
);
2316 if (searchdirs
!= NULL
)
2321 return (err
? 1 : 0);
2324 typedef struct iostat_cbdata
{
2325 boolean_t cb_verbose
;
2328 zpool_list_t
*cb_list
;
2332 print_iostat_separator(iostat_cbdata_t
*cb
)
2336 for (i
= 0; i
< cb
->cb_namewidth
; i
++)
2338 (void) printf(" ----- ----- ----- ----- ----- -----\n");
2342 print_iostat_header(iostat_cbdata_t
*cb
)
2344 (void) printf("%*s capacity operations bandwidth\n",
2345 cb
->cb_namewidth
, "");
2346 (void) printf("%-*s alloc free read write read write\n",
2347 cb
->cb_namewidth
, "pool");
2348 print_iostat_separator(cb
);
2352 * Display a single statistic.
2355 print_one_stat(uint64_t value
)
2359 zfs_nicenum(value
, buf
, sizeof (buf
));
2360 (void) printf(" %5s", buf
);
2364 * Print out all the statistics for the given vdev. This can either be the
2365 * toplevel configuration, or called recursively. If 'name' is NULL, then this
2366 * is a verbose output, and we don't want to display the toplevel pool stats.
2369 print_vdev_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*oldnv
,
2370 nvlist_t
*newnv
, iostat_cbdata_t
*cb
, int depth
)
2372 nvlist_t
**oldchild
, **newchild
;
2374 vdev_stat_t
*oldvs
, *newvs
;
2375 vdev_stat_t zerovs
= { 0 };
2380 if (oldnv
!= NULL
) {
2381 verify(nvlist_lookup_uint64_array(oldnv
,
2382 ZPOOL_CONFIG_VDEV_STATS
, (uint64_t **)&oldvs
, &c
) == 0);
2387 verify(nvlist_lookup_uint64_array(newnv
, ZPOOL_CONFIG_VDEV_STATS
,
2388 (uint64_t **)&newvs
, &c
) == 0);
2390 if (strlen(name
) + depth
> cb
->cb_namewidth
)
2391 (void) printf("%*s%s", depth
, "", name
);
2393 (void) printf("%*s%s%*s", depth
, "", name
,
2394 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2396 tdelta
= newvs
->vs_timestamp
- oldvs
->vs_timestamp
;
2401 scale
= (double)NANOSEC
/ tdelta
;
2403 /* only toplevel vdevs have capacity stats */
2404 if (newvs
->vs_space
== 0) {
2405 (void) printf(" - -");
2407 print_one_stat(newvs
->vs_alloc
);
2408 print_one_stat(newvs
->vs_space
- newvs
->vs_alloc
);
2411 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_READ
] -
2412 oldvs
->vs_ops
[ZIO_TYPE_READ
])));
2414 print_one_stat((uint64_t)(scale
* (newvs
->vs_ops
[ZIO_TYPE_WRITE
] -
2415 oldvs
->vs_ops
[ZIO_TYPE_WRITE
])));
2417 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_READ
] -
2418 oldvs
->vs_bytes
[ZIO_TYPE_READ
])));
2420 print_one_stat((uint64_t)(scale
* (newvs
->vs_bytes
[ZIO_TYPE_WRITE
] -
2421 oldvs
->vs_bytes
[ZIO_TYPE_WRITE
])));
2423 (void) printf("\n");
2425 if (!cb
->cb_verbose
)
2428 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_CHILDREN
,
2429 &newchild
, &children
) != 0)
2432 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_CHILDREN
,
2433 &oldchild
, &c
) != 0)
2436 for (c
= 0; c
< children
; c
++) {
2437 uint64_t ishole
= B_FALSE
, islog
= B_FALSE
;
2439 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_HOLE
,
2442 (void) nvlist_lookup_uint64(newchild
[c
], ZPOOL_CONFIG_IS_LOG
,
2445 if (ishole
|| islog
)
2448 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
], B_FALSE
);
2449 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2450 newchild
[c
], cb
, depth
+ 2);
2455 * Log device section
2458 if (num_logs(newnv
) > 0) {
2459 (void) printf("%-*s - - - - - "
2460 "-\n", cb
->cb_namewidth
, "logs");
2462 for (c
= 0; c
< children
; c
++) {
2463 uint64_t islog
= B_FALSE
;
2464 (void) nvlist_lookup_uint64(newchild
[c
],
2465 ZPOOL_CONFIG_IS_LOG
, &islog
);
2468 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2470 print_vdev_stats(zhp
, vname
, oldnv
?
2471 oldchild
[c
] : NULL
, newchild
[c
],
2480 * Include level 2 ARC devices in iostat output
2482 if (nvlist_lookup_nvlist_array(newnv
, ZPOOL_CONFIG_L2CACHE
,
2483 &newchild
, &children
) != 0)
2486 if (oldnv
&& nvlist_lookup_nvlist_array(oldnv
, ZPOOL_CONFIG_L2CACHE
,
2487 &oldchild
, &c
) != 0)
2491 (void) printf("%-*s - - - - - "
2492 "-\n", cb
->cb_namewidth
, "cache");
2493 for (c
= 0; c
< children
; c
++) {
2494 vname
= zpool_vdev_name(g_zfs
, zhp
, newchild
[c
],
2496 print_vdev_stats(zhp
, vname
, oldnv
? oldchild
[c
] : NULL
,
2497 newchild
[c
], cb
, depth
+ 2);
2504 refresh_iostat(zpool_handle_t
*zhp
, void *data
)
2506 iostat_cbdata_t
*cb
= data
;
2510 * If the pool has disappeared, remove it from the list and continue.
2512 if (zpool_refresh_stats(zhp
, &missing
) != 0)
2516 pool_list_remove(cb
->cb_list
, zhp
);
2522 * Callback to print out the iostats for the given pool.
2525 print_iostat(zpool_handle_t
*zhp
, void *data
)
2527 iostat_cbdata_t
*cb
= data
;
2528 nvlist_t
*oldconfig
, *newconfig
;
2529 nvlist_t
*oldnvroot
, *newnvroot
;
2531 newconfig
= zpool_get_config(zhp
, &oldconfig
);
2533 if (cb
->cb_iteration
== 1)
2536 verify(nvlist_lookup_nvlist(newconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2539 if (oldconfig
== NULL
)
2542 verify(nvlist_lookup_nvlist(oldconfig
, ZPOOL_CONFIG_VDEV_TREE
,
2546 * Print out the statistics for the pool.
2548 print_vdev_stats(zhp
, zpool_get_name(zhp
), oldnvroot
, newnvroot
, cb
, 0);
2551 print_iostat_separator(cb
);
2563 if (isatty(STDOUT_FILENO
)) {
2564 error
= ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
);
2566 columns
= ws
.ws_col
;
2575 get_namewidth(zpool_handle_t
*zhp
, void *data
)
2577 iostat_cbdata_t
*cb
= data
;
2578 nvlist_t
*config
, *nvroot
;
2581 if ((config
= zpool_get_config(zhp
, NULL
)) != NULL
) {
2582 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
2584 if (!cb
->cb_verbose
)
2585 cb
->cb_namewidth
= strlen(zpool_get_name(zhp
));
2587 cb
->cb_namewidth
= max_width(zhp
, nvroot
, 0,
2592 * The width must be at least 10, but may be as large as the
2593 * column width - 42 so that we can still fit in one line.
2595 columns
= get_columns();
2597 if (cb
->cb_namewidth
< 10)
2598 cb
->cb_namewidth
= 10;
2599 if (cb
->cb_namewidth
> columns
- 42)
2600 cb
->cb_namewidth
= columns
- 42;
2606 * Parse the input string, get the 'interval' and 'count' value if there is one.
2609 get_interval_count(int *argcp
, char **argv
, unsigned long *iv
,
2612 unsigned long interval
= 0, count
= 0;
2616 * Determine if the last argument is an integer or a pool name
2618 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2622 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2624 if (*end
== '\0' && errno
== 0) {
2625 if (interval
== 0) {
2626 (void) fprintf(stderr
, gettext("interval "
2627 "cannot be zero\n"));
2631 * Ignore the last parameter
2636 * If this is not a valid number, just plow on. The
2637 * user will get a more informative error message later
2645 * If the last argument is also an integer, then we have both a count
2648 if (argc
> 0 && isdigit(argv
[argc
- 1][0])) {
2653 interval
= strtoul(argv
[argc
- 1], &end
, 10);
2655 if (*end
== '\0' && errno
== 0) {
2656 if (interval
== 0) {
2657 (void) fprintf(stderr
, gettext("interval "
2658 "cannot be zero\n"));
2663 * Ignore the last parameter
2677 get_timestamp_arg(char c
)
2680 timestamp_fmt
= UDATE
;
2682 timestamp_fmt
= DDATE
;
2688 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
2690 * -v Display statistics for individual vdevs
2691 * -T Display a timestamp in date(1) or Unix format
2693 * This command can be tricky because we want to be able to deal with pool
2694 * creation/destruction as well as vdev configuration changes. The bulk of this
2695 * processing is handled by the pool_list_* routines in zpool_iter.c. We rely
2696 * on pool_list_update() to detect the addition of new pools. Configuration
2697 * changes are all handled within libzfs.
2700 zpool_do_iostat(int argc
, char **argv
)
2705 unsigned long interval
= 0, count
= 0;
2707 boolean_t verbose
= B_FALSE
;
2711 while ((c
= getopt(argc
, argv
, "T:v")) != -1) {
2714 get_timestamp_arg(*optarg
);
2720 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
2729 get_interval_count(&argc
, argv
, &interval
, &count
);
2732 * Construct the list of all interesting pools.
2735 if ((list
= pool_list_get(argc
, argv
, NULL
, &ret
)) == NULL
)
2738 if (pool_list_count(list
) == 0 && argc
!= 0) {
2739 pool_list_free(list
);
2743 if (pool_list_count(list
) == 0 && interval
== 0) {
2744 pool_list_free(list
);
2745 (void) fprintf(stderr
, gettext("no pools available\n"));
2750 * Enter the main iostat loop.
2753 cb
.cb_verbose
= verbose
;
2754 cb
.cb_iteration
= 0;
2755 cb
.cb_namewidth
= 0;
2758 pool_list_update(list
);
2760 if ((npools
= pool_list_count(list
)) == 0)
2761 (void) fprintf(stderr
, gettext("no pools available\n"));
2764 * Refresh all statistics. This is done as an
2765 * explicit step before calculating the maximum name
2766 * width, so that any * configuration changes are
2767 * properly accounted for.
2769 (void) pool_list_iter(list
, B_FALSE
, refresh_iostat
,
2773 * Iterate over all pools to determine the maximum width
2774 * for the pool / device name column across all pools.
2776 cb
.cb_namewidth
= 0;
2777 (void) pool_list_iter(list
, B_FALSE
, get_namewidth
,
2780 if (timestamp_fmt
!= NODATE
)
2781 print_timestamp(timestamp_fmt
);
2784 * If it's the first time, or verbose mode, print the
2787 if (++cb
.cb_iteration
== 1 || verbose
)
2788 print_iostat_header(&cb
);
2790 (void) pool_list_iter(list
, B_FALSE
, print_iostat
, &cb
);
2793 * If there's more than one pool, and we're not in
2794 * verbose mode (which prints a separator for us),
2795 * then print a separator.
2797 if (npools
> 1 && !verbose
)
2798 print_iostat_separator(&cb
);
2801 (void) printf("\n");
2805 * Flush the output so that redirection to a file isn't buffered
2808 (void) fflush(stdout
);
2813 if (count
!= 0 && --count
== 0)
2816 (void) sleep(interval
);
2819 pool_list_free(list
);
2824 typedef struct list_cbdata
{
2825 boolean_t cb_verbose
;
2827 boolean_t cb_scripted
;
2828 zprop_list_t
*cb_proplist
;
2832 * Given a list of columns to display, output appropriate headers for each one.
2835 print_header(list_cbdata_t
*cb
)
2837 zprop_list_t
*pl
= cb
->cb_proplist
;
2838 char headerbuf
[ZPOOL_MAXPROPLEN
];
2840 boolean_t first
= B_TRUE
;
2841 boolean_t right_justify
;
2844 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2845 width
= pl
->pl_width
;
2846 if (first
&& cb
->cb_verbose
) {
2848 * Reset the width to accommodate the verbose listing
2851 width
= cb
->cb_namewidth
;
2859 right_justify
= B_FALSE
;
2860 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2861 header
= zpool_prop_column_name(pl
->pl_prop
);
2862 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2866 for (i
= 0; pl
->pl_user_prop
[i
] != '\0'; i
++)
2867 headerbuf
[i
] = toupper(pl
->pl_user_prop
[i
]);
2868 headerbuf
[i
] = '\0';
2872 if (pl
->pl_next
== NULL
&& !right_justify
)
2873 (void) printf("%s", header
);
2874 else if (right_justify
)
2875 (void) printf("%*s", (int)width
, header
);
2877 (void) printf("%-*s", (int)width
, header
);
2880 (void) printf("\n");
2884 * Given a pool and a list of properties, print out all the properties according
2885 * to the described layout.
2888 print_pool(zpool_handle_t
*zhp
, list_cbdata_t
*cb
)
2890 zprop_list_t
*pl
= cb
->cb_proplist
;
2891 boolean_t first
= B_TRUE
;
2892 char property
[ZPOOL_MAXPROPLEN
];
2894 boolean_t right_justify
;
2897 for (; pl
!= NULL
; pl
= pl
->pl_next
) {
2899 width
= pl
->pl_width
;
2900 if (first
&& cb
->cb_verbose
) {
2902 * Reset the width to accommodate the verbose listing
2905 width
= cb
->cb_namewidth
;
2909 if (cb
->cb_scripted
)
2910 (void) printf("\t");
2917 right_justify
= B_FALSE
;
2918 if (pl
->pl_prop
!= ZPROP_INVAL
) {
2919 if (pl
->pl_prop
== ZPOOL_PROP_EXPANDSZ
&&
2920 zpool_get_prop_int(zhp
, pl
->pl_prop
, NULL
) == 0)
2922 else if (zpool_get_prop(zhp
, pl
->pl_prop
, property
,
2923 sizeof (property
), NULL
) != 0)
2928 right_justify
= zpool_prop_align_right(pl
->pl_prop
);
2929 } else if ((zpool_prop_feature(pl
->pl_user_prop
) ||
2930 zpool_prop_unsupported(pl
->pl_user_prop
)) &&
2931 zpool_prop_get_feature(zhp
, pl
->pl_user_prop
, property
,
2932 sizeof (property
)) == 0) {
2940 * If this is being called in scripted mode, or if this is the
2941 * last column and it is left-justified, don't include a width
2944 if (cb
->cb_scripted
|| (pl
->pl_next
== NULL
&& !right_justify
))
2945 (void) printf("%s", propstr
);
2946 else if (right_justify
)
2947 (void) printf("%*s", (int)width
, propstr
);
2949 (void) printf("%-*s", (int)width
, propstr
);
2952 (void) printf("\n");
2956 print_one_column(zpool_prop_t prop
, uint64_t value
, boolean_t scripted
)
2960 size_t width
= zprop_width(prop
, &fixed
, ZFS_TYPE_POOL
);
2962 zfs_nicenum(value
, propval
, sizeof (propval
));
2964 if (prop
== ZPOOL_PROP_EXPANDSZ
&& value
== 0)
2965 (void) strlcpy(propval
, "-", sizeof (propval
));
2968 (void) printf("\t%s", propval
);
2970 (void) printf(" %*s", (int)width
, propval
);
2974 print_list_stats(zpool_handle_t
*zhp
, const char *name
, nvlist_t
*nv
,
2975 list_cbdata_t
*cb
, int depth
)
2981 boolean_t scripted
= cb
->cb_scripted
;
2983 verify(nvlist_lookup_uint64_array(nv
, ZPOOL_CONFIG_VDEV_STATS
,
2984 (uint64_t **)&vs
, &c
) == 0);
2988 (void) printf("\t%s", name
);
2989 else if (strlen(name
) + depth
> cb
->cb_namewidth
)
2990 (void) printf("%*s%s", depth
, "", name
);
2992 (void) printf("%*s%s%*s", depth
, "", name
,
2993 (int)(cb
->cb_namewidth
- strlen(name
) - depth
), "");
2995 /* only toplevel vdevs have capacity stats */
2996 if (vs
->vs_space
== 0) {
2998 (void) printf("\t-\t-\t-");
3000 (void) printf(" - - -");
3002 print_one_column(ZPOOL_PROP_SIZE
, vs
->vs_space
,
3004 print_one_column(ZPOOL_PROP_CAPACITY
, vs
->vs_alloc
,
3006 print_one_column(ZPOOL_PROP_FREE
,
3007 vs
->vs_space
- vs
->vs_alloc
, scripted
);
3009 print_one_column(ZPOOL_PROP_EXPANDSZ
, vs
->vs_esize
,
3011 (void) printf("\n");
3014 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_CHILDREN
,
3015 &child
, &children
) != 0)
3018 for (c
= 0; c
< children
; c
++) {
3019 uint64_t ishole
= B_FALSE
;
3021 if (nvlist_lookup_uint64(child
[c
],
3022 ZPOOL_CONFIG_IS_HOLE
, &ishole
) == 0 && ishole
)
3025 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
], B_FALSE
);
3026 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3031 * Include level 2 ARC devices in iostat output
3033 if (nvlist_lookup_nvlist_array(nv
, ZPOOL_CONFIG_L2CACHE
,
3034 &child
, &children
) != 0)
3038 (void) printf("%-*s - - - - - "
3039 "-\n", cb
->cb_namewidth
, "cache");
3040 for (c
= 0; c
< children
; c
++) {
3041 vname
= zpool_vdev_name(g_zfs
, zhp
, child
[c
],
3043 print_list_stats(zhp
, vname
, child
[c
], cb
, depth
+ 2);
3051 * Generic callback function to list a pool.
3054 list_callback(zpool_handle_t
*zhp
, void *data
)
3056 list_cbdata_t
*cbp
= data
;
3060 config
= zpool_get_config(zhp
, NULL
);
3062 print_pool(zhp
, cbp
);
3063 if (!cbp
->cb_verbose
)
3066 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
3068 print_list_stats(zhp
, NULL
, nvroot
, cbp
, 0);
3074 * zpool list [-H] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3076 * -H Scripted mode. Don't display headers, and separate properties
3078 * -o List of properties to display. Defaults to
3079 * "name,size,allocated,free,capacity,health,altroot"
3080 * -T Display a timestamp in date(1) or Unix format
3082 * List all pools in the system, whether or not they're healthy. Output space
3083 * statistics for each one, as well as health status summary.
3086 zpool_do_list(int argc
, char **argv
)
3090 list_cbdata_t cb
= { 0 };
3091 static char default_props
[] =
3092 "name,size,allocated,free,capacity,dedupratio,"
3094 char *props
= default_props
;
3095 unsigned long interval
= 0, count
= 0;
3097 boolean_t first
= B_TRUE
;
3100 while ((c
= getopt(argc
, argv
, ":Ho:T:v")) != -1) {
3103 cb
.cb_scripted
= B_TRUE
;
3109 get_timestamp_arg(*optarg
);
3112 cb
.cb_verbose
= B_TRUE
;
3115 (void) fprintf(stderr
, gettext("missing argument for "
3116 "'%c' option\n"), optopt
);
3120 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3129 get_interval_count(&argc
, argv
, &interval
, &count
);
3131 if (zprop_get_list(g_zfs
, props
, &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
3134 if ((list
= pool_list_get(argc
, argv
, &cb
.cb_proplist
, &ret
)) == NULL
)
3137 if (argc
== 0 && !cb
.cb_scripted
&& pool_list_count(list
) == 0) {
3138 (void) printf(gettext("no pools available\n"));
3139 zprop_free_list(cb
.cb_proplist
);
3144 pool_list_update(list
);
3146 if (pool_list_count(list
) == 0)
3149 if (timestamp_fmt
!= NODATE
)
3150 print_timestamp(timestamp_fmt
);
3152 if (!cb
.cb_scripted
&& (first
|| cb
.cb_verbose
)) {
3156 ret
= pool_list_iter(list
, B_TRUE
, list_callback
, &cb
);
3161 if (count
!= 0 && --count
== 0)
3164 (void) sleep(interval
);
3167 zprop_free_list(cb
.cb_proplist
);
3172 zpool_do_attach_or_replace(int argc
, char **argv
, int replacing
)
3174 boolean_t force
= B_FALSE
;
3177 char *poolname
, *old_disk
, *new_disk
;
3178 zpool_handle_t
*zhp
;
3179 nvlist_t
*props
= NULL
;
3184 while ((c
= getopt(argc
, argv
, "fo:")) != -1) {
3190 if ((propval
= strchr(optarg
, '=')) == NULL
) {
3191 (void) fprintf(stderr
, gettext("missing "
3192 "'=' for -o option\n"));
3198 if ((strcmp(optarg
, ZPOOL_CONFIG_ASHIFT
) != 0) ||
3199 (add_prop_list(optarg
, propval
, &props
, B_TRUE
)))
3203 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3212 /* get pool name and check number of arguments */
3214 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3221 (void) fprintf(stderr
,
3222 gettext("missing <device> specification\n"));
3230 (void) fprintf(stderr
,
3231 gettext("missing <new_device> specification\n"));
3234 new_disk
= old_disk
;
3244 (void) fprintf(stderr
, gettext("too many arguments\n"));
3248 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3251 if (zpool_get_config(zhp
, NULL
) == NULL
) {
3252 (void) fprintf(stderr
, gettext("pool '%s' is unavailable\n"),
3258 nvroot
= make_root_vdev(zhp
, props
, force
, B_FALSE
, replacing
, B_FALSE
,
3260 if (nvroot
== NULL
) {
3265 ret
= zpool_vdev_attach(zhp
, old_disk
, new_disk
, nvroot
, replacing
);
3267 nvlist_free(nvroot
);
3274 * zpool replace [-f] <pool> <device> <new_device>
3276 * -f Force attach, even if <new_device> appears to be in use.
3278 * Replace <device> with <new_device>.
3282 zpool_do_replace(int argc
, char **argv
)
3284 return (zpool_do_attach_or_replace(argc
, argv
, B_TRUE
));
3288 * zpool attach [-f] [-o property=value] <pool> <device> <new_device>
3290 * -f Force attach, even if <new_device> appears to be in use.
3291 * -o Set property=value.
3293 * Attach <new_device> to the mirror containing <device>. If <device> is not
3294 * part of a mirror, then <device> will be transformed into a mirror of
3295 * <device> and <new_device>. In either case, <new_device> will begin life
3296 * with a DTL of [0, now], and will immediately begin to resilver itself.
3299 zpool_do_attach(int argc
, char **argv
)
3301 return (zpool_do_attach_or_replace(argc
, argv
, B_FALSE
));
3305 * zpool detach [-f] <pool> <device>
3307 * -f Force detach of <device>, even if DTLs argue against it
3308 * (not supported yet)
3310 * Detach a device from a mirror. The operation will be refused if <device>
3311 * is the last device in the mirror, or if the DTLs indicate that this device
3312 * has the only valid copy of some data.
3316 zpool_do_detach(int argc
, char **argv
)
3319 char *poolname
, *path
;
3320 zpool_handle_t
*zhp
;
3324 while ((c
= getopt(argc
, argv
, "f")) != -1) {
3328 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3337 /* get pool name and check number of arguments */
3339 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3344 (void) fprintf(stderr
,
3345 gettext("missing <device> specification\n"));
3352 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3355 ret
= zpool_vdev_detach(zhp
, path
);
3363 * zpool split [-n] [-o prop=val] ...
3365 * [-R altroot] <pool> <newpool> [<device> ...]
3367 * -n Do not split the pool, but display the resulting layout if
3368 * it were to be split.
3369 * -o Set property=value, or set mount options.
3370 * -R Mount the split-off pool under an alternate root.
3372 * Splits the named pool and gives it the new pool name. Devices to be split
3373 * off may be listed, provided that no more than one device is specified
3374 * per top-level vdev mirror. The newly split pool is left in an exported
3375 * state unless -R is specified.
3377 * Restrictions: the top-level of the pool pool must only be made up of
3378 * mirrors; all devices in the pool must be healthy; no device may be
3379 * undergoing a resilvering operation.
3382 zpool_do_split(int argc
, char **argv
)
3384 char *srcpool
, *newpool
, *propval
;
3385 char *mntopts
= NULL
;
3388 zpool_handle_t
*zhp
;
3389 nvlist_t
*config
, *props
= NULL
;
3391 flags
.dryrun
= B_FALSE
;
3392 flags
.import
= B_FALSE
;
3395 while ((c
= getopt(argc
, argv
, ":R:no:")) != -1) {
3398 flags
.import
= B_TRUE
;
3400 zpool_prop_to_name(ZPOOL_PROP_ALTROOT
), optarg
,
3401 &props
, B_TRUE
) != 0) {
3408 flags
.dryrun
= B_TRUE
;
3411 if ((propval
= strchr(optarg
, '=')) != NULL
) {
3414 if (add_prop_list(optarg
, propval
,
3415 &props
, B_TRUE
) != 0) {
3425 (void) fprintf(stderr
, gettext("missing argument for "
3426 "'%c' option\n"), optopt
);
3430 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3437 if (!flags
.import
&& mntopts
!= NULL
) {
3438 (void) fprintf(stderr
, gettext("setting mntopts is only "
3439 "valid when importing the pool\n"));
3447 (void) fprintf(stderr
, gettext("Missing pool name\n"));
3451 (void) fprintf(stderr
, gettext("Missing new pool name\n"));
3461 if ((zhp
= zpool_open(g_zfs
, srcpool
)) == NULL
)
3464 config
= split_mirror_vdev(zhp
, newpool
, props
, flags
, argc
, argv
);
3465 if (config
== NULL
) {
3469 (void) printf(gettext("would create '%s' with the "
3470 "following layout:\n\n"), newpool
);
3471 print_vdev_tree(NULL
, newpool
, config
, 0, B_FALSE
);
3473 nvlist_free(config
);
3478 if (ret
!= 0 || flags
.dryrun
|| !flags
.import
)
3482 * The split was successful. Now we need to open the new
3483 * pool and import it.
3485 if ((zhp
= zpool_open_canfail(g_zfs
, newpool
)) == NULL
)
3487 if (zpool_get_state(zhp
) != POOL_STATE_UNAVAIL
&&
3488 zpool_enable_datasets(zhp
, mntopts
, 0) != 0) {
3490 (void) fprintf(stderr
, gettext("Split was successful, but "
3491 "the datasets could not all be mounted\n"));
3492 (void) fprintf(stderr
, gettext("Try doing '%s' with a "
3493 "different altroot\n"), "zpool import");
3503 * zpool online <pool> <device> ...
3506 zpool_do_online(int argc
, char **argv
)
3510 zpool_handle_t
*zhp
;
3512 vdev_state_t newstate
;
3516 while ((c
= getopt(argc
, argv
, "et")) != -1) {
3519 flags
|= ZFS_ONLINE_EXPAND
;
3523 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3532 /* get pool name and check number of arguments */
3534 (void) fprintf(stderr
, gettext("missing pool name\n"));
3538 (void) fprintf(stderr
, gettext("missing device name\n"));
3544 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3547 for (i
= 1; i
< argc
; i
++) {
3548 if (zpool_vdev_online(zhp
, argv
[i
], flags
, &newstate
) == 0) {
3549 if (newstate
!= VDEV_STATE_HEALTHY
) {
3550 (void) printf(gettext("warning: device '%s' "
3551 "onlined, but remains in faulted state\n"),
3553 if (newstate
== VDEV_STATE_FAULTED
)
3554 (void) printf(gettext("use 'zpool "
3555 "clear' to restore a faulted "
3558 (void) printf(gettext("use 'zpool "
3559 "replace' to replace devices "
3560 "that are no longer present\n"));
3573 * zpool offline [-ft] <pool> <device> ...
3575 * -f Force the device into the offline state, even if doing
3576 * so would appear to compromise pool availability.
3577 * (not supported yet)
3579 * -t Only take the device off-line temporarily. The offline
3580 * state will not be persistent across reboots.
3584 zpool_do_offline(int argc
, char **argv
)
3588 zpool_handle_t
*zhp
;
3590 boolean_t istmp
= B_FALSE
;
3593 while ((c
= getopt(argc
, argv
, "ft")) != -1) {
3600 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3609 /* get pool name and check number of arguments */
3611 (void) fprintf(stderr
, gettext("missing pool name\n"));
3615 (void) fprintf(stderr
, gettext("missing device name\n"));
3621 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3624 for (i
= 1; i
< argc
; i
++) {
3625 if (zpool_vdev_offline(zhp
, argv
[i
], istmp
) != 0)
3635 * zpool clear <pool> [device]
3637 * Clear all errors associated with a pool or a particular device.
3640 zpool_do_clear(int argc
, char **argv
)
3644 boolean_t dryrun
= B_FALSE
;
3645 boolean_t do_rewind
= B_FALSE
;
3646 boolean_t xtreme_rewind
= B_FALSE
;
3647 uint32_t rewind_policy
= ZPOOL_NO_REWIND
;
3648 nvlist_t
*policy
= NULL
;
3649 zpool_handle_t
*zhp
;
3650 char *pool
, *device
;
3653 while ((c
= getopt(argc
, argv
, "FnX")) != -1) {
3662 xtreme_rewind
= B_TRUE
;
3665 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3675 (void) fprintf(stderr
, gettext("missing pool name\n"));
3680 (void) fprintf(stderr
, gettext("too many arguments\n"));
3684 if ((dryrun
|| xtreme_rewind
) && !do_rewind
) {
3685 (void) fprintf(stderr
,
3686 gettext("-n or -X only meaningful with -F\n"));
3690 rewind_policy
= ZPOOL_TRY_REWIND
;
3692 rewind_policy
= ZPOOL_DO_REWIND
;
3694 rewind_policy
|= ZPOOL_EXTREME_REWIND
;
3696 /* In future, further rewind policy choices can be passed along here */
3697 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME
, 0) != 0 ||
3698 nvlist_add_uint32(policy
, ZPOOL_REWIND_REQUEST
, rewind_policy
) != 0)
3702 device
= argc
== 2 ? argv
[1] : NULL
;
3704 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
) {
3705 nvlist_free(policy
);
3709 if (zpool_clear(zhp
, device
, policy
) != 0)
3714 nvlist_free(policy
);
3720 * zpool reguid <pool>
3723 zpool_do_reguid(int argc
, char **argv
)
3727 zpool_handle_t
*zhp
;
3731 while ((c
= getopt(argc
, argv
, "")) != -1) {
3734 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3743 /* get pool name and check number of arguments */
3745 (void) fprintf(stderr
, gettext("missing pool name\n"));
3750 (void) fprintf(stderr
, gettext("too many arguments\n"));
3755 if ((zhp
= zpool_open(g_zfs
, poolname
)) == NULL
)
3758 ret
= zpool_reguid(zhp
);
3766 * zpool reopen <pool>
3768 * Reopen the pool so that the kernel can update the sizes of all vdevs.
3771 zpool_do_reopen(int argc
, char **argv
)
3775 zpool_handle_t
*zhp
;
3779 while ((c
= getopt(argc
, argv
, "")) != -1) {
3782 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3792 (void) fprintf(stderr
, gettext("missing pool name\n"));
3797 (void) fprintf(stderr
, gettext("too many arguments\n"));
3802 if ((zhp
= zpool_open_canfail(g_zfs
, pool
)) == NULL
)
3805 ret
= zpool_reopen(zhp
);
3810 typedef struct scrub_cbdata
{
3817 scrub_callback(zpool_handle_t
*zhp
, void *data
)
3819 scrub_cbdata_t
*cb
= data
;
3823 * Ignore faulted pools.
3825 if (zpool_get_state(zhp
) == POOL_STATE_UNAVAIL
) {
3826 (void) fprintf(stderr
, gettext("cannot scrub '%s': pool is "
3827 "currently unavailable\n"), zpool_get_name(zhp
));
3831 err
= zpool_scan(zhp
, cb
->cb_type
);
3837 * zpool scrub [-s] <pool> ...
3839 * -s Stop. Stops any in-progress scrub.
3842 zpool_do_scrub(int argc
, char **argv
)
3847 cb
.cb_type
= POOL_SCAN_SCRUB
;
3850 while ((c
= getopt(argc
, argv
, "s")) != -1) {
3853 cb
.cb_type
= POOL_SCAN_NONE
;
3856 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
3868 (void) fprintf(stderr
, gettext("missing pool name argument\n"));
3872 return (for_each_pool(argc
, argv
, B_TRUE
, NULL
, scrub_callback
, &cb
));
3875 typedef struct status_cbdata
{
3877 boolean_t cb_allpools
;
3878 boolean_t cb_verbose
;
3879 boolean_t cb_explain
;
3881 boolean_t cb_dedup_stats
;
3885 * Print out detailed scrub status.
3888 print_scan_status(pool_scan_stat_t
*ps
)
3891 uint64_t elapsed
, mins_left
, hours_left
;
3892 uint64_t pass_exam
, examined
, total
;
3894 double fraction_done
;
3895 char processed_buf
[7], examined_buf
[7], total_buf
[7], rate_buf
[7];
3897 (void) printf(gettext(" scan: "));
3899 /* If there's never been a scan, there's not much to say. */
3900 if (ps
== NULL
|| ps
->pss_func
== POOL_SCAN_NONE
||
3901 ps
->pss_func
>= POOL_SCAN_FUNCS
) {
3902 (void) printf(gettext("none requested\n"));
3906 start
= ps
->pss_start_time
;
3907 end
= ps
->pss_end_time
;
3908 zfs_nicenum(ps
->pss_processed
, processed_buf
, sizeof (processed_buf
));
3910 assert(ps
->pss_func
== POOL_SCAN_SCRUB
||
3911 ps
->pss_func
== POOL_SCAN_RESILVER
);
3913 * Scan is finished or canceled.
3915 if (ps
->pss_state
== DSS_FINISHED
) {
3916 uint64_t minutes_taken
= (end
- start
) / 60;
3919 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3920 fmt
= gettext("scrub repaired %s in %lluh%um with "
3921 "%llu errors on %s");
3922 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3923 fmt
= gettext("resilvered %s in %lluh%um with "
3924 "%llu errors on %s");
3927 (void) printf(fmt
, processed_buf
,
3928 (u_longlong_t
)(minutes_taken
/ 60),
3929 (uint_t
)(minutes_taken
% 60),
3930 (u_longlong_t
)ps
->pss_errors
,
3931 ctime((time_t *)&end
));
3933 } else if (ps
->pss_state
== DSS_CANCELED
) {
3934 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3935 (void) printf(gettext("scrub canceled on %s"),
3937 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3938 (void) printf(gettext("resilver canceled on %s"),
3944 assert(ps
->pss_state
== DSS_SCANNING
);
3947 * Scan is in progress.
3949 if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3950 (void) printf(gettext("scrub in progress since %s"),
3952 } else if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3953 (void) printf(gettext("resilver in progress since %s"),
3957 examined
= ps
->pss_examined
? ps
->pss_examined
: 1;
3958 total
= ps
->pss_to_examine
;
3959 fraction_done
= (double)examined
/ total
;
3961 /* elapsed time for this pass */
3962 elapsed
= time(NULL
) - ps
->pss_pass_start
;
3963 elapsed
= elapsed
? elapsed
: 1;
3964 pass_exam
= ps
->pss_pass_exam
? ps
->pss_pass_exam
: 1;
3965 rate
= pass_exam
/ elapsed
;
3966 rate
= rate
? rate
: 1;
3967 mins_left
= ((total
- examined
) / rate
) / 60;
3968 hours_left
= mins_left
/ 60;
3970 zfs_nicenum(examined
, examined_buf
, sizeof (examined_buf
));
3971 zfs_nicenum(total
, total_buf
, sizeof (total_buf
));
3972 zfs_nicenum(rate
, rate_buf
, sizeof (rate_buf
));
3975 * do not print estimated time if hours_left is more than 30 days
3977 (void) printf(gettext(" %s scanned out of %s at %s/s"),
3978 examined_buf
, total_buf
, rate_buf
);
3979 if (hours_left
< (30 * 24)) {
3980 (void) printf(gettext(", %lluh%um to go\n"),
3981 (u_longlong_t
)hours_left
, (uint_t
)(mins_left
% 60));
3983 (void) printf(gettext(
3984 ", (scan is slow, no estimated time)\n"));
3987 if (ps
->pss_func
== POOL_SCAN_RESILVER
) {
3988 (void) printf(gettext(" %s resilvered, %.2f%% done\n"),
3989 processed_buf
, 100 * fraction_done
);
3990 } else if (ps
->pss_func
== POOL_SCAN_SCRUB
) {
3991 (void) printf(gettext(" %s repaired, %.2f%% done\n"),
3992 processed_buf
, 100 * fraction_done
);
3997 print_error_log(zpool_handle_t
*zhp
)
3999 nvlist_t
*nverrlist
= NULL
;
4002 size_t len
= MAXPATHLEN
* 2;
4004 if (zpool_get_errlog(zhp
, &nverrlist
) != 0) {
4005 (void) printf("errors: List of errors unavailable "
4006 "(insufficient privileges)\n");
4010 (void) printf("errors: Permanent errors have been "
4011 "detected in the following files:\n\n");
4013 pathname
= safe_malloc(len
);
4015 while ((elem
= nvlist_next_nvpair(nverrlist
, elem
)) != NULL
) {
4017 uint64_t dsobj
, obj
;
4019 verify(nvpair_value_nvlist(elem
, &nv
) == 0);
4020 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_DATASET
,
4022 verify(nvlist_lookup_uint64(nv
, ZPOOL_ERR_OBJECT
,
4024 zpool_obj_to_path(zhp
, dsobj
, obj
, pathname
, len
);
4025 (void) printf("%7s %s\n", "", pathname
);
4028 nvlist_free(nverrlist
);
4032 print_spares(zpool_handle_t
*zhp
, nvlist_t
**spares
, uint_t nspares
,
4041 (void) printf(gettext("\tspares\n"));
4043 for (i
= 0; i
< nspares
; i
++) {
4044 name
= zpool_vdev_name(g_zfs
, zhp
, spares
[i
], B_FALSE
);
4045 print_status_config(zhp
, name
, spares
[i
],
4046 namewidth
, 2, B_TRUE
);
4052 print_l2cache(zpool_handle_t
*zhp
, nvlist_t
**l2cache
, uint_t nl2cache
,
4061 (void) printf(gettext("\tcache\n"));
4063 for (i
= 0; i
< nl2cache
; i
++) {
4064 name
= zpool_vdev_name(g_zfs
, zhp
, l2cache
[i
], B_FALSE
);
4065 print_status_config(zhp
, name
, l2cache
[i
],
4066 namewidth
, 2, B_FALSE
);
4072 print_dedup_stats(nvlist_t
*config
)
4074 ddt_histogram_t
*ddh
;
4080 * If the pool was faulted then we may not have been able to
4081 * obtain the config. Otherwise, if we have anything in the dedup
4082 * table continue processing the stats.
4084 if (nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_OBJ_STATS
,
4085 (uint64_t **)&ddo
, &c
) != 0)
4088 (void) printf("\n");
4089 (void) printf(gettext(" dedup: "));
4090 if (ddo
->ddo_count
== 0) {
4091 (void) printf(gettext("no DDT entries\n"));
4095 (void) printf("DDT entries %llu, size %llu on disk, %llu in core\n",
4096 (u_longlong_t
)ddo
->ddo_count
,
4097 (u_longlong_t
)ddo
->ddo_dspace
,
4098 (u_longlong_t
)ddo
->ddo_mspace
);
4100 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_STATS
,
4101 (uint64_t **)&dds
, &c
) == 0);
4102 verify(nvlist_lookup_uint64_array(config
, ZPOOL_CONFIG_DDT_HISTOGRAM
,
4103 (uint64_t **)&ddh
, &c
) == 0);
4104 zpool_dump_ddt(dds
, ddh
);
4108 * Display a summary of pool status. Displays a summary such as:
4112 * reason: One or more devices ...
4113 * see: http://zfsonlinux.org/msg/ZFS-xxxx-01
4119 * When given the '-v' option, we print out the complete config. If the '-e'
4120 * option is specified, then we print out error rate information as well.
4123 status_callback(zpool_handle_t
*zhp
, void *data
)
4125 status_cbdata_t
*cbp
= data
;
4126 nvlist_t
*config
, *nvroot
;
4133 config
= zpool_get_config(zhp
, NULL
);
4134 reason
= zpool_get_status(zhp
, &msgid
);
4139 * If we were given 'zpool status -x', only report those pools with
4142 if (cbp
->cb_explain
&&
4143 (reason
== ZPOOL_STATUS_OK
||
4144 reason
== ZPOOL_STATUS_VERSION_OLDER
||
4145 reason
== ZPOOL_STATUS_FEAT_DISABLED
)) {
4146 if (!cbp
->cb_allpools
) {
4147 (void) printf(gettext("pool '%s' is healthy\n"),
4148 zpool_get_name(zhp
));
4150 cbp
->cb_first
= B_FALSE
;
4156 cbp
->cb_first
= B_FALSE
;
4158 (void) printf("\n");
4160 verify(nvlist_lookup_nvlist(config
, ZPOOL_CONFIG_VDEV_TREE
,
4162 verify(nvlist_lookup_uint64_array(nvroot
, ZPOOL_CONFIG_VDEV_STATS
,
4163 (uint64_t **)&vs
, &c
) == 0);
4164 health
= zpool_state_to_name(vs
->vs_state
, vs
->vs_aux
);
4166 (void) printf(gettext(" pool: %s\n"), zpool_get_name(zhp
));
4167 (void) printf(gettext(" state: %s\n"), health
);
4170 case ZPOOL_STATUS_MISSING_DEV_R
:
4171 (void) printf(gettext("status: One or more devices could not "
4172 "be opened. Sufficient replicas exist for\n\tthe pool to "
4173 "continue functioning in a degraded state.\n"));
4174 (void) printf(gettext("action: Attach the missing device and "
4175 "online it using 'zpool online'.\n"));
4178 case ZPOOL_STATUS_MISSING_DEV_NR
:
4179 (void) printf(gettext("status: One or more devices could not "
4180 "be opened. There are insufficient\n\treplicas for the "
4181 "pool to continue functioning.\n"));
4182 (void) printf(gettext("action: Attach the missing device and "
4183 "online it using 'zpool online'.\n"));
4186 case ZPOOL_STATUS_CORRUPT_LABEL_R
:
4187 (void) printf(gettext("status: One or more devices could not "
4188 "be used because the label is missing or\n\tinvalid. "
4189 "Sufficient replicas exist for the pool to continue\n\t"
4190 "functioning in a degraded state.\n"));
4191 (void) printf(gettext("action: Replace the device using "
4192 "'zpool replace'.\n"));
4195 case ZPOOL_STATUS_CORRUPT_LABEL_NR
:
4196 (void) printf(gettext("status: One or more devices could not "
4197 "be used because the label is missing \n\tor invalid. "
4198 "There are insufficient replicas for the pool to "
4199 "continue\n\tfunctioning.\n"));
4200 zpool_explain_recover(zpool_get_handle(zhp
),
4201 zpool_get_name(zhp
), reason
, config
);
4204 case ZPOOL_STATUS_FAILING_DEV
:
4205 (void) printf(gettext("status: One or more devices has "
4206 "experienced an unrecoverable error. An\n\tattempt was "
4207 "made to correct the error. Applications are "
4209 (void) printf(gettext("action: Determine if the device needs "
4210 "to be replaced, and clear the errors\n\tusing "
4211 "'zpool clear' or replace the device with 'zpool "
4215 case ZPOOL_STATUS_OFFLINE_DEV
:
4216 (void) printf(gettext("status: One or more devices has "
4217 "been taken offline by the administrator.\n\tSufficient "
4218 "replicas exist for the pool to continue functioning in "
4219 "a\n\tdegraded state.\n"));
4220 (void) printf(gettext("action: Online the device using "
4221 "'zpool online' or replace the device with\n\t'zpool "
4225 case ZPOOL_STATUS_REMOVED_DEV
:
4226 (void) printf(gettext("status: One or more devices has "
4227 "been removed by the administrator.\n\tSufficient "
4228 "replicas exist for the pool to continue functioning in "
4229 "a\n\tdegraded state.\n"));
4230 (void) printf(gettext("action: Online the device using "
4231 "'zpool online' or replace the device with\n\t'zpool "
4235 case ZPOOL_STATUS_RESILVERING
:
4236 (void) printf(gettext("status: One or more devices is "
4237 "currently being resilvered. The pool will\n\tcontinue "
4238 "to function, possibly in a degraded state.\n"));
4239 (void) printf(gettext("action: Wait for the resilver to "
4243 case ZPOOL_STATUS_CORRUPT_DATA
:
4244 (void) printf(gettext("status: One or more devices has "
4245 "experienced an error resulting in data\n\tcorruption. "
4246 "Applications may be affected.\n"));
4247 (void) printf(gettext("action: Restore the file in question "
4248 "if possible. Otherwise restore the\n\tentire pool from "
4252 case ZPOOL_STATUS_CORRUPT_POOL
:
4253 (void) printf(gettext("status: The pool metadata is corrupted "
4254 "and the pool cannot be opened.\n"));
4255 zpool_explain_recover(zpool_get_handle(zhp
),
4256 zpool_get_name(zhp
), reason
, config
);
4259 case ZPOOL_STATUS_VERSION_OLDER
:
4260 (void) printf(gettext("status: The pool is formatted using a "
4261 "legacy on-disk format. The pool can\n\tstill be used, "
4262 "but some features are unavailable.\n"));
4263 (void) printf(gettext("action: Upgrade the pool using 'zpool "
4264 "upgrade'. Once this is done, the\n\tpool will no longer "
4265 "be accessible on software that does not support\n\t"
4266 "feature flags.\n"));
4269 case ZPOOL_STATUS_VERSION_NEWER
:
4270 (void) printf(gettext("status: The pool has been upgraded to a "
4271 "newer, incompatible on-disk version.\n\tThe pool cannot "
4272 "be accessed on this system.\n"));
4273 (void) printf(gettext("action: Access the pool from a system "
4274 "running more recent software, or\n\trestore the pool from "
4278 case ZPOOL_STATUS_FEAT_DISABLED
:
4279 (void) printf(gettext("status: Some supported features are not "
4280 "enabled on the pool. The pool can\n\tstill be used, but "
4281 "some features are unavailable.\n"));
4282 (void) printf(gettext("action: Enable all features using "
4283 "'zpool upgrade'. Once this is done,\n\tthe pool may no "
4284 "longer be accessible by software that does not support\n\t"
4285 "the features. See zpool-features(5) for details.\n"));
4288 case ZPOOL_STATUS_UNSUP_FEAT_READ
:
4289 (void) printf(gettext("status: The pool cannot be accessed on "
4290 "this system because it uses the\n\tfollowing feature(s) "
4291 "not supported on this system:\n"));
4292 zpool_print_unsup_feat(config
);
4293 (void) printf("\n");
4294 (void) printf(gettext("action: Access the pool from a system "
4295 "that supports the required feature(s),\n\tor restore the "
4296 "pool from backup.\n"));
4299 case ZPOOL_STATUS_UNSUP_FEAT_WRITE
:
4300 (void) printf(gettext("status: The pool can only be accessed "
4301 "in read-only mode on this system. It\n\tcannot be "
4302 "accessed in read-write mode because it uses the "
4303 "following\n\tfeature(s) not supported on this system:\n"));
4304 zpool_print_unsup_feat(config
);
4305 (void) printf("\n");
4306 (void) printf(gettext("action: The pool cannot be accessed in "
4307 "read-write mode. Import the pool with\n"
4308 "\t\"-o readonly=on\", access the pool from a system that "
4309 "supports the\n\trequired feature(s), or restore the "
4310 "pool from backup.\n"));
4313 case ZPOOL_STATUS_FAULTED_DEV_R
:
4314 (void) printf(gettext("status: One or more devices are "
4315 "faulted in response to persistent errors.\n\tSufficient "
4316 "replicas exist for the pool to continue functioning "
4317 "in a\n\tdegraded state.\n"));
4318 (void) printf(gettext("action: Replace the faulted device, "
4319 "or use 'zpool clear' to mark the device\n\trepaired.\n"));
4322 case ZPOOL_STATUS_FAULTED_DEV_NR
:
4323 (void) printf(gettext("status: One or more devices are "
4324 "faulted in response to persistent errors. There are "
4325 "insufficient replicas for the pool to\n\tcontinue "
4327 (void) printf(gettext("action: Destroy and re-create the pool "
4328 "from a backup source. Manually marking the device\n"
4329 "\trepaired using 'zpool clear' may allow some data "
4330 "to be recovered.\n"));
4333 case ZPOOL_STATUS_IO_FAILURE_WAIT
:
4334 case ZPOOL_STATUS_IO_FAILURE_CONTINUE
:
4335 (void) printf(gettext("status: One or more devices are "
4336 "faulted in response to IO failures.\n"));
4337 (void) printf(gettext("action: Make sure the affected devices "
4338 "are connected, then run 'zpool clear'.\n"));
4341 case ZPOOL_STATUS_BAD_LOG
:
4342 (void) printf(gettext("status: An intent log record "
4343 "could not be read.\n"
4344 "\tWaiting for adminstrator intervention to fix the "
4345 "faulted pool.\n"));
4346 (void) printf(gettext("action: Either restore the affected "
4347 "device(s) and run 'zpool online',\n"
4348 "\tor ignore the intent log records by running "
4349 "'zpool clear'.\n"));
4354 * The remaining errors can't actually be generated, yet.
4356 assert(reason
== ZPOOL_STATUS_OK
);
4360 (void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
4363 if (config
!= NULL
) {
4366 nvlist_t
**spares
, **l2cache
;
4367 uint_t nspares
, nl2cache
;
4368 pool_scan_stat_t
*ps
= NULL
;
4370 (void) nvlist_lookup_uint64_array(nvroot
,
4371 ZPOOL_CONFIG_SCAN_STATS
, (uint64_t **)&ps
, &c
);
4372 print_scan_status(ps
);
4374 namewidth
= max_width(zhp
, nvroot
, 0, 0);
4378 (void) printf(gettext("config:\n\n"));
4379 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth
,
4380 "NAME", "STATE", "READ", "WRITE", "CKSUM");
4381 print_status_config(zhp
, zpool_get_name(zhp
), nvroot
,
4382 namewidth
, 0, B_FALSE
);
4384 if (num_logs(nvroot
) > 0)
4385 print_logs(zhp
, nvroot
, namewidth
, B_TRUE
);
4386 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_L2CACHE
,
4387 &l2cache
, &nl2cache
) == 0)
4388 print_l2cache(zhp
, l2cache
, nl2cache
, namewidth
);
4390 if (nvlist_lookup_nvlist_array(nvroot
, ZPOOL_CONFIG_SPARES
,
4391 &spares
, &nspares
) == 0)
4392 print_spares(zhp
, spares
, nspares
, namewidth
);
4394 if (nvlist_lookup_uint64(config
, ZPOOL_CONFIG_ERRCOUNT
,
4396 nvlist_t
*nverrlist
= NULL
;
4399 * If the approximate error count is small, get a
4400 * precise count by fetching the entire log and
4401 * uniquifying the results.
4403 if (nerr
> 0 && nerr
< 100 && !cbp
->cb_verbose
&&
4404 zpool_get_errlog(zhp
, &nverrlist
) == 0) {
4409 while ((elem
= nvlist_next_nvpair(nverrlist
,
4414 nvlist_free(nverrlist
);
4416 (void) printf("\n");
4419 (void) printf(gettext("errors: No known data "
4421 else if (!cbp
->cb_verbose
)
4422 (void) printf(gettext("errors: %llu data "
4423 "errors, use '-v' for a list\n"),
4424 (u_longlong_t
)nerr
);
4426 print_error_log(zhp
);
4429 if (cbp
->cb_dedup_stats
)
4430 print_dedup_stats(config
);
4432 (void) printf(gettext("config: The configuration cannot be "
4440 * zpool status [-vx] [-T d|u] [pool] ... [interval [count]]
4442 * -v Display complete error logs
4443 * -x Display only pools with potential problems
4444 * -D Display dedup status (undocumented)
4445 * -T Display a timestamp in date(1) or Unix format
4447 * Describes the health status of all pools or some subset.
4450 zpool_do_status(int argc
, char **argv
)
4454 unsigned long interval
= 0, count
= 0;
4455 status_cbdata_t cb
= { 0 };
4458 while ((c
= getopt(argc
, argv
, "vxDT:")) != -1) {
4461 cb
.cb_verbose
= B_TRUE
;
4464 cb
.cb_explain
= B_TRUE
;
4467 cb
.cb_dedup_stats
= B_TRUE
;
4470 get_timestamp_arg(*optarg
);
4473 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4482 get_interval_count(&argc
, argv
, &interval
, &count
);
4485 cb
.cb_allpools
= B_TRUE
;
4487 cb
.cb_first
= B_TRUE
;
4490 if (timestamp_fmt
!= NODATE
)
4491 print_timestamp(timestamp_fmt
);
4493 ret
= for_each_pool(argc
, argv
, B_TRUE
, NULL
,
4494 status_callback
, &cb
);
4496 if (argc
== 0 && cb
.cb_count
== 0)
4497 (void) fprintf(stderr
, gettext("no pools available\n"));
4498 else if (cb
.cb_explain
&& cb
.cb_first
&& cb
.cb_allpools
)
4499 (void) printf(gettext("all pools are healthy\n"));
4507 if (count
!= 0 && --count
== 0)
4510 (void) sleep(interval
);
4516 typedef struct upgrade_cbdata
{
4519 uint64_t cb_version
;
4524 upgrade_version(zpool_handle_t
*zhp
, uint64_t version
)
4528 uint64_t oldversion
;
4530 config
= zpool_get_config(zhp
, NULL
);
4531 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4534 assert(SPA_VERSION_IS_SUPPORTED(oldversion
));
4535 assert(oldversion
< version
);
4537 ret
= zpool_upgrade(zhp
, version
);
4541 if (version
>= SPA_VERSION_FEATURES
) {
4542 (void) printf(gettext("Successfully upgraded "
4543 "'%s' from version %llu to feature flags.\n"),
4544 zpool_get_name(zhp
), (u_longlong_t
) oldversion
);
4546 (void) printf(gettext("Successfully upgraded "
4547 "'%s' from version %llu to version %llu.\n"),
4548 zpool_get_name(zhp
), (u_longlong_t
) oldversion
,
4549 (u_longlong_t
) version
);
4556 upgrade_enable_all(zpool_handle_t
*zhp
, int *countp
)
4559 boolean_t firstff
= B_TRUE
;
4560 nvlist_t
*enabled
= zpool_get_features(zhp
);
4563 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4564 const char *fname
= spa_feature_table
[i
].fi_uname
;
4565 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4566 if (!nvlist_exists(enabled
, fguid
)) {
4568 verify(-1 != asprintf(&propname
, "feature@%s", fname
));
4569 ret
= zpool_set_prop(zhp
, propname
,
4570 ZFS_FEATURE_ENABLED
);
4578 (void) printf(gettext("Enabled the "
4579 "following features on '%s':\n"),
4580 zpool_get_name(zhp
));
4583 (void) printf(gettext(" %s\n"), fname
);
4594 upgrade_cb(zpool_handle_t
*zhp
, void *arg
)
4596 upgrade_cbdata_t
*cbp
= arg
;
4599 boolean_t printnl
= B_FALSE
;
4602 config
= zpool_get_config(zhp
, NULL
);
4603 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4606 assert(SPA_VERSION_IS_SUPPORTED(version
));
4608 if (version
< cbp
->cb_version
) {
4609 cbp
->cb_first
= B_FALSE
;
4610 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4616 * If they did "zpool upgrade -a", then we could
4617 * be doing ioctls to different pools. We need
4618 * to log this history once to each pool, and bypass
4619 * the normal history logging that happens in main().
4621 (void) zpool_log_history(g_zfs
, history_str
);
4622 log_history
= B_FALSE
;
4625 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4627 ret
= upgrade_enable_all(zhp
, &count
);
4632 cbp
->cb_first
= B_FALSE
;
4638 (void) printf(gettext("\n"));
4645 upgrade_list_older_cb(zpool_handle_t
*zhp
, void *arg
)
4647 upgrade_cbdata_t
*cbp
= arg
;
4651 config
= zpool_get_config(zhp
, NULL
);
4652 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4655 assert(SPA_VERSION_IS_SUPPORTED(version
));
4657 if (version
< SPA_VERSION_FEATURES
) {
4658 if (cbp
->cb_first
) {
4659 (void) printf(gettext("The following pools are "
4660 "formatted with legacy version numbers and can\n"
4661 "be upgraded to use feature flags. After "
4662 "being upgraded, these pools\nwill no "
4663 "longer be accessible by software that does not "
4664 "support feature\nflags.\n\n"));
4665 (void) printf(gettext("VER POOL\n"));
4666 (void) printf(gettext("--- ------------\n"));
4667 cbp
->cb_first
= B_FALSE
;
4670 (void) printf("%2llu %s\n", (u_longlong_t
)version
,
4671 zpool_get_name(zhp
));
4678 upgrade_list_disabled_cb(zpool_handle_t
*zhp
, void *arg
)
4680 upgrade_cbdata_t
*cbp
= arg
;
4684 config
= zpool_get_config(zhp
, NULL
);
4685 verify(nvlist_lookup_uint64(config
, ZPOOL_CONFIG_VERSION
,
4688 if (version
>= SPA_VERSION_FEATURES
) {
4690 boolean_t poolfirst
= B_TRUE
;
4691 nvlist_t
*enabled
= zpool_get_features(zhp
);
4693 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4694 const char *fguid
= spa_feature_table
[i
].fi_guid
;
4695 const char *fname
= spa_feature_table
[i
].fi_uname
;
4696 if (!nvlist_exists(enabled
, fguid
)) {
4697 if (cbp
->cb_first
) {
4698 (void) printf(gettext("\nSome "
4699 "supported features are not "
4700 "enabled on the following pools. "
4701 "Once a\nfeature is enabled the "
4702 "pool may become incompatible with "
4703 "software\nthat does not support "
4705 "zpool-features(5) for "
4707 (void) printf(gettext("POOL "
4709 (void) printf(gettext("------"
4711 cbp
->cb_first
= B_FALSE
;
4715 (void) printf(gettext("%s\n"),
4716 zpool_get_name(zhp
));
4717 poolfirst
= B_FALSE
;
4720 (void) printf(gettext(" %s\n"), fname
);
4723 * If they did "zpool upgrade -a", then we could
4724 * be doing ioctls to different pools. We need
4725 * to log this history once to each pool, and bypass
4726 * the normal history logging that happens in main().
4728 (void) zpool_log_history(g_zfs
, history_str
);
4729 log_history
= B_FALSE
;
4738 upgrade_one(zpool_handle_t
*zhp
, void *data
)
4740 boolean_t printnl
= B_FALSE
;
4741 upgrade_cbdata_t
*cbp
= data
;
4742 uint64_t cur_version
;
4745 if (strcmp("log", zpool_get_name(zhp
)) == 0) {
4746 (void) printf(gettext("'log' is now a reserved word\n"
4747 "Pool 'log' must be renamed using export and import"
4752 cur_version
= zpool_get_prop_int(zhp
, ZPOOL_PROP_VERSION
, NULL
);
4753 if (cur_version
> cbp
->cb_version
) {
4754 (void) printf(gettext("Pool '%s' is already formatted "
4755 "using more current version '%llu'.\n\n"),
4756 zpool_get_name(zhp
), (u_longlong_t
) cur_version
);
4760 if (cbp
->cb_version
!= SPA_VERSION
&& cur_version
== cbp
->cb_version
) {
4761 (void) printf(gettext("Pool '%s' is already formatted "
4762 "using version %llu.\n\n"), zpool_get_name(zhp
),
4763 (u_longlong_t
) cbp
->cb_version
);
4767 if (cur_version
!= cbp
->cb_version
) {
4769 ret
= upgrade_version(zhp
, cbp
->cb_version
);
4774 if (cbp
->cb_version
>= SPA_VERSION_FEATURES
) {
4776 ret
= upgrade_enable_all(zhp
, &count
);
4782 } else if (cur_version
== SPA_VERSION
) {
4783 (void) printf(gettext("Pool '%s' already has all "
4784 "supported features enabled.\n"),
4785 zpool_get_name(zhp
));
4790 (void) printf(gettext("\n"));
4799 * zpool upgrade [-V version] <-a | pool ...>
4801 * With no arguments, display downrev'd ZFS pool available for upgrade.
4802 * Individual pools can be upgraded by specifying the pool, and '-a' will
4803 * upgrade all pools.
4806 zpool_do_upgrade(int argc
, char **argv
)
4809 upgrade_cbdata_t cb
= { 0 };
4811 boolean_t showversions
= B_FALSE
;
4812 boolean_t upgradeall
= B_FALSE
;
4817 while ((c
= getopt(argc
, argv
, ":avV:")) != -1) {
4820 upgradeall
= B_TRUE
;
4823 showversions
= B_TRUE
;
4826 cb
.cb_version
= strtoll(optarg
, &end
, 10);
4828 !SPA_VERSION_IS_SUPPORTED(cb
.cb_version
)) {
4829 (void) fprintf(stderr
,
4830 gettext("invalid version '%s'\n"), optarg
);
4835 (void) fprintf(stderr
, gettext("missing argument for "
4836 "'%c' option\n"), optopt
);
4840 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
4851 if (cb
.cb_version
== 0) {
4852 cb
.cb_version
= SPA_VERSION
;
4853 } else if (!upgradeall
&& argc
== 0) {
4854 (void) fprintf(stderr
, gettext("-V option is "
4855 "incompatible with other arguments\n"));
4860 if (upgradeall
|| argc
!= 0) {
4861 (void) fprintf(stderr
, gettext("-v option is "
4862 "incompatible with other arguments\n"));
4865 } else if (upgradeall
) {
4867 (void) fprintf(stderr
, gettext("-a option should not "
4868 "be used along with a pool name\n"));
4873 (void) printf(gettext("This system supports ZFS pool feature "
4878 (void) printf(gettext("The following features are "
4880 (void) printf(gettext("FEAT DESCRIPTION\n"));
4881 (void) printf("----------------------------------------------"
4882 "---------------\n");
4883 for (i
= 0; i
< SPA_FEATURES
; i
++) {
4884 zfeature_info_t
*fi
= &spa_feature_table
[i
];
4885 const char *ro
= fi
->fi_can_readonly
?
4886 " (read-only compatible)" : "";
4888 (void) printf("%-37s%s\n", fi
->fi_uname
, ro
);
4889 (void) printf(" %s\n", fi
->fi_desc
);
4891 (void) printf("\n");
4893 (void) printf(gettext("The following legacy versions are also "
4895 (void) printf(gettext("VER DESCRIPTION\n"));
4896 (void) printf("--- -----------------------------------------"
4897 "---------------\n");
4898 (void) printf(gettext(" 1 Initial ZFS version\n"));
4899 (void) printf(gettext(" 2 Ditto blocks "
4900 "(replicated metadata)\n"));
4901 (void) printf(gettext(" 3 Hot spares and double parity "
4903 (void) printf(gettext(" 4 zpool history\n"));
4904 (void) printf(gettext(" 5 Compression using the gzip "
4906 (void) printf(gettext(" 6 bootfs pool property\n"));
4907 (void) printf(gettext(" 7 Separate intent log devices\n"));
4908 (void) printf(gettext(" 8 Delegated administration\n"));
4909 (void) printf(gettext(" 9 refquota and refreservation "
4911 (void) printf(gettext(" 10 Cache devices\n"));
4912 (void) printf(gettext(" 11 Improved scrub performance\n"));
4913 (void) printf(gettext(" 12 Snapshot properties\n"));
4914 (void) printf(gettext(" 13 snapused property\n"));
4915 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
4916 (void) printf(gettext(" 15 user/group space accounting\n"));
4917 (void) printf(gettext(" 16 stmf property support\n"));
4918 (void) printf(gettext(" 17 Triple-parity RAID-Z\n"));
4919 (void) printf(gettext(" 18 Snapshot user holds\n"));
4920 (void) printf(gettext(" 19 Log device removal\n"));
4921 (void) printf(gettext(" 20 Compression using zle "
4922 "(zero-length encoding)\n"));
4923 (void) printf(gettext(" 21 Deduplication\n"));
4924 (void) printf(gettext(" 22 Received properties\n"));
4925 (void) printf(gettext(" 23 Slim ZIL\n"));
4926 (void) printf(gettext(" 24 System attributes\n"));
4927 (void) printf(gettext(" 25 Improved scrub stats\n"));
4928 (void) printf(gettext(" 26 Improved snapshot deletion "
4930 (void) printf(gettext(" 27 Improved snapshot creation "
4932 (void) printf(gettext(" 28 Multiple vdev replacements\n"));
4933 (void) printf(gettext("\nFor more information on a particular "
4934 "version, including supported releases,\n"));
4935 (void) printf(gettext("see the ZFS Administration Guide.\n\n"));
4936 } else if (argc
== 0 && upgradeall
) {
4937 cb
.cb_first
= B_TRUE
;
4938 ret
= zpool_iter(g_zfs
, upgrade_cb
, &cb
);
4939 if (ret
== 0 && cb
.cb_first
) {
4940 if (cb
.cb_version
== SPA_VERSION
) {
4941 (void) printf(gettext("All pools are already "
4942 "formatted using feature flags.\n\n"));
4943 (void) printf(gettext("Every feature flags "
4944 "pool already has all supported features "
4947 (void) printf(gettext("All pools are already "
4948 "formatted with version %llu or higher.\n"),
4949 (u_longlong_t
) cb
.cb_version
);
4952 } else if (argc
== 0) {
4953 cb
.cb_first
= B_TRUE
;
4954 ret
= zpool_iter(g_zfs
, upgrade_list_older_cb
, &cb
);
4958 (void) printf(gettext("All pools are formatted "
4959 "using feature flags.\n\n"));
4961 (void) printf(gettext("\nUse 'zpool upgrade -v' "
4962 "for a list of available legacy versions.\n"));
4965 cb
.cb_first
= B_TRUE
;
4966 ret
= zpool_iter(g_zfs
, upgrade_list_disabled_cb
, &cb
);
4970 (void) printf(gettext("Every feature flags pool has "
4971 "all supported features enabled.\n"));
4973 (void) printf(gettext("\n"));
4976 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
,
4983 typedef struct hist_cbdata
{
4990 * Print out the command history for a specific pool.
4993 get_history_one(zpool_handle_t
*zhp
, void *data
)
4999 hist_cbdata_t
*cb
= (hist_cbdata_t
*)data
;
5001 cb
->first
= B_FALSE
;
5003 (void) printf(gettext("History for '%s':\n"), zpool_get_name(zhp
));
5005 if ((ret
= zpool_get_history(zhp
, &nvhis
)) != 0)
5008 verify(nvlist_lookup_nvlist_array(nvhis
, ZPOOL_HIST_RECORD
,
5009 &records
, &numrecords
) == 0);
5010 for (i
= 0; i
< numrecords
; i
++) {
5011 nvlist_t
*rec
= records
[i
];
5014 if (nvlist_exists(rec
, ZPOOL_HIST_TIME
)) {
5018 tsec
= fnvlist_lookup_uint64(records
[i
],
5020 (void) localtime_r(&tsec
, &t
);
5021 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
5024 if (nvlist_exists(rec
, ZPOOL_HIST_CMD
)) {
5025 (void) printf("%s %s", tbuf
,
5026 fnvlist_lookup_string(rec
, ZPOOL_HIST_CMD
));
5027 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_EVENT
)) {
5029 fnvlist_lookup_uint64(rec
, ZPOOL_HIST_INT_EVENT
);
5032 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
) {
5033 (void) printf("%s unrecognized record:\n",
5035 dump_nvlist(rec
, 4);
5038 (void) printf("%s [internal %s txg:%lld] %s", tbuf
,
5039 zfs_history_event_names
[ievent
],
5040 (long long int)fnvlist_lookup_uint64(rec
, ZPOOL_HIST_TXG
),
5041 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_STR
));
5042 } else if (nvlist_exists(rec
, ZPOOL_HIST_INT_NAME
)) {
5045 (void) printf("%s [txg:%lld] %s", tbuf
,
5046 (long long int)fnvlist_lookup_uint64(rec
, ZPOOL_HIST_TXG
),
5047 fnvlist_lookup_string(rec
, ZPOOL_HIST_INT_NAME
));
5048 if (nvlist_exists(rec
, ZPOOL_HIST_DSNAME
)) {
5049 (void) printf(" %s (%llu)",
5050 fnvlist_lookup_string(rec
,
5052 (long long unsigned int)fnvlist_lookup_uint64(rec
,
5055 (void) printf(" %s", fnvlist_lookup_string(rec
,
5056 ZPOOL_HIST_INT_STR
));
5057 } else if (nvlist_exists(rec
, ZPOOL_HIST_IOCTL
)) {
5060 (void) printf("%s ioctl %s\n", tbuf
,
5061 fnvlist_lookup_string(rec
, ZPOOL_HIST_IOCTL
));
5062 if (nvlist_exists(rec
, ZPOOL_HIST_INPUT_NVL
)) {
5063 (void) printf(" input:\n");
5064 dump_nvlist(fnvlist_lookup_nvlist(rec
,
5065 ZPOOL_HIST_INPUT_NVL
), 8);
5067 if (nvlist_exists(rec
, ZPOOL_HIST_OUTPUT_NVL
)) {
5068 (void) printf(" output:\n");
5069 dump_nvlist(fnvlist_lookup_nvlist(rec
,
5070 ZPOOL_HIST_OUTPUT_NVL
), 8);
5075 (void) printf("%s unrecognized record:\n", tbuf
);
5076 dump_nvlist(rec
, 4);
5080 (void) printf("\n");
5083 (void) printf(" [");
5084 if (nvlist_exists(rec
, ZPOOL_HIST_WHO
)) {
5085 uid_t who
= fnvlist_lookup_uint64(rec
, ZPOOL_HIST_WHO
);
5086 struct passwd
*pwd
= getpwuid(who
);
5087 (void) printf("user %d ", (int)who
);
5089 (void) printf("(%s) ", pwd
->pw_name
);
5091 if (nvlist_exists(rec
, ZPOOL_HIST_HOST
)) {
5092 (void) printf("on %s",
5093 fnvlist_lookup_string(rec
, ZPOOL_HIST_HOST
));
5095 if (nvlist_exists(rec
, ZPOOL_HIST_ZONE
)) {
5096 (void) printf(":%s",
5097 fnvlist_lookup_string(rec
, ZPOOL_HIST_ZONE
));
5101 (void) printf("\n");
5103 (void) printf("\n");
5110 * zpool history <pool>
5112 * Displays the history of commands that modified pools.
5115 zpool_do_history(int argc
, char **argv
)
5117 hist_cbdata_t cbdata
= { 0 };
5121 cbdata
.first
= B_TRUE
;
5123 while ((c
= getopt(argc
, argv
, "li")) != -1) {
5126 cbdata
.longfmt
= B_TRUE
;
5129 cbdata
.internal
= B_TRUE
;
5132 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5140 ret
= for_each_pool(argc
, argv
, B_FALSE
, NULL
, get_history_one
,
5143 if (argc
== 0 && cbdata
.first
== B_TRUE
) {
5144 (void) fprintf(stderr
, gettext("no pools available\n"));
5151 typedef struct ev_opts
{
5159 zpool_do_events_short(nvlist_t
*nvl
)
5161 char ctime_str
[26], str
[32], *ptr
;
5165 verify(nvlist_lookup_int64_array(nvl
, FM_EREPORT_TIME
, &tv
, &n
) == 0);
5166 memset(str
, ' ', 32);
5167 (void) ctime_r((const time_t *)&tv
[0], ctime_str
);
5168 (void) strncpy(str
, ctime_str
+4, 6); /* 'Jun 30' */
5169 (void) strncpy(str
+7, ctime_str
+20, 4); /* '1993' */
5170 (void) strncpy(str
+12, ctime_str
+11, 8); /* '21:49:08' */
5171 (void) sprintf(str
+20, ".%09lld", (longlong_t
)tv
[1]);/* '.123456789' */
5172 (void) printf(gettext("%s "), str
);
5174 verify(nvlist_lookup_string(nvl
, FM_CLASS
, &ptr
) == 0);
5175 (void) printf(gettext("%s\n"), ptr
);
5179 zpool_do_events_nvprint(nvlist_t
*nvl
, int depth
)
5183 for (nvp
= nvlist_next_nvpair(nvl
, NULL
);
5184 nvp
!= NULL
; nvp
= nvlist_next_nvpair(nvl
, nvp
)) {
5186 data_type_t type
= nvpair_type(nvp
);
5187 const char *name
= nvpair_name(nvp
);
5197 printf(gettext("%*s%s = "), depth
, "", name
);
5200 case DATA_TYPE_BOOLEAN
:
5201 printf(gettext("%s"), "1");
5204 case DATA_TYPE_BOOLEAN_VALUE
:
5205 (void) nvpair_value_boolean_value(nvp
, &b
);
5206 printf(gettext("%s"), b
? "1" : "0");
5209 case DATA_TYPE_BYTE
:
5210 (void) nvpair_value_byte(nvp
, &i8
);
5211 printf(gettext("0x%x"), i8
);
5214 case DATA_TYPE_INT8
:
5215 (void) nvpair_value_int8(nvp
, (void *)&i8
);
5216 printf(gettext("0x%x"), i8
);
5219 case DATA_TYPE_UINT8
:
5220 (void) nvpair_value_uint8(nvp
, &i8
);
5221 printf(gettext("0x%x"), i8
);
5224 case DATA_TYPE_INT16
:
5225 (void) nvpair_value_int16(nvp
, (void *)&i16
);
5226 printf(gettext("0x%x"), i16
);
5229 case DATA_TYPE_UINT16
:
5230 (void) nvpair_value_uint16(nvp
, &i16
);
5231 printf(gettext("0x%x"), i16
);
5234 case DATA_TYPE_INT32
:
5235 (void) nvpair_value_int32(nvp
, (void *)&i32
);
5236 printf(gettext("0x%x"), i32
);
5239 case DATA_TYPE_UINT32
:
5240 (void) nvpair_value_uint32(nvp
, &i32
);
5241 printf(gettext("0x%x"), i32
);
5244 case DATA_TYPE_INT64
:
5245 (void) nvpair_value_int64(nvp
, (void *)&i64
);
5246 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5249 case DATA_TYPE_UINT64
:
5250 (void) nvpair_value_uint64(nvp
, &i64
);
5251 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5254 case DATA_TYPE_HRTIME
:
5255 (void) nvpair_value_hrtime(nvp
, (void *)&i64
);
5256 printf(gettext("0x%llx"), (u_longlong_t
)i64
);
5259 case DATA_TYPE_STRING
:
5260 (void) nvpair_value_string(nvp
, &str
);
5261 printf(gettext("\"%s\""), str
? str
: "<NULL>");
5264 case DATA_TYPE_NVLIST
:
5265 printf(gettext("(embedded nvlist)\n"));
5266 (void) nvpair_value_nvlist(nvp
, &cnv
);
5267 zpool_do_events_nvprint(cnv
, depth
+ 8);
5268 printf(gettext("%*s(end %s)"), depth
, "", name
);
5271 case DATA_TYPE_NVLIST_ARRAY
: {
5275 (void) nvpair_value_nvlist_array(nvp
, &val
, &nelem
);
5276 printf(gettext("(%d embedded nvlists)\n"), nelem
);
5277 for (i
= 0; i
< nelem
; i
++) {
5278 printf(gettext("%*s%s[%d] = %s\n"),
5279 depth
, "", name
, i
, "(embedded nvlist)");
5280 zpool_do_events_nvprint(val
[i
], depth
+ 8);
5281 printf(gettext("%*s(end %s[%i])\n"),
5282 depth
, "", name
, i
);
5284 printf(gettext("%*s(end %s)\n"), depth
, "", name
);
5288 case DATA_TYPE_INT8_ARRAY
: {
5292 (void) nvpair_value_int8_array(nvp
, &val
, &nelem
);
5293 for (i
= 0; i
< nelem
; i
++)
5294 printf(gettext("0x%x "), val
[i
]);
5299 case DATA_TYPE_UINT8_ARRAY
: {
5303 (void) nvpair_value_uint8_array(nvp
, &val
, &nelem
);
5304 for (i
= 0; i
< nelem
; i
++)
5305 printf(gettext("0x%x "), val
[i
]);
5310 case DATA_TYPE_INT16_ARRAY
: {
5314 (void) nvpair_value_int16_array(nvp
, &val
, &nelem
);
5315 for (i
= 0; i
< nelem
; i
++)
5316 printf(gettext("0x%x "), val
[i
]);
5321 case DATA_TYPE_UINT16_ARRAY
: {
5325 (void) nvpair_value_uint16_array(nvp
, &val
, &nelem
);
5326 for (i
= 0; i
< nelem
; i
++)
5327 printf(gettext("0x%x "), val
[i
]);
5332 case DATA_TYPE_INT32_ARRAY
: {
5336 (void) nvpair_value_int32_array(nvp
, &val
, &nelem
);
5337 for (i
= 0; i
< nelem
; i
++)
5338 printf(gettext("0x%x "), val
[i
]);
5343 case DATA_TYPE_UINT32_ARRAY
: {
5347 (void) nvpair_value_uint32_array(nvp
, &val
, &nelem
);
5348 for (i
= 0; i
< nelem
; i
++)
5349 printf(gettext("0x%x "), val
[i
]);
5354 case DATA_TYPE_INT64_ARRAY
: {
5358 (void) nvpair_value_int64_array(nvp
, &val
, &nelem
);
5359 for (i
= 0; i
< nelem
; i
++)
5360 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5365 case DATA_TYPE_UINT64_ARRAY
: {
5369 (void) nvpair_value_uint64_array(nvp
, &val
, &nelem
);
5370 for (i
= 0; i
< nelem
; i
++)
5371 printf(gettext("0x%llx "), (u_longlong_t
)val
[i
]);
5376 case DATA_TYPE_STRING_ARRAY
:
5377 case DATA_TYPE_BOOLEAN_ARRAY
:
5378 case DATA_TYPE_BYTE_ARRAY
:
5379 case DATA_TYPE_DOUBLE
:
5380 case DATA_TYPE_UNKNOWN
:
5381 printf(gettext("<unknown>"));
5385 printf(gettext("\n"));
5390 zpool_do_events_next(ev_opts_t
*opts
)
5393 int cleanup_fd
, ret
, dropped
;
5395 cleanup_fd
= open(ZFS_DEV
, O_RDWR
);
5396 VERIFY(cleanup_fd
>= 0);
5398 if (!opts
->scripted
)
5399 (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
5402 ret
= zpool_events_next(g_zfs
, &nvl
, &dropped
,
5403 !!opts
->follow
, cleanup_fd
);
5404 if (ret
|| nvl
== NULL
)
5408 (void) printf(gettext("dropped %d events\n"), dropped
);
5410 zpool_do_events_short(nvl
);
5412 if (opts
->verbose
) {
5413 zpool_do_events_nvprint(nvl
, 8);
5414 printf(gettext("\n"));
5416 (void) fflush(stdout
);
5421 VERIFY(0 == close(cleanup_fd
));
5427 zpool_do_events_clear(ev_opts_t
*opts
)
5431 ret
= zpool_events_clear(g_zfs
, &count
);
5433 (void) printf(gettext("cleared %d events\n"), count
);
5439 * zpool events [-vfc]
5441 * Displays events logs by ZFS.
5444 zpool_do_events(int argc
, char **argv
)
5446 ev_opts_t opts
= { 0 };
5451 while ((c
= getopt(argc
, argv
, "vHfc")) != -1) {
5466 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5475 ret
= zpool_do_events_clear(&opts
);
5477 ret
= zpool_do_events_next(&opts
);
5483 get_callback(zpool_handle_t
*zhp
, void *data
)
5485 zprop_get_cbdata_t
*cbp
= (zprop_get_cbdata_t
*)data
;
5486 char value
[MAXNAMELEN
];
5487 zprop_source_t srctype
;
5490 for (pl
= cbp
->cb_proplist
; pl
!= NULL
; pl
= pl
->pl_next
) {
5493 * Skip the special fake placeholder. This will also skip
5494 * over the name property when 'all' is specified.
5496 if (pl
->pl_prop
== ZPOOL_PROP_NAME
&&
5497 pl
== cbp
->cb_proplist
)
5500 if (pl
->pl_prop
== ZPROP_INVAL
&&
5501 (zpool_prop_feature(pl
->pl_user_prop
) ||
5502 zpool_prop_unsupported(pl
->pl_user_prop
))) {
5503 srctype
= ZPROP_SRC_LOCAL
;
5505 if (zpool_prop_get_feature(zhp
, pl
->pl_user_prop
,
5506 value
, sizeof (value
)) == 0) {
5507 zprop_print_one_property(zpool_get_name(zhp
),
5508 cbp
, pl
->pl_user_prop
, value
, srctype
,
5512 if (zpool_get_prop_literal(zhp
, pl
->pl_prop
, value
,
5513 sizeof (value
), &srctype
, cbp
->cb_literal
) != 0)
5516 zprop_print_one_property(zpool_get_name(zhp
), cbp
,
5517 zpool_prop_to_name(pl
->pl_prop
), value
, srctype
,
5525 zpool_do_get(int argc
, char **argv
)
5527 zprop_get_cbdata_t cb
= { 0 };
5528 zprop_list_t fake_name
= { 0 };
5532 while ((c
= getopt(argc
, argv
, "p")) != -1) {
5535 cb
.cb_literal
= B_TRUE
;
5539 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5549 (void) fprintf(stderr
, gettext("missing property "
5554 cb
.cb_first
= B_TRUE
;
5555 cb
.cb_sources
= ZPROP_SRC_ALL
;
5556 cb
.cb_columns
[0] = GET_COL_NAME
;
5557 cb
.cb_columns
[1] = GET_COL_PROPERTY
;
5558 cb
.cb_columns
[2] = GET_COL_VALUE
;
5559 cb
.cb_columns
[3] = GET_COL_SOURCE
;
5560 cb
.cb_type
= ZFS_TYPE_POOL
;
5562 if (zprop_get_list(g_zfs
, argv
[0], &cb
.cb_proplist
, ZFS_TYPE_POOL
) != 0)
5568 if (cb
.cb_proplist
!= NULL
) {
5569 fake_name
.pl_prop
= ZPOOL_PROP_NAME
;
5570 fake_name
.pl_width
= strlen(gettext("NAME"));
5571 fake_name
.pl_next
= cb
.cb_proplist
;
5572 cb
.cb_proplist
= &fake_name
;
5575 ret
= for_each_pool(argc
, argv
, B_TRUE
, &cb
.cb_proplist
,
5578 if (cb
.cb_proplist
== &fake_name
)
5579 zprop_free_list(fake_name
.pl_next
);
5581 zprop_free_list(cb
.cb_proplist
);
5586 typedef struct set_cbdata
{
5589 boolean_t cb_any_successful
;
5593 set_callback(zpool_handle_t
*zhp
, void *data
)
5596 set_cbdata_t
*cb
= (set_cbdata_t
*)data
;
5598 error
= zpool_set_prop(zhp
, cb
->cb_propname
, cb
->cb_value
);
5601 cb
->cb_any_successful
= B_TRUE
;
5607 zpool_do_set(int argc
, char **argv
)
5609 set_cbdata_t cb
= { 0 };
5612 if (argc
> 1 && argv
[1][0] == '-') {
5613 (void) fprintf(stderr
, gettext("invalid option '%c'\n"),
5619 (void) fprintf(stderr
, gettext("missing property=value "
5625 (void) fprintf(stderr
, gettext("missing pool name\n"));
5630 (void) fprintf(stderr
, gettext("too many pool names\n"));
5634 cb
.cb_propname
= argv
[1];
5635 cb
.cb_value
= strchr(cb
.cb_propname
, '=');
5636 if (cb
.cb_value
== NULL
) {
5637 (void) fprintf(stderr
, gettext("missing value in "
5638 "property=value argument\n"));
5642 *(cb
.cb_value
) = '\0';
5645 error
= for_each_pool(argc
- 2, argv
+ 2, B_TRUE
, NULL
,
5652 find_command_idx(char *command
, int *idx
)
5656 for (i
= 0; i
< NCOMMAND
; i
++) {
5657 if (command_table
[i
].name
== NULL
)
5660 if (strcmp(command
, command_table
[i
].name
) == 0) {
5669 main(int argc
, char **argv
)
5675 (void) setlocale(LC_ALL
, "");
5676 (void) textdomain(TEXT_DOMAIN
);
5681 * Make sure the user has specified some command.
5684 (void) fprintf(stderr
, gettext("missing command\n"));
5693 if ((strcmp(cmdname
, "-?") == 0) ||
5694 strcmp(cmdname
, "--help") == 0)
5697 if ((g_zfs
= libzfs_init()) == NULL
)
5700 libzfs_print_on_error(g_zfs
, B_TRUE
);
5702 zfs_save_arguments(argc
, argv
, history_str
, sizeof (history_str
));
5705 * Run the appropriate command.
5707 if (find_command_idx(cmdname
, &i
) == 0) {
5708 current_command
= &command_table
[i
];
5709 ret
= command_table
[i
].func(argc
- 1, argv
+ 1);
5710 } else if (strchr(cmdname
, '=')) {
5711 verify(find_command_idx("set", &i
) == 0);
5712 current_command
= &command_table
[i
];
5713 ret
= command_table
[i
].func(argc
, argv
);
5714 } else if (strcmp(cmdname
, "freeze") == 0 && argc
== 3) {
5716 * 'freeze' is a vile debugging abomination, so we treat
5720 int fd
= open(ZFS_DEV
, O_RDWR
);
5721 (void) strcpy((void *)buf
, argv
[2]);
5722 return (!!ioctl(fd
, ZFS_IOC_POOL_FREEZE
, buf
));
5724 (void) fprintf(stderr
, gettext("unrecognized "
5725 "command '%s'\n"), cmdname
);
5730 if (ret
== 0 && log_history
)
5731 (void) zpool_log_history(g_zfs
, history_str
);
5736 * The 'ZFS_ABORT' environment variable causes us to dump core on exit
5737 * for the purposes of running ::findleaks.
5739 if (getenv("ZFS_ABORT") != NULL
) {
5740 (void) printf("dumping core by request\n");