changeset 7539:e3f4b4b9f982

6724326 better "can't mountroot" message
author Lin Ling <Lin.Ling@Sun.COM>
date Wed, 10 Sep 2008 08:25:48 -0700
parents 18c2451107fd
children 5a9295982549
files usr/src/uts/common/fs/zfs/spa.c usr/src/uts/common/fs/zfs/vdev_disk.c
diffstat 2 files changed, 29 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/fs/zfs/spa.c	Wed Sep 10 10:59:12 2008 -0400
+++ b/usr/src/uts/common/fs/zfs/spa.c	Wed Sep 10 08:25:48 2008 -0700
@@ -2245,7 +2245,7 @@
  * Get the root pool information from the root disk, then import the root pool
  * during the system boot up time.
  */
-extern nvlist_t *vdev_disk_read_rootlabel(char *, char *);
+extern int vdev_disk_read_rootlabel(char *, char *, nvlist_t **);
 
 int
 spa_check_rootconf(char *devpath, char *devid, nvlist_t **bestconf,
@@ -2253,14 +2253,17 @@
 {
 	nvlist_t *config;
 	uint64_t txg;
-
-	if ((config = vdev_disk_read_rootlabel(devpath, devid)) == NULL)
-		return (-1);
+	int error;
+
+	if (error = vdev_disk_read_rootlabel(devpath, devid, &config))
+		return (error);
 
 	VERIFY(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, &txg) == 0);
 
 	if (bestconf != NULL)
 		*bestconf = config;
+	else
+		nvlist_free(config);
 	*besttxg = txg;
 	return (0);
 }
@@ -2294,13 +2297,13 @@
 	char *bootpath = NULL;
 	uint_t children, c;
 	char *tmp;
+	int error;
 
 	if (devpath && ((tmp = strchr(devpath, ' ')) != NULL))
 		*tmp = '\0';
-	if (spa_check_rootconf(devpath, devid, &conf, &txg) < 0) {
+	if (error = spa_check_rootconf(devpath, devid, &conf, &txg)) {
 		cmn_err(CE_NOTE, "error reading device label");
-		nvlist_free(conf);
-		return (EINVAL);
+		return (error);
 	}
 	if (txg == 0) {
 		cmn_err(CE_NOTE, "this device is detached");
@@ -2341,8 +2344,9 @@
 		if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_DEVID,
 		    &cdevid) != 0)
 			return (EINVAL);
-		if ((spa_check_rootconf(cpath, cdevid, NULL,
-		    &tmptxg) == 0) && (tmptxg > txg)) {
+		if (error = spa_check_rootconf(cpath, cdevid, NULL, &tmptxg))
+			return (error);
+		if (tmptxg > txg) {
 			txg = tmptxg;
 			VERIFY(nvlist_lookup_string(child[c],
 			    ZPOOL_CONFIG_PATH, &bootpath) == 0);
--- a/usr/src/uts/common/fs/zfs/vdev_disk.c	Wed Sep 10 10:59:12 2008 -0400
+++ b/usr/src/uts/common/fs/zfs/vdev_disk.c	Wed Sep 10 08:25:48 2008 -0700
@@ -23,8 +23,6 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/zfs_context.h>
 #include <sys/spa.h>
 #include <sys/refcount.h>
@@ -602,16 +600,15 @@
  * Given the root disk device devid or pathname, read the label from
  * the device, and construct a configuration nvlist.
  */
-nvlist_t *
-vdev_disk_read_rootlabel(char *devpath, char *devid)
+int
+vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config)
 {
-	nvlist_t *config = NULL;
 	ldi_handle_t vd_lh;
 	vdev_label_t *label;
 	uint64_t s, size;
 	int l;
 	ddi_devid_t tmpdevid;
-	int error = -1;
+	int error = 0;
 	char *minor_name;
 
 	/*
@@ -625,13 +622,13 @@
 		ddi_devid_str_free(minor_name);
 	}
 
-	if (error && ldi_open_by_name(devpath, FREAD, kcred, &vd_lh,
-	    zfs_li))
-		return (NULL);
+	if (error && (error = ldi_open_by_name(devpath, FREAD, kcred,
+	    &vd_lh, zfs_li)) != 0)
+		return (error);
 
 	if (ldi_get_size(vd_lh, &s)) {
 		(void) ldi_close(vd_lh, FREAD, kcred);
-		return (NULL);
+		return (EIO);
 	}
 
 	size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);
@@ -648,22 +645,22 @@
 			continue;
 
 		if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
-		    sizeof (label->vl_vdev_phys.vp_nvlist), &config, 0) != 0) {
-			config = NULL;
+		    sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) {
+			*config = NULL;
 			continue;
 		}
 
-		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
+		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
 		    &state) != 0 || state >= POOL_STATE_DESTROYED) {
-			nvlist_free(config);
-			config = NULL;
+			nvlist_free(*config);
+			*config = NULL;
 			continue;
 		}
 
-		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG,
+		if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
 		    &txg) != 0 || txg == 0) {
-			nvlist_free(config);
-			config = NULL;
+			nvlist_free(*config);
+			*config = NULL;
 			continue;
 		}
 
@@ -673,5 +670,5 @@
 	kmem_free(label, sizeof (vdev_label_t));
 	(void) ldi_close(vd_lh, FREAD, kcred);
 
-	return (config);
+	return (error);
 }