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.c94
1 files changed, 60 insertions, 34 deletions
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0336d5d82..96f502e91 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;
@@ -1025,21 +1051,6 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name)
.context.vg_ref.vg_name = vg_name
};
struct format_instance *fid;
- uint32_t rc;
-
- if (!validate_name(vg_name)) {
- log_error("Invalid vg name %s", vg_name);
- /* FIXME: use _vg_make_handle() w/proper error code */
- return NULL;
- }
-
- rc = vg_lock_newname(cmd, vg_name);
- if (rc != SUCCESS)
- /* NOTE: let caller decide - this may be check for existence */
- return _vg_make_handle(cmd, NULL, rc);
-
- /* Strip dev_dir if present */
- vg_name = strip_dir(vg_name, cmd->dev_dir);
if (!(vg = alloc_vg("vg_create", cmd, vg_name)))
goto_bad;
@@ -1081,6 +1092,24 @@ bad:
return NULL;
}
+struct volume_group *vg_lock_and_create(struct cmd_context *cmd, const char *vg_name)
+{
+ uint32_t rc;
+
+ if (!validate_name(vg_name)) {
+ log_error("Invalid vg name %s", vg_name);
+ /* FIXME: use _vg_make_handle() w/proper error code */
+ return NULL;
+ }
+
+ rc = vg_lock_newname(cmd, vg_name);
+ if (rc != SUCCESS)
+ /* NOTE: let caller decide - this may be check for existence */
+ return _vg_make_handle(cmd, NULL, rc);
+
+ return vg_create(cmd, vg_name);
+}
+
/* Rounds up by default */
uint32_t extents_from_size(struct cmd_context *cmd, uint64_t size,
uint32_t extent_size)
@@ -1576,7 +1605,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 +3044,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 +3099,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 +3582,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 +5053,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;