static struct dm_hash_table *_vgid_hash = NULL;
static struct dm_hash_table *_vgname_hash = NULL;
static DM_LIST_INIT(_vginfos);
-static DM_LIST_INIT(_found_duplicate_devs);
-static DM_LIST_INIT(_unused_duplicate_devs);
+static DM_LIST_INIT(_initial_duplicates);
+static DM_LIST_INIT(_unused_duplicates);
static DM_LIST_INIT(_prev_unused_duplicate_devs);
static int _vgs_locked = 0;
static int _found_duplicate_pvs = 0; /* If we never see a duplicate PV we can skip checking for them later. */
_vgs_locked = 0;
dm_list_init(&_vginfos);
- dm_list_init(&_found_duplicate_devs);
- dm_list_init(&_unused_duplicate_devs);
+ dm_list_init(&_initial_duplicates);
+ dm_list_init(&_unused_duplicates);
dm_list_init(&_prev_unused_duplicate_devs);
if (!(_vgname_hash = dm_hash_create(128)))
}
}
-/*
- * When lvmcache sees a duplicate PV, this is set.
- * process_each_pv() can avoid searching for duplicates
- * by checking this and seeing that no duplicate PVs exist.
- *
- *
- * found_duplicate_pvs tells the process_each_pv code
- * to search the devices list for duplicates, so that
- * devices can be processed together with their
- * duplicates (while processing the VG, rather than
- * reporting pv->dev under the VG, and its duplicate
- * outside the VG context.)
- */
-int lvmcache_found_duplicate_pvs(void)
+bool lvmcache_has_duplicate_devs(void)
{
- return _found_duplicate_pvs;
+ return _found_duplicate_pvs ? true : false;
}
int lvmcache_found_duplicate_vgnames(void)
return _found_duplicate_vgnames;
}
-int lvmcache_get_unused_duplicate_devs(struct cmd_context *cmd, struct dm_list *head)
+int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head)
{
struct device_list *devl, *devl2;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (!(devl2 = dm_pool_alloc(cmd->mem, sizeof(*devl2)))) {
log_error("device_list element allocation failed");
return 0;
return 1;
}
-void lvmcache_remove_unchosen_duplicate(struct device *dev)
+void lvmcache_del_dev_from_duplicates(struct device *dev)
{
struct device_list *devl;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (devl->dev == dev) {
dm_list_del(&devl->list);
return;
}
}
-static void _destroy_duplicate_device_list(struct dm_list *head)
+static void _destroy_device_list(struct dm_list *head)
{
struct device_list *devl, *devl2;
struct device_list *devl;
dm_list_iterate_items(pvl, &vg->pvs) {
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (id_equal(&pvl->pv->id, (const struct id *)devl->dev->pvid))
return 1;
}
return 0;
}
-int lvmcache_dev_is_unchosen_duplicate(struct device *dev)
+bool lvmcache_dev_is_unused_duplicate(struct device *dev)
{
- return dev_in_device_list(dev, &_unused_duplicate_devs);
+ return dev_in_device_list(dev, &_unused_duplicates) ? true : false;
}
/*
struct lvmcache_info *info;
struct device_list *devl, *devl2;
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
continue;
}
}
- if (dm_list_empty(&_unused_duplicate_devs))
+ if (dm_list_empty(&_unused_duplicates))
_found_duplicate_pvs = 0;
}
-static void _warn_duplicate_devs(struct cmd_context *cmd)
+static void _warn_unused_duplicates(struct cmd_context *cmd)
{
char uuid[64] __attribute__((aligned(8)));
struct lvmcache_info *info;
struct device_list *devl, *devl2;
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
if (!id_write_format((const struct id *)devl->dev->pvid, uuid, sizeof(uuid)))
stack;
log_warn("WARNING: Not using device %s for PV %s.", dev_name(devl->dev), uuid);
}
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
/* info for the preferred device that we're actually using */
if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
continue;
}
/*
- * Compare _found_duplicate_devs entries with the corresponding duplicate dev
- * in lvmcache. There may be multiple duplicates in _found_duplicate_devs for
- * a given pvid. If a dev from _found_duplicate_devs is preferred over the dev
+ * Compare _initial_duplicates entries with the corresponding duplicate dev
+ * in lvmcache. There may be multiple duplicates in _initial_duplicates for
+ * a given pvid. If a dev from _initial_duplicates is preferred over the dev
* in lvmcache, then drop the dev in lvmcache and rescan the preferred dev to
* add it to lvmcache.
*
- * _found_duplicate_devs: duplicate devs found during initial scan.
+ * _initial_duplicates: duplicate devs found during initial scan.
* These are compared to lvmcache devs to see if any are preferred.
*
- * _unused_duplicate_devs: duplicate devs not chosen to be used.
- * These are _found_duplicate_devs entries that were not chosen,
+ * _unused_duplicates: duplicate devs not chosen to be used.
+ * These are _initial_duplicates entries that were not chosen,
* or unpreferred lvmcache devs that were dropped.
*
* del_cache_devs: devices to drop from lvmcache
* add_cache_devs: devices to scan to add to lvmcache
*/
-static void _choose_preferred_devs(struct cmd_context *cmd,
- struct dm_list *del_cache_devs,
- struct dm_list *add_cache_devs)
+static void _choose_duplicates(struct cmd_context *cmd,
+ struct dm_list *del_cache_devs,
+ struct dm_list *add_cache_devs)
{
const char *reason;
struct dm_list altdevs;
dm_list_init(&altdevs);
alt = NULL;
- dm_list_iterate_items_safe(devl, devl_safe, &_found_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl_safe, &_initial_duplicates) {
if (!alt) {
dm_list_move(&altdevs, &devl->list);
alt = devl;
}
if (!alt) {
- _destroy_duplicate_device_list(&_unused_duplicate_devs);
- dm_list_splice(&_unused_duplicate_devs, &new_unused);
+ _destroy_device_list(&_unused_duplicates);
+ dm_list_splice(&_unused_duplicates, &new_unused);
return;
}
continue;
}
- prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicate_devs);
- prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicate_devs);
+ prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicates);
+ prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicates);
if (!prev_unchosen1 && !prev_unchosen2) {
/*
}
/*
- * alt devs not chosen are moved to _unused_duplicate_devs.
- * del_cache_devs being dropped are moved to _unused_duplicate_devs
- * after being dropped. So, _unused_duplicate_devs represents all
+ * alt devs not chosen are moved to _unused_duplicates.
+ * del_cache_devs being dropped are moved to _unused_duplicates
+ * after being dropped. So, _unused_duplicates represents all
* duplicates not being used in lvmcache.
*/
log_error("Scan failed to refresh device filter.");
/*
- * Duplicates found during this label scan are added to _found_duplicate_devs().
+ * Duplicates found during this label scan are added to _initial_duplicates().
*/
- _destroy_duplicate_device_list(&_found_duplicate_devs);
+ _destroy_device_list(&_initial_duplicates);
/*
* Do the actual scanning. This populates lvmcache
label_scan(cmd);
/*
- * _choose_preferred_devs() returns:
+ * _choose_duplicates() returns:
*
* . del_cache_devs: a list of devs currently in lvmcache that should
* be removed from lvmcache because they will be replaced with
* the devs that are preferred to add them to lvmcache.
*
* Keep a complete list of all devs that are unused by moving the
- * del_cache_devs onto _unused_duplicate_devs.
+ * del_cache_devs onto _unused_duplicates.
*/
- if (!dm_list_empty(&_found_duplicate_devs)) {
+ if (!dm_list_empty(&_initial_duplicates)) {
dm_list_init(&del_cache_devs);
dm_list_init(&add_cache_devs);
log_debug_cache("Resolving duplicate devices");
- _choose_preferred_devs(cmd, &del_cache_devs, &add_cache_devs);
+ _choose_duplicates(cmd, &del_cache_devs, &add_cache_devs);
dm_list_iterate_items(devl, &del_cache_devs) {
log_debug_cache("Drop duplicate device %s in lvmcache", dev_name(devl->dev));
label_read(devl->dev);
}
- dm_list_splice(&_unused_duplicate_devs, &del_cache_devs);
+ dm_list_splice(&_unused_duplicates, &del_cache_devs);
/*
* This may remove some entries from the unused_duplicates list for
* Warn about remaining duplicates that may actually be separate copies of
* the same device.
*/
- _warn_duplicate_devs(cmd);
+ _warn_unused_duplicates(cmd);
}
r = 1;
return NULL;
}
-int lvmcache_pvid_in_unchosen_duplicates(const char *pvid)
+int lvmcache_pvid_in_unused_duplicates(const char *pvid)
{
struct device_list *devl;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (!strncmp(devl->dev->pvid, pvid, ID_LEN))
return 1;
}
return_NULL;
devl->dev = dev;
- dm_list_add(&_found_duplicate_devs, &devl->list);
+ dm_list_add(&_initial_duplicates, &devl->list);
_found_duplicate_pvs = 1;
if (is_duplicate)
*is_duplicate = 1;
dm_list_init(&_vginfos);
/*
- * Move the current _unused_duplicate_devs to _prev_unused_duplicate_devs
- * before destroying _unused_duplicate_devs.
+ * Move the current _unused_duplicates to _prev_unused_duplicate_devs
+ * before destroying _unused_duplicates.
*
* One command can init/populate/destroy lvmcache multiple times. Each
* time it will encounter duplicates and choose the preferrred devs.
* the unpreferred devs here so that _choose_preferred_devs can use
* this to make the same choice each time.
*/
- _destroy_duplicate_device_list(&_prev_unused_duplicate_devs);
- dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicate_devs);
- _destroy_duplicate_device_list(&_unused_duplicate_devs);
- _destroy_duplicate_device_list(&_found_duplicate_devs); /* should be empty anyway */
+ _destroy_device_list(&_prev_unused_duplicate_devs);
+ dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicates);
+ _destroy_device_list(&_unused_duplicates);
+ _destroy_device_list(&_initial_duplicates); /* should be empty anyway */
_found_duplicate_pvs = 0;
if (retain_orphans) {