diff options
author | Brian Behlendorf <[email protected]> | 2017-10-23 09:45:59 -0700 |
---|---|---|
committer | Tony Hutter <[email protected]> | 2017-12-04 17:21:03 -0800 |
commit | 954516cec1817b6bd3755292594b8e3562d0156c (patch) | |
tree | 2e88f7da09482588bda904c4619066086033236c /module | |
parent | 841cb5ee2ae8f1d617cd1f6713c8394e3bb30127 (diff) |
Emit history events for 'zpool create'
History commands and events were being suppressed for the
'zpool create' command since the history object did not
yet exist. Create the object earlier so this history
doesn't get lost.
Split the pool_destroy event in to pool_destroy and
pool_export so they may be distinguished.
Updated events_001_pos and events_002_pos test cases. They
now check for the expected history events and were reworked
to be more reliable.
Reviewed-by: Nathaniel Clark <[email protected]>
Reviewed-by: Giuseppe Di Natale <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #6712
Closes #6486
Conflicts:
tests/zfs-tests/tests/functional/events/events_002_pos.ksh
Diffstat (limited to 'module')
-rw-r--r-- | module/zfs/spa.c | 27 | ||||
-rw-r--r-- | module/zfs/spa_history.c | 16 |
2 files changed, 23 insertions, 20 deletions
diff --git a/module/zfs/spa.c b/module/zfs/spa.c index f1f1444f1..771f4c8d1 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -3257,7 +3257,7 @@ spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, * Log the fact that we booted up (so that we can detect if * we rebooted in the middle of an operation). */ - spa_history_log_version(spa, "open"); + spa_history_log_version(spa, "open", NULL); /* * Delete any inconsistent datasets. @@ -4140,6 +4140,15 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, tx = dmu_tx_create_assigned(dp, txg); /* + * Create the pool's history object. + */ + if (version >= SPA_VERSION_ZPOOL_HISTORY && !spa->spa_history) + spa_history_create_obj(spa, tx); + + spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_CREATE); + spa_history_log_version(spa, "create", tx); + + /* * Create the pool config object. */ spa->spa_config_object = dmu_object_alloc(spa->spa_meta_objset, @@ -4188,12 +4197,6 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, spa->spa_meta_objset, obj)); /* - * Create the pool's history object. - */ - if (version >= SPA_VERSION_ZPOOL_HISTORY) - spa_history_create_obj(spa, tx); - - /* * Generate some random noise for salted checksums to operate on. */ (void) random_get_pseudo_bytes(spa->spa_cksum_salt.zcs_bytes, @@ -4226,9 +4229,6 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, txg_wait_synced(spa->spa_dsl_pool, txg); spa_config_sync(spa, B_FALSE, B_TRUE); - spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_CREATE); - - spa_history_log_version(spa, "create"); /* * Don't count references from objsets that are already closed @@ -4415,7 +4415,7 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags) */ spa_async_request(spa, SPA_ASYNC_AUTOEXPAND); - spa_history_log_version(spa, "import"); + spa_history_log_version(spa, "import", NULL); spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_IMPORT); @@ -4618,7 +4618,10 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig, } export_spa: - spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_DESTROY); + if (new_state == POOL_STATE_DESTROYED) + spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_DESTROY); + else if (new_state == POOL_STATE_EXPORTED) + spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_EXPORT); if (spa->spa_state != POOL_STATE_UNINITIALIZED) { spa_unload(spa); diff --git a/module/zfs/spa_history.c b/module/zfs/spa_history.c index 73571c032..b6a32b31d 100644 --- a/module/zfs/spa_history.c +++ b/module/zfs/spa_history.c @@ -89,17 +89,17 @@ spa_history_create_obj(spa_t *spa, dmu_tx_t *tx) spa_history_phys_t *shpp; objset_t *mos = spa->spa_meta_objset; - ASSERT(spa->spa_history == 0); + ASSERT0(spa->spa_history); spa->spa_history = dmu_object_alloc(mos, DMU_OT_SPA_HISTORY, SPA_OLD_MAXBLOCKSIZE, DMU_OT_SPA_HISTORY_OFFSETS, sizeof (spa_history_phys_t), tx); - VERIFY(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, + VERIFY0(zap_add(mos, DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_HISTORY, sizeof (uint64_t), 1, - &spa->spa_history, tx) == 0); + &spa->spa_history, tx)); - VERIFY(0 == dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)); - ASSERT(dbp->db_size >= sizeof (spa_history_phys_t)); + VERIFY0(dmu_bonus_hold(mos, spa->spa_history, FTAG, &dbp)); + ASSERT3U(dbp->db_size, >=, sizeof (spa_history_phys_t)); shpp = dbp->db_data; dmu_buf_will_dirty(dbp, tx); @@ -525,7 +525,7 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, * initialized yet, so don't bother logging the internal events. * Likewise if the pool is not writeable. */ - if (tx->tx_txg == TXG_INITIAL || !spa_writeable(spa)) { + if (spa_is_initializing(spa) || !spa_writeable(spa)) { fnvlist_free(nvl); return; } @@ -611,11 +611,11 @@ spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation, } void -spa_history_log_version(spa_t *spa, const char *operation) +spa_history_log_version(spa_t *spa, const char *operation, dmu_tx_t *tx) { utsname_t *u = utsname(); - spa_history_log_internal(spa, operation, NULL, + spa_history_log_internal(spa, operation, tx, "pool version %llu; software version %llu/%llu; uts %s %s %s %s", (u_longlong_t)spa_version(spa), SPA_VERSION, ZPL_VERSION, u->nodename, u->release, u->version, u->machine); |