1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

hints: fix recreating hints from pvscan

When aay was included in the pvscan --cache command,
the activation part was complaining about the unusual
state of the hint file since it had been recreated
just prior.
This commit is contained in:
David Teigland 2019-02-13 15:23:43 -06:00
parent 3ebce8dbd2
commit 0aa51a2f61
3 changed files with 38 additions and 5 deletions

View File

@ -1025,6 +1025,34 @@ void clear_hint_file(struct cmd_context *cmd)
stack; 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 * This is used when pvscan --cache sees a new PV, which
* means we should refresh hints. It could catch some case * 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. * so this has to be checked before the cmd->use_hints check.
*/ */
if (cmd->pvscan_recreate_hints) { 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 */ /* create new hints after scan */
log_debug("get_hints: pvscan recreate"); log_debug("get_hints: pvscan recreate");
*newhints = NEWHINTS_FILE; *newhints = NEWHINTS_FILE;

View File

@ -37,5 +37,7 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints);
void hints_exit(void); void hints_exit(void);
void pvscan_recreate_hints_begin(struct cmd_context *cmd);
#endif #endif

View File

@ -660,17 +660,20 @@ int pvscan_cache_cmd(struct cmd_context *cmd, int argc, char **argv)
if (!argc && !devno_args) { if (!argc && !devno_args) {
/* /*
* pvscan --cache removes existing hints and recreates new ones. * pvscan --cache removes existing hints and recreates new ones.
* We begin by clearing hints at the start of the command like * We begin by clearing hints at the start of the command.
* vgcreate would do. The pvscan_recreate_hints flag is used * The pvscan_recreate_hints flag is used to enable the
* to enable the special case hint recreation in label_scan. * special case hint recreation in label_scan.
*/ */
cmd->pvscan_recreate_hints = 1; cmd->pvscan_recreate_hints = 1;
clear_hint_file(cmd); pvscan_recreate_hints_begin(cmd);
log_verbose("pvscan all devices."); log_verbose("pvscan all devices.");
_online_pvid_files_remove(); _online_pvid_files_remove();
_online_pvscan_all_devs(cmd, NULL, NULL); _online_pvscan_all_devs(cmd, NULL, NULL);
all_vgs = 1; all_vgs = 1;
cmd->pvscan_recreate_hints = 0;
cmd->use_hints = 0;
goto activate; goto activate;
} }