Skip to content

Commit 082ac26

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 5796e3a commit 082ac26

File tree

6 files changed

+230
-5
lines changed

6 files changed

+230
-5
lines changed

include/sys/spa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,8 @@ 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(uint64_t pool_guid,
975+
const char *notes);
974976

975977
/* Pool configuration locks */
976978
extern int spa_config_tryenter(spa_t *spa, int locks, const void *tag,

module/zfs/spa.c

Lines changed: 37 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_guid(spa), "spa_load()");
31123113

31133114
gethrestime(&spa->spa_loaded_ts);
31143115
error = spa_load_impl(spa, type, &ereport);
@@ -4995,6 +4996,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
49954996
/*
49964997
* Retrieve the checkpoint txg if the pool has a checkpoint.
49974998
*/
4999+
spa_import_progress_set_notes(spa_guid(spa), "Loading checkpoint txg");
49985000
error = spa_ld_read_checkpoint_txg(spa);
49995001
if (error != 0)
50005002
return (error);
@@ -5007,6 +5009,8 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50075009
* initiated. Otherwise we could be reading from indirect vdevs before
50085010
* we have loaded their mappings.
50095011
*/
5012+
spa_import_progress_set_notes(spa_guid(spa),
5013+
"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_guid(spa), "Checking feature flags");
50185023
error = spa_ld_check_features(spa, &missing_feat_write);
50195024
if (error != 0)
50205025
return (error);
@@ -5023,13 +5028,16 @@ 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_guid(spa),
5032+
"Loading special MOS directories");
50265033
error = spa_ld_load_special_directories(spa);
50275034
if (error != 0)
50285035
return (error);
50295036

50305037
/*
50315038
* Retrieve pool properties from the MOS.
50325039
*/
5040+
spa_import_progress_set_notes(spa_guid(spa), "Loading properties");
50335041
error = spa_ld_get_props(spa);
50345042
if (error != 0)
50355043
return (error);
@@ -5038,6 +5046,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50385046
* Retrieve the list of auxiliary devices - cache devices and spares -
50395047
* and open them.
50405048
*/
5049+
spa_import_progress_set_notes(spa_guid(spa), "Loading AUX vdevs");
50415050
error = spa_ld_open_aux_vdevs(spa, type);
50425051
if (error != 0)
50435052
return (error);
@@ -5046,14 +5055,17 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50465055
* Load the metadata for all vdevs. Also check if unopenable devices
50475056
* should be autoreplaced.
50485057
*/
5058+
spa_import_progress_set_notes(spa_guid(spa), "Loading vdev metadata");
50495059
error = spa_ld_load_vdev_metadata(spa);
50505060
if (error != 0)
50515061
return (error);
50525062

5063+
spa_import_progress_set_notes(spa_guid(spa), "Loading dedup tables");
50535064
error = spa_ld_load_dedup_tables(spa);
50545065
if (error != 0)
50555066
return (error);
50565067

5068+
spa_import_progress_set_notes(spa_guid(spa), "Loading BRT");
50575069
error = spa_ld_load_brt(spa);
50585070
if (error != 0)
50595071
return (error);
@@ -5062,6 +5074,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50625074
* Verify the logs now to make sure we don't have any unexpected errors
50635075
* when we claim log blocks later.
50645076
*/
5077+
spa_import_progress_set_notes(spa_guid(spa), "Verifying Log Devices");
50655078
error = spa_ld_verify_logs(spa, type, ereport);
50665079
if (error != 0)
50675080
return (error);
@@ -5083,6 +5096,7 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50835096
* state. When performing an extreme rewind, we verify the whole pool,
50845097
* which can take a very long time.
50855098
*/
5099+
spa_import_progress_set_notes(spa_guid(spa), "Verifying pool data");
50865100
error = spa_ld_verify_pool_data(spa);
50875101
if (error != 0)
50885102
return (error);
@@ -5092,13 +5106,16 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
50925106
* we write anything to the pool because we'd need to update the space
50935107
* accounting using the deflated sizes.
50945108
*/
5109+
spa_import_progress_set_notes(spa_guid(spa),
5110+
"Calculating deflated space");
50955111
spa_update_dspace(spa);
50965112

