diff options
author | David Teigland <teigland@redhat.com> | 2017-10-26 11:20:13 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2017-10-26 11:31:46 -0500 |
commit | b0e361a06736b6377407937680d0d21317d71980 (patch) | |
tree | 760014df722ae91d68122f6c752b4c64ba4b2204 | |
parent | 7f84c72f66ea2b192aec623c65b68a8d12755355 (diff) | |
download | lvm2-dev-dct-new-scan-12.tar.gz |
lvmetad: use new label_scan for update from pvscandev-dct-new-scan-12
Take advantage of the common implementation with aio
and reduced disk reads.
-rw-r--r-- | lib/cache/lvmetad.c | 44 | ||||
-rw-r--r-- | lib/commands/toolcontext.h | 1 | ||||
-rw-r--r-- | lib/format_text/import_vsn1.c | 14 | ||||
-rw-r--r-- | tools/pvscan.c | 30 |
4 files changed, 69 insertions, 20 deletions
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index 88595e018..24731e768 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -1767,10 +1767,14 @@ struct _lvmetad_pvscan_baton { static int _lvmetad_pvscan_single(struct metadata_area *mda, void *baton) { struct _lvmetad_pvscan_baton *b = baton; + struct device *mda_dev = mda_get_device(mda); + struct label_read_data *ld; struct volume_group *vg; + ld = get_label_read_data(b->cmd, mda_dev); + if (mda_is_ignored(mda) || - !(vg = mda->ops->vg_read(b->fid, "", mda, NULL, NULL, NULL))) + !(vg = mda->ops->vg_read(b->fid, "", mda, ld, NULL, NULL))) return 1; /* FIXME Also ensure contents match etc. */ @@ -2239,9 +2243,12 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, struct label *label; struct lvmcache_info *info; struct _lvmetad_pvscan_baton baton; + const struct format_type *fmt; /* Create a dummy instance. */ struct format_instance_ctx fic = { .type = 0 }; + log_debug_lvmetad("Scan metadata from dev %s", dev_name(dev)); + if (!lvmetad_used()) { log_error("Cannot proceed since lvmetad is not active."); return 0; @@ -2252,23 +2259,31 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, return 1; } - if (!label_read(dev, &label, 0)) { - log_print_unless_silent("No PV label found on %s.", dev_name(dev)); + if (!(info = lvmcache_info_from_pvid(dev->pvid, dev, 0))) { + log_print_unless_silent("No PV info found on %s for PVID %s.", dev_name(dev), dev->pvid); + if (!lvmetad_pv_gone_by_dev(dev)) + goto_bad; + return 1; + } + + if (!(label = lvmcache_get_label(info))) { + log_print_unless_silent("No PV label found for %s.", dev_name(dev)); if (!lvmetad_pv_gone_by_dev(dev)) goto_bad; return 1; } - info = (struct lvmcache_info *) label->info; + fmt = lvmcache_fmt(info); + baton.cmd = cmd; baton.vg = NULL; - baton.fid = lvmcache_fmt(info)->ops->create_instance(lvmcache_fmt(info), &fic); + baton.fid = fmt->ops->create_instance(fmt, &fic); if (!baton.fid) goto_bad; - if (baton.fid->fmt->features & FMT_OBSOLETE) { - lvmcache_fmt(info)->ops->destroy_instance(baton.fid); + if (fmt->features & FMT_OBSOLETE) { + fmt->ops->destroy_instance(baton.fid); log_warn("WARNING: Disabling lvmetad cache which does not support obsolete (lvm1) metadata."); lvmetad_set_disabled(cmd, LVMETAD_DISABLE_REASON_LVM1); _found_lvm1_metadata = 1; @@ -2282,9 +2297,9 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, lvmcache_foreach_mda(info, _lvmetad_pvscan_single, &baton); if (!baton.vg) - lvmcache_fmt(info)->ops->destroy_instance(baton.fid); + fmt->ops->destroy_instance(baton.fid); - if (!lvmetad_pv_found(cmd, (const struct id *) &dev->pvid, dev, lvmcache_fmt(info), + if (!lvmetad_pv_found(cmd, (const struct id *) &dev->pvid, dev, fmt, label->sector, baton.vg, found_vgnames, changed_vgnames)) { release_vg(baton.vg); goto_bad; @@ -2350,6 +2365,13 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, int do_wait) replacing_other_update = 1; } + label_scan(cmd); + + if (lvmcache_found_duplicate_pvs()) { + log_warn("WARNING: Scan found duplicate PVs."); + return 0; + } + log_verbose("Scanning all devices to update lvmetad."); if (!(iter = dev_iter_create(cmd->lvmetad_filter, 1))) { @@ -2720,6 +2742,8 @@ void lvmetad_validate_global_cache(struct cmd_context *cmd, int force) */ _lvmetad_get_pv_cache_list(cmd, &pvc_before); + log_debug_lvmetad("Rescan all devices to validate global cache."); + /* * Update the local lvmetad cache so it correctly reflects any * changes made on remote hosts. (It's possible that this command @@ -2788,7 +2812,7 @@ void lvmetad_validate_global_cache(struct cmd_context *cmd, int force) _update_changed_pvs_in_udev(cmd, &pvc_before, &pvc_after); } - log_debug_lvmetad("Validating global lvmetad cache finished"); + log_debug_lvmetad("Rescanned all devices"); } int lvmetad_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid) diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index 32b4cd9c0..1e3e721db 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -166,6 +166,7 @@ struct cmd_context { unsigned lv_notify:1; unsigned pv_notify:1; unsigned use_aio:1; + unsigned pvscan_cache_single:1; /* * Filtering. diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index e7fc8abcd..af69cfc3a 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -216,12 +216,16 @@ static int _read_pv(struct format_instance *fid, /* * Convert the uuid into a device. */ - if (!(pv->dev = lvmcache_device_from_pvid(fid->fmt->cmd, &pv->id, &pv->label_sector))) { - char buffer[64] __attribute__((aligned(8))); + if (fid->fmt->cmd && !fid->fmt->cmd->pvscan_cache_single) { + if (!(pv->dev = lvmcache_device_from_pvid(fid->fmt->cmd, &pv->id, &pv->label_sector))) { + char buffer[64] __attribute__((aligned(8))); - if (!id_write_format(&pv->id, buffer, sizeof(buffer))) - buffer[0] = '\0'; - log_error_once("Couldn't find device with uuid %s.", buffer); + if (!id_write_format(&pv->id, buffer, sizeof(buffer))) + buffer[0] = '\0'; + log_error_once("Couldn't find device with uuid %s.", buffer); + } + } else { + log_debug_metadata("Skip metadata pvid to device lookup for lvmetad pvscan."); } if (!(pv->vg_name = dm_pool_strdup(mem, vg->name))) diff --git a/tools/pvscan.c b/tools/pvscan.c index 6581990f8..f79b17fa3 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -300,8 +300,10 @@ static int _pvscan_autoactivate(struct cmd_context *cmd, struct pvscan_aa_params static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) { struct pvscan_aa_params pp = { 0 }; + struct dm_list single_devs; struct dm_list found_vgnames; struct device *dev; + struct device_list *devl; const char *pv_name; const char *reason = NULL; int32_t major = -1; @@ -315,6 +317,7 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) int add_errors = 0; int ret = ECMD_PROCESSED; + dm_list_init(&single_devs); dm_list_init(&found_vgnames); dm_list_init(&pp.changed_vgnames); @@ -434,8 +437,10 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) * to drop any devices that have left.) */ - if (argc || devno_args) + if (argc || devno_args) { log_verbose("Scanning devices on command line."); + cmd->pvscan_cache_single = 1; + } while (argc--) { pv_name = *argv++; @@ -453,8 +458,11 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) } else { /* Add device path to lvmetad. */ log_debug("Scanning dev %s for lvmetad cache.", pv_name); - if (!lvmetad_pvscan_single(cmd, dev, &found_vgnames, &pp.changed_vgnames)) - add_errors++; + + if (!(devl = dm_pool_zalloc(cmd->mem, sizeof(*devl)))) + return_0; + devl->dev = dev; + dm_list_add(&single_devs, &devl->list); } } else { if (sscanf(pv_name, "%d:%d", &major, &minor) != 2) { @@ -471,8 +479,11 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) } else { /* Add major:minor to lvmetad. */ log_debug("Scanning dev %d:%d for lvmetad cache.", major, minor); - if (!lvmetad_pvscan_single(cmd, dev, &found_vgnames, &pp.changed_vgnames)) - add_errors++; + + if (!(devl = dm_pool_zalloc(cmd->mem, sizeof(*devl)))) + return_0; + devl->dev = dev; + dm_list_add(&single_devs, &devl->list); } } @@ -482,6 +493,15 @@ static int _pvscan_cache(struct cmd_context *cmd, int argc, char **argv) } } + if (!dm_list_empty(&single_devs)) { + label_scan_devs(cmd, &single_devs); + + dm_list_iterate_items(devl, &single_devs) { + if (!lvmetad_pvscan_single(cmd, devl->dev, &found_vgnames, &pp.changed_vgnames)) + add_errors++; + } + } + if (!devno_args) goto activate; |