From owner-freebsd-fs@FreeBSD.ORG Tue Jun 14 20:26:52 2011 Return-Path: Delivered-To: fs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B68FF106566B for ; Tue, 14 Jun 2011 20:26:52 +0000 (UTC) (envelope-from gibbs@scsiguy.com) Received: from aslan.scsiguy.com (aslan.scsiguy.com [70.89.174.89]) by mx1.freebsd.org (Postfix) with ESMTP id 6FEE68FC1D for ; Tue, 14 Jun 2011 20:26:52 +0000 (UTC) Received: from Justins-MacBook-Pro.local (207-225-98-3.dia.static.qwest.net [207.225.98.3]) (authenticated bits=0) by aslan.scsiguy.com (8.14.4/8.14.4) with ESMTP id p5EKSDYQ015510 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Tue, 14 Jun 2011 14:28:13 -0600 (MDT) (envelope-from gibbs@scsiguy.com) Message-ID: <4DF7C406.1080903@scsiguy.com> Date: Tue, 14 Jun 2011 14:26:46 -0600 From: "Justin T. Gibbs" User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: fs@FreeBSD.org Content-Type: multipart/mixed; boundary="------------060201040900000201070407" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (aslan.scsiguy.com [70.89.174.89]); Tue, 14 Jun 2011 14:28:13 -0600 (MDT) Cc: Subject: [CFR][ZFS] Show removed devices by GUID in zpool output. X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jun 2011 20:26:52 -0000 This is a multi-part message in MIME format. --------------060201040900000201070407 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------060201040900000201070407 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="zpool.diffs" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="zpool.diffs" 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) { --------------060201040900000201070407--