changeset 3741:806e933bf124

6441384 zpool import action message is not correctly localized 6473418 setting user defined property on full filesystem should report error 6513953 Unable to create global hotspare in ja locale
author mmusante
date Thu, 01 Mar 2007 06:09:49 -0800
parents 49e8b86bee75
children 304a05354bf8
files usr/src/cmd/zpool/zpool_main.c usr/src/cmd/zpool/zpool_vdev.c usr/src/lib/libdiskmgt/common/entry.c usr/src/lib/libdiskmgt/common/libdiskmgt.h usr/src/lib/libzfs/common/libzfs_config.c usr/src/lib/libzfs/common/libzfs_impl.h usr/src/lib/libzfs/common/libzfs_import.c usr/src/lib/libzfs/common/libzfs_pool.c usr/src/uts/common/fs/zfs/zfs_ioctl.c usr/src/uts/common/sys/fs/zfs.h
diffstat 10 files changed, 62 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/zpool/zpool_main.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/cmd/zpool/zpool_main.c	Thu Mar 01 06:09:49 2007 -0800
@@ -310,6 +310,23 @@
 }
 
 const char *
+state_to_health(int vs_state)
+{
+	switch (vs_state) {
+	case VDEV_STATE_CLOSED:
+	case VDEV_STATE_CANT_OPEN:
+	case VDEV_STATE_OFFLINE:
+		return (dgettext(TEXT_DOMAIN, "FAULTED"));
+	case VDEV_STATE_DEGRADED:
+		return (dgettext(TEXT_DOMAIN, "DEGRADED"));
+	case VDEV_STATE_HEALTHY:
+		return (dgettext(TEXT_DOMAIN, "ONLINE"));
+	}
+
+	return (dgettext(TEXT_DOMAIN, "UNKNOWN"));
+}
+
+const char *
 state_to_name(vdev_stat_t *vs)
 {
 	switch (vs->vs_state) {
@@ -954,7 +971,7 @@
 	char *msgid;
 	nvlist_t *nvroot;
 	int reason;
-	char *health;
+	const char *health;
 	uint_t vsc;
 	int namewidth;
 
@@ -964,21 +981,20 @@
 	    &guid) == 0);
 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
 	    &pool_state) == 0);
-	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_HEALTH,
-	    &health) == 0);
 	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
 	    &nvroot) == 0);
 
 	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
 	    (uint64_t **)&vs, &vsc) == 0);
+	health = state_to_health(vs->vs_state);
 
 	reason = zpool_import_status(config, &msgid);
 
-	(void) printf("  pool: %s\n", name);
-	(void) printf("    id: %llu\n", (u_longlong_t)guid);
-	(void) printf(" state: %s", health);
+	(void) printf(gettext("  pool: %s\n"), name);
+	(void) printf(gettext("    id: %llu\n"), (u_longlong_t)guid);
+	(void) printf(gettext(" state: %s"), health);
 	if (pool_state == POOL_STATE_DESTROYED)
