int pvremove(struct cmd_context *cmd, int argc, char **argv) { int i; unsigned force_count; unsigned prompt; struct dm_list pv_names; if (!argc) { log_error("Please enter a physical volume path"); return EINVALID_CMD_LINE; } force_count = arg_count(cmd, force_ARG); prompt = arg_count(cmd, yes_ARG); dm_list_init(&pv_names); /* Needed to change the set of orphan PVs. */ if (!lockd_gl(cmd, "ex", 0)) return_ECMD_FAILED; for (i = 0; i < argc; i++) { dm_unescape_colons_and_at_signs(argv[i], NULL, NULL); if (!str_list_add(cmd->mem, &pv_names, argv[i])) return_ECMD_FAILED; } if (!pvremove_many(cmd, &pv_names, force_count, prompt)) return_ECMD_FAILED; return ECMD_PROCESSED; }
int vgremove(struct cmd_context *cmd, int argc, char **argv) { int ret; if (!argc && !arg_is_set(cmd, select_ARG)) { log_error("Please enter one or more volume group paths " "or use --select for selection."); return EINVALID_CMD_LINE; } /* * Needed to change the global VG namespace, * and to change the set of orphan PVs. */ if (!lockd_gl(cmd, "ex", LDGL_UPDATE_NAMES)) return ECMD_FAILED; /* * This is a special case: if vgremove is given a tag, it causes * process_each_vg to do lockd_gl(sh) when getting a list of all * VG names. We don't want the gl converted to sh, so disable it. */ cmd->lockd_gl_disable = 1; cmd->handles_missing_pvs = 1; ret = process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL, &vgremove_single); return ret; }
static int _pvresize_single(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, struct processing_handle *handle) { struct pvresize_params *params = (struct pvresize_params *) handle->custom_handle; if (!params) { log_error(INTERNAL_ERROR "Invalid resize params."); return ECMD_FAILED; } params->total++; if (vg && vg_is_exported(vg)) { log_error("Volume group %s is exported", vg->name); return ECMD_FAILED; } /* * 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)) { if (!lockd_gl(cmd, "ex", 0)) return_ECMD_FAILED; cmd->lockd_gl_disable = 1; } if (!pv_resize_single(cmd, vg, pv, params->new_size, arg_is_set(cmd, yes_ARG))) return_ECMD_FAILED; params->done++; return ECMD_PROCESSED; }
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; }