Skip to content

Commit c39ecc7

Browse files
allanjudedon-brady
andcommitted
Extend import_progress kstat with a notes field
Detail the import progress of log spacemaps as they can take a very long time. Also grab the spa_note() messages to, as they provide insight into what is happening Sponsored-By: OpenDrives Inc. Sponsored-By: Klara Inc. Co-authored-by: Don Brady <[email protected]> Signed-off-by: Don Brady <[email protected]>
1 parent a94860a commit c39ecc7

File tree

6 files changed

+236
-5
lines changed

6 files changed

+236
-5
lines changed

include/sys/spa.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,9 @@ extern int spa_import_progress_set_max_txg(uint64_t pool_guid,
971971
uint64_t max_txg);
972972
extern int spa_import_progress_set_state(uint64_t pool_guid,
973973
spa_load_state_t spa_load_state);
974+
extern void spa_import_progress_set_notes(spa_t *spa, const char *notes);
975+
extern void spa_import_progress_set_notes_nolog(spa_t *spa,
976+
const char *notes);
974977

975978
/* Pool configuration locks */
976979
extern int spa_config_tryenter(spa_t *spa, int locks, const void *tag,

module/zfs/spa.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,7 @@ spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type)
31093109
spa->spa_load_state = state;
31103110
(void) spa_import_progress_set_state(spa_guid(spa),
31113111
spa_load_state(spa));
3112+
spa_import_progress_set_notes(spa, "spa_load()");
31123113

31133114
gethrestime(&spa->spa_loaded_ts);
31143115
error = spa_load_impl(spa, type, &ereport);
@@ -3785,6 +3786,7 @@ spa_ld_select_uberblock(spa_t *spa, spa_import_type_t type)
37853786
return (spa_vdev_err(rvd, VDEV_AUX_ACTIVE, EREMOTEIO));
37863787
}
37873788

3789+
spa_import_progress_set_notes(spa, "checking MMP activity");
37883790
int error = spa_activity_check(spa, ub, spa->spa_config);
37893791
if (error) {
37903792
nvlist_free(label);
@@ -4995,6 +4997,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
49954997
/*
49964998
* Retrieve the checkpoint txg if the pool has a checkpoint.
49974999
*/
5000+
spa_import_progress_set_notes(spa, "Loading checkpoint txg");
49985001
error = spa_ld_read_checkpoint_txg(spa);
49995002
if (error != 0)
50005003
return (error);
@@ -5007,6 +5010,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50075010
* initiated. Otherwise we could be reading from indirect vdevs before
50085011
* we have loaded their mappings.
50095012
*/
5013+
spa_import_progress_set_notes(spa, "Loading indirect vdev metadata");
50105014
error = spa_ld_open_indirect_vdev_metadata(spa);
50115015
if (error != 0)
50125016
return (error);
@@ -5015,6 +5019,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50155019
* Retrieve the full list of active features from the MOS and check if
50165020
* they are all supported.
50175021
*/
5022+
spa_import_progress_set_notes(spa, "Checking feature flags");
50185023
error = spa_ld_check_features(spa, &missing_feat_write);
50195024
if (error != 0)
50205025
return (error);
@@ -5023,13 +5028,15 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50235028
* Load several special directories from the MOS needed by the dsl_pool
50245029
* layer.
50255030
*/
5031+
spa_import_progress_set_notes(spa, "Loading special MOS directories");
50265032
error = spa_ld_load_special_directories(spa);
50275033
if (error != 0)
50285034
return (error);
50295035

50305036
/*
50315037
* Retrieve pool properties from the MOS.
50325038
*/
5039+
spa_import_progress_set_notes(spa, "Loading properties");
50335040
error = spa_ld_get_props(spa);
50345041
if (error != 0)
50355042
return (error);
@@ -5038,6 +5045,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50385045
* Retrieve the list of auxiliary devices - cache devices and spares -
50395046
* and open them.
50405047
*/
5048+
spa_import_progress_set_notes(spa, "Loading AUX vdevs");
50415049
error = spa_ld_open_aux_vdevs(spa, type);
50425050
if (error != 0)
50435051
return (error);
@@ -5046,14 +5054,17 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50465054
* Load the metadata for all vdevs. Also check if unopenable devices
50475055
* should be autoreplaced.
50485056
*/
5057+
spa_import_progress_set_notes(spa, "Loading vdev metadata");
50495058
error = spa_ld_load_vdev_metadata(spa);
50505059
if (error != 0)
50515060
return (error);
50525061

5062+
spa_import_progress_set_notes(spa, "Loading dedup tables");
50535063
error = spa_ld_load_dedup_tables(spa);
50545064
if (error != 0)
50555065
return (error);
50565066

5067+
spa_import_progress_set_notes(spa, "Loading BRT");
50575068
error = spa_ld_load_brt(spa);
50585069
if (error != 0)
50595070
return (error);
@@ -5062,6 +5073,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50625073
* Verify the logs now to make sure we don't have any unexpected errors
50635074
* when we claim log blocks later.
50645075
*/
5076+
spa_import_progress_set_notes(spa, "Verifying Log Devices");
50655077
error = spa_ld_verify_logs(spa, type, ereport);
50665078
if (error != 0)
50675079
return (error);
@@ -5083,6 +5095,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50835095
* state. When performing an extreme rewind, we verify the whole pool,
50845096
* which can take a very long time.
50855097
*/
5098+
spa_import_progress_set_notes(spa, "Verifying pool data");
50865099
error = spa_ld_verify_pool_data(spa);
50875100
if (error != 0)
50885101
return (error);
@@ -5092,13 +5105,15 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50925105
* we write anything to the pool because we'd need to update the space
50935106
* accounting using the deflated sizes.
50945107
*/
5108+
spa_import_progress_set_notes(spa, "Calculating deflated space");
50955109
spa_update_dspace(spa);
50965110

50975111
/*
50985112
* We have now retrieved all the information we needed to open the
50995113
* pool. If we are importing the pool in read-write mode, a few
51005114
* additional steps must be performed to finish the import.
51015115
*/
5116+
spa_import_progress_set_notes(spa, "Starting import");
51025117
if (spa_writeable(spa) && (spa->spa_load_state == SPA_LOAD_RECOVER ||
51035118
spa->spa_load_max_txg == UINT64_MAX)) {
51045119
uint64_t config_cache_txg = spa->spa_config_txg;
@@ -5122,6 +5137,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51225137
(u_longlong_t)spa->spa_uberblock.ub_checkpoint_txg);
51235138
}
51245139

