1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dev_cache: clean up scan

Pull out all of the twisted logic and simply call dev_cache_scan
at the start of the command prior to label scan.
This commit is contained in:
David Teigland 2018-04-09 11:13:43 -05:00
parent 89c65d4f71
commit c0973e70a5
14 changed files with 16 additions and 82 deletions

View File

@ -661,7 +661,6 @@ int do_refresh_cache(void)
return -1; return -1;
} }
init_full_scan_done(0);
init_ignore_suspended_devices(1); init_ignore_suspended_devices(1);
lvmcache_force_next_label_scan(); lvmcache_force_next_label_scan();
lvmcache_label_scan(cmd); lvmcache_label_scan(cmd);

View File

@ -157,6 +157,8 @@ void lvmcache_seed_infos_from_lvmetad(struct cmd_context *cmd)
if (!lvmetad_used() || _has_scanned) if (!lvmetad_used() || _has_scanned)
return; return;
dev_cache_scan();
if (!lvmetad_pv_list_to_lvmcache(cmd)) { if (!lvmetad_pv_list_to_lvmcache(cmd)) {
stack; stack;
return; return;
@ -357,9 +359,6 @@ void lvmcache_drop_metadata(const char *vgname, int drop_precommitted)
_drop_metadata(FMT_TEXT_ORPHAN_VG_NAME, 0); _drop_metadata(FMT_TEXT_ORPHAN_VG_NAME, 0);
_drop_metadata(FMT_LVM1_ORPHAN_VG_NAME, 0); _drop_metadata(FMT_LVM1_ORPHAN_VG_NAME, 0);
_drop_metadata(FMT_POOL_ORPHAN_VG_NAME, 0); _drop_metadata(FMT_POOL_ORPHAN_VG_NAME, 0);
/* Indicate that PVs could now be missing from the cache */
init_full_scan_done(0);
} else } else
_drop_metadata(vgname, drop_precommitted); _drop_metadata(vgname, drop_precommitted);
} }

View File

@ -1648,7 +1648,6 @@ static void _init_rand(struct cmd_context *cmd)
static void _init_globals(struct cmd_context *cmd) static void _init_globals(struct cmd_context *cmd)
{ {
init_full_scan_done(0);
init_mirror_in_sync(0); init_mirror_in_sync(0);
} }

View File

