Deleted Added
full compact
zpool_main.c (207672) zpool_main.c (209962)
1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#include <solaris.h>
28#include <assert.h>
29#include <ctype.h>
30#include <dirent.h>
31#include <errno.h>

--- 341 unchanged lines hidden (view full) ---

373 if (poolprop) {
374 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
375 (void) fprintf(stderr, gettext("property '%s' is "
376 "not a valid pool property\n"), propname);
377 return (2);
378 }
379 normnm = zpool_prop_to_name(prop);
380 } else {
24 * Use is subject to license terms.
25 */
26
27#include <solaris.h>
28#include <assert.h>
29#include <ctype.h>
30#include <dirent.h>
31#include <errno.h>

--- 341 unchanged lines hidden (view full) ---

373 if (poolprop) {
374 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
375 (void) fprintf(stderr, gettext("property '%s' is "
376 "not a valid pool property\n"), propname);
377 return (2);
378 }
379 normnm = zpool_prop_to_name(prop);
380 } else {
381 if ((fprop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
382 (void) fprintf(stderr, gettext("property '%s' is "
383 "not a valid file system property\n"), propname);
384 return (2);
381 if ((fprop = zfs_name_to_prop(propname)) != ZPROP_INVAL) {
382 normnm = zfs_prop_to_name(fprop);
383 } else {
384 normnm = propname;
385 }
385 }
386 normnm = zfs_prop_to_name(fprop);
387 }
388
389 if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
390 prop != ZPOOL_PROP_CACHEFILE) {
391 (void) fprintf(stderr, gettext("property '%s' "
392 "specified multiple times\n"), propname);
393 return (2);
394 }

--- 863 unchanged lines hidden (view full) ---

1258
1259/*
1260 * Perform the import for the given configuration. This passes the heavy
1261 * lifting off to zpool_import_props(), and then mounts the datasets contained
1262 * within the pool.
1263 */
1264static int
1265do_import(nvlist_t *config, const char *newname, const char *mntopts,
386 }
387
388 if (nvlist_lookup_string(proplist, normnm, &strval) == 0 &&
389 prop != ZPOOL_PROP_CACHEFILE) {
390 (void) fprintf(stderr, gettext("property '%s' "
391 "specified multiple times\n"), propname);
392 return (2);
393 }

--- 863 unchanged lines hidden (view full) ---

1257
1258/*
1259 * Perform the import for the given configuration. This passes the heavy
1260 * lifting off to zpool_import_props(), and then mounts the datasets contained
1261 * within the pool.
1262 */
1263static int
1264do_import(nvlist_t *config, const char *newname, const char *mntopts,
1266 int force, nvlist_t *props, boolean_t allowfaulted)
1265 int force, nvlist_t *props, boolean_t do_verbatim)
1267{
1268 zpool_handle_t *zhp;
1269 char *name;
1270 uint64_t state;
1271 uint64_t version;
1272 int error = 0;
1273
1274 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,

--- 36 unchanged lines hidden (view full) ---

1311 (void) fprintf(stderr, gettext("cannot import '%s': "
1312 "pool may be in use from other system\n"), name);
1313 (void) fprintf(stderr, gettext("use '-f' to import "
1314 "anyway\n"));
1315 return (1);
1316 }
1317 }
1318
1266{
1267 zpool_handle_t *zhp;
1268 char *name;
1269 uint64_t state;
1270 uint64_t version;
1271 int error = 0;
1272
1273 verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,

--- 36 unchanged lines hidden (view full) ---

1310 (void) fprintf(stderr, gettext("cannot import '%s': "
1311 "pool may be in use from other system\n"), name);
1312 (void) fprintf(stderr, gettext("use '-f' to import "
1313 "anyway\n"));
1314 return (1);
1315 }
1316 }
1317
1319 if (zpool_import_props(g_zfs, config, newname, props,
1320 allowfaulted) != 0)
1318 if (zpool_import_props(g_zfs, config, newname, props, do_verbatim) != 0)
1321 return (1);
1322
1323 if (newname != NULL)
1324 name = (char *)newname;
1325
1319 return (1);
1320
1321 if (newname != NULL)
1322 name = (char *)newname;
1323
1326 verify((zhp = zpool_open_canfail(g_zfs, name)) != NULL);
1324 if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
1325 return (1);
1327
1326
1328 if (zpool_enable_datasets(zhp, mntopts, 0) != 0) {
1327 if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
1328 zpool_enable_datasets(zhp, mntopts, 0) != 0) {
1329 zpool_close(zhp);
1330 return (1);
1331 }
1332
1333 zpool_close(zhp);
1334 return (error);
1335}
1336