5140+
spa_import_progress_set_notes(spa, "Claiming ZIL blocks");
51255141
/*
51265142
* Traverse the ZIL and claim all blocks.
51275143
*/
@@ -5141,13 +5157,15 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51415157
* will have been set for us by ZIL traversal operations
51425158
* performed above.
51435159
*/
5160+
spa_import_progress_set_notes(spa, "Syncing ZIL claims");
51445161
txg_wait_synced(spa->spa_dsl_pool, spa->spa_claim_max_txg);
51455162

51465163
/*
51475164
* Check if we need to request an update of the config. On the
51485165
* next sync, we would update the config stored in vdev labels
51495166
* and the cachefile (by default /etc/zfs/zpool.cache).
51505167
*/
5168+
spa_import_progress_set_notes(spa, "Updating configs");
51515169
spa_ld_check_for_config_update(spa, config_cache_txg,
51525170
update_config_cache);
51535171

@@ -5156,6 +5174,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51565174
* Then check all DTLs to see if anything needs resilvering.
51575175
* The resilver will be deferred if a rebuild was started.
51585176
*/
5177+
spa_import_progress_set_notes(spa, "Starting resilvers");
51595178
if (vdev_rebuild_active(spa->spa_root_vdev)) {
51605179
vdev_rebuild_restart(spa);
51615180
} else if (!dsl_scan_resilvering(spa->spa_dsl_pool) &&
@@ -5169,6 +5188,8 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51695188
*/
51705189
spa_history_log_version(spa, "open", NULL);
51715190

5191+
spa_import_progress_set_notes(spa,
5192+
"Restarting device removals");
51725193
spa_restart_removal(spa);
51735194
spa_spawn_aux_threads(spa);
51745195

@@ -5181,19 +5202,26 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51815202
* auxiliary threads above (from which the livelist
51825203
* deletion zthr is part of).
51835204
*/
5205+
spa_import_progress_set_notes(spa,
5206+
"Cleaning up inconsistent objsets");
51845207
(void) dmu_objset_find(spa_name(spa),
51855208
dsl_destroy_inconsistent, NULL, DS_FIND_CHILDREN);
51865209

51875210
/*
51885211
* Clean up any stale temporary dataset userrefs.
51895212
*/
5213+
spa_import_progress_set_notes(spa,
5214+
"Cleaning up temporary userrefs");
51905215
dsl_pool_clean_tmp_userrefs(spa->spa_dsl_pool);
51915216

51925217
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
5218+
spa_import_progress_set_notes(spa, "Restarting Initialize");
51935219
vdev_initialize_restart(spa->spa_root_vdev);
5220+
spa_import_progress_set_notes(spa, "Restarting TRIM");
51945221
vdev_trim_restart(spa->spa_root_vdev);
51955222
vdev_autotrim_restart(spa);
51965223
spa_config_exit(spa, SCL_CONFIG, FTAG);
5224+
spa_import_progress_set_notes(spa, "Finished importing");
51975225
}
51985226

