Add --enable-debug-dmu-tx configure option
[zfs.git] / cmd / zpool / zpool_main.c
old mode 100644 (file)
new mode 100755 (executable)
index 074f76e..9e73dda
@@ -241,7 +241,7 @@ get_usage(zpool_help_t idx) {
                    "\tupgrade -v\n"
                    "\tupgrade [-V version] <-a | pool ...>\n"));
        case HELP_EVENTS:
-               return (gettext("\tevents [-vfc]\n"));
+               return (gettext("\tevents [-vHfc]\n"));
        case HELP_GET:
                return (gettext("\tget <\"all\" | property[,...]> "
                    "<pool> ...\n"));
@@ -488,7 +488,7 @@ zpool_do_add(int argc, char **argv)
        }
 
        /* pass off to get_vdev_spec for processing */
-       nvroot = make_root_vdev(zhp, force, !force, B_FALSE, dryrun,
+       nvroot = make_root_vdev(zhp, NULL, force, !force, B_FALSE, dryrun,
            argc, argv);
        if (nvroot == NULL) {
                zpool_close(zhp);
@@ -688,7 +688,7 @@ zpool_do_create(int argc, char **argv)
        }
 
        /* pass off to get_vdev_spec for bulk processing */
-       nvroot = make_root_vdev(NULL, force, !force, B_FALSE, dryrun,
+       nvroot = make_root_vdev(NULL, props, force, !force, B_FALSE, dryrun,
            argc - 1, argv + 1);
        if (nvroot == NULL)
                goto errout;
@@ -1482,7 +1482,7 @@ show_import(nvlist_t *config)
        }
 
        if (msgid != NULL)
-               (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
+               (void) printf(gettext("   see: http://zfsonlinux.org/msg/%s\n"),
                    msgid);
 
        (void) printf(gettext("config:\n\n"));
@@ -1533,7 +1533,9 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
 
                if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
                    &hostid) == 0) {
-                       if ((unsigned long)hostid != gethostid()) {
+                       unsigned long system_hostid = gethostid() & 0xffffffff;
+
+                       if ((unsigned long)hostid != system_hostid) {
                                char *hostname;
                                uint64_t timestamp;
                                time_t t;
@@ -1592,7 +1594,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
  *      -c     Read pool information from a cachefile instead of searching
  *             devices.
  *
- *       -d    Scan in a specific directory, other than /dev/dsk.  More than
+ *       -d    Scan in a specific directory, other than /dev/.  More than
  *             one directory can be specified using multiple '-d' options.
  *
  *       -D     Scan for previously destroyed pools or import all or only
@@ -1773,12 +1775,6 @@ zpool_do_import(int argc, char **argv)
            nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind_policy) != 0)
                goto error;
 
-       if (searchdirs == NULL) {
-               searchdirs = safe_malloc(sizeof (char *));
-               searchdirs[0] = "/dev/dsk";
-               nsearch = 1;
-       }
-
        /* check argument count */
        if (do_all) {
                if (argc != 0) {
@@ -1799,7 +1795,9 @@ zpool_do_import(int argc, char **argv)
                if (argc == 0 && !priv_ineffect(PRIV_SYS_CONFIG)) {
                        (void) fprintf(stderr, gettext("cannot "
                            "discover pools: permission denied\n"));
-                       free(searchdirs);
+                       if (searchdirs != NULL)
+                               free(searchdirs);
+
                        nvlist_free(policy);
                        return (1);
                }
@@ -1867,7 +1865,8 @@ zpool_do_import(int argc, char **argv)
        }
 
        if (err == 1) {
-               free(searchdirs);
+               if (searchdirs != NULL)
+                       free(searchdirs);
                nvlist_free(policy);
                return (1);
        }
@@ -1968,7 +1967,8 @@ error:
        nvlist_free(props);
        nvlist_free(pools);
        nvlist_free(policy);
-       free(searchdirs);
+       if (searchdirs != NULL)
+               free(searchdirs);
 
        return (err ? 1 : 0);
 }
@@ -2358,42 +2358,48 @@ zpool_do_iostat(int argc, char **argv)
                pool_list_update(list);
 
                if ((npools = pool_list_count(list)) == 0)
-                       break;
-
-               /*
-                * Refresh all statistics.  This is done as an explicit step
-                * before calculating the maximum name width, so that any
-                * configuration changes are properly accounted for.
-                */
-               (void) pool_list_iter(list, B_FALSE, refresh_iostat, &cb);
+                       (void) fprintf(stderr, gettext("no pools available\n"));
+               else {
+                       /*
+                        * Refresh all statistics.  This is done as an
+                        * explicit step before calculating the maximum name
+                        * width, so that any * configuration changes are
+                        * properly accounted for.
+                        */
+                       (void) pool_list_iter(list, B_FALSE, refresh_iostat,
+                               &cb);
 
-               /*
-                * Iterate over all pools to determine the maximum width
-                * for the pool / device name column across all pools.
-                */
-               cb.cb_namewidth = 0;
-               (void) pool_list_iter(list, B_FALSE, get_namewidth, &cb);
+                       /*
+                        * Iterate over all pools to determine the maximum width
+                        * for the pool / device name column across all pools.
+                        */
+                       cb.cb_namewidth = 0;
+                       (void) pool_list_iter(list, B_FALSE, get_namewidth,
+                               &cb);
 
-               if (timestamp_fmt != NODATE)
-                       print_timestamp(timestamp_fmt);
+                       if (timestamp_fmt != NODATE)
+                               print_timestamp(timestamp_fmt);
 
-               /*
-                * If it's the first time, or verbose mode, print the header.
-                */
-               if (++cb.cb_iteration == 1 || verbose)
-                       print_iostat_header(&cb);
+                       /*
+                        * If it's the first time, or verbose mode, print the
+                        * header.
+                        */
+                       if (++cb.cb_iteration == 1 || verbose)
+                               print_iostat_header(&cb);
 
-               (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
+                       (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
 
-               /*
-                * If there's more than one pool, and we're not in verbose mode
-                * (which prints a separator for us), then print a separator.
-                */
-               if (npools > 1 && !verbose)
-                       print_iostat_separator(&cb);
+                       /*
+                        * If there's more than one pool, and we're not in
+                        * verbose mode (which prints a separator for us),
+                        * then print a separator.
+                        */
+                       if (npools > 1 && !verbose)
+                               print_iostat_separator(&cb);
 
-               if (verbose)
-                       (void) printf("\n");
+                       if (verbose)
+                               (void) printf("\n");
+               }
 
                /*
                 * Flush the output so that redirection to a file isn't buffered
@@ -2592,10 +2598,12 @@ zpool_do_list(int argc, char **argv)
                ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
                    list_callback, &cb);
 
-               if (argc == 0 && cb.cb_first && !cb.cb_scripted) {
-                       (void) printf(gettext("no pools available\n"));
+               if (argc == 0 && cb.cb_first)
+                       (void) fprintf(stderr, gettext("no pools available\n"));
+               else if (argc && cb.cb_first) {
+                       /* cannot open the given pool */
                        zprop_free_list(cb.cb_proplist);
-                       return (0);
+                       return (1);
                }
 
                if (interval == 0)
@@ -2683,7 +2691,7 @@ zpool_do_attach_or_replace(int argc, char **argv, int replacing)
                return (1);
        }
 
-       nvroot = make_root_vdev(zhp, force, B_FALSE, replacing, B_FALSE,
+       nvroot = make_root_vdev(zhp, NULL, force, B_FALSE, replacing, B_FALSE,
            argc, argv);
        if (nvroot == NULL) {
                zpool_close(zhp);
@@ -3440,7 +3448,7 @@ print_dedup_stats(nvlist_t *config)
  *        pool: tank
  *     status: DEGRADED
  *     reason: One or more devices ...
- *         see: http://www.sun.com/msg/ZFS-xxxx-01
+ *         see: http://zfsonlinux.org/msg/ZFS-xxxx-01
  *     config:
  *             mirror          DEGRADED
  *                c1t0d0       OK
@@ -3648,7 +3656,7 @@ status_callback(zpool_handle_t *zhp, void *data)
        }
 
        if (msgid != NULL)
-               (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
+               (void) printf(gettext("   see: http://zfsonlinux.org/msg/%s\n"),
                    msgid);
 
        if (config != NULL) {
@@ -3785,7 +3793,7 @@ zpool_do_status(int argc, char **argv)
                    status_callback, &cb);
 
                if (argc == 0 && cb.cb_count == 0)
-                       (void) printf(gettext("no pools available\n"));
+                       (void) fprintf(stderr, gettext("no pools available\n"));
                else if (cb.cb_explain && cb.cb_first && cb.cb_allpools)
                        (void) printf(gettext("all pools are healthy\n"));
 
@@ -4211,7 +4219,7 @@ zpool_do_history(int argc, char **argv)
            &cbdata);
 
        if (argc == 0 && cbdata.first == B_TRUE) {
-               (void) printf(gettext("no pools available\n"));
+               (void) fprintf(stderr, gettext("no pools available\n"));
                return (0);
        }
 
@@ -4220,6 +4228,7 @@ zpool_do_history(int argc, char **argv)
 
 typedef struct ev_opts {
        int verbose;
+       int scripted;
        int follow;
        int clear;
 } ev_opts_t;
@@ -4334,7 +4343,7 @@ zpool_do_events_nvprint(nvlist_t *nvl, int depth)
                        printf(gettext("(embedded nvlist)\n"));
                        (void) nvpair_value_nvlist(nvp, &cnv);
                        zpool_do_events_nvprint(cnv, depth + 8);
-                       printf(gettext("%*s(end %s)\n"), depth, "", name);
+                       printf(gettext("%*s(end %s)"), depth, "", name);
                        break;
 
                case DATA_TYPE_NVLIST_ARRAY: {
@@ -4464,7 +4473,8 @@ zpool_do_events_next(ev_opts_t *opts)
         cleanup_fd = open(ZFS_DEV, O_RDWR);
         VERIFY(cleanup_fd >= 0);
 
-       (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
+       if (!opts->scripted)
+               (void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
 
        while (1) {
                ret = zpool_events_next(g_zfs, &nvl, &dropped,
@@ -4515,11 +4525,14 @@ zpool_do_events(int argc, char **argv)
        int c;
 
        /* check options */
-       while ((c = getopt(argc, argv, "vfc")) != -1) {
+       while ((c = getopt(argc, argv, "vHfc")) != -1) {
                switch (c) {
                case 'v':
                        opts.verbose = 1;
                        break;
+               case 'H':
+                       opts.scripted = 1;
+                       break;
                case 'f':
                        opts.follow = 1;
                        break;
@@ -4704,14 +4717,6 @@ main(int argc, char **argv)
        (void) setlocale(LC_ALL, "");
        (void) textdomain(TEXT_DOMAIN);
 
-       if ((g_zfs = libzfs_init()) == NULL) {
-               (void) fprintf(stderr, gettext("internal error: failed to "
-                   "initialize ZFS library\n"));
-               return (1);
-       }
-
-       libzfs_print_on_error(g_zfs, B_TRUE);
-
        opterr = 0;
 
        /*
@@ -4727,9 +4732,15 @@ main(int argc, char **argv)
        /*
         * Special case '-?'
         */
-       if (strcmp(cmdname, "-?") == 0)
+       if ((strcmp(cmdname, "-?") == 0) ||
+            strcmp(cmdname, "--help") == 0)
                usage(B_TRUE);
 
+       if ((g_zfs = libzfs_init()) == NULL)
+               return (1);
+
+       libzfs_print_on_error(g_zfs, B_TRUE);
+
        zpool_set_history_str("zpool", argc, argv, history_str);
        verify(zpool_stage_history(g_zfs, history_str) == 0);