Hello request-sponsor,

http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6276934

I added -D option to 'zpool import'.
With '-D' only destroyed pools are showed or imported.


Diffs for snv_b29


--- lib/libzfs/common/libzfs_import.c.orig      Tue Jan 31 23:51:06 2006
+++ lib/libzfs/common/libzfs_import.c   Tue Jan 31 23:51:58 2006
@@ -547,7 +547,7 @@
                }

                if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
-                   &state) != 0 || state > POOL_STATE_EXPORTED) {
+                   &state) != 0 || state > POOL_STATE_DESTROYED) {
                        nvlist_free(config);
                        continue;
                }




--- uts/common/fs/zfs/vdev.c.orig       Sat Dec 17 06:15:08 2005
+++ uts/common/fs/zfs/vdev.c    Wed Feb  1 01:24:58 2006
@@ -1147,7 +1147,7 @@
                }

                if (state != POOL_STATE_ACTIVE &&
-                   (!import || state != POOL_STATE_EXPORTED)) {
+                   (!import || (state != POOL_STATE_EXPORTED && state != 
POOL_STATE_DESTROYED))) {
                        dprintf("pool state not active (%llu)\n", state);
                        nvlist_free(label);
                        return (EBADF);




--- cmd/zpool/zpool_main.c.orig Sat Dec 17 06:16:00 2005
+++ cmd/zpool/zpool_main.c      Sun Feb  5 02:08:24 2006
@@ -142,9 +142,9 @@
        { NULL },

        { "import",     zpool_do_import,
-           "\timport [-d dir]\n"
-           "\timport [-d dir] [-f] [-o opts] [-R root] -a\n"
-           "\timport [-d dir] [-f] [-o opts] [-R root ]<pool | id> "
+           "\timport [-d dir] [-D]\n"
+           "\timport [-d dir] [-D] [-f] [-o opts] [-R root] -a\n"
+           "\timport [-d dir] [-D] [-f] [-o opts] [-R root ] <pool | id> "
            "[newpool]\n"                                               },
        { "export",     zpool_do_export,
            "\texport [-f] <pool> ...\n"                                },
@@ -799,7 +799,10 @@

        (void) printf("  pool: %s\n", name);
        (void) printf("    id: %llu\n", guid);
-       (void) printf(" state: %s\n", health);
+       (void) printf(" state: %s", health);
+       if (pool_state == POOL_STATE_DESTROYED)
+               (void) printf(" (DESTROYED)");
+       (void) printf("\n");

        switch (reason) {
        case ZPOOL_STATUS_MISSING_DEV_R:
@@ -832,7 +835,10 @@
        if (strcmp(health, gettext("ONLINE")) == 0) {
                (void) printf(gettext("action: The pool can be imported"
                    " using its name or numeric identifier."));
-               if (pool_state != POOL_STATE_EXPORTED)
+               if (pool_state == POOL_STATE_DESTROYED)
+                       (void) printf(gettext("  The\n\tpool was destroyed, "
+                           "but can be imported using the '-Df' flags.\n"));
+               else if (pool_state != POOL_STATE_EXPORTED)
                        (void) printf(gettext("  The\n\tpool may be active on "
                            "on another system, but can be imported using\n\t"
                            "the '-f' flag.\n"));
@@ -842,7 +848,10 @@
                (void) printf(gettext("action: The pool can be imported "
                    "despite missing or damaged devices.  The\n\tfault "
                    "tolerance of the pool may be compromised if imported."));
-               if (pool_state != POOL_STATE_EXPORTED)
+               if (pool_state == POOL_STATE_DESTROYED)
+                       (void) printf(gettext("  The\n\tpool was destroyed, "
+                           "but can be imported using the '-Df' flags.\n"));
+               else if (pool_state != POOL_STATE_EXPORTED)
                        (void) printf(gettext("  The\n\tpool may be active on "
                            "on another system, but can be imported using\n\t"
                            "the '-f' flag.\n"));
@@ -921,12 +930,14 @@
 }

 /*
- * zpool import [-d dir]
- *       import [-R root] [-d dir] [-f] -a
- *       import [-R root] [-d dir] [-f] <pool | id> [newpool]
+ * zpool import [-d dir] [-D]
+ *       import [-R root] [-D] [-d dir] [-f] -a
+ *       import [-R root] [-D] [-d dir] [-f] <pool | id> [newpool]
  *
  *       -d    Scan in a specific directory, other than /dev/dsk.  More than
  *             one directory can be specified using multiple '-d' options.
+ *       -D    Scan for previously destroyed pools or import all or only
+ *             specified destroyed pools.
  *
  *       -R    Temporarily import the pool, with all mountpoints relative to
  *             the given root.  The pool will remain exported when the machine
@@ -948,6 +959,7 @@
        int err;
        nvlist_t *pools;
        int do_all = FALSE;
+       int do_destroyed = FALSE;
        char *altroot = NULL;
        char *mntopts = NULL;
        int do_force = FALSE;
@@ -957,9 +969,10 @@
        char *searchname;
        nvlist_t *found_config;
        int first;
+       uint64_t pool_state;

        /* check options */
-       while ((c = getopt(argc, argv, ":fd:R:ao:")) != -1) {
+       while ((c = getopt(argc, argv, ":Dfd:R:ao:")) != -1) {
                switch (c) {
                case 'a':
                        do_all = TRUE;
@@ -986,6 +999,9 @@
                case 'R':
                        altroot = optarg;
                        break;
+               case 'D':
+                       do_destroyed = TRUE;
+                       break;
                case ':':
                        (void) fprintf(stderr, gettext("missing argument for "
                            "'%c' option\n"), optopt);
@@ -1045,6 +1061,8 @@
         *
         *      <id>    Find the pool that corresponds to the given GUID/pool
         *              name and import that one.
+        *
+        *      -D      Above options applies only to destroyed pools.
         */
        if (argc != 0) {
                char *endptr;
@@ -1065,6 +1083,13 @@

                verify(nvpair_value_nvlist(elem, &config) == 0);

+               verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
+                   &pool_state) == 0);
+               if (!do_destroyed && pool_state == POOL_STATE_DESTROYED)
+                       continue;
+               if (do_destroyed && pool_state != POOL_STATE_DESTROYED)
+                       continue;
+
                if (argc == 0) {
                        if (first)
                                first = FALSE;




                                

-- 
Best regards,
 Robert                          mailto:rmilkowski at task.gda.pl
                                 http://milek.blogspot.com


Reply via email to