changeset 9946:86a051e72232

6842809 zfs history needs to record system info on import/create
author Mark J Musante <Mark.Musante@Sun.COM>
date Mon, 22 Jun 2009 21:15:44 -0400
parents 727d00dde35c
children 56695b51ca83
files usr/src/uts/common/fs/zfs/spa.c usr/src/uts/common/fs/zfs/spa_history.c usr/src/uts/common/fs/zfs/sys/spa.h
diffstat 3 files changed, 65 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/fs/zfs/spa.c	Tue Jun 23 09:05:45 2009 +0800
+++ b/usr/src/uts/common/fs/zfs/spa.c	Mon Jun 22 21:15:44 2009 -0400
@@ -2271,6 +2271,7 @@
 
 	if (version >= SPA_VERSION_ZPOOL_HISTORY && history_str != NULL)
 		(void) spa_history_log(spa, history_str, LOG_CMD_POOL_CREATE);
+	spa_history_log_version(spa, LOG_POOL_CREATE);
 
 	spa->spa_minref = refcount_count(&spa->spa_refcount);
 
@@ -2459,6 +2460,7 @@
 
 	VERIFY(nvlist_dup(config, &spa->spa_config, 0) == 0);
 	error = 0;
+	spa_history_log_version(spa, LOG_POOL_IMPORT);
 out:
 	spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
 	vdev_free(rvd);
@@ -2499,6 +2501,7 @@
 	spa_config_sync(spa, B_FALSE, B_TRUE);
 
 	mutex_exit(&spa_namespace_lock);
+	spa_history_log_version(spa, LOG_POOL_IMPORT);
 
 	return (0);
 }
@@ -2634,6 +2637,7 @@
 	spa_async_request(spa, SPA_ASYNC_AUTOEXPAND);
 
 	mutex_exit(&spa_namespace_lock);
+	spa_history_log_version(spa, LOG_POOL_IMPORT);
 
 	return (0);
 }
@@ -2991,7 +2995,6 @@
 	vdev_t *rvd = spa->spa_root_vdev;
 	vdev_t *oldvd, *newvd, *newrootvd, *pvd, *tvd;
 	vdev_ops_t *pvops;
-	dmu_tx_t *tx;
 	char *oldvdpath, *newvdpath;
 	int newvd_isspare;
 	int error;
@@ -3147,17 +3150,11 @@
 
 	(void) spa_vdev_exit(spa, newrootvd, open_txg, 0);
 
-	tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
-	if (dmu_tx_assign(tx, TXG_WAIT) == 0) {
-		spa_history_internal_log(LOG_POOL_VDEV_ATTACH, spa, tx,
-		    CRED(),  "%s vdev=%s %s vdev=%s",
-		    replacing && newvd_isspare ? "spare in" :
-		    replacing ? "replace" : "attach", newvdpath,
-		    replacing ? "for" : "to", oldvdpath);
-		dmu_tx_commit(tx);
-	} else {
-		dmu_tx_abort(tx);
-	}
+	spa_history_internal_log(LOG_POOL_VDEV_ATTACH, spa, NULL,
+	    CRED(),  "%s vdev=%s %s vdev=%s",
+	    replacing && newvd_isspare ? "spare in" :
+	    replacing ? "replace" : "attach", newvdpath,
+	    replacing ? "for" : "to", oldvdpath);
 
 	spa_strfree(oldvdpath);
 	spa_strfree(newvdpath);
@@ -3747,19 +3744,11 @@
 		 * then log an internal history event.
 		 */
 		if (space_update) {
-			dmu_tx_t *tx;
-
-			tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
-			if (dmu_tx_assign(tx, TXG_WAIT) == 0) {
-				spa_history_internal_log(LOG_POOL_VDEV_ONLINE,
-				    spa, tx, CRED(),
-				    "pool '%s' size: %llu(+%llu)",
-				    spa_name(spa), spa_get_space(spa),
-				    space_update);
-				dmu_tx_commit(tx);
-			} else {
-				dmu_tx_abort(tx);
-			}
+			spa_history_internal_log(LOG_POOL_VDEV_ONLINE,
+			    spa, NULL, CRED(),
+			    "pool '%s' size: %llu(+%llu)",
+			    spa_name(spa), spa_get_space(spa),
+			    space_update);
 		}
 	}
 
