usr/src/uts/common/fs/zfs/spa.c
changeset 2926 acfcfefbc60d
parent 2856 6f4d5ee1906a
child 2986 c782fcf7a319
--- a/usr/src/uts/common/fs/zfs/spa.c	Mon Oct 16 10:09:13 2006 -0700
+++ b/usr/src/uts/common/fs/zfs/spa.c	Mon Oct 16 10:35:01 2006 -0700
@@ -131,6 +131,7 @@
 	mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL);
 	mutex_init(&spa->spa_config_lock.scl_lock, NULL, MUTEX_DEFAULT, NULL);
 	mutex_init(&spa->spa_sync_bplist.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
+	mutex_init(&spa->spa_history_lock, NULL, MUTEX_DEFAULT, NULL);
 
 	list_create(&spa->spa_dirty_list, sizeof (vdev_t),
 	    offsetof(vdev_t, vdev_dirty_node));
@@ -598,6 +599,20 @@
 	}
 
 	/*
+	 * Load the history object.  If we have an older pool, this
+	 * will not be present.
+	 */
+	error = zap_lookup(spa->spa_meta_objset,
+	    DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_HISTORY,
+	    sizeof (uint64_t), 1, &spa->spa_history);
+	if (error != 0 && error != ENOENT) {
+		vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN,
+		    VDEV_AUX_CORRUPT_DATA);
+		error = EIO;
+		goto out;
+	}
+
+	/*
 	 * Load any hot spares for this pool.
 	 */
 	error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
@@ -1106,6 +1121,11 @@
 		cmn_err(CE_PANIC, "failed to add bplist");
 	}
 
+	/*
+	 * Create the pool's history object.
+	 */
+	spa_history_create_obj(spa, tx);
+
 	dmu_tx_commit(tx);
 
 	spa->spa_sync_on = B_TRUE;
@@ -2714,6 +2734,7 @@
 	}
 
 	spa_sync_nvlist(spa, spa->spa_spares_object, nvroot, tx);
+	nvlist_free(nvroot);
 
 	spa->spa_sync_spares = B_FALSE;
 }