mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
pv/vgchange --uuid to change (non-random) UUIDs to random values
This commit is contained in:
parent
cc8f6e3dbc
commit
15e6db353d
@ -315,17 +315,18 @@ xx(lvscan,
|
|||||||
xx(pvchange,
|
xx(pvchange,
|
||||||
"Change attributes of physical volume(s)",
|
"Change attributes of physical volume(s)",
|
||||||
"pvchange\n"
|
"pvchange\n"
|
||||||
|
"\t[-a|--all]\n"
|
||||||
"\t[-A|--autobackup y|n]\n"
|
"\t[-A|--autobackup y|n]\n"
|
||||||
"\t[-d|--debug]\n"
|
"\t[-d|--debug]\n"
|
||||||
"\t[-h|--help]\n"
|
"\t[-h|--help]\n"
|
||||||
|
"\t[-t|--test]\n"
|
||||||
|
"\t[-u|--uuid]\n"
|
||||||
|
"\t[-x|--allocatable y|n]\n"
|
||||||
"\t[-v|--verbose]\n"
|
"\t[-v|--verbose]\n"
|
||||||
"\t[--version]" "\n"
|
"\t[--version]" "\n"
|
||||||
"\t[-a|--all]\n"
|
|
||||||
"\t[-t|--test]\n"
|
|
||||||
"\t[-x|--allocatable y|n]\n"
|
|
||||||
"\t[PhysicalVolumePath...]\n",
|
"\t[PhysicalVolumePath...]\n",
|
||||||
|
|
||||||
all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, test_ARG)
|
all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, test_ARG, uuid_ARG)
|
||||||
|
|
||||||
xx(pvcreate,
|
xx(pvcreate,
|
||||||
"Initialize physical volume(s) for use by LVM",
|
"Initialize physical volume(s) for use by LVM",
|
||||||
@ -531,6 +532,7 @@ xx(vgchange,
|
|||||||
"\t[-h|--help] " "\n"
|
"\t[-h|--help] " "\n"
|
||||||
"\t[--ignorelockingfailure]\n"
|
"\t[--ignorelockingfailure]\n"
|
||||||
"\t[-t|--test]" "\n"
|
"\t[-t|--test]" "\n"
|
||||||
|
"\t[-u|--uuid] " "\n"
|
||||||
"\t[-v|--verbose] " "\n"
|
"\t[-v|--verbose] " "\n"
|
||||||
"\t[--version]" "\n"
|
"\t[--version]" "\n"
|
||||||
"\t{-a|--available {y|n} |" "\n"
|
"\t{-a|--available {y|n} |" "\n"
|
||||||
@ -539,7 +541,8 @@ xx(vgchange,
|
|||||||
"\t[VolumeGroupName...]\n",
|
"\t[VolumeGroupName...]\n",
|
||||||
|
|
||||||
allocation_ARG, autobackup_ARG, available_ARG, ignorelockingfailure_ARG,
|
allocation_ARG, autobackup_ARG, available_ARG, ignorelockingfailure_ARG,
|
||||||
logicalvolume_ARG, partial_ARG, resizeable_ARG, resizable_ARG, test_ARG)
|
logicalvolume_ARG, partial_ARG, resizeable_ARG, resizable_ARG, test_ARG,
|
||||||
|
uuid_ARG)
|
||||||
|
|
||||||
xx(vgck,
|
xx(vgck,
|
||||||
"Check the consistency of volume group(s)",
|
"Check the consistency of volume group(s)",
|
||||||
|
@ -33,8 +33,11 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
const char *pv_name = dev_name(pv->dev);
|
const char *pv_name = dev_name(pv->dev);
|
||||||
|
|
||||||
int consistent = 1;
|
int consistent = 1;
|
||||||
int allocatable =
|
int allocatable = 0;
|
||||||
!strcmp(arg_str_value(cmd, allocatable_ARG, "n"), "y");
|
|
||||||
|
if (arg_count(cmd, allocatable_ARG))
|
||||||
|
allocatable = !strcmp(arg_str_value(cmd, allocatable_ARG, "n"),
|
||||||
|
"y");
|
||||||
|
|
||||||
/* If in a VG, must change using volume group. */
|
/* If in a VG, must change using volume group. */
|
||||||
if (*pv->vg_name) {
|
if (*pv->vg_name) {
|
||||||
@ -43,7 +46,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
|
|
||||||
if (!lock_vol(cmd, pv->vg_name, LCK_VG_WRITE)) {
|
if (!lock_vol(cmd, pv->vg_name, LCK_VG_WRITE)) {
|
||||||
log_error("Can't get lock for %s", pv->vg_name);
|
log_error("Can't get lock for %s", pv->vg_name);
|
||||||
return ECMD_FAILED;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vg = vg_read(cmd, pv->vg_name, &consistent))) {
|
if (!(vg = vg_read(cmd, pv->vg_name, &consistent))) {
|
||||||
@ -56,13 +59,13 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
if (vg->status & EXPORTED_VG) {
|
if (vg->status & EXPORTED_VG) {
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
log_error("Volume group \"%s\" is exported", vg->name);
|
log_error("Volume group \"%s\" is exported", vg->name);
|
||||||
return ECMD_FAILED;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vg->status & LVM_WRITE)) {
|
if (!(vg->status & LVM_WRITE)) {
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
log_error("Volume group \"%s\" is read-only", vg->name);
|
log_error("Volume group \"%s\" is read-only", vg->name);
|
||||||
return ECMD_FAILED;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
|
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
|
||||||
@ -72,13 +75,19 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
pv_name, vg->name);
|
pv_name, vg->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (arg_count(cmd, uuid_ARG) && lvs_in_vg_activated(vg)) {
|
||||||
|
unlock_vg(cmd, pv->vg_name);
|
||||||
|
log_error("Volume group containing %s has active "
|
||||||
|
"logical volumes", pv_name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
pv = pvl->pv;
|
pv = pvl->pv;
|
||||||
if (!archive(vg))
|
if (!archive(vg))
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (!lock_vol(cmd, ORPHAN, LCK_VG_WRITE)) {
|
if (!lock_vol(cmd, ORPHAN, LCK_VG_WRITE)) {
|
||||||
log_error("Can't get lock for orphans");
|
log_error("Can't get lock for orphans");
|
||||||
return ECMD_FAILED;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pv = pv_read(cmd, pv_name, &mdas, §or))) {
|
if (!(pv = pv_read(cmd, pv_name, &mdas, §or))) {
|
||||||
@ -89,6 +98,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg_count(cmd, allocatable_ARG)) {
|
||||||
if (!*pv->vg_name &&
|
if (!*pv->vg_name &&
|
||||||
!(pv->fmt->features & FMT_ORPHAN_ALLOCATABLE)) {
|
!(pv->fmt->features & FMT_ORPHAN_ALLOCATABLE)) {
|
||||||
log_error("Allocatability not supported by orphan "
|
log_error("Allocatability not supported by orphan "
|
||||||
@ -99,8 +109,8 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
|
|
||||||
/* change allocatability for a PV */
|
/* change allocatability for a PV */
|
||||||
if (allocatable && (pv->status & ALLOCATABLE_PV)) {
|
if (allocatable && (pv->status & ALLOCATABLE_PV)) {
|
||||||
log_error("Physical volume \"%s\" is already allocatable",
|
log_error("Physical volume \"%s\" is already "
|
||||||
pv_name);
|
"allocatable", pv_name);
|
||||||
if (*pv->vg_name)
|
if (*pv->vg_name)
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
else
|
else
|
||||||
@ -109,8 +119,8 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!allocatable && !(pv->status & ALLOCATABLE_PV)) {
|
if (!allocatable && !(pv->status & ALLOCATABLE_PV)) {
|
||||||
log_error("Physical volume \"%s\" is already unallocatable",
|
log_error("Physical volume \"%s\" is already "
|
||||||
pv_name);
|
"unallocatable", pv_name);
|
||||||
if (*pv->vg_name)
|
if (*pv->vg_name)
|
||||||
unlock_vg(cmd, pv->vg_name);
|
unlock_vg(cmd, pv->vg_name);
|
||||||
else
|
else
|
||||||
@ -119,14 +129,18 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (allocatable) {
|
if (allocatable) {
|
||||||
log_verbose("Setting physical volume \"%s\" allocatable",
|
log_verbose("Setting physical volume \"%s\" "
|
||||||
pv_name);
|
"allocatable", pv_name);
|
||||||
pv->status |= ALLOCATABLE_PV;
|
pv->status |= ALLOCATABLE_PV;
|
||||||
} else {
|
} else {
|
||||||
log_verbose("Setting physical volume \"%s\" NOT allocatable",
|
log_verbose("Setting physical volume \"%s\" NOT "
|
||||||
pv_name);
|
"allocatable", pv_name);
|
||||||
pv->status &= ~ALLOCATABLE_PV;
|
pv->status &= ~ALLOCATABLE_PV;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* --uuid: Change PV ID randomly */
|
||||||
|
id_create(&pv->id);
|
||||||
|
}
|
||||||
|
|
||||||
log_verbose("Updating physical volume \"%s\"", pv_name);
|
log_verbose("Updating physical volume \"%s\"", pv_name);
|
||||||
if (*pv->vg_name) {
|
if (*pv->vg_name) {
|
||||||
@ -168,8 +182,9 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
list_init(&mdas);
|
list_init(&mdas);
|
||||||
|
|
||||||
if (arg_count(cmd, allocatable_ARG) == 0) {
|
if (arg_count(cmd, allocatable_ARG) +
|
||||||
log_error("Please give the x option");
|
+ arg_count(cmd, uuid_ARG) != 1) {
|
||||||
|
log_error("Please give exactly one option of -x or --uuid");
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,8 +226,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
|
|
||||||
log_print("%d physical volume%s changed / %d physical volume%s "
|
log_print("%d physical volume%s changed / %d physical volume%s "
|
||||||
"not changed",
|
"not changed",
|
||||||
done, done > 1 ? "s" : "",
|
done, done == 1 ? "" : "s",
|
||||||
total - done, total - done > 1 ? "s" : "");
|
total - done, (total - done) == 1 ? "" : "s");
|
||||||
|
|
||||||
return (total == done) ? ECMD_PROCESSED : ECMD_FAILED;
|
return (total == done) ? ECMD_PROCESSED : ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,34 @@ static int _vgchange_logicalvolume(struct cmd_context *cmd,
|
|||||||
return ECMD_PROCESSED;
|
return ECMD_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _vgchange_uuid(struct cmd_context *cmd, struct volume_group *vg)
|
||||||
|
{
|
||||||
|
struct lv_list *lvl;
|
||||||
|
|
||||||
|
if (lvs_in_vg_activated(vg)) {
|
||||||
|
log_error("Volume group has active logical volumes");
|
||||||
|
return ECMD_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!archive(vg))
|
||||||
|
return ECMD_FAILED;
|
||||||
|
|
||||||
|
id_create(&vg->id);
|
||||||
|
|
||||||
|
list_iterate_items(lvl, &vg->lvs) {
|
||||||
|
memcpy(&lvl->lv->lvid, &vg->id, sizeof(vg->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vg_write(vg) || !vg_commit(vg))
|
||||||
|
return ECMD_FAILED;
|
||||||
|
|
||||||
|
backup(vg);
|
||||||
|
|
||||||
|
log_print("Volume group \"%s\" successfully changed", vg->name);
|
||||||
|
|
||||||
|
return ECMD_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
|
static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
|
||||||
struct volume_group *vg, int consistent,
|
struct volume_group *vg, int consistent,
|
||||||
void *handle)
|
void *handle)
|
||||||
@ -201,6 +229,9 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
|
|||||||
else if (arg_count(cmd, logicalvolume_ARG))
|
else if (arg_count(cmd, logicalvolume_ARG))
|
||||||
r = _vgchange_logicalvolume(cmd, vg);
|
r = _vgchange_logicalvolume(cmd, vg);
|
||||||
|
|
||||||
|
else if (arg_count(cmd, uuid_ARG))
|
||||||
|
r = _vgchange_uuid(cmd, vg);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,14 +239,14 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
if (!
|
if (!
|
||||||
(arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
|
(arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
|
||||||
arg_count(cmd, resizeable_ARG))) {
|
arg_count(cmd, resizeable_ARG) + arg_count(cmd, uuid_ARG))) {
|
||||||
log_error("One of -a, -l or -x options required");
|
log_error("One of -a, -l, --uuid or -x options required");
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
|
if (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
|
||||||
arg_count(cmd, resizeable_ARG) > 1) {
|
arg_count(cmd, resizeable_ARG) + arg_count(cmd, uuid_ARG) > 1) {
|
||||||
log_error("Only one of -a, -l or -x options allowed");
|
log_error("Only one of -a, -l, --uuid or -x options allowed");
|
||||||
return EINVALID_CMD_LINE;
|
return EINVALID_CMD_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user