/* Rearrange the metadata_areas_in_use so ignored mdas come first. */
dm_list_init(&ignored);
- dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_in_use) {
+ dm_list_iterate_items_safe(mda, tmda, &vg->fid->metadata_areas_in_use)
if (mda_is_ignored(mda))
dm_list_move(&ignored, &mda->list);
- }
- dm_list_iterate_items_safe(mda, tmda, &ignored) {
+
+ dm_list_iterate_items_safe(mda, tmda, &ignored)
dm_list_move(&vg->fid->metadata_areas_in_use, &mda->list);
- }
/* Commit to each copy of the metadata area */
dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
void fid_add_mda(struct format_instance *fid, struct metadata_area *mda)
{
- if (mda_is_ignored(mda))
- dm_list_add(&fid->metadata_areas_ignored,
- &mda->list);
- else
- dm_list_add(&fid->metadata_areas_in_use,
- &mda->list);
+ dm_list_add(mda_is_ignored(mda) ? &fid->metadata_areas_ignored :
+ &fid->metadata_areas_in_use, &mda->list);
}
int fid_add_mdas(struct format_instance *fid, struct dm_list *mdas)
return (mda->flags & MDA_IGNORED);
}
-void mda_set_ignored(struct metadata_area *mda, unsigned ignored)
+void mda_set_ignored(struct metadata_area *mda, unsigned mda_ignored)
{
void *locn = mda->metadata_locn;
- unsigned old_ignored = mda_is_ignored(mda);
+ unsigned old_mda_ignored = mda_is_ignored(mda);
- if (ignored && !old_ignored)
+ if (mda_ignored && !old_mda_ignored)
mda->flags |= MDA_IGNORED;
- else if (!ignored && old_ignored)
+ else if (!mda_ignored && old_mda_ignored)
mda->flags &= ~MDA_IGNORED;
else
return; /* No change */
log_debug("%s ignored flag for mda %s at offset %" PRIu64 ".",
- ignored ? "Setting" : "Clearing",
+ mda_ignored ? "Setting" : "Clearing",
mda->ops->mda_metadata_locn_name ? mda->ops->mda_metadata_locn_name(locn) : "",
mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0));
}
return used_count;
}
-unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored)
+unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored)
{
struct lvmcache_info *info;
struct metadata_area *mda, *vg_mda, *tmda;
struct dm_list *vg_mdas_in_use, *vg_mdas_ignored;
- info = info_from_pvid((const char *)&pv->id.uuid, 0);
- if (!info)
+ if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0)))
return_0;
if (is_orphan(pv)) {
- dm_list_iterate_items(mda, &info->mdas) {
- mda_set_ignored(mda, ignored);
- }
+ dm_list_iterate_items(mda, &info->mdas)
+ mda_set_ignored(mda, mda_ignored);
return 1;
}
* Do not allow disabling of the the last PV in a VG.
*/
if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) {
- log_error("Cannot disable all metadata areas in Volume Group.");
+ log_error("Cannot disable all metadata areas in volume group %s.",
+ pv->vg->name);
return 0;
}
*/
vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use;
vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored;
+
dm_list_iterate_items(mda, &info->mdas) {
- if (mda_is_ignored(mda) && !ignored) {
+ if (mda_is_ignored(mda) && !mda_ignored)
/* Changing an ignored mda to one in_use requires moving it */
- dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored) {
+ dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored)
if (mda_locns_match(mda, vg_mda)) {
- mda_set_ignored(vg_mda, ignored);
+ mda_set_ignored(vg_mda, mda_ignored);
dm_list_move(vg_mdas_in_use, &vg_mda->list);
}
- }
- }
- dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use) {
- if (mda_locns_match(mda, vg_mda)) {
- mda_set_ignored(vg_mda, ignored);
- /* don't move mda - needs written to disk */
- }
- }
- mda_set_ignored(mda, ignored);
+
+ dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use)
+ if (mda_locns_match(mda, vg_mda))
+ /* Don't move mda: needs writing to disk. */
+ mda_set_ignored(vg_mda, mda_ignored);
+
+ mda_set_ignored(mda, mda_ignored);
}
+
return 1;
}
{
const char *pv_name = pv_dev_name(pv);
- if (mda_ignore && (pv_mda_used_count(pv) == 0)) {
- log_error("Physical volume \"%s\" metadata already "
- "ignored", pv_name);
+ if (mda_ignore && !pv_mda_used_count(pv)) {
+ log_error("Metadata areas on physical volume \"%s\" already "
+ "ignored.", pv_name);
return 0;
}
+
if (!mda_ignore && (pv_mda_used_count(pv) == pv_mda_count(pv))) {
- log_error("Physical volume \"%s\" metadata already "
- "not ignored", pv_name);
+ log_error("Metadata areas on physical volume \"%s\" already "
+ "marked as in-use.", pv_name);
return 0;
}
+
if (!pv_mda_count(pv)) {
log_error("Physical volume \"%s\" has no metadata "
- "areas ", pv_name);
- return 0;
- }
- if (mda_ignore) {
- log_verbose("Setting physical volume \"%s\" "
- "metadata ignored", pv_name);
- } else {
- log_verbose("Setting physical volume \"%s\" "
- "metadata not ignored", pv_name);
- }
- if (!pv_mda_set_ignored(pv, mda_ignore)) {
+ "areas.", pv_name);
return 0;
}
+
+ log_verbose("Marking metadata areas on physical volume \"%s\" "
+ "as %s.", pv_name, mda_ignore ? "ignored" : "in-use");
+
+ if (!pv_mda_set_ignored(pv, mda_ignore))
+ return_0;
+
/*
* Update vg_mda_copies based on the mdas in this PV.
* This is most likely what the user would expect - if they
* This does not guarantee this PV's ignore bits will be
* preserved in future operations.
*/
- if (!is_orphan(pv) && vg_mda_copies(pv->vg)) {
+ if (!is_orphan(pv) && vg_mda_copies(pv->vg))
vg_set_mda_copies(pv->vg, vg_mda_used_count(pv->vg));
- }
+
return 1;
}
* may have changed from ignored to un-ignored and we need to write
* the state to disk.
*/
- dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
+ dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use)
if (!mda_is_ignored(mda))
used_count++;
- }
- dm_list_iterate_items(mda, &vg->fid->metadata_areas_ignored) {
+
+ dm_list_iterate_items(mda, &vg->fid->metadata_areas_ignored)
if (!mda_is_ignored(mda))
used_count++;
- }
return used_count;
}