[CFR][ZFS] Show removed devices by GUID in zpool output.

Justin T. Gibbs gibbs at scsiguy.com
Tue Jun 14 20:26:52 UTC 2011


The current behavior of zpool_vdev_name() is to report the vdev path 
(e.g. /dev/da0) unless
a vdev has the ZPOOL_CONFIG_NOT_PRESENT attribute set.  This attribute 
is only set when
a vdev is not found during import/mount of a pool.  The attached patch 
also displays a vdev
by GUID if it cannot be opened post import or is marked removed (e.g. 
via a GEOM orphan
event).

The main motivation for this change is that vdev paths are not unique to 
a physical leaf vdev.
It is easy to get into a situation where you need to "detach /dev/da0" 
event though da0 is
an active member of the same pool in which a "previous da0" was once 
removed.  With
zpool_vdev_name() reporting the GUID, the user is equipped to provide an 
unambiguous
command that represents their desired action.

--
Justin
-------------- next part --------------
Index: libzfs_pool.c
===================================================================
--- libzfs_pool.c	(revision 223089)
+++ libzfs_pool.c	(working copy)
@@ -3082,15 +3082,25 @@
 	char buf[64];
 	vdev_stat_t *vs;
 	uint_t vsc;
+	int have_stats;
+	int have_path;
 
-	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
-	    &value) == 0) {
+	have_stats = nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
+	    (uint64_t **)&vs, &vsc) == 0;
+	have_path = nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0;
+
+	/*
+	 * If the device is not currently present, assume it will not
+	 * come back at the same device path.  Display the device by GUID.
+	 */
+	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, &value) == 0 ||
+	    have_path && have_stats && vs->vs_state <= VDEV_STATE_CANT_OPEN) {
 		verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
 		    &value) == 0);
 		(void) snprintf(buf, sizeof (buf), "%llu",
 		    (u_longlong_t)value);
 		path = buf;
-	} else if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) {
+	} else if (have_path) {
 
 		/*
 		 * If the device is dead (faulted, offline, etc) then don't
@@ -3098,8 +3108,7 @@
 		 * open a misbehaving device, which can have undesirable
 		 * effects.
 		 */
-		if ((nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
-		    (uint64_t **)&vs, &vsc) != 0 ||
+		if ((have_stats == 0 ||
 		    vs->vs_state >= VDEV_STATE_DEGRADED) &&
 		    zhp != NULL &&
 		    nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &devid) == 0) {


More information about the freebsd-fs mailing list