Add linux unused code tracking
[zfs.git] / lib / libzfs / libzfs_import.c
index fd3044b..386ab00 100644 (file)
@@ -19,8 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -371,7 +370,7 @@ static nvlist_t *
 refresh_config(libzfs_handle_t *hdl, nvlist_t *config)
 {
        nvlist_t *nvl;
-       zfs_cmd_t zc = { 0 };
+       zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 };
        int err;
 
        if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0)
@@ -411,7 +410,9 @@ refresh_config(libzfs_handle_t *hdl, nvlist_t *config)
 boolean_t
 vdev_is_hole(uint64_t *hole_array, uint_t holes, uint_t id)
 {
-       for (int c = 0; c < holes; c++) {
+       int c;
+
+       for (c = 0; c < holes; c++) {
 
                /* Top-level is a hole */
                if (hole_array[c] == id)
@@ -433,7 +434,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
        pool_entry_t *pe;
        vdev_entry_t *ve;
        config_entry_t *ce;
-       nvlist_t *ret = NULL, *config = NULL, *tmp, *nvtop, *nvroot;
+       nvlist_t *ret = NULL, *config = NULL, *tmp = NULL, *nvtop, *nvroot;
        nvlist_t **spares, **l2cache;
        uint_t i, nspares, nl2cache;
        boolean_t config_seen;
@@ -1559,6 +1560,17 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
 
        switch (stateval) {
        case POOL_STATE_EXPORTED:
+               /*
+                * A pool with an exported state may in fact be imported
+                * read-only, so check the in-core state to see if it's
+                * active and imported read-only.  If it is, set
+                * its state to active.
+                */
+               if (pool_active(hdl, name, guid, &isactive) == 0 && isactive &&
+                   (zhp = zpool_open_canfail(hdl, name)) != NULL &&
+                   zpool_get_prop_int(zhp, ZPOOL_PROP_READONLY, NULL))
+                       stateval = POOL_STATE_ACTIVE;
+
                ret = B_TRUE;
                break;