summaryrefslogtreecommitdiff
path: root/lib/metadata/metadata.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/metadata/metadata.c')
-rw-r--r--lib/metadata/metadata.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0336d5d82..b48e16dbb 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -179,7 +179,6 @@ void del_pvl_from_vgs(struct volume_group *vg, struct pv_list *pvl)
int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
struct physical_volume *pv, struct pvcreate_params *pp)
{
- struct pv_to_create *pvc;
struct pv_list *pvl;
struct format_instance *fid = vg->fid;
struct dm_pool *mem = vg->vgmem;
@@ -278,16 +277,6 @@ int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
break;
}
- if (pv->status & UNLABELLED_PV) {
- if (!(pvc = dm_pool_zalloc(mem, sizeof(*pvc)))) {
- log_error("pv_to_create allocation for '%s' failed", pv_name);
- return 0;
- }
- pvc->pv = pv;
- pvc->pp = pp;
- dm_list_add(&vg->pvs_to_create, &pvc->list);
- }
-
return 1;
}
@@ -747,6 +736,43 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names
return 1;
}
+int vg_extend_each_pv(struct volume_group *vg, struct pvcreate_each_params *pp)
+{
+ struct pv_list *pvl;
+ unsigned int max_phys_block_size = 0;
+
+ log_debug_metadata("Adding PVs to VG %s", vg->name);
+
+ if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
+ return_0;
+
+ dm_list_iterate_items(pvl, &pp->pvs) {
+ log_debug_metadata("Adding PV %s to VG %s", pv_dev_name(pvl->pv), vg->name);
+
+ if (!(check_dev_block_size_for_vg(pvl->pv->dev,
+ (const struct volume_group *) vg,
+ &max_phys_block_size))) {
+ log_error("PV %s has wrong block size", pv_dev_name(pvl->pv));
+ return_0;
+ }
+
+ if (!add_pv_to_vg(vg, pv_dev_name(pvl->pv), pvl->pv, NULL)) {
+ log_error("PV %s cannot be added to the VG.", pv_dev_name(pvl->pv));
+ return_0;
+ }
+
+ log_verbose("Writing PV data to disk for %s VG %s",
+ pv_dev_name(pvl->pv), vg->name);
+
+ if (!(pv_write(vg->cmd, pvl->pv, 1))) {
+ log_error("Failed to write physical volume \"%s\"", pv_dev_name(pvl->pv));
+ return_0;
+ }
+ }
+
+ return 1;
+}
+
int vg_reduce(struct volume_group *vg, const char *pv_name)
{
struct physical_volume *pv;
@@ -1009,6 +1035,8 @@ int vg_has_unknown_segments(const struct volume_group *vg)
return 0;
}
+static uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname);
+
/*
* Create a VG with default parameters.
* Returns:
@@ -1576,7 +1604,6 @@ void pvcreate_params_set_defaults(struct pvcreate_params *pp)
pp->rp.extent_size = 0;
}
-
static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_create *pvc)
{
int zero = pvc->pp->zero;
@@ -3016,7 +3043,6 @@ out:
int vg_write(struct volume_group *vg)
{
struct dm_list *mdah;
- struct pv_to_create *pv_to_create, *pv_to_create_safe;
struct metadata_area *mda;
struct lv_list *lvl;
int revert = 0, wrote = 0;
@@ -3072,12 +3098,6 @@ int vg_write(struct volume_group *vg)
memlock_unlock(vg->cmd);
vg->seqno++;
- dm_list_iterate_items_safe(pv_to_create, pv_to_create_safe, &vg->pvs_to_create) {
- if (!_pvcreate_write(vg->cmd, pv_to_create))
- return 0;
- dm_list_del(&pv_to_create->list);
- }
-
/* Write to each copy of the metadata area */
dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) {
if (!mda->ops->vg_write) {
@@ -3561,6 +3581,8 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
struct cached_vg_fmtdata *vg_fmtdata = NULL; /* Additional format-specific data about the vg */
unsigned use_previous_vg;
+ log_very_verbose("Reading VG %s %.32s", vgname ?: "<no name>", vgid ?: "<no vgid>");
+
if (is_orphan_vg(vgname)) {
if (use_precommitted) {
log_error(INTERNAL_ERROR "vg_read_internal requires vgname "
@@ -5030,6 +5052,9 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
return _vg_make_handle(cmd, vg, FAILED_LOCKING);
}
+ if (already_locked)
+ log_very_verbose("Locking %s already done", vg_name);
+
if (is_orphan_vg(vg_name))
status_flags &= ~LVM_WRITE;
@@ -5178,7 +5203,7 @@ uint32_t vg_read_error(struct volume_group *vg_handle)
* FAILED_EXIST - VG name already exists - cannot reserve
* SUCCESS - VG name does not exist in system and WRITE lock held
*/
-uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)
+static uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)
{
if (!lock_vol(cmd, vgname, LCK_VG_WRITE, NULL)) {
return FAILED_LOCKING;