diff --git a/lib/label/hints.c b/lib/label/hints.c index 4fe44b023..a2e76468a 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -1025,6 +1025,34 @@ void clear_hint_file(struct cmd_context *cmd) stack; } +/* + * This is only used at the start of pvscan --cache [-aay] to + * set up for recreating the hint file. + */ +void pvscan_recreate_hints_begin(struct cmd_context *cmd) +{ + /* No commands are using hints. */ + if (!cmd->enable_hints) + return; + + log_debug("pvscan_recreate_hints_begin"); + + if (!_touch_hints()) + return; + + /* limit potential delay blocking on hints lock next */ + if (!_touch_nohints()) + stack; + + if (!_lock_hints(LOCK_EX, 0)) + stack; + + _unlink_nohints(); + + if (!_clear_hints(cmd)) + stack; +} + /* * This is used when pvscan --cache sees a new PV, which * means we should refresh hints. It could catch some case @@ -1136,7 +1164,7 @@ int get_hints(struct cmd_context *cmd, struct dm_list *hints, int *newhints, * so this has to be checked before the cmd->use_hints check. */ if (cmd->pvscan_recreate_hints) { - /* clear_hint_file already locked hints ex */ + /* pvscan_recreate_hints_begin already locked hints ex */ /* create new hints after scan */ log_debug("get_hints: pvscan recreate"); *newhints = NEWHINTS_FILE; diff --git a/lib/label/hints.h b/lib/label/hints.h index 469e8c41d..0134f1e97 100644 --- a/lib/label/hints.h +++ b/lib/label/hints.h @@ -37,5 +37,7 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints); void hints_exit(void); +void pvscan_recreate_hints_begin(struct cmd_context *cmd); + #endif diff --git a/tools/pvscan.c b/tools/pvscan.c index 098c50261..55b6f5ff2 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -660,17 +660,20 @@ int pvscan_cache_cmd(struct cmd_context *cmd, int argc, char **argv) if (!argc && !devno_args) { /* * pvscan --cache removes existing hints and recreates new ones. - * We begin by clearing hints at the start of the command like - * vgcreate would do. The pvscan_recreate_hints flag is used - * to enable the special case hint recreation in label_scan. + * We begin by clearing hints at the start of the command. + * The pvscan_recreate_hints flag is used to enable the + * special case hint recreation in label_scan. */ cmd->pvscan_recreate_hints = 1; - clear_hint_file(cmd); + pvscan_recreate_hints_begin(cmd); log_verbose("pvscan all devices."); _online_pvid_files_remove(); _online_pvscan_all_devs(cmd, NULL, NULL); all_vgs = 1; + + cmd->pvscan_recreate_hints = 0; + cmd->use_hints = 0; goto activate; }