#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);
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;
int r = -1;
struct dm_info info;
- if (!_info(lv, &info)) {
+ if (!lv_info(lv, &info)) {
stack;
return r;
}
int r = -1;
struct dm_info info;
- if (!_info(lv, &info)) {
+ if (!lv_info(lv, &info)) {
stack;
return r;
}
if (!(r = dm_task_run(dmt)))
stack;
+ log_verbose("Logical volume %s activated", lv->name);
+
out:
dm_task_destroy(dmt);
return r;
#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);
#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)
{
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;
}
{
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",
}
***********/
- 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);
(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
#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;
}
lv->le_count = extents;
+ lv->size = extents * lv->vg->extent_size;
return 1;
}
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;
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",
return 0;
}
- /* FIXME activate change */
-
log_print("Logical volume %s changed", lv->name);
/* FIXME do_autobackup */
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;
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;
-
- log_very_verbose("Updating %s in kernel", lv->name);
- if (lv_stat & ACTIVE) {
- if (!lv_activate(lv))
- return 0;
- } else {
- if (!lv_deactivate(lv))
+ 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;
}
+ 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;
}
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 "
/* 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;
__init_log(cmd->cf);
}
+ dm_log_init(print_log);
+
if (!dev_cache_setup(cmd->cf)) {
goto out;
}
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",
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
}
}
+ 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);
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 "
return ECMD_FAILED;
}
- /* FIXME Update symlink. lv_reactivate? */
+ /* FIXME Update symlink. */
+ lv_reactivate(lv);
/* FIXME backup */
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))) {
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 */
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);
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) {
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) {
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))) {
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;
}
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;
}
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;
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;
}
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);
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);
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)",
return ECMD_FAILED;
}
+/******* FIXME Any LV things to update? */
+
/***********
if ((ret = do_autobackup(vg_name_new, vg_old)))
return ECMD_FAILED;
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;
}