/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* FIXME we used to print an error about EXPORTED, but proceeded
nevertheless. */
vg = vg_read_for_update(cmd, vg_name_old, vgid, READ_ALLOW_EXPORTED);
if (vg_read_error(vg)) {
vg_release(vg);
return_NULL;
}
if (lvs_in_vg_activated_by_uuid_only(vg)) {
unlock_and_release_vg(cmd, vg, vg_name_old);
log_error("Volume group \"%s\" still has active LVs",
vg_name_old);
/* FIXME Remove this restriction */
return NULL;
}
return vg;
}
static int vg_rename_new(struct cmd_context *cmd,
const char *vg_name_new)
{
int rc;
log_verbose("Checking for new volume group \"%s\"", vg_name_new);
rc = vg_lock_newname(cmd, vg_name_new);
if (rc == FAILED_LOCKING) {
log_error("Can't get lock for %s", vg_name_new);
return 0;
}
if (rc == FAILED_EXIST) {
log_error("New volume group \"%s\" already exists",
vg_name_new);
return 0;
}
return 1;
}
static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
const char *new_vg_path)
{
char *dev_dir;
struct id id;
int match = 0;
int found_id = 0;
struct dm_list *vgids;
struct str_list *sl;
char *vg_name_new;
const char *vgid = NULL, *vg_name, *vg_name_old;
char old_path[NAME_LEN], new_path[NAME_LEN];
struct volume_group *vg = NULL;
int lock_vg_old_first = 1;
int vgrename(struct cmd_context *cmd, int argc, char **argv)
{
if (argc != 2) {
log_error("Old and new volume group names need specifying");
return EINVALID_CMD_LINE;
}
if (!vg_rename_path(cmd, argv[0], argv[1])) {
stack;
return ECMD_FAILED;
}