1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-01 09:47:48 +03:00

Remove force parameter from vg_remove_single, now the liblvm function.

Move check for active LVs outside of library function.  The vgremove
liblvm function function will fail if there are active LVs.  It will
be the application's responsibility to check this condition and remove
the LVs individually before calling vgremove.  Note also that we've
duplicated the EXPORTED_VG check in vgremove_single (tools) and
vg_remove_single (library).  Duplication seemed the only option here
since we don't want to do the automatic removal of LVs (in the tools)
if the vg is exported, and we still need to protect the library call
from removal if the vg is exported.

We still need to deal with the ORPHAN lock but vg_remove_single is now
very close to our liblvm function.

TODO: Refactor lvremove in a similar way.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
Dave Wysochanski 2009-07-10 20:07:02 +00:00
parent a6ad9c6166
commit 42ae96fa3d
3 changed files with 32 additions and 21 deletions

View File

@ -425,7 +425,7 @@ uint32_t pv_list_extents_free(const struct dm_list *pvh);
vg_t *vg_create(struct cmd_context *cmd, const char *vg_name);
int vg_remove(struct volume_group *vg);
int vg_remove_single(vg_t *vg, force_t force);
int vg_remove_single(vg_t *vg);
int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
const char *new_name);
int vg_extend(struct volume_group *vg, int pv_count, char **pv_names);
@ -436,6 +436,10 @@ int vg_set_alloc_policy(vg_t *vg, alloc_policy_t alloc);
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
struct volume_group *vg_to);
/* FIXME: refactor / unexport when lvremove liblvm refactoring dones */
int remove_lvs_in_vg(struct cmd_context *cmd,
struct volume_group *vg,
force_t force);
/*
* vg_release() must be called on every struct volume_group allocated
* by vg_create() or vg_read_internal() to free it when no longer required.

View File

@ -343,9 +343,9 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
return 1;
}
static int remove_lvs_in_vg(struct cmd_context *cmd,
struct volume_group *vg,
force_t force)
int remove_lvs_in_vg(struct cmd_context *cmd,
struct volume_group *vg,
force_t force)
{
struct dm_list *lst;
struct lv_list *lvl;
@ -359,7 +359,7 @@ static int remove_lvs_in_vg(struct cmd_context *cmd,
return 1;
}
int vg_remove_single(vg_t *vg, force_t force)
int vg_remove_single(vg_t *vg)
{
struct physical_volume *pv;
struct pv_list *pvl;
@ -379,21 +379,6 @@ int vg_remove_single(vg_t *vg, force_t force)
lv_count = vg_visible_lvs(vg);
if (lv_count) {
if ((force == PROMPT) &&
(yes_no_prompt("Do you really want to remove volume "
"group \"%s\" containing %u "
"logical volumes? [y/n]: ",
vg->name, lv_count) == 'n')) {
log_print("Volume group \"%s\" not removed", vg_name);
return 0;
}
if (!remove_lvs_in_vg(vg->cmd, vg, force))
return 0;
}
lv_count = vg_visible_lvs(vg);
if (lv_count) {
log_error("Volume group \"%s\" still contains %u "
"logical volume(s)", vg->name, lv_count);

View File

@ -19,7 +19,29 @@ static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg,
void *handle __attribute((unused)))
{
if (!vg_remove_single(vg, arg_count(cmd, force_ARG)))
unsigned lv_count;
force_t force;
if (!vg_check_status(vg, EXPORTED_VG))
return ECMD_FAILED;
lv_count = vg_visible_lvs(vg);
force = arg_count(cmd, force_ARG);
if (lv_count) {
if ((force == PROMPT) &&
(yes_no_prompt("Do you really want to remove volume "
"group \"%s\" containing %u "
"logical volumes? [y/n]: ",
vg_name, lv_count) == 'n')) {
log_print("Volume group \"%s\" not removed", vg_name);
return ECMD_FAILED;
}
if (!remove_lvs_in_vg(cmd, vg, force))
return ECMD_FAILED;
}
if (!vg_remove_single(vg))
return ECMD_FAILED;
return ECMD_PROCESSED;