Deleted Added
sdiff udiff text old ( 212067 ) new ( 213197 )
full compact
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

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

975 max)) > max)
976 max = ret;
977 }
978
979
980 return (max);
981}
982
983typedef struct spare_cbdata {
984 uint64_t cb_guid;
985 zpool_handle_t *cb_zhp;
986} spare_cbdata_t;
987
988static boolean_t
989find_vdev(nvlist_t *nv, uint64_t search)
990{
991 uint64_t guid;
992 nvlist_t **child;
993 uint_t c, children;
994
995 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) == 0 &&
996 search == guid)
997 return (B_TRUE);
998
999 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1000 &child, &children) == 0) {
1001 for (c = 0; c < children; c++)
1002 if (find_vdev(child[c], search))
1003 return (B_TRUE);
1004 }
1005
1006 return (B_FALSE);
1007}
1008
1009static int
1010find_spare(zpool_handle_t *zhp, void *data)
1011{
1012 spare_cbdata_t *cbp = data;
1013 nvlist_t *config, *nvroot;
1014
1015 config = zpool_get_config(zhp, NULL);
1016 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1017 &nvroot) == 0);
1018
1019 if (find_vdev(nvroot, cbp->cb_guid)) {
1020 cbp->cb_zhp = zhp;
1021 return (1);
1022 }
1023
1024 zpool_close(zhp);
1025 return (0);
1026}
1027
1028/*
1029 * Print out configuration state as requested by status_callback.
1030 */
1031void
1032print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
1033 int namewidth, int depth, boolean_t isspare)
1034{
1035 nvlist_t **child;
1036 uint_t c, children;
1037 vdev_stat_t *vs;
1038 char rbuf[6], wbuf[6], cbuf[6], repaired[7];
1039 char *vname;
1040 uint64_t notpresent;
1041 spare_cbdata_t cb;
1042 char *state;
1043
1044 verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_STATS,
1045 (uint64_t **)&vs, &c) == 0);
1046
1047 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
1048 &child, &children) != 0)
1049 children = 0;
1050
1051 state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1052 if (isspare) {
1053 /*
1054 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
1055 * online drives.
1056 */
1057 if (vs->vs_aux == VDEV_AUX_SPARED)
1058 state = "INUSE";
1059 else if (vs->vs_state == VDEV_STATE_HEALTHY)
1060 state = "AVAIL";
1061 }
1062
1063 (void) printf("\t%*s%-*s %-8s", depth, "", namewidth - depth,
1064 name, state);
1065
1066 if (!isspare) {
1067 zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
1068 zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
1069 zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
1070 (void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
1071 }
1072
1073 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
1074 &notpresent) == 0) {
1075 char *path;
1076 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0);
1077 (void) printf(" was %s", path);
1078 } else if (vs->vs_aux != 0) {
1079 (void) printf(" ");
1080
1081 switch (vs->vs_aux) {
1082 case VDEV_AUX_OPEN_FAILED:
1083 (void) printf(gettext("cannot open"));
1084 break;
1085
1086 case VDEV_AUX_BAD_GUID_SUM:
1087 (void) printf(gettext("missing device"));
1088 break;
1089
1090 case VDEV_AUX_NO_REPLICAS:
1091 (void) printf(gettext("insufficient replicas"));
1092 break;
1093
1094 case VDEV_AUX_VERSION_NEWER:
1095 (void) printf(gettext("newer version"));
1096 break;
1097
1098 case VDEV_AUX_SPARED:
1099 verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
1100 &cb.cb_guid) == 0);
1101 if (zpool_iter(g_zfs, find_spare, &cb) == 1) {
1102 if (strcmp(zpool_get_name(cb.cb_zhp),
1103 zpool_get_name(zhp)) == 0)
1104 (void) printf(gettext("currently in "
1105 "use"));
1106 else
1107 (void) printf(gettext("in use by "
1108 "pool '%s'"),
1109 zpool_get_name(cb.cb_zhp));
1110 zpool_close(cb.cb_zhp);
1111 } else {
1112 (void) printf(gettext("currently in use"));
1113 }
1114 break;
1115
1116 case VDEV_AUX_ERR_EXCEEDED:
1117 (void) printf(gettext("too many errors"));
1118 break;
1119
1120 case VDEV_AUX_IO_FAILURE:
1121 (void) printf(gettext("experienced I/O failures"));
1122 break;
1123
1124 case VDEV_AUX_BAD_LOG:
1125 (void) printf(gettext("bad intent log"));
1126 break;
1127
1128 default:
1129 (void) printf(gettext("corrupted data"));
1130 break;
1131 }
1132 } else if (vs->vs_scrub_repaired != 0 && children == 0) {
1133 /*
1134 * Report bytes resilvered/repaired on leaf devices.
1135 */
1136 zfs_nicenum(vs->vs_scrub_repaired, repaired, sizeof (repaired));
1137 (void) printf(gettext(" %s %s"), repaired,
1138 (vs->vs_scrub_type == POOL_SCRUB_RESILVER) ?
1139 "resilvered" : "repaired");
1140 }
1141
1142 (void) printf("\n");
1143
1144 for (c = 0; c < children; c++) {
1145 uint64_t is_log = B_FALSE;
1146
1147 /* Don't print logs here */
1148 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1149 &is_log);
1150 if (is_log)
1151 continue;
1152 vname = zpool_vdev_name(g_zfs, zhp, child[c]);
1153 print_status_config(zhp, vname, child[c],
1154 namewidth, depth + 2, isspare);
1155 free(vname);
1156 }
1157}
1158
1159
1160/*
1161 * Print the configuration of an exported pool. Iterate over all vdevs in the
1162 * pool, printing out the name and status for each one.
1163 */
1164void
1165print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
1166{
1167 nvlist_t **child;
1168 uint_t c, children;
1169 vdev_stat_t *vs;
1170 char *type, *vname;
1171
1172 verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
1173 if (strcmp(type, VDEV_TYPE_MISSING) == 0)

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

1214 &child, &children) != 0)
1215 return;
1216
1217 for (c = 0; c < children; c++) {
1218 uint64_t is_log = B_FALSE;
1219
1220 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1221 &is_log);
1222 if (is_log)
1223 continue;
1224
1225 vname = zpool_vdev_name(g_zfs, NULL, child[c]);
1226 print_import_config(vname, child[c], namewidth, depth + 2);
1227 free(vname);
1228 }
1229
1230 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
1231 &child, &children) == 0) {
1232 (void) printf(gettext("\tcache\n"));
1233 for (c = 0; c < children; c++) {
1234 vname = zpool_vdev_name(g_zfs, NULL, child[c]);

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

1244 vname = zpool_vdev_name(g_zfs, NULL, child[c]);
1245 (void) printf("\t %s\n", vname);
1246 free(vname);
1247 }
1248 }
1249}
1250
1251/*
1252 * Print log vdevs.
1253 * Logs are recorded as top level vdevs in the main pool child array
1254 * but with "is_log" set to 1. We use either print_status_config() or
1255 * print_import_config() to print the top level logs then any log
1256 * children (eg mirrored slogs) are printed recursively - which
1257 * works because only the top level vdev is marked "is_log"
1258 */
1259static void
1260print_logs(zpool_handle_t *zhp, nvlist_t *nv, int namewidth, boolean_t verbose)
1261{
1262 uint_t c, children;
1263 nvlist_t **child;
1264
1265 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child,
1266 &children) != 0)
1267 return;
1268
1269 (void) printf(gettext("\tlogs\n"));
1270
1271 for (c = 0; c < children; c++) {
1272 uint64_t is_log = B_FALSE;
1273 char *name;
1274
1275 (void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
1276 &is_log);
1277 if (!is_log)
1278 continue;
1279 name = zpool_vdev_name(g_zfs, zhp, child[c]);
1280 if (verbose)
1281 print_status_config(zhp, name, child[c], namewidth,
1282 2, B_FALSE);
1283 else
1284 print_import_config(name, child[c], namewidth, 2);
1285 free(name);
1286 }
1287}
1288/*
1289 * Display the status for the given pool.
1290 */
1291static void
1292show_import(nvlist_t *config)
1293{
1294 uint64_t pool_state;
1295 vdev_stat_t *vs;
1296 char *name;

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

1448 msgid);
1449
1450 (void) printf(gettext("config:\n\n"));
1451
1452 namewidth = max_width(NULL, nvroot, 0, 0);
1453 if (namewidth < 10)
1454 namewidth = 10;
1455
1456 print_import_config(name, nvroot, namewidth, 0);
1457 if (num_logs(nvroot) > 0)
1458 print_logs(NULL, nvroot, namewidth, B_FALSE);
1459
1460 if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
1461 (void) printf(gettext("\n\tAdditional devices are known to "
1462 "be part of this pool, though their\n\texact "
1463 "configuration cannot be determined.\n"));
1464 }
1465}
1466

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

2921
2922 (void) printf(gettext("%s in progress for %lluh%um, %.2f%% done, "
2923 "%lluh%um to go\n"),
2924 scrub_type, (u_longlong_t)(minutes_taken / 60),
2925 (uint_t)(minutes_taken % 60), 100 * fraction_done,
2926 (u_longlong_t)(minutes_left / 60), (uint_t)(minutes_left % 60));
2927}
2928
2929static void
2930print_error_log(zpool_handle_t *zhp)
2931{
2932 nvlist_t *nverrlist = NULL;
2933 nvpair_t *elem;
2934 char *pathname;
2935 size_t len = MAXPATHLEN * 2;
2936

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

2997 name = zpool_vdev_name(g_zfs, zhp, l2cache[i]);
2998 print_status_config(zhp, name, l2cache[i],
2999 namewidth, 2, B_FALSE);
3000 free(name);
3001 }
3002}
3003
3004/*
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

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

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,
3229 namewidth, 0, B_FALSE);
3230
3231 if (num_logs(nvroot) > 0)
3232 print_logs(zhp, nvroot, namewidth, B_TRUE);
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

--- 800 unchanged lines hidden ---