mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
metadata: ask for confirmation before really initializing/removing PV that is marked as belonging to a VG
Ask for confirmation when using pvcreate/pvremove on a PV which is marked as belonging to a VG, just like we do in case of a PV which belongs to known VG: $ pvcreate -ff /dev/sda Really INITIALIZE physical volume "/dev/sda" that is marked as belonging to a VG [y/n]? n /dev/sda: physical volume not initialized $ pvremove -ff /dev/sda Really WIPE LABELS from physical volume "/dev/sda" that is marked as belonging to a VG [y/n]? n /dev/sda: physical volume label not removed
This commit is contained in:
parent
1a141e8623
commit
ecfa465366
@ -1470,6 +1470,8 @@ int vg_split_mdas(struct cmd_context *cmd __attribute__((unused)),
|
|||||||
static int _pvcreate_check(struct cmd_context *cmd, const char *name,
|
static int _pvcreate_check(struct cmd_context *cmd, const char *name,
|
||||||
struct pvcreate_params *pp, int *wiped)
|
struct pvcreate_params *pp, int *wiped)
|
||||||
{
|
{
|
||||||
|
static const char really_init_msg[] = "Really INITIALIZE physical volume";
|
||||||
|
static const char not_init_msg[] = "physical volume not initialized";
|
||||||
struct physical_volume *pv;
|
struct physical_volume *pv;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
@ -1504,11 +1506,22 @@ static int _pvcreate_check(struct cmd_context *cmd, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* prompt */
|
/* prompt */
|
||||||
if (pv && !is_orphan(pv) && !pp->yes &&
|
if (pv && !pp->yes) {
|
||||||
yes_no_prompt("Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? ",
|
if (is_orphan(pv)) {
|
||||||
name, pv_vg_name(pv)) == 'n') {
|
if (used) {
|
||||||
log_error("%s: physical volume not initialized", name);
|
if (yes_no_prompt("%s \"%s\" that is marked as belonging to a VG [y/n]? ",
|
||||||
goto out;
|
really_init_msg, name) == 'n') {
|
||||||
|
log_error("%s: %s", name, not_init_msg);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (yes_no_prompt("%s \"%s\" of volume group \"%s\" [y/n]? ",
|
||||||
|
really_init_msg, name, pv_vg_name(pv)) == 'n') {
|
||||||
|
log_error("%s: %s", name, not_init_msg);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sigint_caught())
|
if (sigint_caught())
|
||||||
|
@ -687,9 +687,6 @@ out:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char _really_wipe[] =
|
|
||||||
"Really WIPE LABELS from physical volume \"%s\" of volume group \"%s\" [y/n]? ";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decide whether it is "safe" to wipe the labels on this device.
|
* Decide whether it is "safe" to wipe the labels on this device.
|
||||||
* 0 indicates we may not.
|
* 0 indicates we may not.
|
||||||
@ -697,6 +694,8 @@ const char _really_wipe[] =
|
|||||||
static int pvremove_check(struct cmd_context *cmd, const char *name,
|
static int pvremove_check(struct cmd_context *cmd, const char *name,
|
||||||
unsigned force_count, unsigned prompt, struct dm_list *pvslist)
|
unsigned force_count, unsigned prompt, struct dm_list *pvslist)
|
||||||
{
|
{
|
||||||
|
static const char really_wipe_msg[] = "Really WIPE LABELS from physical volume";
|
||||||
|
static const char not_removed_msg[] = "physical volume label not removed";
|
||||||
static const char pvremove_force_hint_msg[] = "(If you are certain you need pvremove, then confirm by using --force twice.)";
|
static const char pvremove_force_hint_msg[] = "(If you are certain you need pvremove, then confirm by using --force twice.)";
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
struct label *label;
|
struct label *label;
|
||||||
@ -741,25 +740,32 @@ static int pvremove_check(struct cmd_context *cmd, const char *name,
|
|||||||
log_error("%s", pvremove_force_hint_msg);
|
log_error("%s", pvremove_force_hint_msg);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
r = 1;
|
/* we must have -ff to overwrite a non orphan */
|
||||||
goto out;
|
if (force_count < 2) {
|
||||||
}
|
log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
|
||||||
|
log_error("%s", pvremove_force_hint_msg);
|
||||||
/* we must have -ff to overwrite a non orphan */
|
goto out;
|
||||||
if (force_count < 2) {
|
}
|
||||||
log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
|
|
||||||
log_error("%s", pvremove_force_hint_msg);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prompt */
|
/* prompt */
|
||||||
if (!prompt &&
|
if (!prompt) {
|
||||||
yes_no_prompt("Really WIPE LABELS from physical volume \"%s\" "
|
if (is_orphan(pv)) {
|
||||||
"of volume group \"%s\" [y/n]? ",
|
if (used) {
|
||||||
name, pv_vg_name(pv)) == 'n') {
|
if (yes_no_prompt("%s \"%s\" that is marked as belonging to a VG [y/n]? ",
|
||||||
log_error("%s: physical volume label not removed", name);
|
really_wipe_msg, name) == 'n') {
|
||||||
goto out;
|
log_error("%s: %s", name, not_removed_msg);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (yes_no_prompt("%s \"%s\" of volume group \"%s\" [y/n]? ",
|
||||||
|
really_wipe_msg, name, pv_vg_name(pv)) == 'n') {
|
||||||
|
log_error("%s: %s", name, not_removed_msg);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (force_count) {
|
if (force_count) {
|
||||||
|
@ -55,9 +55,9 @@ grep "$MARKED_AS_USED_MSG" err
|
|||||||
dd if="$dev1" of=dev1_backup bs=1M
|
dd if="$dev1" of=dev1_backup bs=1M
|
||||||
|
|
||||||
# pvcreate and pvremove can be forced even if the PV is marked as used
|
# pvcreate and pvremove can be forced even if the PV is marked as used
|
||||||
pvremove -ff "$dev1"
|
pvremove -ff -y "$dev1"
|
||||||
dd if=dev1_backup of="$dev1" bs=1M
|
dd if=dev1_backup of="$dev1" bs=1M
|
||||||
pvcreate -ff "$dev1"
|
pvcreate -ff -y "$dev1"
|
||||||
dd if=dev1_backup of="$dev1" bs=1M
|
dd if=dev1_backup of="$dev1" bs=1M
|
||||||
|
|
||||||
# prepare a VG with $dev1 and $dev both having 1 MDA
|
# prepare a VG with $dev1 and $dev both having 1 MDA
|
||||||
@ -120,9 +120,9 @@ grep "$MARKED_AS_USED_MSG" err
|
|||||||
dd if="$dev1" of=dev1_backup bs=1M
|
dd if="$dev1" of=dev1_backup bs=1M
|
||||||
|
|
||||||
# pvcreate and pvremove can be forced even if the PV is marked as used
|
# pvcreate and pvremove can be forced even if the PV is marked as used
|
||||||
pvremove -ff "$dev1"
|
pvremove -ff -y "$dev1"
|
||||||
dd if=dev1_backup of="$dev1" bs=1M
|
dd if=dev1_backup of="$dev1" bs=1M
|
||||||
pvcreate -ff "$dev1"
|
pvcreate -ff -y "$dev1"
|
||||||
dd if=dev1_backup of="$dev1" bs=1M
|
dd if=dev1_backup of="$dev1" bs=1M
|
||||||
|
|
||||||
# prepare a VG with $dev1 and $dev both having 1 MDA
|
# prepare a VG with $dev1 and $dev both having 1 MDA
|
||||||
|
Loading…
Reference in New Issue
Block a user