--- 17 unchanged lines hidden (view full) ---

1354 * the given root. The pool will remain exported when the machine
1355 * is rebooted.
1356 *
1357 * -f Force import, even if it appears that the pool is active.
1358 *
1359 * -F Import even in the presence of faulted vdevs. This is an
1360 * intentionally undocumented option for testing purposes, and
1361 * treats the pool configuration as complete, leaving any bad
1329 zpool_close(zhp);
1330 return (1);
1331 }
1332
1333 zpool_close(zhp);
1334 return (error);
1335}
1336

--- 17 unchanged lines hidden (view full) ---

1354 * the given root. The pool will remain exported when the machine
1355 * is rebooted.
1356 *
1357 * -f Force import, even if it appears that the pool is active.
1358 *
1359 * -F Import even in the presence of faulted vdevs. This is an
1360 * intentionally undocumented option for testing purposes, and
1361 * treats the pool configuration as complete, leaving any bad
1362 * vdevs in the FAULTED state.
1362 * vdevs in the FAULTED state. In other words, it does verbatim
1363 * import.
1363 *
1364 * -a Import all pools found.
1365 *
1366 * -o Set property=value and/or temporary mount options (without '=').
1367 *
1368 * The import command scans for pools to import, and import pools based on pool
1369 * name and GUID. The pool can also be renamed as part of the import process.
1370 */

--- 12 unchanged lines hidden (view full) ---

1383 nvpair_t *elem;
1384 nvlist_t *config;
1385 uint64_t searchguid = 0;
1386 char *searchname = NULL;
1387 char *propval;
1388 nvlist_t *found_config;
1389 nvlist_t *props = NULL;
1390 boolean_t first;
1364 *
1365 * -a Import all pools found.
1366 *
1367 * -o Set property=value and/or temporary mount options (without '=').
1368 *
1369 * The import command scans for pools to import, and import pools based on pool
1370 * name and GUID. The pool can also be renamed as part of the import process.
1371 */

--- 12 unchanged lines hidden (view full) ---

