mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
process_each_label: use lvmcache
In the same way as the other process_each functions. In the common case all the info that's needed can be used from lvmcache after a label scan. But this means that unchosen devs for duplicate PVs need to be handled explicitly.
This commit is contained in:
parent
f17c2cf7c6
commit
4343280ebc
@ -1493,13 +1493,19 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
|
|||||||
struct label *label;
|
struct label *label;
|
||||||
struct dev_iter *iter;
|
struct dev_iter *iter;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
struct lvmcache_info *info;
|
||||||
|
struct dm_list process_duplicates;
|
||||||
|
struct device_list *devl;
|
||||||
int ret_max = ECMD_PROCESSED;
|
int ret_max = ECMD_PROCESSED;
|
||||||
int ret;
|
int ret;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
|
|
||||||
|
dm_list_init(&process_duplicates);
|
||||||
|
|
||||||
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
|
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
|
||||||
|
|
||||||
|
lvmcache_label_scan(cmd);
|
||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
for (; opt < argc; opt++) {
|
for (; opt < argc; opt++) {
|
||||||
if (!(dev = dev_cache_get(argv[opt], cmd->full_filter))) {
|
if (!(dev = dev_cache_get(argv[opt], cmd->full_filter))) {
|
||||||
@ -1509,15 +1515,55 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_set_report_object_name_and_id(dev_name(dev), NULL);
|
if (!(label = lvmcache_get_dev_label(dev))) {
|
||||||
|
if (!lvmcache_dev_is_unchosen_duplicate(dev)) {
|
||||||
if (!label_read(dev, &label, 0)) {
|
log_error("No physical volume label read from %s.", argv[opt]);
|
||||||
log_error("No physical volume label read from %s.",
|
|
||||||
argv[opt]);
|
|
||||||
ret_max = ECMD_FAILED;
|
ret_max = ECMD_FAILED;
|
||||||
|
} else {
|
||||||
|
if (!(devl = dm_malloc(sizeof(*devl))))
|
||||||
|
return_0;
|
||||||
|
devl->dev = dev;
|
||||||
|
dm_list_add(&process_duplicates, &devl->list);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_set_report_object_name_and_id(dev_name(dev), NULL);
|
||||||
|
|
||||||
|
ret = process_single_label(cmd, label, handle);
|
||||||
|
report_log_ret_code(ret);
|
||||||
|
|
||||||
|
if (ret > ret_max)
|
||||||
|
ret_max = ret;
|
||||||
|
|
||||||
|
log_set_report_object_name_and_id(NULL, NULL);
|
||||||
|
|
||||||
|
if (sigint_caught())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dm_list_iterate_items(devl, &process_duplicates) {
|
||||||
|
/*
|
||||||
|
* remove the existing dev for this pvid from lvmcache
|
||||||
|
* so that the duplicate dev can replace it.
|
||||||
|
*/
|
||||||
|
if ((info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
|
||||||
|
lvmcache_del(info);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add info to lvmcache from the duplicate dev.
|
||||||
|
*/
|
||||||
|
label_read(devl->dev, NULL, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the info/label should now be found because
|
||||||
|
* the label_read should have added it.
|
||||||
|
*/
|
||||||
|
if (!(label = lvmcache_get_dev_label(devl->dev)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
log_set_report_object_name_and_id(dev_name(dev), NULL);
|
||||||
|
|
||||||
ret = process_single_label(cmd, label, handle);
|
ret = process_single_label(cmd, label, handle);
|
||||||
report_log_ret_code(ret);
|
report_log_ret_code(ret);
|
||||||
|
|
||||||
@ -1541,7 +1587,7 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
|
|||||||
|
|
||||||
while ((dev = dev_iter_get(iter)))
|
while ((dev = dev_iter_get(iter)))
|
||||||
{
|
{
|
||||||
if (!label_read(dev, &label, 0))
|
if (!(label = lvmcache_get_dev_label(dev)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
log_set_report_object_name_and_id(dev_name(label->dev), NULL);
|
log_set_report_object_name_and_id(dev_name(label->dev), NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user