1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

o ACTIVE is no longer a status flag - lv_active() used to check if an LV

is active in the device-mapper.
o Many operations can be carried out regardless of whether the VG is
  active or not.
o vgscan does not activate anything - use vgchange.
o Change lvrename to support renaming of active LVs.
o Remove '//' appearing in some pathnames.
o Dummy lv_check_segments() for compilation.
This commit is contained in:
Alasdair Kergon 2002-01-10 23:21:07 +00:00
parent c6cc24ea3f
commit 4a624ca055
31 changed files with 195 additions and 272 deletions

View File

@ -11,12 +11,14 @@
#include "fs.h" #include "fs.h"
#include "lvm-string.h" #include "lvm-string.h"
static void _build_lv_name(char *buffer, size_t s, struct logical_volume *lv) static void _build_lv_name(char *buffer, size_t s, const char *vg_name,
const char *lv_name)
{ {
snprintf(buffer, s, "%s_%s", lv->vg->name, lv->name); snprintf(buffer, s, "%s_%s", vg_name, lv_name);
} }
static struct dm_task *_setup_task(struct logical_volume *lv, int task) static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
const char *lv_name, int task)
{ {
char name[128]; char name[128];
struct dm_task *dmt; struct dm_task *dmt;
@ -26,12 +28,17 @@ static struct dm_task *_setup_task(struct logical_volume *lv, int task)
return NULL; return NULL;
} }
_build_lv_name(name, sizeof(name), lv); _build_lv_name(name, sizeof(name), lv->vg->name, lv_name);
dm_task_set_name(dmt, name); dm_task_set_name(dmt, name);
return dmt; return dmt;
} }
static struct dm_task *_setup_task(struct logical_volume *lv, int task)
{
return _setup_task_with_name(lv, lv->name, task);
}
int lv_info(struct logical_volume *lv, struct dm_info *info) int lv_info(struct logical_volume *lv, struct dm_info *info)
{ {
int r = 0; int r = 0;
@ -59,6 +66,42 @@ int lv_info(struct logical_volume *lv, struct dm_info *info)
return r; return r;
} }
int lv_rename(const char *old_name, struct logical_volume *lv)
{
int r = 0;
char new_name[128];
struct dm_task *dmt;
if (test_mode())
return 0;
if (!(dmt = _setup_task_with_name(lv, old_name, DM_DEVICE_RENAME))) {
stack;
return 0;
}
_build_lv_name(new_name, sizeof(new_name), lv->vg->name, lv->name);
if (!dm_task_set_newname(dmt, new_name)) {
stack;
r = 0;
goto end;
}
if (!dm_task_run(dmt)) {
stack;
r = 0;
goto end;
}
fs_rename_lv(old_name, lv);
end:
dm_task_destroy(dmt);
return r;
}
int lv_active(struct logical_volume *lv) int lv_active(struct logical_volume *lv)
{ {
int r = -1; int r = -1;
@ -128,6 +171,16 @@ static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg)
for (s = 0; s < stripes; s++, w += tw) { for (s = 0; s < stripes; s++, w += tw) {
/******
log_debug("stripes: %d", stripes);
log_debug("dev_name(seg->area[s].pv->dev): %s",
dev_name(seg->area[s].pv->dev));
log_debug("esize: %" PRIu64, esize);
log_debug("seg->area[s].pe: %" PRIu64, seg->area[s].pe);
log_debug("seg->area[s].pv->pe_start: %" PRIu64,
seg->area[s].pv->pe_start);
*******/
tw = lvm_snprintf(params + w, sizeof(params) - w, tw = lvm_snprintf(params + w, sizeof(params) - w,
"%s %" PRIu64 "%s", "%s %" PRIu64 "%s",
dev_name(seg->area[s].pv->dev), dev_name(seg->area[s].pv->dev),
@ -224,6 +277,11 @@ int _suspend(struct logical_volume *lv, int sus)
return r; return r;
} }
int lv_suspend(struct logical_volume *lv)
{
return _suspend(lv, 1);
}
int lv_reactivate(struct logical_volume *lv) int lv_reactivate(struct logical_volume *lv)
{ {
int r; int r;
@ -246,6 +304,7 @@ int lv_reactivate(struct logical_volume *lv)
return r; return r;
} }
int lv_deactivate(struct logical_volume *lv) int lv_deactivate(struct logical_volume *lv)
{ {
int r; int r;

View File

@ -15,10 +15,12 @@ int lv_active(struct logical_volume *lv);
int lv_suspended(struct logical_volume *lv); int lv_suspended(struct logical_volume *lv);
int lv_open_count(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_info(struct logical_volume *lv, struct dm_info *info);
int lv_rename(const char *old_name, struct logical_volume *lv);
int lv_activate(struct logical_volume *lv); int lv_activate(struct logical_volume *lv);
int lv_reactivate(struct logical_volume *lv); int lv_reactivate(struct logical_volume *lv);
int lv_deactivate(struct logical_volume *lv); int lv_deactivate(struct logical_volume *lv);
int lv_suspend(struct logical_volume *lv);
/* /*
* Return number of LVs in the VG that are * Return number of LVs in the VG that are

View File

@ -17,20 +17,23 @@
#include <libdevmapper.h> #include <libdevmapper.h>
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv)
void _build_lv_path(char *buffer, size_t len, struct logical_volume *lv,
const char *lv_name)
{ {
snprintf(buffer, len, "%s/%s_%s", dm_dir(), lv->vg->name, lv->name); snprintf(buffer, len, "%s/%s_%s", dm_dir(), lv->vg->name, lv_name);
} }
void _build_vg_path(char *buffer, size_t len, struct volume_group *vg) void _build_vg_path(char *buffer, size_t len, struct volume_group *vg)
{ {
snprintf(buffer, len, "%s/%s", vg->cmd->dev_dir, vg->name); snprintf(buffer, len, "%s%s", vg->cmd->dev_dir, vg->name);
} }
void _build_link_path(char *buffer, size_t len, struct logical_volume *lv) void _build_link_path(char *buffer, size_t len, struct logical_volume *lv,
const char *lv_name)
{ {
snprintf(buffer, len, "%s/%s/%s", lv->vg->cmd->dev_dir, snprintf(buffer, len, "%s%s/%s", lv->vg->cmd->dev_dir,
lv->vg->name, lv->name); lv->vg->name, lv_name);
} }
/* /*
@ -62,8 +65,8 @@ static int _mk_link(struct logical_volume *lv)
{ {
char lv_path[PATH_MAX], link_path[PATH_MAX]; char lv_path[PATH_MAX], link_path[PATH_MAX];
_build_lv_path(lv_path, sizeof(lv_path), lv); _build_lv_path(lv_path, sizeof(lv_path), lv, lv->name);
_build_link_path(link_path, sizeof(link_path), lv); _build_link_path(link_path, sizeof(link_path), lv, lv->name);
log_very_verbose("Linking %s to %s", link_path, lv_path); log_very_verbose("Linking %s to %s", link_path, lv_path);
if (symlink(lv_path, link_path) < 0) { if (symlink(lv_path, link_path) < 0) {
@ -74,11 +77,14 @@ static int _mk_link(struct logical_volume *lv)
return 1; return 1;
} }
static int _rm_link(struct logical_volume *lv) static int _rm_link(struct logical_volume *lv, const char *lv_name)
{ {
char link_path[PATH_MAX]; char link_path[PATH_MAX];
_build_link_path(link_path, sizeof(link_path), lv); if (!lv_name)
lv_name = lv->name;
_build_link_path(link_path, sizeof(link_path), lv, lv_name);
log_very_verbose("Removing link %s", link_path); log_very_verbose("Removing link %s", link_path);
if (unlink(link_path) < 0) { if (unlink(link_path) < 0) {
@ -103,7 +109,7 @@ int fs_add_lv(struct logical_volume *lv)
int fs_del_lv(struct logical_volume *lv) int fs_del_lv(struct logical_volume *lv)
{ {
if (!_rm_link(lv)) { if (!_rm_link(lv, NULL)) {
stack; stack;
return 0; return 0;
} }
@ -113,3 +119,13 @@ int fs_del_lv(struct logical_volume *lv)
return 1; return 1;
} }
int fs_rename_lv(const char *old_name, struct logical_volume *lv)
{
if (!_rm_link(lv, old_name))
stack;
if (!_mk_link(lv))
stack;
return 1;
}

View File

@ -17,5 +17,7 @@
int fs_add_lv(struct logical_volume *lv); int fs_add_lv(struct logical_volume *lv);
int fs_del_lv(struct logical_volume *lv); int fs_del_lv(struct logical_volume *lv);
int fs_rename_lv(const char *old_name, struct logical_volume *lv);
#endif #endif

View File

@ -157,9 +157,6 @@ void pvdisplay_full(struct physical_volume *pv)
log_print("PV# %u", pv->pv_number); log_print("PV# %u", pv->pv_number);
**********/ **********/
log_print("PV Status %savailable",
(pv->status & ACTIVE) ? "" : "NOT ");
pe_free = pv->pe_count - pv->pe_allocated; pe_free = pv->pe_count - pv->pe_allocated;
if (pv->pe_count && (pv->status & ALLOCATABLE_PV)) if (pv->pe_count && (pv->status & ALLOCATABLE_PV))
log_print("Allocatable yes %s", log_print("Allocatable yes %s",
@ -194,8 +191,7 @@ int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv)
log_print("PV Name %s ", dev_name(pv->dev)); log_print("PV Name %s ", dev_name(pv->dev));
/* FIXME pv->pv_number); */ /* FIXME pv->pv_number); */
log_print("PV Status %savailable / %sallocatable", log_print("PV Status %sallocatable",
(pv->status & ACTIVE) ? "" : "NOT ",
(pv->status & ALLOCATABLE_PV) ? "" : "NOT "); (pv->status & ALLOCATABLE_PV) ? "" : "NOT ");
log_print("Total PE / Free PE %u / %u", log_print("Total PE / Free PE %u / %u",
pv->pe_count, pv->pe_count - pv->pe_allocated); pv->pe_count, pv->pe_count - pv->pe_allocated);
@ -204,7 +200,6 @@ int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv)
return 0; return 0;
} }
void lvdisplay_colons(struct logical_volume *lv) void lvdisplay_colons(struct logical_volume *lv)
{ {
int inkernel; int inkernel;
@ -470,9 +465,8 @@ void vgdisplay_full(struct volume_group *vg)
access == LVM_READ ? "read" : "", access == LVM_READ ? "read" : "",
access == LVM_WRITE ? "write" : "", access == LVM_WRITE ? "write" : "",
access == 0 ? "error" : ""); access == 0 ? "error" : "");
log_print("VG Status %savailable%s/%sresizable", log_print("VG Status %s/%sresizable",
vg->status & ACTIVE ? "" : "NOT ", vg->status & EXPORTED_VG ? "exported" : "",
vg->status & EXPORTED_VG ? "/exported" : "",
vg->status & RESIZEABLE_VG ? "" : "NOT "); vg->status & RESIZEABLE_VG ? "" : "NOT ");
/******* FIXME vg number /******* FIXME vg number
log_print ("VG # %u\n", vg->vg_number); log_print ("VG # %u\n", vg->vg_number);
@ -547,8 +541,7 @@ void vgdisplay_short(struct volume_group *vg)
display_size((vg->extent_count - vg->free_count) * vg->extent_size / display_size((vg->extent_count - vg->free_count) * vg->extent_size /
2, SIZE_SHORT); 2, SIZE_SHORT);
s3 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT); s3 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT);
log_print("%s (%s) %-9s [%-9s used / %s free]", vg->name, log_print("%s %-9s [%-9s used / %s free]", vg->name,
(vg->status & ACTIVE) ? "active" : "inactive",
/********* FIXME if "open" print "/used" else print "/idle"??? ******/ /********* FIXME if "open" print "/used" else print "/idle"??? ******/
s1, s2, s3); s1, s2, s3);
dbg_free(s1); dbg_free(s1);

View File

@ -48,9 +48,6 @@ int import_pv(struct pool *mem, struct device *dev,
return 0; return 0;
} }
if (pvd->pv_status & PV_ACTIVE)
pv->status |= ACTIVE;
if (pvd->pv_allocatable) if (pvd->pv_allocatable)
pv->status |= ALLOCATABLE_PV; pv->status |= ALLOCATABLE_PV;
@ -98,9 +95,6 @@ int export_pv(struct pv_disk *pvd, struct physical_volume *pv)
//pvd->pv_major = MAJOR(pv->dev); //pvd->pv_major = MAJOR(pv->dev);
if (pv->status & ACTIVE)
pvd->pv_status |= PV_ACTIVE;
if (pv->status & ALLOCATABLE_PV) if (pv->status & ALLOCATABLE_PV)
pvd->pv_allocatable = PV_ALLOCATABLE; pvd->pv_allocatable = PV_ALLOCATABLE;
@ -135,9 +129,6 @@ int import_vg(struct pool *mem,
return 0; return 0;
} }
if (vgd->vg_status & VG_ACTIVE)
vg->status |= ACTIVE;
if (vgd->vg_status & VG_EXPORTED) if (vgd->vg_status & VG_EXPORTED)
vg->status |= EXPORTED_VG; vg->status |= EXPORTED_VG;
@ -181,9 +172,6 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
if (vg->status & SHARED) if (vg->status & SHARED)
vgd->vg_access |= VG_SHARED; vgd->vg_access |= VG_SHARED;
if (vg->status & ACTIVE)
vgd->vg_status |= VG_ACTIVE;
if (vg->status & EXPORTED_VG) if (vg->status & EXPORTED_VG)
vgd->vg_status |= VG_EXPORTED; vgd->vg_status |= VG_EXPORTED;
@ -211,9 +199,6 @@ int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
return 0; return 0;
} }
if (lvd->lv_status & LV_ACTIVE)
lv->status |= ACTIVE;
if (lvd->lv_status & LV_SPINDOWN) if (lvd->lv_status & LV_SPINDOWN)
lv->status |= SPINDOWN_LV; lv->status |= SPINDOWN_LV;
@ -272,9 +257,6 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg,
if (lv->status & SNAPSHOT_ORG) if (lv->status & SNAPSHOT_ORG)
lvd->lv_access |= LV_SNAPSHOT_ORG; lvd->lv_access |= LV_SNAPSHOT_ORG;
if (lv->status & ACTIVE)
lvd->lv_status |= LV_ACTIVE;
if (lv->status & SPINDOWN_LV) if (lv->status & SPINDOWN_LV)
lvd->lv_status |= LV_SPINDOWN; lvd->lv_status |= LV_SPINDOWN;

