diff options
author | pjd <pjd@FreeBSD.org> | 2007-04-08 16:29:25 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2007-04-08 16:29:25 +0000 |
commit | 2b260dcd5e356a3d85c66dff3715260105c412f7 (patch) | |
tree | 414979d8bf91ece25474dc6b933621fc94bb051b /contrib/opensolaris/cmd | |
parent | 4b06e89211feda93bee19a93c165c0d4b9911622 (diff) | |
download | FreeBSD-src-2b260dcd5e356a3d85c66dff3715260105c412f7.zip FreeBSD-src-2b260dcd5e356a3d85c66dff3715260105c412f7.tar.gz |
MFp4: Synchronize with recent OpenSolaris changes.
Diffstat (limited to 'contrib/opensolaris/cmd')
-rw-r--r-- | contrib/opensolaris/cmd/zpool/zpool_main.c | 43 | ||||
-rw-r--r-- | contrib/opensolaris/cmd/ztest/ztest.c | 46 |
2 files changed, 71 insertions, 18 deletions
diff --git a/contrib/opensolaris/cmd/zpool/zpool_main.c b/contrib/opensolaris/cmd/zpool/zpool_main.c index e8dc64a..5b1d856 100644 --- a/contrib/opensolaris/cmd/zpool/zpool_main.c +++ b/contrib/opensolaris/cmd/zpool/zpool_main.c @@ -1082,6 +1082,10 @@ show_import(nvlist_t *config) "incompatible version.\n")); break; + case ZPOOL_STATUS_HOSTID_MISMATCH: + (void) printf(gettext("status: The pool was last accessed by " + "another system.\n")); + break; default: /* * No other status can be seen when importing pools. @@ -1098,6 +1102,10 @@ show_import(nvlist_t *config) "imported using its name or numeric identifier, " "though\n\tsome features will not be available " "without an explicit 'zpool upgrade'.\n")); + else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH) + (void) printf(gettext("action: The pool can be " + "imported using its name or numeric " + "identifier and\n\tthe '-f' flag.\n")); else (void) printf(gettext("action: The pool can be " "imported using its name or numeric " @@ -1187,10 +1195,37 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts, "is formatted using a newer ZFS version\n"), name); return (1); } else if (state != POOL_STATE_EXPORTED && !force) { - (void) fprintf(stderr, gettext("cannot import '%s': pool " - "may be in use from other system\n"), name); - (void) fprintf(stderr, gettext("use '-f' to import anyway\n")); - return (1); + uint64_t hostid; + + if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, + &hostid) == 0) { + if ((unsigned long)hostid != gethostid()) { + char *hostname; + uint64_t timestamp; + time_t t; + + verify(nvlist_lookup_string(config, + ZPOOL_CONFIG_HOSTNAME, &hostname) == 0); + verify(nvlist_lookup_uint64(config, + ZPOOL_CONFIG_TIMESTAMP, ×tamp) == 0); + t = timestamp; + (void) fprintf(stderr, gettext("cannot import " + "'%s': pool may be in use from other " + "system, it was last accessed by %s " + "(hostid: 0x%lx) on %s"), name, hostname, + (unsigned long)hostid, + asctime(localtime(&t))); + (void) fprintf(stderr, gettext("use '-f' to " + "import anyway\n")); + return (1); + } + } else { + (void) fprintf(stderr, gettext("cannot import '%s': " + "pool may be in use from other system\n"), name); + (void) fprintf(stderr, gettext("use '-f' to import " + "anyway\n")); + return (1); + } } if (zpool_import(g_zfs, config, newname, altroot) != 0) diff --git a/contrib/opensolaris/cmd/ztest/ztest.c b/contrib/opensolaris/cmd/ztest/ztest.c index 45f5f8c..53b754b 100644 --- a/contrib/opensolaris/cmd/ztest/ztest.c +++ b/contrib/opensolaris/cmd/ztest/ztest.c @@ -246,6 +246,8 @@ extern uint16_t zio_zil_fail_shift; #define ZTEST_DIROBJ_BLOCKSIZE (1 << 10) #define ZTEST_DIRSIZE 256 +static void usage(boolean_t); + /* * These libumem hooks provide a reasonable set of defaults for the allocator's * debugging facilities. @@ -303,13 +305,17 @@ str2shift(const char *buf) if (toupper(buf[0]) == ends[i]) break; } - if (i == strlen(ends)) - fatal(0, "invalid bytes suffix: %s", buf); + if (i == strlen(ends)) { + (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", + buf); + usage(B_FALSE); + } if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0')) { return (10*i); } - fatal(0, "invalid bytes suffix: %s", buf); - return (-1); + (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf); + usage(B_FALSE); + /* NOTREACHED */ } static uint64_t @@ -320,32 +326,40 @@ nicenumtoull(const char *buf) val = strtoull(buf, &end, 0); if (end == buf) { - fatal(0, "bad numeric value: %s", buf); + (void) fprintf(stderr, "ztest: bad numeric value: %s\n", buf); + usage(B_FALSE); } else if (end[0] == '.') { double fval = strtod(buf, &end); fval *= pow(2, str2shift(end)); - if (fval > UINT64_MAX) - fatal(0, "value too large: %s", buf); + if (fval > UINT64_MAX) { + (void) fprintf(stderr, "ztest: value too large: %s\n", + buf); + usage(B_FALSE); + } val = (uint64_t)fval; } else { int shift = str2shift(end); - if (shift >= 64 || (val << shift) >> shift != val) - fatal(0, "value too large: %s", buf); + if (shift >= 64 || (val << shift) >> shift != val) { + (void) fprintf(stderr, "ztest: value too large: %s\n", + buf); + usage(B_FALSE); + } val <<= shift; } return (val); } static void -usage(void) +usage(boolean_t requested) { char nice_vdev_size[10]; char nice_gang_bang[10]; + FILE *fp = requested ? stdout : stderr; nicenum(zopt_vdev_size, nice_vdev_size); nicenum(zio_gang_bang, nice_gang_bang); - (void) printf("Usage: %s\n" + (void) fprintf(fp, "Usage: %s\n" "\t[-v vdevs (default: %llu)]\n" "\t[-s size_of_each_vdev (default: %s)]\n" "\t[-a alignment_shift (default: %d) (use 0 for random)]\n" @@ -364,6 +378,7 @@ usage(void) "\t[-T time] total run time (default: %llu sec)\n" "\t[-P passtime] time per pass (default: %llu sec)\n" "\t[-z zil failure rate (default: fail every 2^%llu allocs)]\n" + "\t[-h] (print help)\n" "", cmdname, (u_longlong_t)zopt_vdevs, /* -v */ @@ -382,7 +397,7 @@ usage(void) (u_longlong_t)zopt_time, /* -T */ (u_longlong_t)zopt_passtime, /* -P */ (u_longlong_t)zio_zil_fail_shift); /* -z */ - exit(1); + exit(requested ? 0 : 1); } static uint64_t @@ -422,7 +437,7 @@ process_options(int argc, char **argv) zio_zil_fail_shift = 5; while ((opt = getopt(argc, argv, - "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:z:")) != EOF) { + "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:z:h")) != EOF) { value = 0; switch (opt) { case 'v': @@ -496,9 +511,12 @@ process_options(int argc, char **argv) case 'z': zio_zil_fail_shift = MIN(value, 16); break; + case 'h': + usage(B_TRUE); + break; case '?': default: - usage(); + usage(B_FALSE); break; } } |