--- a/usr/src/uts/common/fs/zfs/spa_history.c	Tue Jun 23 09:05:45 2009 +0800
+++ b/usr/src/uts/common/fs/zfs/spa_history.c	Mon Jun 22 21:15:44 2009 -0400
@@ -390,13 +390,12 @@
 	return (err);
 }
 
-void
-spa_history_internal_log(history_internal_events_t event, spa_t *spa,
-    dmu_tx_t *tx, cred_t *cr, const char *fmt, ...)
+static void
+log_internal(history_internal_events_t event, spa_t *spa,
+    dmu_tx_t *tx, cred_t *cr, const char *fmt, va_list adx)
 {
 	history_arg_t *hap;
 	char *str;
-	va_list adx;
 
 	/*
 	 * If this is part of creating a pool, not everything is
@@ -408,9 +407,7 @@
 	hap = kmem_alloc(sizeof (history_arg_t), KM_SLEEP);
 	str = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
 
-	va_start(adx, fmt);
 	(void) vsnprintf(str, HIS_MAX_RECORD_LEN, fmt, adx);
-	va_end(adx);
 
 	hap->ha_log_type = LOG_INTERNAL;
 	hap->ha_history_str = str;
@@ -425,3 +422,48 @@
 	}
 	/* spa_history_log_sync() will free hap and str */
 }
+
+void
+spa_history_internal_log(history_internal_events_t event, spa_t *spa,
+    dmu_tx_t *tx, cred_t *cr, const char *fmt, ...)
+{
+	dmu_tx_t *htx = tx;
+	va_list adx;
+
+	/* create a tx if we didn't get one */
+	if (tx == NULL) {
+		htx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
+		if (dmu_tx_assign(htx, TXG_WAIT) != 0) {
+			dmu_tx_abort(htx);
+			return;
+		}
+	}
+
+	va_start(adx, fmt);
+	log_internal(event, spa, htx, cr, fmt, adx);
+	va_end(adx);
+
+	/* if we didn't get a tx from the caller, commit the one we made */
+	if (tx == NULL)
+		dmu_tx_commit(htx);
+}
+
+void
+spa_history_log_version(spa_t *spa, history_internal_events_t event)
+{
+#ifdef _KERNEL
+	uint64_t current_vers = spa_version(spa);
+
+	if (current_vers >= SPA_VERSION_ZPOOL_HISTORY) {
+		spa_history_internal_log(event, spa, NULL, CRED(),
+		    "pool spa %llu; zfs spa %llu; zpl %d; uts %s %s %s %s",
+		    (u_longlong_t)current_vers, SPA_VERSION, ZPL_VERSION,
+		    utsname.nodename, utsname.release, utsname.version,
+		    utsname.machine);
+	}
+	cmn_err(CE_CONT, "!%s version %llu pool %s using %llu",
+	    event == LOG_POOL_IMPORT ? "imported" :
+	    event == LOG_POOL_CREATE ? "created" : "accessed",
+	    (u_longlong_t)current_vers, spa_name(spa), SPA_VERSION);
+#endif
+}
--- a/usr/src/uts/common/fs/zfs/sys/spa.h	Tue Jun 23 09:05:45 2009 +0800
+++ b/usr/src/uts/common/fs/zfs/sys/spa.h	Mon Jun 22 21:15:44 2009 -0400
@@ -500,8 +500,9 @@
     char *his_buf);
 extern int spa_history_log(spa_t *spa, const char *his_buf,
     history_log_type_t what);
-void spa_history_internal_log(history_internal_events_t event, spa_t *spa,
-    dmu_tx_t *tx, cred_t *cr, const char *fmt, ...);
+extern void spa_history_internal_log(history_internal_events_t event,
+    spa_t *spa, dmu_tx_t *tx, cred_t *cr, const char *fmt, ...);
+extern void spa_history_log_version(spa_t *spa, history_internal_events_t evt);
 
 /* error handling */
 struct zbookmark;