1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

vgrename accepts vgid and exported VG.

This commit is contained in:
Alasdair Kergon 2006-04-13 21:08:29 +00:00
parent f855ac3807
commit dbd3026f8a
6 changed files with 96 additions and 17 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.03 -
===================================
vgrename accepts vgid and exported VG.
Add --partial to pvs.
When choosing between identically-named VGs, also consider creation_host.
Provide total log suppression with 2.

47
lib/cache/lvmcache.c vendored
View File

@ -163,12 +163,15 @@ struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid)
return vginfo;
}
const char *vgname_from_vgid(const char *vgid)
const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid)
{
struct lvmcache_vginfo *vginfo;
if ((vginfo = vginfo_from_vgid(vgid)))
if ((vginfo = vginfo_from_vgid(vgid))) {
if (mem)
return dm_pool_strdup(mem, vginfo->vgname);
return vginfo->vgname;
}
return NULL;
}
@ -523,6 +526,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
uint32_t vgstatus, const char *creation_host)
{
struct lvmcache_vginfo *vginfo, *primary_vginfo;
// struct lvmcache_vginfo *old_vginfo, *next;
/* If vgname is NULL and we don't already have a vgname,
* assume ORPHAN - we want every entry to have a vginfo
@ -541,6 +545,42 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
/* Get existing vginfo or create new one */
if (!(vginfo = vginfo_from_vgname(vgname, vgid))) {
/*** FIXME - vginfo ends up duplicated instead of renamed.
// Renaming? This lookup fails.
if ((vginfo = vginfo_from_vgid(vgid))) {
next = vginfo->next;
old_vginfo = vginfo_from_vgname(vginfo->vgname, NULL);
if (old_vginfo == vginfo) {
dm_hash_remove(_vgname_hash, old_vginfo->vgname);
if (old_vginfo->next) {
if (!dm_hash_insert(_vgname_hash, old_vginfo->vgname, old_vginfo->next)) {
log_error("vg hash re-insertion failed: %s",
old_vginfo->vgname);
return 0;
}
}
} else do {
if (old_vginfo->next == vginfo) {
old_vginfo->next = vginfo->next;
break;
}
} while ((old_vginfo = old_vginfo->next));
vginfo->next = NULL;
dm_free(vginfo->vgname);
if (!(vginfo->vgname = dm_strdup(vgname))) {
log_error("cache vgname alloc failed for %s", vgname);
return 0;
}
// Rename so can assume new name does not already exist
if (!dm_hash_insert(_vgname_hash, vginfo->vgname, vginfo->next)) {
log_error("vg hash re-insertion failed: %s",
vginfo->vgname);
return 0;
}
} else {
***/
if (!(vginfo = dm_malloc(sizeof(*vginfo)))) {
log_error("lvmcache_update_vgname: list alloc failed");
return 0;
@ -564,6 +604,9 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
list_add(&_vginfos, &vginfo->list);
else
list_add_h(&_vginfos, &vginfo->list);
/***
}
***/
}
info->vginfo = vginfo;

View File

@ -88,7 +88,7 @@ struct lvmcache_vginfo *vginfo_from_vgname(const char *vgname,
const char *vgid);
struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid);
struct lvmcache_info *info_from_pvid(const char *pvid);
const char *vgname_from_vgid(const char *vgid);
const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid);
struct device *device_from_pvid(struct cmd_context *cmd, struct id *pvid);
int vgs_locked(void);
int vgname_is_locked(const char *vgname);

View File

@ -1292,7 +1292,7 @@ struct list *get_pvs(struct cmd_context *cmd)
if (!vgid)
continue; /* FIXME Unnecessary? */
consistent = 0;
if (!(vgname = vgname_from_vgid(vgid))) {
if (!(vgname = vgname_from_vgid(NULL, vgid))) {
stack;
continue;
}

View File

@ -440,7 +440,8 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
}
list_iterate_items(sl, vgids) {
vgid = sl->str;
if (!vgid || !(vg_name = vgname_from_vgid(vgid)) || !*vg_name)
if (!vgid || !(vg_name = vgname_from_vgid(cmd->mem, vgid)) ||
!*vg_name)
continue;
ret_max = _process_one_vg(cmd, vg_name, vgid, &tags,
&arg_vgnames,

View File

@ -19,12 +19,15 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
{
char *dev_dir;
unsigned int length;
struct id id;
int consistent = 1;
char *vg_name_old, *vg_name_new;
int match = 0;
int found_id = 0;
struct 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_old, *vg_new;
if (argc != 2) {
@ -64,22 +67,49 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_verbose("Checking for existing volume group \"%s\"", vg_name_old);
/* Avoid duplicates */
if (!(vgids = get_vgids(cmd, 0)) || list_empty(vgids)) {
log_error("No complete volume groups found");
return ECMD_FAILED;
}
list_iterate_items(sl, vgids) {
vgid = sl->str;
if (!vgid || !(vg_name = vgname_from_vgid(NULL, vgid)) || !*vg_name)
continue;
if (!strcmp(vg_name, vg_name_old)) {
if (match) {
log_error("Found more than one VG called %s. "
"Please supply VG uuid.", vg_name_old);
return ECMD_FAILED;
}
match = 1;
}
}
log_suppress(2);
found_id = id_read_format(&id, vg_name_old);
log_suppress(0);
if (found_id && (vg_name = vgname_from_vgid(cmd->mem, id.uuid))) {
vg_name_old = vg_name;
vgid = id.uuid;
} else
vgid = NULL;
if (!lock_vol(cmd, vg_name_old, LCK_VG_WRITE)) {
log_error("Can't get lock for %s", vg_name_old);
return ECMD_FAILED;
}
if (!(vg_old = vg_read(cmd, vg_name_old, NULL, &consistent)) || !consistent) {
log_error("Volume group \"%s\" doesn't exist", vg_name_old);
if (!(vg_old = vg_read(cmd, vg_name_old, vgid, &consistent)) || !consistent) {
log_error("Volume group %s %s%s%snot found.", vg_name_old,
vgid ? "(" : "", vgid ? vgid : "", vgid ? ") " : "");
unlock_vg(cmd, vg_name_old);
return ECMD_FAILED;
}
if (vg_old->status & EXPORTED_VG) {
unlock_vg(cmd, vg_name_old);
log_error("Volume group \"%s\" is exported", vg_old->name);
return ECMD_FAILED;
}
if (vg_old->status & EXPORTED_VG)
log_info("Volume group \"%s\" is exported", vg_old->name);
if (!(vg_old->status & LVM_WRITE)) {
unlock_vg(cmd, vg_name_old);
@ -146,6 +176,10 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
log_print("Volume group \"%s\" successfully renamed to \"%s\"",
vg_name_old, vg_name_new);
/* FIXME lvmcache corruption - vginfo duplicated instead of renamed */
persistent_filter_wipe(cmd->filter);
lvmcache_destroy();
return ECMD_PROCESSED;
error: