summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2015-12-23 15:10:17 -0600
committerDavid Teigland <teigland@redhat.com>2015-12-23 15:10:17 -0600
commit457b03f00d885311170eb8b816c2866877fcab1a (patch)
tree69f6dd871338206f8b85cf8dfb1e6d3b32d4ce33
parentbf7bd1f81f2dca6aa44892f667044df24749f165 (diff)
downloadlvm2-dev-dct-pvcreate-5.tar.gz
vgextend: use pvcreate_each_devicedev-dct-pvcreate-5
Create PVs at the top level of the command.
-rw-r--r--tools/vgextend.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/tools/vgextend.c b/tools/vgextend.c
index 761df7521..7e896e695 100644
--- a/tools/vgextend.c
+++ b/tools/vgextend.c
@@ -16,9 +16,7 @@
#include "tools.h"
struct vgextend_params {
- struct pvcreate_params pp;
- int pv_count;
- const char *const *pv_names;
+ struct pvcreate_each_params pp;
};
static int _restore_pv(struct volume_group *vg, const char *pv_name)
@@ -49,14 +47,15 @@ static int _vgextend_restoremissing(struct cmd_context *cmd __attribute__((unuse
struct processing_handle *handle)
{
struct vgextend_params *vp = (struct vgextend_params *) handle->custom_handle;
+ struct pvcreate_each_params *pp = &vp->pp;
int fixed = 0;
int i;
if (!archive(vg))
return_0;
- for (i = 0; i < vp->pv_count; i++)
- if (_restore_pv(vg, vp->pv_names[i]))
+ for (i = 0; i < pp->pv_count; i++)
+ if (_restore_pv(vg, pp->pv_names[i]))
fixed++;
if (!fixed) {
@@ -78,7 +77,7 @@ static int _vgextend_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg, struct processing_handle *handle)
{
struct vgextend_params *vp = (struct vgextend_params *) handle->custom_handle;
- struct pvcreate_params *pp = &vp->pp;
+ struct pvcreate_each_params *pp = &vp->pp;
uint32_t mda_copies;
uint32_t mda_used;
int ret = ECMD_FAILED;
@@ -94,12 +93,17 @@ static int _vgextend_single(struct cmd_context *cmd, const char *vg_name,
if (!archive(vg))
return_ECMD_FAILED;
+ /*
+ * TODO: pass a flag to pvcreate_each_device to tell it
+ * not to release VG_ORPHANS after creating PVs, but
+ * to leave it locked, then remove this lock call.
+ */
if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
log_error("Can't get lock for orphan PVs");
return ECMD_FAILED;
}
- if (!vg_extend(vg, vp->pv_count, vp->pv_names, pp))
+ if (!vg_extend_each_pv(vg, &pp))
goto_out;
if (arg_count(cmd, metadataignore_ARG)) {
@@ -133,9 +137,10 @@ out:
int vgextend(struct cmd_context *cmd, int argc, char **argv)
{
struct vgextend_params vp;
+ struct pvcreate_each_params *pp = &vp->pp;
unsigned restoremissing = arg_is_set(cmd, restoremissing_ARG);
struct processing_handle *handle;
- const char *one_vgname;
+ const char *vg_name;
int ret;
if (!argc) {
@@ -144,22 +149,40 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- one_vgname = skip_dev_dir(cmd, argv[0], NULL);
-
if (arg_count(cmd, metadatacopies_ARG)) {
log_error("Invalid option --metadatacopies, "
"use --pvmetadatacopies instead.");
return EINVALID_CMD_LINE;
}
- pvcreate_params_set_defaults(&vp.pp);
- vp.pv_count = argc - 1;
- vp.pv_names = (const char* const*)(argv + 1);
+ vg_name = skip_dev_dir(cmd, argv[0], NULL);
+ argc--;
+ argv++;
- if (!pvcreate_params_validate(cmd, vp.pv_count, &vp.pp))
- return_EINVALID_CMD_LINE;
+ pvcreate_each_params_set_defaults(pp);
+
+ if (!pvcreate_each_params_from_args(cmd, pp))
+ return EINVALID_CMD_LINE;
- if (!(handle = init_processing_handle(cmd))) {
+ pp->pv_count = argc;
+ pp->pv_names = argv;
+
+ /* Don't create a new PV on top of an existing PV like pvcreate does. */
+ pp->preserve_existing = 1;
+
+ /*
+ * Needed to change the set of orphan PVs.
+ * (disable afterward to prevent process_each_pv from doing
+ * a shared global lock since it's already acquired it ex.)
+ */
+ if (!lockd_gl(cmd, "ex", 0))
+ return_ECMD_FAILED;
+ cmd->lockd_gl_disable = 1;
+
+ if (!pvcreate_each_device(cmd, pp))
+ return ECMD_FAILED;
+
+ if (!(handle = init_processing_handle(cmd))) {
log_error("Failed to initialize processing handle.");
return ECMD_FAILED;
}
@@ -174,11 +197,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
*/
cmd->handles_missing_pvs = 1;
- /* Needed to change the set of orphan PVs. */
- if (!lockd_gl(cmd, "ex", 0))
- return_ECMD_FAILED;
-
- ret = process_each_vg(cmd, 0, NULL, one_vgname,
+ ret = process_each_vg(cmd, 0, NULL, vg_name,
READ_FOR_UPDATE, handle,
restoremissing ? &_vgextend_restoremissing : &_vgextend_single);