diff options
Diffstat (limited to 'tools/pvresize.c')
-rw-r--r-- | tools/pvresize.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/pvresize.c b/tools/pvresize.c index 631e63e0b..0b055e6ef 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -26,9 +26,9 @@ struct pvresize_params { static int _pvresize_single(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, - void *handle) + struct processing_handle *handle) { - struct pvresize_params *params = (struct pvresize_params *) handle; + struct pvresize_params *params = (struct pvresize_params *) handle->custom_handle; if (!params) { log_error(INTERNAL_ERROR "Invalid resize params."); @@ -36,6 +36,14 @@ static int _pvresize_single(struct cmd_context *cmd, } params->total++; + /* + * Needed to change a property on an orphan PV. + * i.e. the global lock is only needed for orphans. + * Convert sh to ex. + */ + if (is_orphan(pv) && !lockd_gl(cmd, "ex", 0)) + return_ECMD_FAILED; + if (!pv_resize_single(cmd, vg, pv, params->new_size)) return_ECMD_FAILED; @@ -47,16 +55,19 @@ static int _pvresize_single(struct cmd_context *cmd, int pvresize(struct cmd_context *cmd, int argc, char **argv) { struct pvresize_params params; + struct processing_handle *handle = NULL; int ret; if (!argc) { log_error("Please supply physical volume(s)"); - return EINVALID_CMD_LINE; + ret = EINVALID_CMD_LINE; + goto out; } if (arg_sign_value(cmd, physicalvolumesize_ARG, SIGN_NONE) == SIGN_MINUS) { log_error("Physical volume size may not be negative"); - return EINVALID_CMD_LINE; + ret = EINVALID_CMD_LINE; + goto out; } params.new_size = arg_uint64_value(cmd, physicalvolumesize_ARG, @@ -65,11 +76,20 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv) params.done = 0; params.total = 0; - ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, ¶ms, + if (!(handle = init_processing_handle(cmd))) { + log_error("Failed to initialize processing handle."); + ret = ECMD_FAILED; + goto out; + } + + handle->custom_handle = ¶ms; + + ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, handle, _pvresize_single); log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) " "not resized", params.done, params.total - params.done); - +out: + destroy_processing_handle(cmd, handle); return ret; } |