1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-01 08:58:47 +03:00

Prepare to move guts of lvremove into lvm library

This commit is contained in:
Dave Wysochanski 2007-08-20 16:16:54 +00:00
parent 626c6d1124
commit a94195c6cd
2 changed files with 37 additions and 18 deletions

View File

@ -103,6 +103,15 @@ typedef enum {
AREA_LV AREA_LV
} area_type_t; } area_type_t;
/*
* Whether or not to force an operation.
*/
typedef enum {
DONT_FORCE = 0,
FORCE = 1,
FORCE_2 = 2
} force_t;
struct cmd_context; struct cmd_context;
struct format_handler; struct format_handler;
struct labeller; struct labeller;

View File

@ -15,8 +15,9 @@
#include "tools.h" #include "tools.h"
static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv, /* TODO: Next checkin, move to lvm library (lv_manip.c, metadata-exported.h) */
void *handle __attribute((unused))) static int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
force_t force)
{ {
struct volume_group *vg; struct volume_group *vg;
struct lvinfo info; struct lvinfo info;
@ -25,29 +26,29 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
vg = lv->vg; vg = lv->vg;
if (!vg_check_status(vg, LVM_WRITE)) if (!vg_check_status(vg, LVM_WRITE))
return ECMD_FAILED; return 0;
if (lv_is_origin(lv)) { if (lv_is_origin(lv)) {
log_error("Can't remove logical volume \"%s\" under snapshot", log_error("Can't remove logical volume \"%s\" under snapshot",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
if (lv->status & MIRROR_IMAGE) { if (lv->status & MIRROR_IMAGE) {
log_error("Can't remove logical volume %s used by a mirror", log_error("Can't remove logical volume %s used by a mirror",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
if (lv->status & MIRROR_LOG) { if (lv->status & MIRROR_LOG) {
log_error("Can't remove logical volume %s used as mirror log", log_error("Can't remove logical volume %s used as mirror log",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
if (lv->status & LOCKED) { if (lv->status & LOCKED) {
log_error("Can't remove locked LV %s", lv->name); log_error("Can't remove locked LV %s", lv->name);
return ECMD_FAILED; return 0;
} }
/* FIXME Ensure not referred to by another existing LVs */ /* FIXME Ensure not referred to by another existing LVs */
@ -56,22 +57,22 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (info.open_count) { if (info.open_count) {
log_error("Can't remove open logical volume \"%s\"", log_error("Can't remove open logical volume \"%s\"",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
if (info.exists && !arg_count(cmd, force_ARG)) { if (info.exists && (force == DONT_FORCE)) {
if (yes_no_prompt("Do you really want to remove active " if (yes_no_prompt("Do you really want to remove active "
"logical volume \"%s\"? [y/n]: ", "logical volume \"%s\"? [y/n]: ",
lv->name) == 'n') { lv->name) == 'n') {
log_print("Logical volume \"%s\" not removed", log_print("Logical volume \"%s\" not removed",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
} }
} }
if (!archive(vg)) if (!archive(vg))
return ECMD_FAILED; return 0;
/* If the VG is clustered then make sure no-one else is using the LV /* If the VG is clustered then make sure no-one else is using the LV
we are about to remove */ we are about to remove */
@ -79,7 +80,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!activate_lv_excl(cmd, lv)) { if (!activate_lv_excl(cmd, lv)) {
log_error("Can't get exclusive access to volume \"%s\"", log_error("Can't get exclusive access to volume \"%s\"",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
} }
@ -87,7 +88,7 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!deactivate_lv(cmd, lv)) { if (!deactivate_lv(cmd, lv)) {
log_error("Unable to deactivate logical volume \"%s\"", log_error("Unable to deactivate logical volume \"%s\"",
lv->name); lv->name);
return ECMD_FAILED; return 0;
} }
if (lv_is_cow(lv)) { if (lv_is_cow(lv)) {
@ -95,24 +96,24 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
log_verbose("Removing snapshot %s", lv->name); log_verbose("Removing snapshot %s", lv->name);
if (!vg_remove_snapshot(lv)) { if (!vg_remove_snapshot(lv)) {
stack; stack;
return ECMD_FAILED; return 0;
} }
} }
log_verbose("Releasing logical volume \"%s\"", lv->name); log_verbose("Releasing logical volume \"%s\"", lv->name);
if (!lv_remove(lv)) { if (!lv_remove(lv)) {
log_error("Error releasing logical volume \"%s\"", lv->name); log_error("Error releasing logical volume \"%s\"", lv->name);
return ECMD_FAILED; return 0;
} }
/* store it on disks */ /* store it on disks */
if (!vg_write(vg)) if (!vg_write(vg))
return ECMD_FAILED; return 0;
backup(vg); backup(vg);
if (!vg_commit(vg)) if (!vg_commit(vg))
return ECMD_FAILED; return 0;
/* If no snapshots left, reload without -real. */ /* If no snapshots left, reload without -real. */
if (origin && !lv_is_origin(origin)) { if (origin && !lv_is_origin(origin)) {
@ -123,7 +124,16 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
} }
log_print("Logical volume \"%s\" successfully removed", lv->name); log_print("Logical volume \"%s\" successfully removed", lv->name);
return ECMD_PROCESSED; return 1;
}
static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle __attribute((unused)))
{
if (!lv_remove_single(cmd, lv, arg_count(cmd, force_ARG)))
return ECMD_FAILED;
else
return ECMD_PROCESSED;
} }
int lvremove(struct cmd_context *cmd, int argc, char **argv) int lvremove(struct cmd_context *cmd, int argc, char **argv)