View File

@ -19,7 +19,6 @@ struct flag {
}; };
static struct flag _vg_flags[] = { static struct flag _vg_flags[] = {
{ACTIVE, "ACTIVE"},
{EXPORTED_VG, "EXPORTED"}, {EXPORTED_VG, "EXPORTED"},
{RESIZEABLE_VG, "RESIZEABLE"}, {RESIZEABLE_VG, "RESIZEABLE"},
{CLUSTERED, "CLUSTERED"}, {CLUSTERED, "CLUSTERED"},
@ -28,13 +27,11 @@ static struct flag _vg_flags[] = {
}; };
static struct flag _pv_flags[] = { static struct flag _pv_flags[] = {
{ACTIVE, "ACTIVE"},
{ALLOCATABLE_PV, "ALLOCATABLE"}, {ALLOCATABLE_PV, "ALLOCATABLE"},
{0, NULL} {0, NULL}
}; };
static struct flag _lv_flags[] = { static struct flag _lv_flags[] = {
{ACTIVE, "ACTIVE"},
{LVM_READ, "READ"}, {LVM_READ, "READ"},
{LVM_WRITE, "WRITE"}, {LVM_WRITE, "WRITE"},
{ALLOC_SIMPLE, "ALLOC_SIMPLE"}, {ALLOC_SIMPLE, "ALLOC_SIMPLE"},

View File

@ -4,6 +4,7 @@
* This file is released under the LGPL. * This file is released under the LGPL.
*/ */
#include "metadata.h"
#include "import-export.h" #include "import-export.h"
#include "pool.h" #include "pool.h"
#include "log.h" #include "log.h"

View File

@ -497,7 +497,7 @@ int lv_extend(struct logical_volume *lv,
return 0; return 0;
} }
if (!merge_segments(lv)) { if (!lv_merge_segments(lv)) {
log_err("Couldn't merge segments after extending " log_err("Couldn't merge segments after extending "
"logical volume."); "logical volume.");
return 0; return 0;

View File

@ -53,3 +53,8 @@ int lv_merge_segments(struct logical_volume *lv)
return 1; return 1;
} }
/**** FIXME Dummy ****/
int lv_check_segments(struct logical_volume *lv)
{
return 1;
}

View File

@ -47,9 +47,6 @@ int _add_pv_to_vg(struct format_instance *fi, struct volume_group *vg,
return 0; return 0;
} }
/* FIXME Tie this to activation or not? */
pv->status |= ACTIVE;
/* Units of 512-byte sectors */ /* Units of 512-byte sectors */
if (!dev_get_size(pv->dev, &pv->size)) { if (!dev_get_size(pv->dev, &pv->size)) {
stack; stack;
@ -156,7 +153,7 @@ struct volume_group *vg_create(struct format_instance *fi, const char *vg_name,
goto bad; goto bad;
} }
vg->status = (ACTIVE | RESIZEABLE_VG | LVM_READ | LVM_WRITE); vg->status = (RESIZEABLE_VG | LVM_READ | LVM_WRITE);
vg->extent_size = extent_size; vg->extent_size = extent_size;
vg->extent_count = 0; vg->extent_count = 0;

View File

@ -27,8 +27,7 @@
/* Various flags */ /* Various flags */
/* Note that the bits no longer necessarily correspond to LVM1 disk format */ /* Note that the bits no longer necessarily correspond to LVM1 disk format */
#define ACTIVE 0x00000001 /* PV VG LV */ #define EXPORTED_VG 0x00000002 /* VG */
#define EXPORTED_VG 0x00000002 /* VG */ /* And PV too perhaps? */
#define RESIZEABLE_VG 0x00000004 /* VG */ #define RESIZEABLE_VG 0x00000004 /* VG */
/* May any free extents on this PV be used or must they be left free? */ /* May any free extents on this PV be used or must they be left free? */

View File

@ -11,9 +11,12 @@
#include "lvm-string.h" #include "lvm-string.h"
#include "toollib.h" #include "toollib.h"
#include "tools.h"
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
static struct { static struct {
int enabled; int enabled;
char *dir; char *dir;
@ -198,10 +201,10 @@ int backup_remove(const char *vg_name)
return 1; return 1;
} }
static int _read_vg(struct command_context *cmd, static struct volume_group *_read_vg(struct cmd_context *cmd,
const char *vg_name, const char *file) const char *vg_name, const char *file)
{ {
int r; struct volume_group *vg;
struct format_instance *tf; struct format_instance *tf;
if (!(tf = text_format_create(cmd, file))) { if (!(tf = text_format_create(cmd, file))) {
@ -209,11 +212,11 @@ static int _read_vg(struct command_context *cmd,
return 0; return 0;
} }
if (!(r = tf->ops->vg_read(tf, vg_name))) if (!(vg = tf->ops->vg_read(tf, vg_name)))
stack; stack;
tf->ops->destroy(tf); tf->ops->destroy(tf);
return r; return vg;
} }
int backup_restore_from_file(const char *vg_name, const char *file) int backup_restore_from_file(const char *vg_name, const char *file)
@ -223,7 +226,7 @@ int backup_restore_from_file(const char *vg_name, const char *file)
/* /*
* Read in the volume group. * Read in the volume group.
*/ */
if (!(vg = _read_vg(vg_name, file))) { if (!(vg = _read_vg(vg->cmd, vg_name, file))) {
stack; stack;
return 0; return 0;
} }

View File

@ -45,16 +45,7 @@ int lvchange(int argc, char **argv)
static int lvchange_single(struct logical_volume *lv) static int lvchange_single(struct logical_volume *lv)
{ {
int doit = 0; int doit = 0;
int archived = 0;
/******* 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);
return ECMD_FAILED;
}
********/
if (lv->status & SNAPSHOT_ORG) { if (lv->status & SNAPSHOT_ORG) {
log_error("Can't change logical volume %s under snapshot", log_error("Can't change logical volume %s under snapshot",
@ -67,30 +58,37 @@ static int lvchange_single(struct logical_volume *lv)
return ECMD_FAILED; return ECMD_FAILED;
} }
if (!archive(lv->vg))
return 0;
/* access permission change */ /* access permission change */
if (arg_count(permission_ARG)) if (arg_count(permission_ARG)) {
if (!archive(lv->vg))
return ECMD_FAILED;
archived = 1;
doit += lvchange_permission(lv); doit += lvchange_permission(lv);
}
/* allocation policy change */
if (arg_count(contiguous_ARG)) {
if (!archived && !archive(lv->vg))
return ECMD_FAILED;
archived = 1;
doit += lvchange_contiguous(lv);
}
/* read ahead sector change */
if (arg_count(readahead_ARG)) {
if (!archived && !archive(lv->vg))
return ECMD_FAILED;
archived = 1;
doit += lvchange_readahead(lv);
}
if (doit)
log_print("Logical volume %s changed", lv->name);
/* availability change */ /* availability change */
if (arg_count(available_ARG)) if (arg_count(available_ARG))
doit += lvchange_availability(lv); if (!lvchange_availability(lv))
return ECMD_FAILED;
/* allocation policy change */
if (arg_count(contiguous_ARG))
doit += lvchange_contiguous(lv);
/* read ahead sector change */
if (arg_count(readahead_ARG))
doit += lvchange_readahead(lv);
if (!doit) {
return 0;
}
log_print("Logical volume %s changed", lv->name);
return 0; return 0;
} }
@ -135,55 +133,39 @@ static int lvchange_permission(struct logical_volume *lv)
static int lvchange_availability(struct logical_volume *lv) static int lvchange_availability(struct logical_volume *lv)
{ {
int lv_stat = 0; int activate = 0;
int active; int active;
if (strcmp(arg_str_value(available_ARG, "n"), "n")) if (strcmp(arg_str_value(available_ARG, "n"), "n"))
lv_stat |= ACTIVE; activate = 1;
active = lv_active(lv); active = lv_active(lv);
if (lv_stat & ACTIVE) { if (activate && active) {
lv->status |= ACTIVE;
log_verbose("Activating logical volume %s", lv->name);
} else {
lv->status &= ~ACTIVE;
log_verbose("Deactivating logical volume %s", lv->name);
}
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;
backup(lv->vg);
}
if ((lv_stat & ACTIVE) && (active & ACTIVE))
log_verbose("Logical volume %s is already active", lv->name); log_verbose("Logical volume %s is already active", lv->name);
else if (!(lv_stat & ACTIVE) && !(active & ACTIVE)) return 0;
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;
}
} }
if (lv_suspended(lv)) { if (!activate && !active) {
log_verbose("Logical volume %s is already inactive", lv->name);
return 0;
}
if (activate & lv_suspended(lv)) {
log_verbose("Reactivating logical volume %s", lv->name); log_verbose("Reactivating logical volume %s", lv->name);
if (!lv_reactivate(lv)) if (!lv_reactivate(lv))
return 0; return 0;
return 1;
}
if (activate) {
log_verbose("Activating logical volume %s", lv->name);
if (!lv_activate(lv))
return 0;
} else {
log_verbose("Deactivating logical volume %s", lv->name);
if (!lv_deactivate(lv))
return 0;
} }
return 1; return 1;

View File

@ -121,14 +121,6 @@ int lvcreate(int argc, char **argv)
return ECMD_FAILED; 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))) { if (lv_name && (lvh = find_lv_in_vg(vg, lv_name))) {
log_error("Logical volume %s already exists in " log_error("Logical volume %s already exists in "
"volume group %s", lv_name, vg_name); "volume group %s", lv_name, vg_name);

View File

@ -38,14 +38,6 @@ static int lvremove_single(struct logical_volume *lv)
vg = lv->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) { if (lv->status & SNAPSHOT_ORG) {
log_error("Can't remove logical volume %s under snapshot", log_error("Can't remove logical volume %s under snapshot",
lv->name); lv->name);

View File

@ -23,6 +23,7 @@
int lvrename(int argc, char **argv) int lvrename(int argc, char **argv)
{ {
int maxlen; int maxlen;
int active;
char *lv_name_old, *lv_name_new; char *lv_name_old, *lv_name_new;
char *vg_name, *vg_name_new; char *vg_name, *vg_name_new;
char *st; char *st;
@ -89,14 +90,6 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED; 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))) { if ((lvh = find_lv_in_vg(vg, lv_name_new))) {
log_error("Logical volume %s already exists in " log_error("Logical volume %s already exists in "
"volume group %s", lv_name_new, vg_name); "volume group %s", lv_name_new, vg_name);
@ -114,6 +107,13 @@ int lvrename(int argc, char **argv)
if (!archive(lv->vg)) if (!archive(lv->vg))
return ECMD_FAILED; return ECMD_FAILED;
active = lv_active(lv);
if (active && !lv_suspend(lv)) {
log_error("Failed to suspend %s", lv->name);
return ECMD_FAILED;
}
if (!(lv->name = pool_strdup(fid->cmd->mem, lv_name_new))) { if (!(lv->name = pool_strdup(fid->cmd->mem, lv_name_new))) {
log_error("Failed to allocate space for new name"); log_error("Failed to allocate space for new name");
return ECMD_FAILED; return ECMD_FAILED;
@ -125,10 +125,12 @@ int lvrename(int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
} }
backup(lv->vg); if (active) {
lv_rename(lv_name_old, lv);
lv_reactivate(lv);
}
/* FIXME Update symlink. */ backup(lv->vg);
lv_reactivate(lv);
log_print("Renamed %s to %s in volume group %s%s", log_print("Renamed %s to %s in volume group %s%s",
lv_name_old, lv_name_new, fid->cmd->dev_dir, vg_name); lv_name_old, lv_name_new, fid->cmd->dev_dir, vg_name);

View File

@ -106,14 +106,6 @@ int lvresize(int argc, char **argv)
return ECMD_FAILED; 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? */ /* does LV exist? */
if (!(lvh = find_lv_in_vg(vg, lv_name))) { if (!(lvh = find_lv_in_vg(vg, lv_name))) {
log_error("Logical volume %s not found in volume group %s", log_error("Logical volume %s not found in volume group %s",
@ -123,14 +115,6 @@ int lvresize(int argc, char **argv)
lv = &list_item(lvh, struct lv_list)->lv; 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) { if (size) {
/* No of 512-byte sectors */ /* No of 512-byte sectors */
extents = size * 2; extents = size * 2;

View File

@ -56,16 +56,17 @@ int lvscan(int argc, char **argv)
static int lvscan_single(struct logical_volume *lv) static int lvscan_single(struct logical_volume *lv)
{ {
int lv_active = 0; int active = 0;
int lv_total = 0; int lv_total = 0;
ulong lv_capacity_total = 0; ulong lv_capacity_total = 0;
char *dummy; char *dummy;
const char *active_str, *snapshot_str; const char *active_str, *snapshot_str;
if (lv->status & ACTIVE) { /* FIXME Add -D arg to skip this! */
if (lv_active(lv)) {
active_str = "ACTIVE "; active_str = "ACTIVE ";
lv_active++; active++;
} else } else
active_str = "inactive "; active_str = "inactive ";

View File

@ -128,12 +128,6 @@ int pvchange_single(struct physical_volume *pv)
pv->status &= ~ALLOCATABLE_PV; pv->status &= ~ALLOCATABLE_PV;
} }
/******* Ignore active
if (!(pv->status & ACTIVE)) {
log_verbose("Physical volume %s inactive", pv_name);
}
********/
log_verbose("Updating physical volume %s", pv_name); log_verbose("Updating physical volume %s", pv_name);
if (*pv->vg_name) { if (*pv->vg_name) {
if (!(fid->ops->vg_write(fid,vg))) { if (!(fid->ops->vg_write(fid,vg))) {

View File

@ -50,13 +50,6 @@ static int pvcreate_check(const char *name)
return 0; 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 */ /* we must have -ff to overwrite a non orphan */
if (arg_count(force_ARG) < 2) { if (arg_count(force_ARG) < 2) {
log_error("Can't initialize physical volume %s of " log_error("Can't initialize physical volume %s of "

View File

@ -133,7 +133,6 @@ void pvscan_display_single(struct physical_volume *pv)
{ {
int vg_name_len = 0; int vg_name_len = 0;
const char *active_str;
char *s1, *s2; char *s1, *s2;
@ -159,8 +158,6 @@ void pvscan_display_single(struct physical_volume *pv)
memset(pv_tmp_name, 0, sizeof (pv_tmp_name)); memset(pv_tmp_name, 0, sizeof (pv_tmp_name));
active_str = (pv->status & ACTIVE) ? "ACTIVE " : "Inactive";
vg_name_len = strlen(pv->vg_name) - sizeof (EXPORTED_TAG) + 1; vg_name_len = strlen(pv->vg_name) - sizeof (EXPORTED_TAG) + 1;
if (arg_count(uuid_ARG)) { if (arg_count(uuid_ARG)) {
@ -173,7 +170,7 @@ void pvscan_display_single(struct physical_volume *pv)
} }
if (!*pv->vg_name) { if (!*pv->vg_name) {
log_print("%s PV %-*s is in no VG %-*s [%s]", active_str, log_print("PV %-*s is in no VG %-*s [%s]",
pv_max_name_len, pv_tmp_name, pv_max_name_len, pv_tmp_name,
vg_max_name_len - 6, " ", vg_max_name_len - 6, " ",
(s1 = display_size(pv->size / 2, SIZE_SHORT))); (s1 = display_size(pv->size / 2, SIZE_SHORT)));
@ -183,8 +180,8 @@ void pvscan_display_single(struct physical_volume *pv)
if (strcmp(&pv->vg_name[vg_name_len], EXPORTED_TAG) == 0) { if (strcmp(&pv->vg_name[vg_name_len], EXPORTED_TAG) == 0) {
strncpy(vg_name_this, pv->vg_name, vg_name_len); strncpy(vg_name_this, pv->vg_name, vg_name_len);
log_print("%s PV %-*s is in EXPORTED VG %s [%s / %s free]", log_print("PV %-*s is in EXPORTED VG %s [%s / %s free]",
active_str, pv_max_name_len, pv_tmp_name, pv_max_name_len, pv_tmp_name,
vg_name_this, (s1 = vg_name_this, (s1 =
display_size(pv->pe_count * display_size(pv->pe_count *
pv->pe_size / 2, pv->pe_size / 2,
@ -198,7 +195,7 @@ void pvscan_display_single(struct physical_volume *pv)
sprintf(vg_tmp_name, "%s", pv->vg_name); sprintf(vg_tmp_name, "%s", pv->vg_name);
log_print log_print
("%s PV %-*s of VG %-*s [%s / %s free]", active_str, pv_max_name_len, ("PV %-*s of VG %-*s [%s / %s free]", pv_max_name_len,
pv_tmp_name, vg_max_name_len, vg_tmp_name, pv_tmp_name, vg_max_name_len, vg_tmp_name,
(s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)), (s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)),
(s2 = (s2 =

View File

@ -13,4 +13,5 @@ int vgexport(int argc, char **argv) {return 1;}
int vgimport(int argc, char **argv) {return 1;} int vgimport(int argc, char **argv) {return 1;}
int vgmknodes(int argc, char **argv) {return 1;} int vgmknodes(int argc, char **argv) {return 1;}
int vgsplit(int argc, char **argv) {return 1;} int vgsplit(int argc, char **argv) {return 1;}
int vgcfgrestore(int argc, char **argv) {return 1;}

View File

@ -35,9 +35,6 @@ static int vg_backup_single(const char *vg_name)
return ECMD_FAILED; return ECMD_FAILED;
} }
log_print("Found %sactive volume group %s",
(vg->status & ACTIVE) ? "" : "in", vg_name);
if (arg_count(file_ARG)) { if (arg_count(file_ARG)) {
_backup_to_file(arg_value(file_ARG), vg); _backup_to_file(arg_value(file_ARG), vg);

View File

@ -76,18 +76,8 @@ static int vgchange_single(const char *vg_name)
void vgchange_available(struct volume_group *vg) void vgchange_available(struct volume_group *vg)
{ {
int lv_open, lv_active; int lv_open, lv_active;
struct list *lvh;
int available = !strcmp(arg_str_value(available_ARG, "n"), "y"); int available = !strcmp(arg_str_value(available_ARG, "n"), "y");
/* 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_verbose("Volume group %s is already inactive on disk",
vg->name);
/* FIXME: Force argument to deactivate them? */ /* FIXME: Force argument to deactivate them? */
if (!available && (lv_open = lvs_in_vg_opened(vg))) { if (!available && (lv_open = lvs_in_vg_opened(vg))) {
log_error("Can't deactivate volume group '%s' with %d open " log_error("Can't deactivate volume group '%s' with %d open "
@ -99,26 +89,6 @@ void vgchange_available(struct volume_group *vg)
log_verbose("%d logical volume(s) in volume group %s " log_verbose("%d logical volume(s) in volume group %s "
"already active", lv_active, vg->name); "already active", lv_active, vg->name);
if (!archive(vg))
return;
if (available) {
vg->status |= ACTIVE;
list_iterate(lvh, &vg->lvs)
list_item(lvh, struct lv_list)->lv.status
|= ACTIVE;
} else {
vg->status &= ~ACTIVE;
list_iterate(lvh, &vg->lvs)
list_item(lvh, struct lv_list)->lv.status
&= ~ACTIVE;
}
if (!fid->ops->vg_write(fid, vg))
return;
backup(vg);
if (available && (lv_open = activate_lvs_in_vg(vg))) if (available && (lv_open = activate_lvs_in_vg(vg)))
log_verbose("Activated %d logical volumes in " log_verbose("Activated %d logical volumes in "
"volume group %s", lv_open, vg->name); "volume group %s", lv_open, vg->name);
@ -169,12 +139,6 @@ void vgchange_logicalvolume(struct volume_group *vg)
{ {
int max_lv = arg_int_value(logicalvolume_ARG, 0); int max_lv = arg_int_value(logicalvolume_ARG, 0);
if (vg->status & ACTIVE) {
log_error("MaxLogicalVolume can't be changed in "
"active volume group '%s'", vg->name);
return;
}
if (!(vg->status & RESIZEABLE_VG)) { if (!(vg->status & RESIZEABLE_VG)) {
log_error("Volume group '%s' must be resizeable " log_error("Volume group '%s' must be resizeable "
"to change MaxLogicalVolume", vg->name); "to change MaxLogicalVolume", vg->name);

View File

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

View File

@ -50,6 +50,7 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
{ {
struct volume_group *vg_to, *vg_from; struct volume_group *vg_to, *vg_from;
struct list *lvh1, *lvh2; struct list *lvh1, *lvh2;
int active;
if (!strcmp(vg_name_to, vg_name_from)) { if (!strcmp(vg_name_to, vg_name_from)) {
log_error("Duplicate volume group name %s", vg_name_from); log_error("Duplicate volume group name %s", vg_name_from);
@ -68,9 +69,9 @@ int vgmerge_single(const char *vg_name_to, const char *vg_name_from)
return ECMD_FAILED; return ECMD_FAILED;
} }
/* FIXME status - confirm no active LVs? */ if ((active = lvs_in_vg_activated(vg_from))) {
if (vg_from->status & ACTIVE) { log_error("Logical volumes in %s must be inactive",
log_error("Volume group %s must be inactive", vg_name_from); vg_name_from);
return ECMD_FAILED; return ECMD_FAILED;
} }

View File

@ -54,13 +54,6 @@ int vgreduce(int argc, char **argv)
return ECMD_FAILED; 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 & RESIZEABLE_VG)) { if (!(vg->status & RESIZEABLE_VG)) {
log_error("Volume group %s is not reducable", vg_name); log_error("Volume group %s is not reducable", vg_name);
return ECMD_FAILED; return ECMD_FAILED;

View File

@ -40,13 +40,6 @@ static int vgremove_single(const char *vg_name)
return ECMD_FAILED; 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) { if (vg->lv_count) {
log_error("Volume group %s still contains %d logical volume(s)", log_error("Volume group %s still contains %d logical volume(s)",
vg_name, vg->lv_count); vg_name, vg->lv_count);

View File

@ -73,12 +73,14 @@ int vgrename(int argc, char **argv)
return ECMD_FAILED; return ECMD_FAILED;
} }
if (vg_old->status & ACTIVE) { if (lvs_in_vg_activated(vg_old)) {
log_error("Volume group %s still active", vg_name_old); log_error("Volume group %s still has active LVs", vg_name_old);
/***** FIXME Handle this with multiple LV renames!
if (!force_ARG) { if (!force_ARG) {
log_error("Use -f to force the rename"); log_error("Use -f to force the rename");
return ECMD_FAILED; return ECMD_FAILED;
} }
*****/
} }
log_verbose("Checking for new volume group %s", vg_name_new); log_verbose("Checking for new volume group %s", vg_name_new);

View File

@ -50,23 +50,7 @@ static int vgscan_single(const char *vg_name)
return ECMD_FAILED; return ECMD_FAILED;
} }
log_print("Found %sactive volume group %s", log_print("Found volume group %s", vg_name);
(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;
}
}
*********/
log_print("%d logical volumes in volume group %s activated",
activate_lvs_in_vg(vg), vg_name);
return 0; return 0;
} }