50975113
/*
50985114
* We have now retrieved all the information we needed to open the
50995115
* pool. If we are importing the pool in read-write mode, a few
51005116
* additional steps must be performed to finish the import.
51015117
*/
5118+
spa_import_progress_set_notes(spa_guid(spa), "Starting import");
51025119
if (spa_writeable(spa) && (spa->spa_load_state == SPA_LOAD_RECOVER ||
51035120
spa->spa_load_max_txg == UINT64_MAX)) {
51045121
uint64_t config_cache_txg = spa->spa_config_txg;
@@ -5122,6 +5139,8 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51225139
(u_longlong_t)spa->spa_uberblock.ub_checkpoint_txg);
51235140
}
51245141

5142+
spa_import_progress_set_notes(spa_guid(spa),
5143+
"Claiming ZIL blocks");
51255144
/*
51265145
* Traverse the ZIL and claim all blocks.
51275146
*/
@@ -5141,13 +5160,17 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51415160
* will have been set for us by ZIL traversal operations
51425161
* performed above.
51435162
*/
5163+
spa_import_progress_set_notes(spa_guid(spa),
5164+
"Syncing ZIL claims");
51445165
txg_wait_synced(spa->spa_dsl_pool, spa->spa_claim_max_txg);
51455166

51465167
/*
51475168
* Check if we need to request an update of the config. On the
51485169
* next sync, we would update the config stored in vdev labels
51495170
* and the cachefile (by default /etc/zfs/zpool.cache).
51505171
*/
5172+
spa_import_progress_set_notes(spa_guid(spa),
5173+
"Updating configs");
51515174
spa_ld_check_for_config_update(spa, config_cache_txg,
51525175
update_config_cache);
51535176

@@ -5156,6 +5179,8 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51565179
* Then check all DTLs to see if anything needs resilvering.
51575180
* The resilver will be deferred if a rebuild was started.
51585181
*/
5182+
spa_import_progress_set_notes(spa_guid(spa),
5183+
"Starting resilvers");
51595184
if (vdev_rebuild_active(spa->spa_root_vdev)) {
51605185
vdev_rebuild_restart(spa);
51615186
} else if (!dsl_scan_resilvering(spa->spa_dsl_pool) &&
@@ -5169,6 +5194,8 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51695194
*/
51705195
spa_history_log_version(spa, "open", NULL);
51715196

5197+
spa_import_progress_set_notes(spa_guid(spa),
5198+
"Restarting device removals");
51725199
spa_restart_removal(spa);
51735200
spa_spawn_aux_threads(spa);
51745201

@@ -5181,19 +5208,29 @@ spa_load_impl(spa_t *spa, spa_import_type_t type, const char **ereport)
51815208
* auxiliary threads above (from which the livelist
51825209
* deletion zthr is part of).
51835210
*/
5211+
spa_import_progress_set_notes(spa_guid(spa),
5212+
"Cleaning up inconsistent objsets");
51845213
(void) dmu_objset_find(spa_name(spa),
51855214
dsl_destroy_inconsistent, NULL, DS_FIND_CHILDREN);
51865215

51875216
/*
51885217
* Clean up any stale temporary dataset userrefs.
51895218
*/
5219+
spa_import_progress_set_notes(spa_guid(spa),
5220+
"Cleaning up temporary uerrefs");
51905221
dsl_pool_clean_tmp_userrefs(spa->spa_dsl_pool);
51915222

51925223
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
5224+
spa_import_progress_set_notes(spa_guid(spa),
5225+
"Restarting Initialize");
51935226
vdev_initialize_restart(spa->spa_root_vdev);
5227+
spa_import_progress_set_notes(spa_guid(spa),
5228+
"Restarting TRIM");
51945229
vdev_trim_restart(spa->spa_root_vdev);
51955230
vdev_autotrim_restart(spa);
51965231
spa_config_exit(spa, SCL_CONFIG, FTAG);
5232+
spa_import_progress_set_notes(spa_guid(spa),
5233+
"Finished importing");
51975234
}
51985235