1384 nvpair_t *elem;
1385 nvlist_t *config;
1386 uint64_t searchguid = 0;
1387 char *searchname = NULL;
1388 char *propval;
1389 nvlist_t *found_config;
1390 nvlist_t *props = NULL;
1391 boolean_t first;
1391 boolean_t allow_faulted = B_FALSE;
1392 boolean_t do_verbatim = B_FALSE;
1392 uint64_t pool_state;
1393 char *cachefile = NULL;
1394
1395 /* check options */
1396 while ((c = getopt(argc, argv, ":ac:d:DfFo:p:R:")) != -1) {
1397 switch (c) {
1398 case 'a':
1399 do_all = B_TRUE;

--- 16 unchanged lines hidden (view full) ---

1416 break;
1417 case 'D':
1418 do_destroyed = B_TRUE;
1419 break;
1420 case 'f':
1421 do_force = B_TRUE;
1422 break;
1423 case 'F':
1393 uint64_t pool_state;
1394 char *cachefile = NULL;
1395
1396 /* check options */
1397 while ((c = getopt(argc, argv, ":ac:d:DfFo:p:R:")) != -1) {
1398 switch (c) {
1399 case 'a':
1400 do_all = B_TRUE;

--- 16 unchanged lines hidden (view full) ---

1417 break;
1418 case 'D':
1419 do_destroyed = B_TRUE;
1420 break;
1421 case 'f':
1422 do_force = B_TRUE;
1423 break;
1424 case 'F':
1424 allow_faulted = B_TRUE;
1425 do_verbatim = B_TRUE;
1425 break;
1426 case 'o':
1427 if ((propval = strchr(optarg, '=')) != NULL) {
1428 *propval = '\0';
1429 propval++;
1430 if (add_prop_list(optarg, propval,
1431 &props, B_TRUE))
1432 goto error;

--- 133 unchanged lines hidden (view full) ---

1566 if (argc == 0) {
1567 if (first)
1568 first = B_FALSE;
1569 else if (!do_all)
1570 (void) printf("\n");
1571
1572 if (do_all)
1573 err |= do_import(config, NULL, mntopts,
1426 break;
1427 case 'o':
1428 if ((propval = strchr(optarg, '=')) != NULL) {
1429 *propval = '\0';
1430 propval++;
1431 if (add_prop_list(optarg, propval,
1432 &props, B_TRUE))
1433 goto error;

--- 133 unchanged lines hidden (view full) ---

1567 if (argc == 0) {
1568 if (first)
1569 first = B_FALSE;
1570 else if (!do_all)
1571 (void) printf("\n");
1572
1573 if (do_all)
1574 err |= do_import(config, NULL, mntopts,
1574 do_force, props, allow_faulted);
1575 do_force, props, do_verbatim);
1575 else
1576 show_import(config);
1577 } else if (searchname != NULL) {
1578 char *name;
1579
1580 /*
1581 * We are searching for a pool based on name.
1582 */

--- 31 unchanged lines hidden (view full) ---

1614 */
1615 if (argc != 0 && err == 0) {
1616 if (found_config == NULL) {
1617 (void) fprintf(stderr, gettext("cannot import '%s': "
1618 "no such pool available\n"), argv[0]);
1619 err = B_TRUE;
1620 } else {
1621 err |= do_import(found_config, argc == 1 ? NULL :
1576 else
1577 show_import(config);
1578 } else if (searchname != NULL) {
1579 char *name;
1580
1581 /*
1582 * We are searching for a pool based on name.
1583 */

--- 31 unchanged lines hidden (view full) ---

1615 */
1616 if (argc != 0 && err == 0) {
1617 if (found_config == NULL) {
1618 (void) fprintf(stderr, gettext("cannot import '%s': "
1619 "no such pool available\n"), argv[0]);
1620 err = B_TRUE;
1621 } else {
1622 err |= do_import(found_config, argc == 1 ? NULL :
1622 argv[1], mntopts, do_force, props, allow_faulted);
1623 argv[1], mntopts, do_force, props, do_verbatim);
1623 }
1624 }
1625
1626 /*
1627 * If we were just looking for pools, report an error if none were
1628 * found.
1629 */
1630 if (argc == 0 && first)

--- 1130 unchanged lines hidden (view full) ---

2761 return (0);
2762}
2763
2764/*
2765 * Print out configuration state as requested by status_callback.
2766 */
2767void
2768print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
1624 }
1625 }
1626
1627 /*
1628 * If we were just looking for pools, report an error if none were
1629 * found.
1630 */
1631 if (argc == 0 && first)

--- 1130 unchanged lines hidden (view full) ---

2762 return (0);
2763}
2764
2765/*
2766 * Print out configuration state as requested by status_callback.
2767 */
2768void
2769print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
2769 int namewidth, int depth, boolean_t isspare, boolean_t print_logs)
2770 int namewidth, int depth, boolean_t isspare)
2770{
2771 nvlist_t **child;
2772 uint_t c, children;
2773 vdev_stat_t *vs;
2774 char rbuf[6], wbuf[6], cbuf[6], repaired[7];
2775 char *vname;
2776 uint64_t notpresent;
2777 spare_cbdata_t cb;

--- 97 unchanged lines hidden (view full) ---

2875 "resilvered" : "repaired");
2876 }
2877
2878 (void) printf("\n");
2879
2880 for (c = 0; c < children; c++) {
2881 uint64_t is_log = B_FALSE;
2882
2771{
2772 nvlist_t **child;
2773 uint_t c, children;
2774 vdev_stat_t *vs;
2775 char rbuf[6], wbuf[6], cbuf[6], repaired[7];
2776 char *vname;
2777 uint64_t notpresent;
2778 spare_cbdata_t cb;

--- 97 unchanged lines hidden (view full) ---

2876 "resilvered" : "repaired");
2877 }
2878
2879 (void) printf("\n");
2880
2881 for (c = 0; c < children; c++) {
2882 uint64_t is_log = B_FALSE;
2883
2884 /* Don't print logs here */
2883 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2884 &is_log);
2885 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2886 &is_log);
2885 if ((is_log && !print_logs) || (!is_log && print_logs))
2887 if (is_log)
2886 continue;
2887 vname = zpool_vdev_name(g_zfs, zhp, child[c]);
2888 print_status_config(zhp, vname, child[c],
2888 continue;
2889 vname = zpool_vdev_name(g_zfs, zhp, child[c]);
2890 print_status_config(zhp, vname, child[c],
2889 namewidth, depth + 2, isspare, B_FALSE);
2891 namewidth, depth + 2, isspare);
2890 free(vname);
2891 }
2892}
2893
2894static void
2895print_error_log(zpool_handle_t *zhp)
2896{
2897 nvlist_t *nverrlist = NULL;

--- 38 unchanged lines hidden (view full) ---

2936 if (nspares == 0)
2937 return;
2938
2939 (void) printf(gettext("\tspares\n"));
2940
2941 for (i = 0; i < nspares; i++) {
2942 name = zpool_vdev_name(g_zfs, zhp, spares[i]);
2943 print_status_config(zhp, name, spares[i],
2892 free(vname);
2893 }
2894}
2895
2896static void
2897print_error_log(zpool_handle_t *zhp)
2898{
2899 nvlist_t *nverrlist = NULL;

--- 38 unchanged lines hidden (view full) ---

2938 if (nspares == 0)
2939 return;
2940
2941 (void) printf(gettext("\tspares\n"));
2942
2943 for (i = 0; i < nspares; i++) {
2944 name = zpool_vdev_name(g_zfs, zhp, spares[i]);
2945 print_status_config(zhp, name, spares[i],
2944 namewidth, 2, B_TRUE, B_FALSE);
2946 namewidth, 2, B_TRUE);
2945 free(name);
2946 }
2947}
2948
2949static void
2950print_l2cache(zpool_handle_t *zhp, nvlist_t **l2cache, uint_t nl2cache,
2951 int namewidth)
2952{
2953 uint_t i;
2954 char *name;
2955
2956 if (nl2cache == 0)
2957 return;
2958
2959 (void) printf(gettext("\tcache\n"));
2960
2961 for (i = 0; i < nl2cache; i++) {
2962 name = zpool_vdev_name(g_zfs, zhp, l2cache[i]);
2963 print_status_config(zhp, name, l2cache[i],
2947 free(name);
2948 }
2949}
2950
2951static void
2952print_l2cache(zpool_handle_t *zhp, nvlist_t **l2cache, uint_t nl2cache,
2953 int namewidth)
2954{
2955 uint_t i;
2956 char *name;
2957
2958 if (nl2cache == 0)
2959 return;
2960
2961 (void) printf(gettext("\tcache\n"));
2962
2963 for (i = 0; i < nl2cache; i++) {
2964 name = zpool_vdev_name(g_zfs, zhp, l2cache[i]);
2965 print_status_config(zhp, name, l2cache[i],
2964 namewidth, 2, B_FALSE, B_FALSE);
2966 namewidth, 2, B_FALSE);
2965 free(name);
2966 }
2967}
2968
2969/*
2967 free(name);
2968 }
2969}
2970
2971/*
2972 * Print log vdevs.
2973 * Logs are recorded as top level vdevs in the main pool child array but with
2974 * "is_log" set to 1. We use print_status_config() to print the top level logs
2975 * then any log children (eg mirrored slogs) are printed recursively - which
2976 * works because only the top level vdev is marked "is_log"
2977 */
2978static void
2979print_logs(zpool_handle_t *zhp, nvlist_t *nv, int namewidth)
2980{
2981 uint_t c, children;
2982 nvlist_t **child;
2983
2984 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child,
2985 &children) != 0)
2986 return;
2987
2988 (void) printf(gettext("\tlogs\n"));
2989
2990 for (c = 0; c < children; c++) {
2991 uint64_t is_log = B_FALSE;
2992 char *name;
2993
2994 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
2995 &is_log);
2996 if (!is_log)
2997 continue;
2998 name = zpool_vdev_name(g_zfs, zhp, child[c]);
2999 print_status_config(zhp, name, child[c], namewidth, 2, B_FALSE);
3000 free(name);
3001 }
3002}
3003
3004/*
2970 * Display a summary of pool status. Displays a summary such as:
2971 *
2972 * pool: tank
2973 * status: DEGRADED
2974 * reason: One or more devices ...
2975 * see: http://www.sun.com/msg/ZFS-xxxx-01
2976 * config:
2977 * mirror DEGRADED

--- 208 unchanged lines hidden (view full) ---

3186 namewidth = max_width(zhp, nvroot, 0, 0);
3187 if (namewidth < 10)
3188 namewidth = 10;
3189
3190 (void) printf(gettext("config:\n\n"));
3191 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth,
3192 "NAME", "STATE", "READ", "WRITE", "CKSUM");
3193 print_status_config(zhp, zpool_get_name(zhp), nvroot,
3005 * Display a summary of pool status. Displays a summary such as:
3006 *
3007 * pool: tank
3008 * status: DEGRADED
3009 * reason: One or more devices ...
3010 * see: http://www.sun.com/msg/ZFS-xxxx-01
3011 * config:
3012 * mirror DEGRADED

--- 208 unchanged lines hidden (view full) ---

3221 namewidth = max_width(zhp, nvroot, 0, 0);
3222 if (namewidth < 10)
3223 namewidth = 10;
3224
3225 (void) printf(gettext("config:\n\n"));
3226 (void) printf(gettext("\t%-*s %-8s %5s %5s %5s\n"), namewidth,
3227 "NAME", "STATE", "READ", "WRITE", "CKSUM");
3228 print_status_config(zhp, zpool_get_name(zhp), nvroot,
3194 namewidth, 0, B_FALSE, B_FALSE);
3195 if (num_logs(nvroot) > 0)
3196 print_status_config(zhp, "logs", nvroot, namewidth, 0,
3197 B_FALSE, B_TRUE);
3229 namewidth, 0, B_FALSE);
3198
3230
3231 if (num_logs(nvroot) > 0)
3232 print_logs(zhp, nvroot, namewidth);
3199 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
3200 &l2cache, &nl2cache) == 0)
3201 print_l2cache(zhp, l2cache, nl2cache, namewidth);
3202
3203 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
3204 &spares, &nspares) == 0)
3205 print_spares(zhp, spares, nspares, namewidth);
3206

--- 284 unchanged lines hidden (view full) ---

3491 (void) printf(gettext(" 7 Separate intent log devices\n"));
3492 (void) printf(gettext(" 8 Delegated administration\n"));
3493 (void) printf(gettext(" 9 refquota and refreservation "
3494 "properties\n"));
3495 (void) printf(gettext(" 10 Cache devices\n"));
3496 (void) printf(gettext(" 11 Improved scrub performance\n"));
3497 (void) printf(gettext(" 12 Snapshot properties\n"));
3498 (void) printf(gettext(" 13 snapused property\n"));
3233 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE,
3234 &l2cache, &nl2cache) == 0)
3235 print_l2cache(zhp, l2cache, nl2cache, namewidth);
3236
3237 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
3238 &spares, &nspares) == 0)
3239 print_spares(zhp, spares, nspares, namewidth);
3240

--- 284 unchanged lines hidden (view full) ---

3525 (void) printf(gettext(" 7 Separate intent log devices\n"));
3526 (void) printf(gettext(" 8 Delegated administration\n"));
3527 (void) printf(gettext(" 9 refquota and refreservation "
3528 "properties\n"));
3529 (void) printf(gettext(" 10 Cache devices\n"));
3530 (void) printf(gettext(" 11 Improved scrub performance\n"));
3531 (void) printf(gettext(" 12 Snapshot properties\n"));
3532 (void) printf(gettext(" 13 snapused property\n"));
3499 (void) printf(gettext(" 14 passthrough-x aclinherit "
3500 "support\n"));
3533 (void) printf(gettext(" 14 passthrough-x aclinherit\n"));
3534 (void) printf(gettext(" 15 user/group space accounting\n"));
3501 (void) printf(gettext("For more information on a particular "
3502 "version, including supported releases, see:\n\n"));
3503 (void) printf("http://www.opensolaris.org/os/community/zfs/"
3504 "version/N\n\n");
3505 (void) printf(gettext("Where 'N' is the version number.\n"));
3506 } else if (argc == 0) {
3507 int notfound;
3508

--- 452 unchanged lines hidden ---
3535 (void) printf(gettext("For more information on a particular "
3536 "version, including supported releases, see:\n\n"));
3537 (void) printf("http://www.opensolaris.org/os/community/zfs/"
3538 "version/N\n\n");
3539 (void) printf(gettext("Where 'N' is the version number.\n"));
3540 } else if (argc == 0) {
3541 int notfound;
3542

--- 452 unchanged lines hidden ---