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

lv_info replaces lv_active etc.

This commit is contained in:
Alasdair Kergon 2002-03-11 19:02:28 +00:00
parent be326a2f1b
commit 41967a0276
6 changed files with 76 additions and 77 deletions

View File

@ -75,8 +75,7 @@ int lv_info(struct logical_volume *lv, struct dm_info *info)
return r;
}
/* FIXME Change these into query macros with lv_get_info() to fill struct? */
int lv_active(struct logical_volume *lv)
static int _lv_active(struct logical_volume *lv)
{
struct dm_info info;
@ -88,19 +87,7 @@ int lv_active(struct logical_volume *lv)
return info.exists;
}
int lv_suspended(struct logical_volume *lv)
{
struct dm_info info;
if (!lv_info(lv, &info)) {
stack;
return -1;
}
return info.suspended;
}
int lv_open_count(struct logical_volume *lv)
static int _lv_open_count(struct logical_volume *lv)
{
struct dm_info info;
@ -178,7 +165,7 @@ static int _lv_suspend(struct logical_volume *lv)
#endif
}
int lv_rename(const char *old_name, struct logical_volume *lv)
static int _lv_rename(const char *old_name, struct logical_volume *lv)
{
#if 0
int r = 0;
@ -236,7 +223,7 @@ int lvs_in_vg_activated(struct volume_group *vg)
list_iterate(lvh, &vg->lvs) {
lv = list_item(lvh, struct lv_list)->lv;
count += (lv_active(lv) == 1);
count += (_lv_active(lv) == 1);
}
return count;
@ -250,7 +237,7 @@ int lvs_in_vg_opened(struct volume_group *vg)
list_iterate(lvh, &vg->lvs) {
lv = list_item(lvh, struct lv_list)->lv;
count += (lv_open_count(lv) == 1);
count += (_lv_open_count(lv) == 1);
}
return count;
@ -294,11 +281,17 @@ static struct logical_volume *_lv_from_lvid(struct cmd_context *cmd,
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
{
struct logical_volume *lv;
struct dm_info info;
if (!(lv = _lv_from_lvid(cmd, lvid_s)))
return 0;
if (lv_active(lv) > 0)
if (!lv_info(lv, &info)) {
stack;
return 0;
}
if (info.exists && !info.suspended)
_lv_suspend(lv);
return 1;
@ -308,11 +301,17 @@ int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
{
struct logical_volume *lv;
struct dm_info info;
if (!(lv = _lv_from_lvid(cmd, lvid_s)))
return 0;
if ((lv_active(lv) > 0) && lv_suspended(lv))
if (!lv_info(lv, &info)) {
stack;
return 0;
}
if (info.exists && info.suspended)
_lv_activate(lv);
return 1;
@ -321,11 +320,17 @@ int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
{
struct logical_volume *lv;
struct dm_info info;
if (!(lv = _lv_from_lvid(cmd, lvid_s)))
return 0;
if (lv_active(lv) > 0)
if (!lv_info(lv, &info)) {
stack;
return 0;
}
if (info.exists)
_lv_deactivate(lv);
return 1;
@ -334,14 +339,17 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
int lv_activate(struct cmd_context *cmd, const char *lvid_s)
{
struct logical_volume *lv;
int active;
struct dm_info info;
if (!(lv = _lv_from_lvid(cmd, lvid_s)))
return 0;
active = lv_active(lv);
if (!lv_info(lv, &info)) {
stack;
return 0;
}
if (!active || ((active > 0) && lv_suspended(lv)))
if (!info.exists || info.suspended)
_lv_activate(lv);
return 1;

View File

@ -12,35 +12,20 @@
int driver_version(char *version, size_t size);
int library_version(char *version, size_t size);
/*
* Status functions. Return count (0 upwards) or else -1 on
* error.
*/
int lv_active(struct logical_volume *lv);
int lv_suspended(struct logical_volume *lv);
int lv_open_count(struct logical_volume *lv);
/*
* Returns 1 if info structure has been populated, else 0.
*/
int lv_info(struct logical_volume *lv, struct dm_info *info);
/*
* Activation proper.
*/
int lv_rename(const char *old_name, struct logical_volume *lv);
/*
* These should eventually replace some of the above and maybe
* use config file to determine whether or not to activate
* These should eventually use config file
* to determine whether or not to activate
*/
int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s);
int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s);
int lv_activate(struct cmd_context *cmd, const char *lvid_s);
int lv_deactivate(struct cmd_context *cmd, const char *lvid_s);
/*
* FIXME:
* I don't like the *lvs_in_vg* function names.

View File

@ -253,7 +253,6 @@ static int lvchange_contiguous(struct cmd_context *cmd,
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!unlock_lv(cmd, lv->lvid.s)) {
log_error("Problem reactivating %s", lv->name);
return 0;
@ -302,7 +301,6 @@ static int lvchange_readahead(struct cmd_context *cmd,
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!unlock_lv(cmd, lv->lvid.s)) {
log_error("Problem reactivating %s", lv->name);
return 0;
@ -325,14 +323,15 @@ static int lvchange_persistent(struct cmd_context *cmd,
lv->minor = -1;
log_verbose("Disabling persistent minor for \"%s\"", lv->name);
} else {
if (lv_active(lv) > 0) {
log_error("Cannot change minor number when active");
return 0;
}
if (!arg_count(cmd, minor_ARG)) {
log_error("Minor number must be specified with -My");
return 0;
}
log_verbose("Ensuring %s is inactive", lv->name);
if (!lock_vol(cmd, lv->lvid.s, LCK_LV_DEACTIVATE)) {
log_error("%s: deactivation failed", lv->name);
return 0;
}
lv->status |= FIXED_MINOR;
lv->minor = arg_int_value(cmd, minor_ARG, -1);
log_verbose("Setting persistent minor number to %d for \"%s\"",
@ -353,7 +352,6 @@ static int lvchange_persistent(struct cmd_context *cmd,
backup(lv->vg);
log_very_verbose("Reactivating \"%s\" in kernel", lv->name);
if (!unlock_lv(cmd, lv->lvid.s)) {
log_error("Problem reactivating %s", lv->name);
return 0;

View File

@ -35,7 +35,7 @@ int lvremove(struct cmd_context *cmd, int argc, char **argv)
static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
{
struct volume_group *vg;
int active;
struct dm_info info;
vg = lv->vg;
@ -50,14 +50,17 @@ static int lvremove_single(struct cmd_context *cmd, struct logical_volume *lv)
return ECMD_FAILED;
}
if (lv_open_count(lv) > 0) {
if (!lv_info(lv, &info)) {
stack;
return ECMD_FAILED;
}
if (info.open_count) {
log_error("Can't remove open logical volume \"%s\"", lv->name);
return ECMD_FAILED;
}
active = (lv_active(lv) > 0);
if (active && !arg_count(cmd, force_ARG)) {
if (info.exists && !arg_count(cmd, force_ARG)) {
if (yes_no_prompt("Do you really want to remove active "
"logical volume \"%s\"? [y/n]: ",
lv->name) == 'n') {

View File

@ -24,6 +24,7 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
{
struct volume_group *vg;
struct logical_volume *lv;
struct dm_info info;
uint32_t extents = 0;
uint32_t size = 0;
uint32_t stripes = 0, stripesize = 0;
@ -276,13 +277,18 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
if (argc)
log_print("Ignoring PVs on command line when reducing");
if (lv_active(lv) > 0) {
if (!lv_info(lv, &info)) {
stack;
goto error;
}
if (info.exists) {
dummy =
display_size((uint64_t)
extents * (vg->extent_size / 2),
SIZE_SHORT);
log_print("WARNING: Reducing active%s logical volume "
"to %s", lv_open_count(lv) ? " and open" : "",
"to %s", info.open_count ? " and open" : "",
dummy);
log_print("THIS MAY DESTROY YOUR DATA "

View File

@ -32,31 +32,31 @@ int lvscan(struct cmd_context *cmd, int argc, char **argv)
return process_each_lv(cmd, argc, argv, &lvscan_single);
/*********** FIXME Count! Add private struct to process_each*
if (!lv_total)
log_print("no logical volumes found");
else {
log_print
("%d logical volumes with %s total in %d volume group%s",
lv_total, (dummy =
display_size(lv_capacity_total / 2, SIZE_SHORT)),
vg_total, vg_total == 1 ? "" : "s");
dbg_free(dummy);
dummy = NULL;
if (lv_active > 0)
printf("%d active", lv_active);
if (lv_active > 0 && lv_total - lv_active > 0)
printf(" / ");
if (lv_total - lv_active > 0)
printf("%d inactive", lv_total - lv_active);
printf(" logical volumes\n");
}
* if (!lv_total)
* log_print("no logical volumes found");
* else {
* log_print
* ("%d logical volumes with %s total in %d volume group%s",
* lv_total, (dummy =
* display_size(lv_capacity_total / 2, SIZE_SHORT)),
* vg_total, vg_total == 1 ? "" : "s");
* dbg_free(dummy);
* dummy = NULL;
* if (lv_active > 0)
* printf("%d active", lv_active);
* if (lv_active > 0 && lv_total - lv_active > 0)
* printf(" / ");
* if (lv_total - lv_active > 0)
* printf("%d inactive", lv_total - lv_active);
* printf(" logical volumes\n");
* }
*************/
}
static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv)
{
int active = 0;
struct dm_info info;
int lv_total = 0;
ulong lv_capacity_total = 0;
@ -64,10 +64,9 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv)
const char *active_str, *snapshot_str;
/* FIXME Add -D arg to skip this! */
if (lv_active(lv) > 0) {
if (lv_info(lv, &info) && info.exists)
active_str = "ACTIVE ";
active++;
} else
else
active_str = "inactive ";
if (lv_is_origin(lv))