@ -1077,12 +1077,11 @@ static int _insert(const char *path, const struct stat *info,
return 1; return 1;
} }
static void _full_scan(int dev_scan) void dev_cache_scan(void)
{ {
struct dir_list *dl; struct dir_list *dl;
if (_cache.has_scanned && !dev_scan) _cache.has_scanned = 1;
return;
_insert_dirs(&_cache.dirs); _insert_dirs(&_cache.dirs);
@ -1090,9 +1089,6 @@ static void _full_scan(int dev_scan)
dm_list_iterate_items(dl, &_cache.files) dm_list_iterate_items(dl, &_cache.files)
_insert_file(dl->dir); _insert_file(dl->dir);
_cache.has_scanned = 1;
init_full_scan_done(1);
} }
int dev_cache_has_scanned(void) int dev_cache_has_scanned(void)
@ -1100,14 +1096,6 @@ int dev_cache_has_scanned(void)
return _cache.has_scanned; return _cache.has_scanned;
} }
void dev_cache_scan(int do_scan)
{
if (!do_scan)
_cache.has_scanned = 1;
else
_full_scan(1);
}
static int _init_preferred_names(struct cmd_context *cmd) static int _init_preferred_names(struct cmd_context *cmd)
{ {
const struct dm_config_node *cn; const struct dm_config_node *cn;
@ -1171,7 +1159,6 @@ out:
int dev_cache_init(struct cmd_context *cmd) int dev_cache_init(struct cmd_context *cmd)
{ {
_cache.names = NULL; _cache.names = NULL;
_cache.has_scanned = 0;
if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024))) if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024)))
return_0; return_0;
@ -1413,7 +1400,7 @@ struct device *dev_cache_get(const char *name, struct dev_filter *f)
_insert(name, info_available ? &buf : NULL, 0, obtain_device_list_from_udev()); _insert(name, info_available ? &buf : NULL, 0, obtain_device_list_from_udev());
d = (struct device *) dm_hash_lookup(_cache.names, name); d = (struct device *) dm_hash_lookup(_cache.names, name);
if (!d) { if (!d) {
_full_scan(0); dev_cache_scan();
d = (struct device *) dm_hash_lookup(_cache.names, name); d = (struct device *) dm_hash_lookup(_cache.names, name);
} }
} }
@ -1469,7 +1456,7 @@ struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f)
} }
} }
_full_scan(0); dev_cache_scan();
d = _dev_cache_seek_devt(dev); d = _dev_cache_seek_devt(dev);
} }
@ -1477,17 +1464,7 @@ struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f)
f->passes_filter(f, d))) ? d : NULL; f->passes_filter(f, d))) ? d : NULL;
} }
void dev_cache_full_scan(struct dev_filter *f) struct dev_iter *dev_iter_create(struct dev_filter *f, int unused)
{
if (f && f->wipe) {
f->wipe(f); /* might call _full_scan(1) */
if (!full_scan_done())
_full_scan(1);
} else
_full_scan(1);
}
struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
{ {
struct dev_iter *di = dm_malloc(sizeof(*di)); struct dev_iter *di = dm_malloc(sizeof(*di));
@ -1496,13 +1473,6 @@ struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
return NULL; return NULL;
} }
if (dev_scan && !trust_cache()) {
/* Flag gets reset between each command */
if (!full_scan_done())
dev_cache_full_scan(f);
} else
_full_scan(0);
di->current = btree_first(_cache.devices); di->current = btree_first(_cache.devices);
di->filter = f; di->filter = f;
if (di->filter) if (di->filter)

View File

@ -46,10 +46,8 @@ int dev_cache_exit(void);
*/ */
int dev_cache_check_for_open_devices(void); int dev_cache_check_for_open_devices(void);
/* Trigger(1) or avoid(0) a scan */ void dev_cache_scan(void);
void dev_cache_scan(int do_scan);
int dev_cache_has_scanned(void); int dev_cache_has_scanned(void);
void dev_cache_full_scan(struct dev_filter *f);
int dev_cache_add_dir(const char *path); int dev_cache_add_dir(const char *path);
int dev_cache_add_loopfile(const char *path); int dev_cache_add_loopfile(const char *path);
@ -66,7 +64,7 @@ void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev);
* Object for iterating through the cache. * Object for iterating through the cache.
*/ */
struct dev_iter; struct dev_iter;
struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan); struct dev_iter *dev_iter_create(struct dev_filter *f, int unused);
void dev_iter_destroy(struct dev_iter *iter); void dev_iter_destroy(struct dev_iter *iter);
struct device *dev_iter_get(struct dev_iter *iter); struct device *dev_iter_get(struct dev_iter *iter);

View File

