1317                 free(name);
1318         }
1319 }
1320 
1321 /*
1322  * Display the status for the given pool.
1323  */
1324 static void
1325 show_import(nvlist_t *config)
1326 {
1327         uint64_t pool_state;
1328         vdev_stat_t *vs;
1329         char *name;
1330         uint64_t guid;
1331         char *msgid;
1332         nvlist_t *nvroot;
1333         int reason;
1334         const char *health;
1335         uint_t vsc;
1336         int namewidth;
1337 
1338         verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
1339             &name) == 0);
1340         verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
1341             &guid) == 0);
1342         verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
1343             &pool_state) == 0);
1344         verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1345             &nvroot) == 0);
1346 
1347         verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
1348             (uint64_t **)&vs, &vsc) == 0);
1349         health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1350 
1351         reason = zpool_import_status(config, &msgid);
1352 
1353         (void) printf(gettext("  pool: %s\n"), name);
1354         (void) printf(gettext("    id: %llu\n"), (u_longlong_t)guid);
1355         (void) printf(gettext(" state: %s"), health);
1356         if (pool_state == POOL_STATE_DESTROYED)
1357                 (void) printf(gettext(" (DESTROYED)"));
1358         (void) printf("\n");
1359 
1360         switch (reason) {
1361         case ZPOOL_STATUS_MISSING_DEV_R:
1362         case ZPOOL_STATUS_MISSING_DEV_NR:
1363         case ZPOOL_STATUS_BAD_GUID_SUM:
1364                 (void) printf(gettext("status: One or more devices are missing "
1365                     "from the system.\n"));
1366                 break;
1367 
1368         case ZPOOL_STATUS_CORRUPT_LABEL_R:
1369         case ZPOOL_STATUS_CORRUPT_LABEL_NR:
1370                 (void) printf(gettext("status: One or more devices contains "
1371                     "corrupted data.\n"));
1372                 break;
1373 
1374         case ZPOOL_STATUS_CORRUPT_DATA:
1375                 (void) printf(gettext("status: The pool data is corrupted.\n"));
1376                 break;
1377 
1378         case ZPOOL_STATUS_OFFLINE_DEV:
1379                 (void) printf(gettext("status: One or more devices "
1380                     "are offlined.\n"));
1381                 break;
1382 
1383         case ZPOOL_STATUS_CORRUPT_POOL:
1384                 (void) printf(gettext("status: The pool metadata is "
1385                     "corrupted.\n"));
1386                 break;
1387 
1388         case ZPOOL_STATUS_VERSION_OLDER:
1389                 (void) printf(gettext("status: The pool is formatted using an "
1390                     "older on-disk version.\n"));
1391                 break;
1392 
1393         case ZPOOL_STATUS_VERSION_NEWER:
1394                 (void) printf(gettext("status: The pool is formatted using an "
1395                     "incompatible version.\n"));
1396                 break;
1397 
1398         case ZPOOL_STATUS_HOSTID_MISMATCH:
1399                 (void) printf(gettext("status: The pool was last accessed by "
1400                     "another system.\n"));
1401                 break;
1402 
1403         case ZPOOL_STATUS_FAULTED_DEV_R:
1404         case ZPOOL_STATUS_FAULTED_DEV_NR:
1405                 (void) printf(gettext("status: One or more devices are "
1406                     "faulted.\n"));
1407                 break;
1408 
1409         case ZPOOL_STATUS_BAD_LOG:
1410                 (void) printf(gettext("status: An intent log record cannot be "
1411                     "read.\n"));
1412                 break;
1413 
1414         case ZPOOL_STATUS_RESILVERING:
1415                 (void) printf(gettext("status: One or more devices were being "
1416                     "resilvered.\n"));
1417                 break;
1418 
1419         default:
1420                 /*
1421                  * No other status can be seen when importing pools.
1422                  */
1423                 assert(reason == ZPOOL_STATUS_OK);
1424         }
1425 
1426         /*
1427          * Print out an action according to the overall state of the pool.
1428          */
1429         if (vs->vs_state == VDEV_STATE_HEALTHY) {
1430                 if (reason == ZPOOL_STATUS_VERSION_OLDER)
1431                         (void) printf(gettext("action: The pool can be "
1432                             "imported using its name or numeric identifier, "
1433                             "though\n\tsome features will not be available "
1434                             "without an explicit 'zpool upgrade'.\n"));
1435                 else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH)
1436                         (void) printf(gettext("action: The pool can be "
1437                             "imported using its name or numeric "
1438                             "identifier and\n\tthe '-f' flag.\n"));
1439                 else
1440                         (void) printf(gettext("action: The pool can be "
1441                             "imported using its name or numeric "
1442                             "identifier.\n"));
1443         } else if (vs->vs_state == VDEV_STATE_DEGRADED) {
1444                 (void) printf(gettext("action: The pool can be imported "
1445                     "despite missing or damaged devices.  The\n\tfault "
1446                     "tolerance of the pool may be compromised if imported.\n"));
1447         } else {
1448                 switch (reason) {
1449                 case ZPOOL_STATUS_VERSION_NEWER:
1450                         (void) printf(gettext("action: The pool cannot be "
1451                             "imported.  Access the pool on a system running "
1452                             "newer\n\tsoftware, or recreate the pool from "
1453                             "backup.\n"));
1454                         break;
1455                 case ZPOOL_STATUS_MISSING_DEV_R:
1456                 case ZPOOL_STATUS_MISSING_DEV_NR:
1457                 case ZPOOL_STATUS_BAD_GUID_SUM:
1458                         (void) printf(gettext("action: The pool cannot be "
1459                             "imported. Attach the missing\n\tdevices and try "
1460                             "again.\n"));
1461                         break;
1462                 default:
1463                         (void) printf(gettext("action: The pool cannot be "
1464                             "imported due to damaged devices or data.\n"));
1465                 }
1466         }
1467 
1468         /*
1469          * If the state is "closed" or "can't open", and the aux state
1470          * is "corrupt data":
1471          */
1472         if (((vs->vs_state == VDEV_STATE_CLOSED) ||
1473             (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
1474             (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
1475                 if (pool_state == POOL_STATE_DESTROYED)
1476                         (void) printf(gettext("\tThe pool was destroyed, "
1477                             "but can be imported using the '-Df' flags.\n"));
1478                 else if (pool_state != POOL_STATE_EXPORTED)
1479                         (void) printf(gettext("\tThe pool may be active on "
1480                             "another system, but can be imported using\n\t"
1481                             "the '-f' flag.\n"));
1482         }
1483 
1484         if (msgid != NULL)
1485                 (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
1486                     msgid);
1487 
1488         (void) printf(gettext("config:\n\n"));
1489 
1490         namewidth = max_width(NULL, nvroot, 0, 0);
1491         if (namewidth < 10)
1492                 namewidth = 10;
1493 
1494         print_import_config(name, nvroot, namewidth, 0);
1495         if (num_logs(nvroot) > 0)
1496                 print_logs(NULL, nvroot, namewidth, B_FALSE);
1497 
1498         if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
1499                 (void) printf(gettext("\n\tAdditional devices are known to "
1500                     "be part of this pool, though their\n\texact "
1501                     "configuration cannot be determined.\n"));
1502         }
1503 }
1504 
1505 /*
1506  * Perform the import for the given configuration.  This passes the heavy
1507  * lifting off to zpool_import_props(), and then mounts the datasets contained
1508  * within the pool.
 
 | 
 
 
1317                 free(name);
1318         }
1319 }
1320 
1321 /*
1322  * Display the status for the given pool.
1323  */
1324 static void
1325 show_import(nvlist_t *config)
1326 {
1327         uint64_t pool_state;
1328         vdev_stat_t *vs;
1329         char *name;
1330         uint64_t guid;
1331         char *msgid;
1332         nvlist_t *nvroot;
1333         int reason;
1334         const char *health;
1335         uint_t vsc;
1336         int namewidth;
1337         char *comment;
1338 
1339         verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
1340             &name) == 0);
1341         verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
1342             &guid) == 0);
1343         verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
1344             &pool_state) == 0);
1345         verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
1346             &nvroot) == 0);
1347 
1348         verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
1349             (uint64_t **)&vs, &vsc) == 0);
1350         health = zpool_state_to_name(vs->vs_state, vs->vs_aux);
1351 
1352         reason = zpool_import_status(config, &msgid);
1353 
1354         (void) printf(gettext("   pool: %s\n"), name);
1355         (void) printf(gettext("     id: %llu\n"), (u_longlong_t)guid);
1356         (void) printf(gettext("  state: %s"), health);
1357         if (pool_state == POOL_STATE_DESTROYED)
1358                 (void) printf(gettext(" (DESTROYED)"));
1359         (void) printf("\n");
1360 
1361         switch (reason) {
1362         case ZPOOL_STATUS_MISSING_DEV_R:
1363         case ZPOOL_STATUS_MISSING_DEV_NR:
1364         case ZPOOL_STATUS_BAD_GUID_SUM:
1365                 (void) printf(gettext(" status: One or more devices are "
1366                     "missing from the system.\n"));
1367                 break;
1368 
1369         case ZPOOL_STATUS_CORRUPT_LABEL_R:
1370         case ZPOOL_STATUS_CORRUPT_LABEL_NR:
1371                 (void) printf(gettext(" status: One or more devices contains "
1372                     "corrupted data.\n"));
1373                 break;
1374 
1375         case ZPOOL_STATUS_CORRUPT_DATA:
1376                 (void) printf(
1377                     gettext(" status: The pool data is corrupted.\n"));
1378                 break;
1379 
1380         case ZPOOL_STATUS_OFFLINE_DEV:
1381                 (void) printf(gettext(" status: One or more devices "
1382                     "are offlined.\n"));
1383                 break;
1384 
1385         case ZPOOL_STATUS_CORRUPT_POOL:
1386                 (void) printf(gettext(" status: The pool metadata is "
1387                     "corrupted.\n"));
1388                 break;
1389 
1390         case ZPOOL_STATUS_VERSION_OLDER:
1391                 (void) printf(gettext(" status: The pool is formatted using an "
1392                     "older on-disk version.\n"));
1393                 break;
1394 
1395         case ZPOOL_STATUS_VERSION_NEWER:
1396                 (void) printf(gettext(" status: The pool is formatted using an "
1397                     "incompatible version.\n"));
1398                 break;
1399 
1400         case ZPOOL_STATUS_HOSTID_MISMATCH:
1401                 (void) printf(gettext(" status: The pool was last accessed by "
1402                     "another system.\n"));
1403                 break;
1404 
1405         case ZPOOL_STATUS_FAULTED_DEV_R:
1406         case ZPOOL_STATUS_FAULTED_DEV_NR:
1407                 (void) printf(gettext(" status: One or more devices are "
1408                     "faulted.\n"));
1409                 break;
1410 
1411         case ZPOOL_STATUS_BAD_LOG:
1412                 (void) printf(gettext(" status: An intent log record cannot be "
1413                     "read.\n"));
1414                 break;
1415 
1416         case ZPOOL_STATUS_RESILVERING:
1417                 (void) printf(gettext(" status: One or more devices were being "
1418                     "resilvered.\n"));
1419                 break;
1420 
1421         default:
1422                 /*
1423                  * No other status can be seen when importing pools.
1424                  */
1425                 assert(reason == ZPOOL_STATUS_OK);
1426         }
1427 
1428         /*
1429          * Print out an action according to the overall state of the pool.
1430          */
1431         if (vs->vs_state == VDEV_STATE_HEALTHY) {
1432                 if (reason == ZPOOL_STATUS_VERSION_OLDER)
1433                         (void) printf(gettext(" action: The pool can be "
1434                             "imported using its name or numeric identifier, "
1435                             "though\n\tsome features will not be available "
1436                             "without an explicit 'zpool upgrade'.\n"));
1437                 else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH)
1438                         (void) printf(gettext(" action: The pool can be "
1439                             "imported using its name or numeric "
1440                             "identifier and\n\tthe '-f' flag.\n"));
1441                 else
1442                         (void) printf(gettext(" action: The pool can be "
1443                             "imported using its name or numeric "
1444                             "identifier.\n"));
1445         } else if (vs->vs_state == VDEV_STATE_DEGRADED) {
1446                 (void) printf(gettext(" action: The pool can be imported "
1447                     "despite missing or damaged devices.  The\n\tfault "
1448                     "tolerance of the pool may be compromised if imported.\n"));
1449         } else {
1450                 switch (reason) {
1451                 case ZPOOL_STATUS_VERSION_NEWER:
1452                         (void) printf(gettext(" action: The pool cannot be "
1453                             "imported.  Access the pool on a system running "
1454                             "newer\n\tsoftware, or recreate the pool from "
1455                             "backup.\n"));
1456                         break;
1457                 case ZPOOL_STATUS_MISSING_DEV_R:
1458                 case ZPOOL_STATUS_MISSING_DEV_NR:
1459                 case ZPOOL_STATUS_BAD_GUID_SUM:
1460                         (void) printf(gettext(" action: The pool cannot be "
1461                             "imported. Attach the missing\n\tdevices and try "
1462                             "again.\n"));
1463                         break;
1464                 default:
1465                         (void) printf(gettext(" action: The pool cannot be "
1466                             "imported due to damaged devices or data.\n"));
1467                 }
1468         }
1469 
1470         /* Print the comment attached to the pool. */
1471         if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
1472                 (void) printf(gettext("comment: %s\n"), comment);
1473 
1474         /*
1475          * If the state is "closed" or "can't open", and the aux state
1476          * is "corrupt data":
1477          */
1478         if (((vs->vs_state == VDEV_STATE_CLOSED) ||
1479             (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
1480             (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
1481                 if (pool_state == POOL_STATE_DESTROYED)
1482                         (void) printf(gettext("\tThe pool was destroyed, "
1483                             "but can be imported using the '-Df' flags.\n"));
1484                 else if (pool_state != POOL_STATE_EXPORTED)
1485                         (void) printf(gettext("\tThe pool may be active on "
1486                             "another system, but can be imported using\n\t"
1487                             "the '-f' flag.\n"));
1488         }
1489 
1490         if (msgid != NULL)
1491                 (void) printf(gettext("   see: http://www.sun.com/msg/%s\n"),
1492                     msgid);
1493 
1494         (void) printf(gettext(" config:\n\n"));
1495 
1496         namewidth = max_width(NULL, nvroot, 0, 0);
1497         if (namewidth < 10)
1498                 namewidth = 10;
1499 
1500         print_import_config(name, nvroot, namewidth, 0);
1501         if (num_logs(nvroot) > 0)
1502                 print_logs(NULL, nvroot, namewidth, B_FALSE);
1503 
1504         if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
1505                 (void) printf(gettext("\n\tAdditional devices are known to "
1506                     "be part of this pool, though their\n\texact "
1507                     "configuration cannot be determined.\n"));
1508         }
1509 }
1510 
1511 /*
1512  * Perform the import for the given configuration.  This passes the heavy
1513  * lifting off to zpool_import_props(), and then mounts the datasets contained
1514  * within the pool.
 
 |