-	    (void) printf(" (DESTROYED)");
+	    (void) printf(gettext(" (DESTROYED)"));
 	(void) printf("\n");
 
 	switch (reason) {
@@ -1029,7 +1045,7 @@
 	/*
 	 * Print out an action according to the overall state of the pool.
 	 */
-	if (strcmp(health, gettext("ONLINE")) == 0) {
+	if (vs->vs_state == VDEV_STATE_HEALTHY) {
 		if (reason == ZPOOL_STATUS_VERSION_OLDER)
 			(void) printf(gettext("action: The pool can be "
 			    "imported using its name or numeric identifier, "
@@ -1039,7 +1055,7 @@
 			(void) printf(gettext("action: The pool can be "
 			    "imported using its name or numeric "
 			    "identifier.\n"));
-	} else if (strcmp(health, gettext("DEGRADED")) == 0) {
+	} else if (vs->vs_state == VDEV_STATE_DEGRADED) {
 		(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.\n"));
@@ -1064,7 +1080,13 @@
 		}
 	}
 
-	if (strcmp(health, gettext("FAULTED")) != 0) {
+	/*
+	 * If the state is "closed" or "can't open", and the aux state
+	 * is "corrupt data":
+	 */
+	if (((vs->vs_state == VDEV_STATE_CLOSED) ||
+	    (vs->vs_state == VDEV_STATE_CANT_OPEN)) &&
+	    (vs->vs_aux == VDEV_AUX_CORRUPT_DATA)) {
 		if (pool_state == POOL_STATE_DESTROYED)
 			(void) printf(gettext("\tThe pool was destroyed, "
 			    "but can be imported using the '-Df' flags.\n"));
@@ -1086,9 +1108,9 @@
 	print_import_config(name, nvroot, namewidth, 0);
 
 	if (reason == ZPOOL_STATUS_BAD_GUID_SUM) {
-		(void) printf("\n\tAdditional devices are known to "
+		(void) printf(gettext("\n\tAdditional devices are known to "
 		    "be part of this pool, though their\n\texact "
-		    "configuration cannot be determined.\n");
+		    "configuration cannot be determined.\n"));
 	}
 }
 
@@ -2733,7 +2755,9 @@
 	nvlist_t *config, *nvroot;
 	char *msgid;
 	int reason;
-	char *health;
+	const char *health;
+	uint_t c;
+	vdev_stat_t *vs;
 
 	config = zpool_get_config(zhp, NULL);
 	reason = zpool_get_status(zhp, &msgid);
@@ -2759,8 +2783,11 @@
 	else
 		(void) printf("\n");
 
-	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_HEALTH,
-	    &health) == 0);
+	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
+	    &nvroot) == 0);
+	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
+	    (uint64_t **)&vs, &c) == 0);
+	health = state_to_name(vs);
 
 	(void) printf(gettext("  pool: %s\n"), zpool_get_name(zhp));
 	(void) printf(gettext(" state: %s\n"), health);
@@ -2880,8 +2907,6 @@
 		nvlist_t **spares;
 		uint_t nspares;
 
-		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
-		    &nvroot) == 0);
 
 		(void) printf(gettext(" scrub: "));
 		print_scrub_status(nvroot);
--- a/usr/src/cmd/zpool/zpool_vdev.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/cmd/zpool/zpool_vdev.c	Thu Mar 01 06:09:49 2007 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -139,18 +139,12 @@
 	int error = 0;
 	int ret = 0;
 
