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)"); ret = EINVALID_CMD_LINE; goto out; } if (arg_sign_value(cmd, setphysicalvolumesize_ARG, SIGN_NONE) == SIGN_MINUS) { log_error("Physical volume size may not be negative"); ret = EINVALID_CMD_LINE; goto out; } params.new_size = arg_uint64_value(cmd, setphysicalvolumesize_ARG, UINT64_C(0)); params.done = 0; params.total = 0; set_pv_notify(cmd); if (!(handle = init_processing_handle(cmd, NULL))) { log_error("Failed to initialize processing handle."); ret = ECMD_FAILED; goto out; } handle->custom_handle = ¶ms; ret = process_each_pv(cmd, argc, argv, NULL, 0, READ_FOR_UPDATE | READ_ALLOW_EXPORTED, handle, _pvresize_single); log_print_unless_silent("%d physical volume(s) resized or updated / %d physical volume(s) " "not resized", params.done, params.total - params.done); out: destroy_processing_handle(cmd, handle); return ret; }
int vgrename(struct cmd_context *cmd, int argc, char **argv) { struct vgrename_params vp = { 0 }; struct processing_handle *handle; const char *vg_name_new; const char *vg_name_old; struct id id; int ret; if (argc != 2) { log_error("Old and new volume group names need specifying"); return EINVALID_CMD_LINE; } vg_name_old = skip_dev_dir(cmd, argv[0], NULL); vg_name_new = skip_dev_dir(cmd, argv[1], NULL); if (!validate_vg_rename_params(cmd, vg_name_old, vg_name_new)) return_0; if (!(vp.vg_name_old = dm_pool_strdup(cmd->mem, vg_name_old))) return_ECMD_FAILED; if (!(vp.vg_name_new = dm_pool_strdup(cmd->mem, vg_name_new))) return_ECMD_FAILED; /* Needed change the global VG namespace. */ if (!lockd_gl(cmd, "ex", LDGL_UPDATE_NAMES)) return_ECMD_FAILED; /* * Special case where vg_name_old may be a UUID: * If vg_name_old is a UUID, then process_each may * translate it to an actual VG name that we don't * yet know. The lock ordering, and pre-locking, * needs to be done based on VG names. When * vg_name_old is a UUID, do not do any pre-locking * based on it, since it's likely to be wrong, and * defer all the locking to the _single function. * * When it's not a UUID, we know the two VG names, * and we can pre-lock the new VG name if the lock * ordering wants it locked before the old VG name * which will be locked by process_each. If lock * ordering wants the old name locked first, then * the _single function will lock the new VG name. */ if (!(vp.old_name_is_uuid = id_read_format_try(&id, vg_name_old))) { if (strcmp(vg_name_new, vg_name_old) < 0) { vp.lock_vg_old_first = 0; vp.unlock_new_name = 1; if (!_lock_new_vg_for_rename(cmd, vg_name_new)) return ECMD_FAILED; } else { /* The old VG is locked by process_each_vg. */ vp.lock_vg_old_first = 1; } } if (!(handle = init_processing_handle(cmd))) { log_error("Failed to initialize processing handle."); return ECMD_FAILED; } handle->custom_handle = &vp; ret = process_each_vg(cmd, 0, NULL, vg_name_old, READ_FOR_UPDATE | READ_ALLOW_EXPORTED, handle, _vgrename_single); /* Needed if process_each_vg returns error before calling _single. */ if (vp.unlock_new_name) unlock_vg(cmd, vg_name_new); destroy_processing_handle(cmd, handle); return ret; }
int pvcreate(struct cmd_context *cmd, int argc, char **argv) { struct processing_handle *handle; struct pvcreate_params pp; int ret; /* * Five kinds of pvcreate param values: * 1. defaults * 2. recovery-related command line args * 3. recovery-related args from backup file * 4. normal command line args * (this also checks some settings from 2 & 3) * 5. argc/argv free args specifying devices */ pvcreate_params_set_defaults(&pp); if (!_pvcreate_restore_params_from_args(cmd, argc, &pp)) return EINVALID_CMD_LINE; if (!_pvcreate_restore_params_from_backup(cmd, &pp)) return EINVALID_CMD_LINE; if (!pvcreate_params_from_args(cmd, &pp)) return EINVALID_CMD_LINE; /* * If --metadatasize was not given with --restorefile, set it to pe_start. * Later code treats this as a maximum size and reduces it to fit. */ if (!arg_is_set(cmd, metadatasize_ARG) && arg_is_set(cmd, restorefile_ARG)) pp.pva.pvmetadatasize = pp.pva.pe_start; /* FIXME Also needs to check any 2nd metadata area isn't inside the data area! */ pp.pv_count = argc; pp.pv_names = argv; /* Check for old md signatures at the end of devices. */ cmd->use_full_md_check = 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; clear_hint_file(cmd); if (!(handle = init_processing_handle(cmd, NULL))) { log_error("Failed to initialize processing handle."); return ECMD_FAILED; } if (!pvcreate_each_device(cmd, handle, &pp)) ret = ECMD_FAILED; else { /* pvcreate_each_device returns with orphans locked */ unlock_vg(cmd, NULL, VG_ORPHANS); ret = ECMD_PROCESSED; } destroy_processing_handle(cmd, handle); return ret; }