Improve normal allocation algorithm to include clinging to existing areas.
Add allocation/maximise_cling & mirror_logs_require_separate_pvs to lvm.conf.
Fix metadata balance code to work with recent changes in metadata handling.
- Add old_uuid field to physical_volume and fix pvchange -u for recent changes.
- Allow pvresize on a PV with two metadata areas (for PVs not in a VG).
+ Add old_id field to physical_volume and fix pvchange -u for recent changes.
+ Allow pvresize on a PV with two metadata areas.
Change pvcreate to use new metadata handling interface.
Restructure existing pv_setup and pv_write fn, add pv_initialise fn.
Add internal interface to support adding and removing metadata areas.
/* Add a new cache entry with PV info or update existing one. */
if (!(info = lvmcache_add(fmt->labeller, (const char *) &pv->id,
- pv->dev, FMT_TEXT_ORPHAN_VG_NAME, NULL, 0)))
+ pv->dev, pv->vg ? pv->vg->name : FMT_TEXT_ORPHAN_VG_NAME,
+ NULL, 0)))
return_0;
label = info->label;
/* If there's an mda at the end, move it to a new position. */
if ((mda = fid_get_mda_indexed(fid, pvid, ID_LEN, 1)) &&
(mdac = mda->metadata_locn)) {
- /*
- * FIXME: Remove this restriction - we need to
- * allow writing PV labels on non-orphan VGs
- * for this to work correctly.
- */
- if (vg) {
- log_error("Resizing a PV with two metadata areas "
- "that is part of a VG is not supported.");
- return 0;
- }
-
/* FIXME: Maybe MDA0 size would be better? */
mda_size = mdac->area.size >> SECTOR_SHIFT;
mda_ignored = mda_is_ignored(mda);
struct dm_list *get_vgids(struct cmd_context *cmd, int include_internal);
int scan_vgs_for_pvs(struct cmd_context *cmd, int warnings);
-int pv_write(struct cmd_context *cmd, struct physical_volume *pv);
+int pv_write(struct cmd_context *cmd, struct physical_volume *pv, int allow_non_orphan);
int move_pv(struct volume_group *vg_from, struct volume_group *vg_to,
const char *pv_name);
int move_pvs_used_by_lv(struct volume_group *vg_from,
}
/* FIXME Write to same sector label was read from */
- if (!pv_write(vg->cmd, pv)) {
+ if (!pv_write(vg->cmd, pv, 0)) {
log_error("Failed to remove physical volume \"%s\""
" from volume group \"%s\"",
pv_dev_name(pv), vg->name);
log_very_verbose("Writing physical volume data to disk \"%s\"",
pv_name);
- if (!(pv_write(cmd, pv))) {
+ if (!(pv_write(cmd, pv, 0))) {
log_error("Failed to write physical volume \"%s\"", pv_name);
goto error;
}
}
int pv_write(struct cmd_context *cmd __attribute__((unused)),
- struct physical_volume *pv)
+ struct physical_volume *pv, int allow_non_orphan)
{
if (!pv->fmt->ops->pv_write) {
log_error("Format does not support writing physical volumes");
* to provide some revert mechanism since PV label together
* with VG metadata write is not atomic.
*/
- if (!is_orphan_vg(pv->vg_name) || pv->pe_alloc_count) {
+ if (!allow_non_orphan &&
+ (!is_orphan_vg(pv->vg_name) || pv->pe_alloc_count)) {
log_error("Assertion failed: can't _pv_write non-orphan PV "
"(in VG %s)", pv->vg_name);
return 0;
return 0;
}
- if (!pv_write(cmd, pv)) {
+ if (!pv_write(cmd, pv, 0)) {
log_error("Failed to clear metadata from physical "
"volume \"%s\" after removal from \"%s\"",
pv_dev_name(pv), old_vg_name);
void mda_set_ignored(struct metadata_area *mda, unsigned ignored);
unsigned mda_locns_match(struct metadata_area *mda1, struct metadata_area *mda2);
void vg_set_fid(struct volume_group *vg, struct format_instance *fid);
+/* FIXME: Add generic interface for mda counts based on given key. */
int fid_add_mda(struct format_instance *fid, struct metadata_area *mda,
const char *key, size_t key_len, const unsigned sub_key);
int fid_add_mdas(struct format_instance *fid, struct dm_list *mdas,
pv->vg_name = pv->fmt->orphan_vg_name;
pv->pe_alloc_count = 0;
- if (!(pv_write(cmd, pv))) {
+ if (!(pv_write(cmd, pv, 0))) {
log_error("pv_write with new uuid failed "
"for %s.", pv_name);
return 0;
return 0;
}
backup(vg);
- } else if (!(pv_write(cmd, pv))) {
+ } else if (!(pv_write(cmd, pv, 0))) {
log_error("Failed to store physical volume \"%s\"",
pv_name);
return 0;
*/
#include "tools.h"
+#include "metadata.h"
struct pvresize_params {
uint64_t new_size;
goto_out;
log_verbose("Updating physical volume \"%s\"", pv_name);
+
+ /* Write PV label only if this an orphan PV or it has 2nd mda. */
+ if ((is_orphan_vg(vg_name) ||
+ fid_get_mda_indexed(vg->fid, (const char *) &pv->id, ID_LEN, 1)) &&
+ !pv_write(cmd, pv, 1)) {
+ log_error("Failed to store physical volume \"%s\"",
+ pv_name);
+ goto out;
+ }
+
if (!is_orphan_vg(vg_name)) {
if (!vg_write(vg) || !vg_commit(vg)) {
log_error("Failed to store physical volume \"%s\" in "
goto out;
}
backup(vg);
- } else if (!(pv_write(cmd, pv))) {
- log_error("Failed to store physical volume \"%s\"",
- pv_name);
- goto out;
}
log_print("Physical volume \"%s\" changed", pv_name);
log_very_verbose("Writing physical volume data to disk \"%s\"",
pv_dev_name(pv));
- if (!(pv_write(cmd, pv))) {
+ if (!(pv_write(cmd, pv, 0))) {
log_error("Failed to write physical volume \"%s\"",
pv_dev_name(pv));
log_error("Use pvcreate and vgcfgrestore to repair "
goto bad;
}
- if (!pv_write(cmd, pv)) {
+ if (!pv_write(cmd, pv, 0)) {
log_error("Failed to clear metadata from physical "
"volume \"%s\" "
"after removal from \"%s\"", name, vg->name);