-	if (dm_inuse((char *)path, &msg,
-	    force ? DM_WHO_ZPOOL_FORCE : DM_WHO_ZPOOL, &error) || error) {
+	if (dm_inuse((char *)path, &msg, isspare ? DM_WHO_ZPOOL_SPARE :
+	    (force ? DM_WHO_ZPOOL_FORCE : DM_WHO_ZPOOL), &error) || error) {
 		if (error != 0) {
 			libdiskmgt_error(error);
 			return (0);
-		} else if (!isspare ||
-		    strstr(msg, gettext("hot spare")) == NULL) {
-			/*
-			 * The above check is a rather severe hack.  It would
-			 * probably make more sense to have DM_WHO_ZPOOL_SPARE
-			 * instead.
-			 */
+		} else {
 			vdev_error("%s", msg);
 			free(msg);
 			ret = -1;
--- a/usr/src/lib/libdiskmgt/common/entry.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libdiskmgt/common/entry.c	Thu Mar 01 06:09:49 2007 -0800
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -743,7 +743,6 @@
 	int	found = 0;
 	char	*dname = NULL;
 
-
 	*errp = 0;
 	*msg = NULL;
 
@@ -892,6 +891,16 @@
 				}
 				break;
 
+			case DM_WHO_ZPOOL_SPARE:
+				if (strcmp(by, DM_USE_SPARE_ZPOOL) != 0) {
+					if (build_usage_string(dname, by,
+					    data, msg, &found, errp) != 0) {
+						if (*errp)
+							goto out;
+					}
+				}
+				break;
+
 			default:
 				/*
 				 * nothing found in use for this client
--- a/usr/src/lib/libdiskmgt/common/libdiskmgt.h	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libdiskmgt/common/libdiskmgt.h	Thu Mar 01 06:09:49 2007 -0800
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -48,7 +48,8 @@
 	DM_WHO_ZPOOL_FORCE,
 	DM_WHO_FORMAT,
 	DM_WHO_SWAP,
-	DM_WHO_DUMP
+	DM_WHO_DUMP,
+	DM_WHO_ZPOOL_SPARE
 } dm_who_type_t;
 
 typedef enum {
--- a/usr/src/lib/libzfs/common/libzfs_config.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libzfs/common/libzfs_config.c	Thu Mar 01 06:09:49 2007 -0800
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -289,11 +289,6 @@
 
 	zhp->zpool_config_size = zc.zc_nvlist_dst_size;
 
-	if (set_pool_health(config) != 0) {
-		nvlist_free(config);
-		return (no_memory(zhp->zpool_hdl));
-	}
-
 	if (zhp->zpool_config != NULL) {
 		uint64_t oldtxg, newtxg;
 
--- a/usr/src/lib/libzfs/common/libzfs_impl.h	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libzfs/common/libzfs_impl.h	Thu Mar 01 06:09:49 2007 -0800
@@ -120,7 +120,6 @@
 void remove_mountpoint(zfs_handle_t *);
 
 zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);
-int set_pool_health(nvlist_t *);
 
 int zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **);
 
--- a/usr/src/lib/libzfs/common/libzfs_import.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libzfs/common/libzfs_import.c	Thu Mar 01 06:09:49 2007 -0800
@@ -621,9 +621,6 @@
 			}
 		}
 
-		if (set_pool_health(config) != 0)
-			goto nomem;
-
 		/*
 		 * Add this pool to the list of configs.
 		 */
--- a/usr/src/lib/libzfs/common/libzfs_pool.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c	Thu Mar 01 06:09:49 2007 -0800
@@ -132,45 +132,6 @@
 }
 
 /*
- * Set the pool-wide health based on the vdev state of the root vdev.
- */
-int
-set_pool_health(nvlist_t *config)
-{
-	nvlist_t *nvroot;
-	vdev_stat_t *vs;
-	uint_t vsc;
-	char *health;
-
-	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
-	    &nvroot) == 0);
-	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
-	    (uint64_t **)&vs, &vsc) == 0);
-
-	switch (vs->vs_state) {
-
-	case VDEV_STATE_CLOSED:
-	case VDEV_STATE_CANT_OPEN:
-	case VDEV_STATE_OFFLINE:
-		health = dgettext(TEXT_DOMAIN, "FAULTED");
-		break;
-
-	case VDEV_STATE_DEGRADED:
-		health = dgettext(TEXT_DOMAIN, "DEGRADED");
-		break;
-
-	case VDEV_STATE_HEALTHY:
-		health = dgettext(TEXT_DOMAIN, "ONLINE");
-		break;
-
-	default:
-		abort();
-	}
-
-	return (nvlist_add_string(config, ZPOOL_CONFIG_POOL_HEALTH, health));
-}
-
-/*
  * Open a handle to the given pool, even if the pool is currently in the FAULTED
  * state.
  */
--- a/usr/src/uts/common/fs/zfs/zfs_ioctl.c	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/uts/common/fs/zfs/zfs_ioctl.c	Thu Mar 01 06:09:49 2007 -0800
@@ -869,7 +869,7 @@
 			if (error == 0)
 				continue;
 			else
-				break;
+				return (error);
 		}
 
 		/*
--- a/usr/src/uts/common/sys/fs/zfs.h	Wed Feb 28 22:48:17 2007 -0800
+++ b/usr/src/uts/common/sys/fs/zfs.h	Thu Mar 01 06:09:49 2007 -0800
@@ -157,7 +157,6 @@
 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
-#define	ZPOOL_CONFIG_POOL_HEALTH	"pool_health"
 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
 #define	ZPOOL_CONFIG_TYPE		"type"
 #define	ZPOOL_CONFIG_CHILDREN		"children"