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

o activation & active status tests

o lvdisplay fields from kernel
o update lv->size on resize
This commit is contained in:
Alasdair Kergon 2001-11-21 19:32:35 +00:00
parent ab2799eb14
commit 3080a75445
20 changed files with 141 additions and 89 deletions

View File

@ -10,8 +10,6 @@
#include "log.h"
#include "fs.h"
#include <devmapper/libdevmapper.h>
static void _build_lv_name(char *buffer, size_t s, struct logical_volume *lv)
{
snprintf(buffer, s, "%s_%s", lv->vg->name, lv->name);
@ -33,7 +31,7 @@ static struct dm_task *_setup_task(struct logical_volume *lv, int task)
return dmt;
}
static int _info(struct logical_volume *lv, struct dm_info *info)
int lv_info(struct logical_volume *lv, struct dm_info *info)
{
int r = 0;
struct dm_task *dmt;
@ -64,7 +62,7 @@ int lv_active(struct logical_volume *lv)
int r = -1;
struct dm_info info;
if (!_info(lv, &info)) {
if (!lv_info(lv, &info)) {
stack;
return r;
}
@ -77,7 +75,7 @@ int lv_open_count(struct logical_volume *lv)
int r = -1;
struct dm_info info;
if (!_info(lv, &info)) {
if (!lv_info(lv, &info)) {
stack;
return r;
}
@ -153,6 +151,8 @@ int _load(struct logical_volume *lv, int task)
if (!(r = dm_task_run(dmt)))
stack;
log_verbose("Logical volume %s activated", lv->name);
out:
dm_task_destroy(dmt);
return r;

View File

@ -7,10 +7,13 @@
#ifndef LVM_ACTIVATE_H
#define LVM_ACTIVATE_H
#include <libdevmapper.h>
/* FIXME Snapshot handling? */
int lv_active(struct logical_volume *lv);
int lv_open_count(struct logical_volume *lv);
int lv_info(struct logical_volume *lv, struct dm_info *info);
int lv_activate(struct logical_volume *lv);
int lv_reactivate(struct logical_volume *lv);

View File

@ -15,7 +15,7 @@
#include "fs.h"
#include "log.h"
#include <devmapper/libdevmapper.h>
#include <libdevmapper.h>
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv)
{

View File

@ -207,19 +207,24 @@ int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv)
void lvdisplay_colons(struct logical_volume *lv)
{
log_print("%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:-1:-1",
/* FIXME Prefix - attach to struct volume_group? */
int inkernel;
struct dm_info info;
inkernel = lv_info(lv, &info) && info.exists;
log_print("%s%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:%d:%d",
lv->vg->cmd->dev_dir,
lv->vg->name,
lv->name,
lv->vg->name,
(lv->status & (LVM_READ | LVM_WRITE)) >> 8,
lv->status & ACTIVE,
inkernel ? 1 : 0,
/* FIXME lv->lv_number, */
lvs_in_vg_opened(lv->vg), lv->size, lv->le_count,
inkernel ? info.open_count : 0, lv->size, lv->le_count,
/* FIXME Add num allocated to struct! lv->lv_allocated_le, */
((lv->status & ALLOC_STRICT) +
(lv->status & ALLOC_CONTIGUOUS) * 2), lv->read_ahead
/* FIXME device num MAJOR(lv->lv_dev), MINOR(lv->lv_dev) */
(lv->status & ALLOC_CONTIGUOUS) * 2), lv->read_ahead,
inkernel ? info.major : -1,
inkernel ? info.minor : -1
);
return;
}
@ -228,11 +233,15 @@ int lvdisplay_full(struct logical_volume *lv)
{
char *size;
uint32_t alloc;
struct dm_info info;
int inkernel;
inkernel = lv_info(lv, &info) && info.exists;
log_print("--- Logical volume ---");
/* FIXME Add dev_dir */
log_print("LV Name %s/%s", lv->vg->name, lv->name);
log_print("LV Name %s%s/%s", lv->vg->cmd->dev_dir,
lv->vg->name, lv->name);
log_print("VG Name %s", lv->vg->name);
log_print("LV Write Access %s",
@ -283,16 +292,19 @@ int lvdisplay_full(struct logical_volume *lv)
}
***********/
log_print("LV Status %savailable",
(lv->status & ACTIVE) ? "" : "NOT ");
if (inkernel && info.suspended)
log_print("LV Status suspended");
else
log_print("LV Status %savailable",
inkernel ? "" : "NOT ");
/********* FIXME lv_number
log_print("LV # %u", lv->lv_number + 1);
************/
/********* FIXME lv_open
log_print("# open %u\n", lv->lv_open);
**********/
if (inkernel)
log_print("# open %u", info.open_count);
/********
#ifdef LVM_FUTURE
printf("Mirror copies %u\n", lv->lv_mirror_copies);
@ -374,7 +386,7 @@ int lvdisplay_full(struct logical_volume *lv)
(ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "strict/contiguous" :
"");
log_print("Read ahead sectors %u\n", lv->read_ahead);
log_print("Read ahead sectors %u", lv->read_ahead);
/****************
#ifdef LVM_FUTURE
@ -386,15 +398,15 @@ int lvdisplay_full(struct logical_volume *lv)
#endif
*************/
/********* FIXME blockdev
printf("Block device %d:%d\n",
MAJOR(lv->lv_dev), MINOR(lv->lv_dev));
*************/
if (inkernel)
log_print("Block device %d:%d", info.major,
info.minor);
log_print(" ");
return 0;
}
void lvdisplay_extents(struct logical_volume *lv)
{
int le;

View File

@ -296,6 +296,7 @@ int lv_reduce(struct logical_volume *lv, uint32_t extents)
}
lv->le_count = extents;
lv->size = extents * lv->vg->extent_size;
return 1;
}
@ -325,6 +326,7 @@ int lv_extend(struct logical_volume *lv, uint32_t extents,
memcpy(new_lv, lv, sizeof(*lv));
new_lv->map = new_map;
new_lv->le_count += extents;
new_lv->size += extents * lv->vg->extent_size;
if (!_allocate(new_lv->vg, new_lv, acceptable_pvs, lv->le_count)) {
stack;

View File

@ -44,14 +44,17 @@ int lvchange(int argc, char **argv)
static int lvchange_single(struct logical_volume *lv)
{
char *vg_name;
int doit = 0;
if (!(lv->vg->status & ACTIVE)) {
/******* Removed requirement for VG to be active before making changes
if (!(lv->vg->status & ACTIVE) &&
!(arg_count(available_ARG) &&
strcmp(arg_str_value(available_ARG, "n"), "n"))) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
"logical volume", vg->name);
return ECMD_FAILED;
}
********/
if (lv->status & SNAPSHOT_ORG) {
log_error("Can't change logical volume %s under snapshot",
@ -84,8 +87,6 @@ static int lvchange_single(struct logical_volume *lv)
return 0;
}
/* FIXME activate change */
log_print("Logical volume %s changed", lv->name);
/* FIXME do_autobackup */
@ -131,19 +132,12 @@ static int lvchange_permission(struct logical_volume *lv)
static int lvchange_availability(struct logical_volume *lv)
{
int lv_stat = 0;
int active;
if (strcmp(arg_str_value(available_ARG, "n"), "n"))
lv_stat |= ACTIVE;
if ((lv_stat & ACTIVE) && (lv->status & ACTIVE)) {
log_error("Logical volume %s is already active", lv->name);
return 0;
}
if (!(lv_stat & ACTIVE) && !(lv->status & ACTIVE)) {
log_error("Logical volume %s is already not active", lv->name);
return 0;
}
active = lv_active(lv);
if (lv_stat & ACTIVE) {
lv->status |= ACTIVE;
@ -153,17 +147,32 @@ static int lvchange_availability(struct logical_volume *lv)
log_verbose("Deactivating logical volume %s", lv->name);
}
log_very_verbose("Updating logical volume %s on disk(s)", lv->name);
if (!fid->ops->vg_write(fid, lv->vg))
return 0;
if ((lv_stat & ACTIVE) && (lv->status & ACTIVE))
log_verbose("Logical volume %s is already active on disk",
lv->name);
else if (!(lv_stat & ACTIVE) && !(lv->status & ACTIVE))
log_verbose("Logical volume %s is already inactive on disk",
lv->name);
else {
log_very_verbose("Updating logical volume %s on disk(s)",
lv->name);
if (!fid->ops->vg_write(fid, lv->vg))
return 0;
}
log_very_verbose("Updating %s in kernel", lv->name);
if (lv_stat & ACTIVE) {
if (!lv_activate(lv))
return 0;
} else {
if (!lv_deactivate(lv))
return 0;
if ((lv_stat & ACTIVE) && (active & ACTIVE))
log_verbose("Logical volume %s is already active", lv->name);
else if (!(lv_stat & ACTIVE) && !(active & ACTIVE))
log_verbose("Logical volume %s is already inactive", lv->name);
else {
log_very_verbose("Updating %s in kernel", lv->name);
if (lv_stat & ACTIVE) {
if (!lv_activate(lv))
return 0;
} else {
if (!lv_deactivate(lv))
return 0;
}
}
return 1;

View File

@ -115,11 +115,13 @@ int lvcreate(int argc, char **argv)
return ECMD_FAILED;
}
/******* Removed check
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
return ECMD_FAILED;
}
********/
if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) {
log_error("Logical volume %s already exists in "

View File

@ -721,6 +721,7 @@ static int init(void)
/* FIXME: Override from config file. (Append trailing slash if reqd) */
cmd->dev_dir = "/dev/";
dm_set_dev_dir(cmd->dev_dir);
if (!(cmd->cf = create_config_file())) {
stack;
@ -744,6 +745,8 @@ static int init(void)
__init_log(cmd->cf);
}
dm_log_init(print_log);
if (!dev_cache_setup(cmd->cf)) {
goto out;
}

View File

@ -37,11 +37,14 @@ static int lvremove_single(struct logical_volume *lv)
struct volume_group *vg;
vg = lv->vg;
/******* Removed requirement
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before removing a "
"logical volume", vg->name);
return ECMD_FAILED;
}
********/
if (lv->status & SNAPSHOT_ORG) {
log_error("Can't remove logical volume %s under snapshot",
@ -49,14 +52,11 @@ static int lvremove_single(struct logical_volume *lv)
return ECMD_FAILED;
}
/********** FIXME Ensure logical volume is not open on *any* machine
if (lv->open) {
log_error("can't remove open %s logical volume %s",
lv->status & SNAPSHOT ? "snapshot" : "",
lv->name);
/* FIXME Force option? */
if (lv_open_count(lv)) {
log_error("Can't remove open logical volume %s", lv->name);
return ECMD_FAILED;
}
************/
if (!arg_count(force_ARG)) {
if (yes_no_prompt
@ -67,6 +67,10 @@ static int lvremove_single(struct logical_volume *lv)
}
}
if (!lv_deactivate(lv)) {
log_error("Unable to deactivate logical volume %s", lv->name);
}
log_verbose("Releasing logical volume %s", lv->name);
if (!lv_remove(vg, lv)) {
log_error("Error releasing logical volume %s", lv->name);

View File

@ -89,11 +89,13 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED;
}
/******* Removed requirement
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
return ECMD_FAILED;
}
*******/
if ((lvh = find_lv_in_vg(vg, lv_name_new))) {
log_error("Logical volume %s already exists in "
@ -120,7 +122,8 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED;
}
/* FIXME Update symlink. lv_reactivate? */
/* FIXME Update symlink. */
lv_reactivate(lv);
/* FIXME backup */

View File

@ -95,11 +95,13 @@ int lvresize(int argc, char **argv)
return ECMD_FAILED;
}
/******* Remove requirement
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s must be active before changing a "
"logical volume", vg_name);
return ECMD_FAILED;
}
********/
/* does LV exist? */
if (!(lvh = find_lv_in_vg(vg, lv_name))) {
@ -110,11 +112,13 @@ int lvresize(int argc, char **argv)
lv = &list_item(lvh, struct lv_list)->lv;
/******* Remove requirement
if (!(lv->status & ACTIVE)) {
log_error("Logical volume %s must be active before change",
lv_name);
return ECMD_FAILED;
}
********/
if (size) {
/* No of 512-byte sectors */
@ -196,7 +200,7 @@ int lvresize(int argc, char **argv)
if (argc)
log_print("Ignoring PVs on command line when reducing");
if (lv->status & ACTIVE || lv_active(lv)) {
if (lv_active(lv)) {
dummy =
display_size(extents * vg->extent_size / 2,
SIZE_SHORT);

View File

@ -131,9 +131,11 @@ int pvchange_single(struct physical_volume *pv)
pv->status &= ~ALLOCATED_PV;
}
/******* Ignore active
if (!(pv->status & ACTIVE)) {
log_verbose("Physical volume %s inactive", pv_name);
}
********/
log_verbose("Updating physical volume %s", pv_name);
if (*pv->vg_name) {

View File

@ -50,10 +50,12 @@ static int pvcreate_check(const char *name)
return 0;
}
/******* Removed check
if (pv->status & ACTIVE) {
log_error("Can't create on active physical volume %s", name);
return 0;
}
********/
/* we must have -ff to overwrite a non orphan */
if (arg_count(force_ARG) < 2) {

View File

@ -78,20 +78,18 @@ static int vgchange_single(const char *vg_name)
void vgchange_available(struct volume_group *vg)
{
int lv_open;
struct list *pvh;
int lv_open, lv_active;
struct list *lvh;
int available = !strcmp(arg_str_value(available_ARG, "n"), "y");
/* FIXME Kernel status to override disk flags ! */
if (available && (vg->status & ACTIVE)) {
log_error("Volume group '%s' is already active", vg->name);
return;
}
/* Ignore existing disk status */
if (available && (vg->status & ACTIVE))
log_verbose("Volume group %s is already active on disk",
vg->name);
if (!available && !(vg->status & ACTIVE)) {
log_error("Volume group '%s' is already not active", vg->name);
return;
}
if (!available && !(vg->status & ACTIVE))
log_verbose("Volume group %s is already inactive on disk",
vg->name);
/* FIXME: Force argument to deactivate them? */
if (!available && (lv_open = lvs_in_vg_opened(vg))) {
@ -100,15 +98,19 @@ void vgchange_available(struct volume_group *vg)
return;
}
if (available && (lv_active = lvs_in_vg_activated(vg)))
log_verbose("%d logical volume(s) in volume group %s "
"already active", lv_active, vg->name);
if (available) {
vg->status |= ACTIVE;
list_iterate(pvh, &vg->pvs)
list_item(pvh, struct pv_list)->pv.status
list_iterate(lvh, &vg->lvs)
list_item(lvh, struct lv_list)->lv.status
|= ACTIVE;
} else {
vg->status &= ~ACTIVE;
list_iterate(pvh, &vg->pvs)
list_item(pvh, struct pv_list)->pv.status
list_iterate(lvh, &vg->lvs)
list_item(lvh, struct lv_list)->lv.status
&= ~ACTIVE;
}
@ -117,13 +119,13 @@ void vgchange_available(struct volume_group *vg)
if (available && (lv_open = activate_lvs_in_vg(vg)))
log_verbose("Activated %d logical volumes in "
"volume group '%s'", lv_open, vg->name);
"volume group %s", lv_open, vg->name);
if (!available && (lv_open = deactivate_lvs_in_vg(vg)))
log_verbose("Deactivated %d logical volumes in "
"volume group '%s'", lv_open, vg->name);
"volume group %s", lv_open, vg->name);
log_print("Volume group %s successfully changed", vg->name);
log_print("Volume group %s updated", vg->name);
return;
}

View File

@ -71,7 +71,7 @@ int vgcreate(int argc, char **argv)
return ECMD_FAILED;
}
/* create the new vg */
/* Create the new VG */
if (!(vg = vg_create(fid, vg_name, extent_size, max_pv, max_lv,
argc - 1, argv + 1)))
return ECMD_FAILED;
@ -84,15 +84,11 @@ int vgcreate(int argc, char **argv)
log_error("Warning: Setting maxphysicalvolumes to %d",
vg->max_pv);
/* store vg on disk(s) */
/* Store VG on disk(s) */
if (!fid->ops->vg_write(fid, vg))
return ECMD_FAILED;
/* FIXME Create /dev/vg */
/* FIXME Activate */
log_print("Volume group %s successfully created and activated",
vg_name);
log_print("Volume group %s successfully created", vg->name);
return 0;
}

View File

@ -46,10 +46,10 @@ int vgextend(int argc, char **argv)
return ECMD_FAILED;
}
if (!(vg->status & ACTIVE)) {
/******* Ignore active
if (!(vg->status & ACTIVE))
log_error("Volume group '%s' is not active.", vg_name);
return ECMD_FAILED;
}
********/
if (!(vg->status & EXTENDABLE_VG)) {
log_error("Volume group '%s' is not extendable.", vg_name);

View File

@ -54,10 +54,12 @@ int vgreduce(int argc, char **argv)
return ECMD_FAILED;
}
/******* Ignore active status
if (!(vg->status & ACTIVE)) {
log_error("Volume group %s is not active", vg_name);
return ECMD_FAILED;
}
*******/
if (!(vg->status & EXTENDABLE_VG)) {
log_error("Volume group %s is not reducable", vg_name);

View File

@ -40,10 +40,12 @@ static int vgremove_single(const char *vg_name)
return ECMD_FAILED;
}
/******* Ignore active status
if (vg->status & ACTIVE) {
log_error("Volume group %s is still active", vg_name);
return ECMD_FAILED;
}
********/
if (vg->lv_count) {
log_error("Volume group %s still contains %d logical volume(s)",

View File

@ -118,6 +118,8 @@ int vgrename(int argc, char **argv)
return ECMD_FAILED;
}
/******* FIXME Any LV things to update? */
/***********
if ((ret = do_autobackup(vg_name_new, vg_old)))
return ECMD_FAILED;

View File

@ -50,20 +50,22 @@ static int vgscan_single(const char *vg_name)
log_print("Found %sactive volume group %s",
(vg->status & ACTIVE) ? "" : "in", vg_name);
/******* Ignore active flag
if (!(vg->status & ACTIVE)) {
return 0;
vg->status |= ACTIVE;
if (!(fid->ops->vg_write(fid, vg))) {
log_error("Failed to activate volume group %s",
vg_name);
return ECMD_FAILED;
}
}
*********/
/* FIXME: Creates /dev/vg */
activate_lvs_in_vg(vg);
log_print("Volume Group %s activated", vg_name);
log_print("%d logical volumes in volume group %s activated",
activate_lvs_in_vg(vg), vg_name);
return 0;
}