51995236
spa_import_progress_remove(spa_guid(spa));

module/zfs/spa_log_spacemap.c

Lines changed: 12 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,16 @@ 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[256];
1190+
(void) snprintf(buf, sizeof (buf),
1191+
"read %llu of %llu log space maps "
1192+
"in %lld ms", (u_longlong_t)nsm,
1193+
(u_longlong_t)avl_numnodes(&spa->spa_sm_logs_by_txg),
1194+
(longlong_t)((gethrtime() - read_logs_starttime)
1195+
/ 1000000));
1196+
1197+
spa_import_progress_set_notes(spa_guid(spa), buf);
1198+
11881199
struct spa_ld_log_sm_arg vla = {
11891200
.slls_spa = spa,
11901201
.slls_txg = sls->sls_txg
@@ -1200,6 +1211,7 @@ spa_ld_log_sm_data(spa_t *spa)
12001211

12011212
pn--;
12021213
ps -= space_map_length(sls->sls_sm);
1214+
nsm++;
12031215
space_map_close(sls->sls_sm);
12041216
sls->sls_sm = NULL;
12051217
sls = AVL_NEXT(&spa->spa_sm_logs_by_txg, sls);

module/zfs/spa_misc.c

Lines changed: 44 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(spa_guid(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,33 @@ spa_import_progress_set_state(uint64_t pool_guid,
22872297
return (error);
22882298
}
22892299

2300+
void
2301+
spa_import_progress_set_notes(uint64_t pool_guid, const char *notes)
2302+
{
2303+
spa_history_list_t *shl = spa_import_progress_list;
2304+
spa_import_progress_t *sip;
2305+
2306+
if (shl->size == 0)
2307+
return;
2308+
2309+
mutex_enter(&shl->procfs_list.pl_lock);
2310+
for (sip = list_tail(&shl->procfs_list.pl_list); sip != NULL;
2311+
sip = list_prev(&shl->procfs_list.pl_list, sip)) {
2312+
if (sip->pool_guid == pool_guid) {
2313+
if (sip->spa_load_notes != NULL) {
2314+
spa_strfree(sip->spa_load_notes);
2315+
sip->spa_load_notes = NULL;
2316+
}
2317+
if (notes != NULL) {
2318+
sip->spa_load_notes = spa_strdup(notes);
2319+
zfs_dbgmsg("'%s' %s", sip->pool_name, notes);
2320+
}
2321+
break;
2322+
}
2323+
}
2324+
mutex_exit(&shl->procfs_list.pl_lock);
2325+
}
2326+
22902327
int
22912328
spa_import_progress_set_max_txg(uint64_t pool_guid, uint64_t load_max_txg)
22922329
{
@@ -2355,6 +2392,7 @@ spa_import_progress_add(spa_t *spa)
23552392
poolname = spa_name(spa);
23562393
sip->pool_name = spa_strdup(poolname);
23572394
sip->spa_load_state = spa_load_state(spa);
2395+
sip->spa_load_notes = NULL;
23582396

23592397
mutex_enter(&shl->procfs_list.pl_lock);
23602398
procfs_list_add(&shl->procfs_list, sip);
@@ -2374,6 +2412,8 @@ spa_import_progress_remove(uint64_t pool_guid)
23742412
if (sip->pool_guid == pool_guid) {
23752413
if (sip->pool_name)
23762414
spa_strfree(sip->pool_name);
2415+
if (sip->spa_load_notes)
2416+
spa_strfree(sip->spa_load_notes);
23772417
list_remove(&shl->procfs_list.pl_list, sip);
23782418
shl->size--;
23792419
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)