51995227
spa_import_progress_remove(spa_guid(spa));

module/zfs/spa_log_spacemap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ spa_ld_log_sm_data(spa_t *spa)
11531153

11541154
uint_t pn = 0;
11551155
uint64_t ps = 0;
1156+
uint64_t nsm = 0;
11561157
psls = sls = avl_first(&spa->spa_sm_logs_by_txg);
11571158
while (sls != NULL) {
11581159
/* Prefetch log spacemaps up to 16 TXGs or MBs ahead. */
@@ -1185,6 +1186,13 @@ spa_ld_log_sm_data(spa_t *spa)
11851186
summary_add_data(spa, sls->sls_txg,
11861187
sls->sls_mscount, 0, sls->sls_nblocks);
11871188

1189+
char buf[128];
1190+
(void) snprintf(buf, sizeof (buf),
1191+
"read %llu of %llu log space maps",
1192+
(u_longlong_t)nsm,
1193+
(u_longlong_t)avl_numnodes(&spa->spa_sm_logs_by_txg));
1194+
spa_import_progress_set_notes_nolog(spa, buf);
1195+
11881196
struct spa_ld_log_sm_arg vla = {
11891197
.slls_spa = spa,
11901198
.slls_txg = sls->sls_txg
@@ -1200,6 +1208,7 @@ spa_ld_log_sm_data(spa_t *spa)
12001208

12011209
pn--;
12021210
ps -= space_map_length(sls->sls_sm);
1211+
nsm++;
12031212
space_map_close(sls->sls_sm);
12041213
sls->sls_sm = NULL;
12051214
sls = AVL_NEXT(&spa->spa_sm_logs_by_txg, sls);

module/zfs/spa_misc.c

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ spa_load_note(spa_t *spa, const char *fmt, ...)
426426

427427
zfs_dbgmsg("spa_load(%s, config %s): %s", spa->spa_name,
428428
spa->spa_trust_config ? "trusted" : "untrusted", buf);
429+
430+
spa_import_progress_set_notes_nolog(spa, buf);
429431
}
430432

431433
/*
@@ -2184,6 +2186,7 @@ typedef struct spa_import_progress {
21842186
uint64_t pool_guid; /* unique id for updates */
21852187
char *pool_name;
21862188
spa_load_state_t spa_load_state;
2189+
char *spa_load_notes;
21872190
uint64_t mmp_sec_remaining; /* MMP activity check */
21882191
uint64_t spa_load_max_txg; /* rewind txg */
21892192
procfs_list_node_t smh_node;
@@ -2194,9 +2197,9 @@ spa_history_list_t *spa_import_progress_list = NULL;
21942197
static int
21952198
spa_import_progress_show_header(struct seq_file *f)
21962199
{
2197-
seq_printf(f, "%-20s %-14s %-14s %-12s %s\n", "pool_guid",
2200+
seq_printf(f, "%-20s %-14s %-14s %-12s %s %s\n", "pool_guid",
21982201
"load_state", "multihost_secs", "max_txg",
2199-
"pool_name");
2202+
"pool_name", "notes");
22002203
return (0);
22012204
}
22022205

@@ -2205,11 +2208,12 @@ spa_import_progress_show(struct seq_file *f, void *data)
22052208
{
22062209
spa_import_progress_t *sip = (spa_import_progress_t *)data;
22072210

2208-
seq_printf(f, "%-20llu %-14llu %-14llu %-12llu %s\n",
2211+
seq_printf(f, "%-20llu %-14llu %-14llu %-12llu %s %s\n",
22092212
(u_longlong_t)sip->pool_guid, (u_longlong_t)sip->spa_load_state,
22102213
(u_longlong_t)sip->mmp_sec_remaining,
22112214
(u_longlong_t)sip->spa_load_max_txg,
2212-
(sip->pool_name ? sip->pool_name : "-"));
2215+
(sip->pool_name ? sip->pool_name : "-"),
2216+
(sip->spa_load_notes ? sip->spa_load_notes : "-"));
22132217

22142218
return (0);
22152219
}
@@ -2223,6 +2227,8 @@ spa_import_progress_truncate(spa_history_list_t *shl, unsigned int size)
22232227
sip = list_remove_head(&shl->procfs_list.pl_list);
22242228
if (sip->pool_name)
22252229
spa_strfree(sip->pool_name);
2230+
if (sip->spa_load_notes)
2231+
spa_strfree(sip->spa_load_notes);
22262232
kmem_free(sip, sizeof (spa_import_progress_t));
22272233
shl->size--;
22282234
}
@@ -2278,6 +2284,10 @@ spa_import_progress_set_state(uint64_t pool_guid,
22782284
sip = list_prev(&shl->procfs_list.pl_list, sip)) {
22792285
if (sip->pool_guid == pool_guid) {
22802286
sip->spa_load_state = load_state;
2287+
if (sip->spa_load_notes != NULL) {
2288+
spa_strfree(sip->spa_load_notes);
2289+
sip->spa_load_notes = NULL;
2290+
}
22812291
error = 0;
22822292
break;
22832293
}
@@ -2287,6 +2297,50 @@ spa_import_progress_set_state(uint64_t pool_guid,
22872297
return (error);
22882298
}
22892299

2300+
static void
2301+
spa_import_progress_set_notes_impl(spa_t *spa, const char *notes,
2302+
boolean_t log_dbgmsg)
2303+
{
2304+
spa_history_list_t *shl = spa_import_progress_list;
2305+
spa_import_progress_t *sip;
2306+
uint64_t pool_guid = spa_guid(spa);
2307+
2308+
if (shl->size == 0)
2309+
return;
2310+
2311+
mutex_enter(&shl->procfs_list.pl_lock);
2312+
for (sip = list_tail(&shl->procfs_list.pl_list); sip != NULL;
2313+
sip = list_prev(&shl->procfs_list.pl_list, sip)) {
2314+
if (sip->pool_guid == pool_guid) {
2315+
if (sip->spa_load_notes != NULL) {
2316+
spa_strfree(sip->spa_load_notes);
2317+
sip->spa_load_notes = NULL;
2318+
}
2319+
if (notes != NULL) {
2320+
sip->spa_load_notes = spa_strdup(notes);
2321+
if (log_dbgmsg) {
2322+
zfs_dbgmsg("'%s' %s", sip->pool_name,
2323+
notes);
2324+
}
2325+
}
2326+
break;
2327+
}
2328+
}
2329+
mutex_exit(&shl->procfs_list.pl_lock);
2330+
}
2331+
2332+
void
2333+
spa_import_progress_set_notes(spa_t *spa, const char *notes)
2334+
{
2335+
spa_import_progress_set_notes_impl(spa, notes, B_TRUE);
2336+
}
2337+
2338+
void
2339+
spa_import_progress_set_notes_nolog(spa_t *spa, const char *notes)
2340+
{
2341+
spa_import_progress_set_notes_impl(spa, notes, B_FALSE);
2342+
}
2343+
22902344
int
22912345
spa_import_progress_set_max_txg(uint64_t pool_guid, uint64_t load_max_txg)
22922346
{
@@ -2355,6 +2409,7 @@ spa_import_progress_add(spa_t *spa)
23552409
poolname = spa_name(spa);
23562410
sip->pool_name = spa_strdup(poolname);
23572411
sip->spa_load_state = spa_load_state(spa);
2412+
sip->spa_load_notes = NULL;
23582413

23592414
mutex_enter(&shl->procfs_list.pl_lock);
23602415
procfs_list_add(&shl->procfs_list, sip);
@@ -2374,6 +2429,8 @@ spa_import_progress_remove(uint64_t pool_guid)
23742429
if (sip->pool_guid == pool_guid) {
23752430
if (sip->pool_name)
23762431
spa_strfree(sip->pool_name);
2432+
if (sip->spa_load_notes)
2433+
spa_strfree(sip->spa_load_notes);
23772434
list_remove(&shl->procfs_list.pl_list, sip);
23782435
shl->size--;
23792436
kmem_free(sip, sizeof (spa_import_progress_t));

tests/runfiles/linux.run

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ tags = ['functional', 'cli_root', 'zpool_expand']
8686
tests = ['zpool_import_hostid_changed',
8787
'zpool_import_hostid_changed_unclean_export',
8888
'zpool_import_hostid_changed_cachefile',
89-
'zpool_import_hostid_changed_cachefile_unclean_export']
89+
'zpool_import_hostid_changed_cachefile_unclean_export',
90+
'zpool_import_status']
9091
tags = ['functional', 'cli_root', 'zpool_import']
9192

9293
[tests/functional/cli_root/zpool_reopen:Linux]

0 commit comments

Comments
 (0)