@ -48,11 +48,7 @@ static void _persistent_filter_wipe(struct dev_filter *f)
{ {
struct pfilter *pf = (struct pfilter *) f->private; struct pfilter *pf = (struct pfilter *) f->private;
log_verbose("Wiping cache of LVM-capable devices");
dm_hash_wipe(pf->devices); dm_hash_wipe(pf->devices);
/* Trigger complete device scan */
dev_cache_scan(1);
} }
static int _read_array(struct pfilter *pf, struct dm_config_tree *cft, static int _read_array(struct pfilter *pf, struct dm_config_tree *cft,
@ -126,15 +122,6 @@ int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out
/* _read_array(pf, cft, "persistent_filter_cache/invalid_devices", /* _read_array(pf, cft, "persistent_filter_cache/invalid_devices",
PF_BAD_DEVICE); */ PF_BAD_DEVICE); */
/* Did we find anything? */
if (dm_hash_get_num_entries(pf->devices)) {
/* We populated dev_cache ourselves */
dev_cache_scan(0);
if (!dev_cache_index_devs())
stack;
r = 1;
}
log_very_verbose("Loaded persistent filter cache from %s", pf->file); log_very_verbose("Loaded persistent filter cache from %s", pf->file);
out: out:

View File

@ -631,7 +631,7 @@ int label_scan(struct cmd_context *cmd)
* on it. This info will be used by the vg_read() phase of the * on it. This info will be used by the vg_read() phase of the
* command. * command.
*/ */
dev_cache_full_scan(cmd->full_filter); dev_cache_scan();
if (!(iter = dev_iter_create(cmd->full_filter, 0))) { if (!(iter = dev_iter_create(cmd->full_filter, 0))) {
log_error("Scanning failed to get devices."); log_error("Scanning failed to get devices.");

View File

@ -28,7 +28,6 @@ static int _md_filtering = 0;
static int _internal_filtering = 0; static int _internal_filtering = 0;
static int _fwraid_filtering = 0; static int _fwraid_filtering = 0;
static int _pvmove = 0; static int _pvmove = 0;
static int _full_scan_done = 0; /* Restrict to one full scan during each cmd */
static int _obtain_device_list_from_udev = DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV; static int _obtain_device_list_from_udev = DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV;
static enum dev_ext_e _external_device_info_source = DEV_EXT_NONE; static enum dev_ext_e _external_device_info_source = DEV_EXT_NONE;
static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */ static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */
@ -92,11 +91,6 @@ void init_pvmove(int level)
_pvmove = level; _pvmove = level;
} }
void init_full_scan_done(int level)
{
_full_scan_done = level;
}
void init_obtain_device_list_from_udev(int device_list_from_udev) void init_obtain_device_list_from_udev(int device_list_from_udev)
{ {
_obtain_device_list_from_udev = device_list_from_udev; _obtain_device_list_from_udev = device_list_from_udev;
@ -253,11 +247,6 @@ int pvmove_mode(void)
return _pvmove; return _pvmove;
} }
int full_scan_done(void)
{
return _full_scan_done;
}
int obtain_device_list_from_udev(void) int obtain_device_list_from_udev(void)
{ {
return _obtain_device_list_from_udev; return _obtain_device_list_from_udev;

View File

@ -29,7 +29,6 @@ void init_md_filtering(int level);
void init_internal_filtering(int level); void init_internal_filtering(int level);
void init_fwraid_filtering(int level); void init_fwraid_filtering(int level);
void init_pvmove(int level); void init_pvmove(int level);
void init_full_scan_done(int level);
void init_external_device_info_source(enum dev_ext_e src); void init_external_device_info_source(enum dev_ext_e src);
void init_obtain_device_list_from_udev(int device_list_from_udev); void init_obtain_device_list_from_udev(int device_list_from_udev);
void init_trust_cache(int trustcache); void init_trust_cache(int trustcache);
@ -63,7 +62,6 @@ int md_filtering(void);
int internal_filtering(void); int internal_filtering(void);
int fwraid_filtering(void); int fwraid_filtering(void);
int pvmove_mode(void); int pvmove_mode(void);
int full_scan_done(void);
int obtain_device_list_from_udev(void); int obtain_device_list_from_udev(void);
enum dev_ext_e external_device_info_source(void); enum dev_ext_e external_device_info_source(void);
int trust_cache(void); int trust_cache(void);

View File

@ -2446,7 +2446,6 @@ static void _apply_current_settings(struct cmd_context *cmd)
_apply_current_output_settings(cmd); _apply_current_output_settings(cmd);
init_test(cmd->current_settings.test); init_test(cmd->current_settings.test);
init_full_scan_done(0);
init_mirror_in_sync(0); init_mirror_in_sync(0);
init_dmeventd_monitor(DEFAULT_DMEVENTD_MONITOR); init_dmeventd_monitor(DEFAULT_DMEVENTD_MONITOR);

View File

@ -123,13 +123,12 @@ static void _nanosleep(unsigned secs, unsigned allow_zero_time)
while (!nanosleep(&wtime, &wtime) && errno == EINTR) {} while (!nanosleep(&wtime, &wtime) && errno == EINTR) {}
} }
static void _sleep_and_rescan_devices(struct daemon_parms *parms) static void _sleep_and_rescan_devices(struct cmd_context *cmd, struct daemon_parms *parms)
{ {
if (parms->interval && !parms->aborting) { if (parms->interval && !parms->aborting) {
dev_close_all(); dev_close_all();
_nanosleep(parms->interval, 1); _nanosleep(parms->interval, 1);
/* Devices might have changed while we slept */ lvmcache_label_scan(cmd);
init_full_scan_done(0);
} }
} }
@ -145,7 +144,7 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id,
/* Poll for completion */ /* Poll for completion */
while (!finished) { while (!finished) {
if (parms->wait_before_testing) if (parms->wait_before_testing)
_sleep_and_rescan_devices(parms); _sleep_and_rescan_devices(cmd, parms);
/* /*
* An ex VG lock is needed because the check can call finish_copy * An ex VG lock is needed because the check can call finish_copy
@ -218,7 +217,7 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id,
* continue polling an LV that doesn't have a "status". * continue polling an LV that doesn't have a "status".
*/ */
if (!parms->wait_before_testing && !finished) if (!parms->wait_before_testing && !finished)
_sleep_and_rescan_devices(parms); _sleep_and_rescan_devices(cmd, parms);
} }
return 1; return 1;

View File

@ -288,8 +288,6 @@ static int _pvscan_autoactivate(struct cmd_context *cmd, struct pvscan_aa_params
pp->refresh_all = 1; pp->refresh_all = 1;
} }
dev_cache_full_scan(cmd->full_filter);
ret = process_each_vg(cmd, 0, NULL, NULL, vgnames, 0, 0, handle, _pvscan_autoactivate_single); ret = process_each_vg(cmd, 0, NULL, NULL, vgnames, 0, 0, handle, _pvscan_autoactivate_single);
destroy_processing_handle(cmd, handle); destroy_processing_handle(cmd, handle);
@ -495,6 +493,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
} }
if (!dm_list_empty(&single_devs)) { if (!dm_list_empty(&single_devs)) {
dev_cache_scan();
label_scan_devs(cmd, &single_devs); label_scan_devs(cmd, &single_devs);
dm_list_iterate_items(devl, &single_devs) { dm_list_iterate_items(devl, &single_devs) {
@ -540,6 +539,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv)
} }
if (!dm_list_empty(&single_devs)) { if (!dm_list_empty(&single_devs)) {
dev_cache_scan();
label_scan_devs(cmd, &single_devs); label_scan_devs(cmd, &single_devs);
dm_list_iterate_items(devl, &single_devs) { dm_list_iterate_items(devl, &single_devs) {

View File

@ -5503,8 +5503,6 @@ int pvcreate_each_device(struct cmd_context *cmd,
return 0; return 0;
} }
dev_cache_full_scan(cmd->full_filter);
lvmcache_label_scan(cmd); lvmcache_label_scan(cmd);
/* /*

View File

@ -332,7 +332,6 @@ retry_name:
dm_list_iterate_items(vd, &vp.arg_import) dm_list_iterate_items(vd, &vp.arg_import)
internal_filter_allow(cmd->mem, vd->dev); internal_filter_allow(cmd->mem, vd->dev);
lvmcache_destroy(cmd, 1, 0); lvmcache_destroy(cmd, 1, 0);
dev_cache_full_scan(cmd->full_filter);
log_debug("Changing VG %s to %s.", vp.old_vgname, vp.new_vgname); log_debug("Changing VG %s to %s.", vp.old_vgname, vp.new_vgname);