From 4a624ca05565fb3e6cb12a588823b551a528e86a Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 10 Jan 2002 23:21:07 +0000 Subject: [PATCH] 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. --- lib/activate/activate.c | 67 +++++++++++++++++++-- lib/activate/activate.h | 2 + lib/activate/fs.c | 38 ++++++++---- lib/activate/fs.h | 2 + lib/display/display.c | 15 ++--- lib/format1/import-export.c | 18 ------ lib/format_text/flags.c | 3 - lib/format_text/import.c | 1 + lib/metadata/lv_manip.c | 2 +- lib/metadata/merge.c | 5 ++ lib/metadata/metadata.c | 5 +- lib/metadata/metadata.h | 3 +- tools/archive.c | 15 +++-- tools/lvchange.c | 114 +++++++++++++++--------------------- tools/lvcreate.c | 8 --- tools/lvremove.c | 8 --- tools/lvrename.c | 24 ++++---- tools/lvresize.c | 16 ----- tools/lvscan.c | 7 ++- tools/pvchange.c | 6 -- tools/pvcreate.c | 7 --- tools/pvscan.c | 11 ++-- tools/stub.h | 1 + tools/vgcfgbackup.c | 3 - tools/vgchange.c | 36 ------------ tools/vgextend.c | 5 -- tools/vgmerge.c | 7 ++- tools/vgreduce.c | 7 --- tools/vgremove.c | 7 --- tools/vgrename.c | 6 +- tools/vgscan.c | 18 +----- 31 files changed, 195 insertions(+), 272 deletions(-) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 931a93d1a..188c3759c 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -11,12 +11,14 @@ #include "fs.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]; struct dm_task *dmt; @@ -26,12 +28,17 @@ static struct dm_task *_setup_task(struct logical_volume *lv, int task) 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); 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 r = 0; @@ -59,6 +66,42 @@ int lv_info(struct logical_volume *lv, struct dm_info *info) 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 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) { +/****** + 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, "%s %" PRIu64 "%s", dev_name(seg->area[s].pv->dev), @@ -224,6 +277,11 @@ int _suspend(struct logical_volume *lv, int sus) return r; } +int lv_suspend(struct logical_volume *lv) +{ + return _suspend(lv, 1); +} + int lv_reactivate(struct logical_volume *lv) { int r; @@ -246,6 +304,7 @@ int lv_reactivate(struct logical_volume *lv) return r; } + int lv_deactivate(struct logical_volume *lv) { int r; diff --git a/lib/activate/activate.h b/lib/activate/activate.h index 170af0959..50278411f 100644 --- a/lib/activate/activate.h +++ b/lib/activate/activate.h @@ -15,10 +15,12 @@ int lv_active(struct logical_volume *lv); int lv_suspended(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_rename(const char *old_name, struct logical_volume *lv); int lv_activate(struct logical_volume *lv); int lv_reactivate(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 diff --git a/lib/activate/fs.c b/lib/activate/fs.c index 795c22d61..c12ff2bff 100644 --- a/lib/activate/fs.c +++ b/lib/activate/fs.c @@ -17,20 +17,23 @@ #include -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) { - 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, - lv->vg->name, lv->name); + snprintf(buffer, len, "%s%s/%s", lv->vg->cmd->dev_dir, + 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]; - _build_lv_path(lv_path, sizeof(lv_path), lv); - _build_link_path(link_path, sizeof(link_path), lv); + _build_lv_path(lv_path, sizeof(lv_path), lv, lv->name); + _build_link_path(link_path, sizeof(link_path), lv, lv->name); log_very_verbose("Linking %s to %s", link_path, lv_path); if (symlink(lv_path, link_path) < 0) { @@ -74,11 +77,14 @@ static int _mk_link(struct logical_volume *lv) 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]; - _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); 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) { - if (!_rm_link(lv)) { + if (!_rm_link(lv, NULL)) { stack; return 0; } @@ -113,3 +119,13 @@ int fs_del_lv(struct logical_volume *lv) 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; +} diff --git a/lib/activate/fs.h b/lib/activate/fs.h index 98bfbfe5c..fe95c033d 100644 --- a/lib/activate/fs.h +++ b/lib/activate/fs.h @@ -17,5 +17,7 @@ int fs_add_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 diff --git a/lib/display/display.c b/lib/display/display.c index 35e4c7fea..cc9a3ad00 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -157,9 +157,6 @@ void pvdisplay_full(struct physical_volume *pv) log_print("PV# %u", pv->pv_number); **********/ - log_print("PV Status %savailable", - (pv->status & ACTIVE) ? "" : "NOT "); - pe_free = pv->pe_count - pv->pe_allocated; if (pv->pe_count && (pv->status & ALLOCATABLE_PV)) 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)); /* FIXME pv->pv_number); */ - log_print("PV Status %savailable / %sallocatable", - (pv->status & ACTIVE) ? "" : "NOT ", + log_print("PV Status %sallocatable", (pv->status & ALLOCATABLE_PV) ? "" : "NOT "); log_print("Total PE / Free PE %u / %u", 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; } - void lvdisplay_colons(struct logical_volume *lv) { int inkernel; @@ -470,9 +465,8 @@ void vgdisplay_full(struct volume_group *vg) access == LVM_READ ? "read" : "", access == LVM_WRITE ? "write" : "", access == 0 ? "error" : ""); - log_print("VG Status %savailable%s/%sresizable", - vg->status & ACTIVE ? "" : "NOT ", - vg->status & EXPORTED_VG ? "/exported" : "", + log_print("VG Status %s/%sresizable", + vg->status & EXPORTED_VG ? "exported" : "", vg->status & RESIZEABLE_VG ? "" : "NOT "); /******* FIXME 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 / 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, - (vg->status & ACTIVE) ? "active" : "inactive", + log_print("%s %-9s [%-9s used / %s free]", vg->name, /********* FIXME if "open" print "/used" else print "/idle"??? ******/ s1, s2, s3); dbg_free(s1); diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index f733ce1e9..36dfb1de4 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -48,9 +48,6 @@ int import_pv(struct pool *mem, struct device *dev, return 0; } - if (pvd->pv_status & PV_ACTIVE) - pv->status |= ACTIVE; - if (pvd->pv_allocatable) 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); - if (pv->status & ACTIVE) - pvd->pv_status |= PV_ACTIVE; - if (pv->status & ALLOCATABLE_PV) pvd->pv_allocatable = PV_ALLOCATABLE; @@ -135,9 +129,6 @@ int import_vg(struct pool *mem, return 0; } - if (vgd->vg_status & VG_ACTIVE) - vg->status |= ACTIVE; - if (vgd->vg_status & VG_EXPORTED) vg->status |= EXPORTED_VG; @@ -181,9 +172,6 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg) if (vg->status & SHARED) vgd->vg_access |= VG_SHARED; - if (vg->status & ACTIVE) - vgd->vg_status |= VG_ACTIVE; - if (vg->status & EXPORTED_VG) 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; } - if (lvd->lv_status & LV_ACTIVE) - lv->status |= ACTIVE; - if (lvd->lv_status & LV_SPINDOWN) lv->status |= SPINDOWN_LV; @@ -272,9 +257,6 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg, if (lv->status & SNAPSHOT_ORG) lvd->lv_access |= LV_SNAPSHOT_ORG; - if (lv->status & ACTIVE) - lvd->lv_status |= LV_ACTIVE; - if (lv->status & SPINDOWN_LV) lvd->lv_status |= LV_SPINDOWN; diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c index 25b5c7e7b..5be0b7ac6 100644 --- a/lib/format_text/flags.c +++ b/lib/format_text/flags.c @@ -19,7 +19,6 @@ struct flag { }; static struct flag _vg_flags[] = { - {ACTIVE, "ACTIVE"}, {EXPORTED_VG, "EXPORTED"}, {RESIZEABLE_VG, "RESIZEABLE"}, {CLUSTERED, "CLUSTERED"}, @@ -28,13 +27,11 @@ static struct flag _vg_flags[] = { }; static struct flag _pv_flags[] = { - {ACTIVE, "ACTIVE"}, {ALLOCATABLE_PV, "ALLOCATABLE"}, {0, NULL} }; static struct flag _lv_flags[] = { - {ACTIVE, "ACTIVE"}, {LVM_READ, "READ"}, {LVM_WRITE, "WRITE"}, {ALLOC_SIMPLE, "ALLOC_SIMPLE"}, diff --git a/lib/format_text/import.c b/lib/format_text/import.c index 0455a604d..5e3ed18f0 100644 --- a/lib/format_text/import.c +++ b/lib/format_text/import.c @@ -4,6 +4,7 @@ * This file is released under the LGPL. */ +#include "metadata.h" #include "import-export.h" #include "pool.h" #include "log.h" diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index a62382e04..19a3bd9c2 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -497,7 +497,7 @@ int lv_extend(struct logical_volume *lv, return 0; } - if (!merge_segments(lv)) { + if (!lv_merge_segments(lv)) { log_err("Couldn't merge segments after extending " "logical volume."); return 0; diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c index 4d7f674bf..ea17931e3 100644 --- a/lib/metadata/merge.c +++ b/lib/metadata/merge.c @@ -53,3 +53,8 @@ int lv_merge_segments(struct logical_volume *lv) return 1; } +/**** FIXME Dummy ****/ +int lv_check_segments(struct logical_volume *lv) +{ + return 1; +} diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 3f04324dd..6b01f6a46 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -47,9 +47,6 @@ int _add_pv_to_vg(struct format_instance *fi, struct volume_group *vg, return 0; } - /* FIXME Tie this to activation or not? */ - pv->status |= ACTIVE; - /* Units of 512-byte sectors */ if (!dev_get_size(pv->dev, &pv->size)) { stack; @@ -156,7 +153,7 @@ struct volume_group *vg_create(struct format_instance *fi, const char *vg_name, 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_count = 0; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 7b6de37f5..875e9e6d9 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -27,8 +27,7 @@ /* Various flags */ /* Note that the bits no longer necessarily correspond to LVM1 disk format */ -#define ACTIVE 0x00000001 /* PV VG LV */ -#define EXPORTED_VG 0x00000002 /* VG */ /* And PV too perhaps? */ +#define EXPORTED_VG 0x00000002 /* VG */ #define RESIZEABLE_VG 0x00000004 /* VG */ /* May any free extents on this PV be used or must they be left free? */ diff --git a/tools/archive.c b/tools/archive.c index 42d4117f5..5ca151acc 100644 --- a/tools/archive.c +++ b/tools/archive.c @@ -11,9 +11,12 @@ #include "lvm-string.h" #include "toollib.h" +#include "tools.h" + #include #include + static struct { int enabled; char *dir; @@ -198,10 +201,10 @@ int backup_remove(const char *vg_name) return 1; } -static int _read_vg(struct command_context *cmd, - const char *vg_name, const char *file) +static struct volume_group *_read_vg(struct cmd_context *cmd, + const char *vg_name, const char *file) { - int r; + struct volume_group *vg; struct format_instance *tf; if (!(tf = text_format_create(cmd, file))) { @@ -209,11 +212,11 @@ static int _read_vg(struct command_context *cmd, return 0; } - if (!(r = tf->ops->vg_read(tf, vg_name))) + if (!(vg = tf->ops->vg_read(tf, vg_name))) stack; tf->ops->destroy(tf); - return r; + return vg; } 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. */ - if (!(vg = _read_vg(vg_name, file))) { + if (!(vg = _read_vg(vg->cmd, vg_name, file))) { stack; return 0; } diff --git a/tools/lvchange.c b/tools/lvchange.c index 566bab8ba..d774f3c65 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -45,16 +45,7 @@ int lvchange(int argc, char **argv) static int lvchange_single(struct logical_volume *lv) { int doit = 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; - } -********/ + int archived = 0; if (lv->status & SNAPSHOT_ORG) { 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; } - if (!archive(lv->vg)) - return 0; - /* 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); + } + + /* 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 */ if (arg_count(available_ARG)) - doit += lvchange_availability(lv); - - /* 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); + if (!lvchange_availability(lv)) + return ECMD_FAILED; return 0; } @@ -135,55 +133,39 @@ static int lvchange_permission(struct logical_volume *lv) static int lvchange_availability(struct logical_volume *lv) { - int lv_stat = 0; + int activate = 0; int active; if (strcmp(arg_str_value(available_ARG, "n"), "n")) - lv_stat |= ACTIVE; + activate = 1; active = lv_active(lv); - if (lv_stat & 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)) + if (activate && 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 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); if (!lv_reactivate(lv)) 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; diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 12c4e568f..2fdd97b79 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -121,14 +121,6 @@ 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 " "volume group %s", lv_name, vg_name); diff --git a/tools/lvremove.c b/tools/lvremove.c index 934f87162..cac6e4d9b 100644 --- a/tools/lvremove.c +++ b/tools/lvremove.c @@ -38,14 +38,6 @@ static int lvremove_single(struct logical_volume *lv) 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", lv->name); diff --git a/tools/lvrename.c b/tools/lvrename.c index b7b08e5d0..73cf0fe98 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -23,6 +23,7 @@ int lvrename(int argc, char **argv) { int maxlen; + int active; char *lv_name_old, *lv_name_new; char *vg_name, *vg_name_new; char *st; @@ -89,14 +90,6 @@ 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 " "volume group %s", lv_name_new, vg_name); @@ -114,6 +107,13 @@ int lvrename(int argc, char **argv) if (!archive(lv->vg)) 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))) { log_error("Failed to allocate space for new name"); return ECMD_FAILED; @@ -125,10 +125,12 @@ int lvrename(int argc, char **argv) return ECMD_FAILED; } - backup(lv->vg); + if (active) { + lv_rename(lv_name_old, lv); + lv_reactivate(lv); + } - /* FIXME Update symlink. */ - lv_reactivate(lv); + backup(lv->vg); log_print("Renamed %s to %s in volume group %s%s", lv_name_old, lv_name_new, fid->cmd->dev_dir, vg_name); diff --git a/tools/lvresize.c b/tools/lvresize.c index e15a5f93d..3c7df5c63 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -106,14 +106,6 @@ 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))) { 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; -/******* 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 */ extents = size * 2; diff --git a/tools/lvscan.c b/tools/lvscan.c index 13f8979d9..2ee7ce98e 100644 --- a/tools/lvscan.c +++ b/tools/lvscan.c @@ -56,16 +56,17 @@ int lvscan(int argc, char **argv) static int lvscan_single(struct logical_volume *lv) { - int lv_active = 0; + int active = 0; int lv_total = 0; ulong lv_capacity_total = 0; char *dummy; const char *active_str, *snapshot_str; - if (lv->status & ACTIVE) { +/* FIXME Add -D arg to skip this! */ + if (lv_active(lv)) { active_str = "ACTIVE "; - lv_active++; + active++; } else active_str = "inactive "; diff --git a/tools/pvchange.c b/tools/pvchange.c index a71585658..959eb92d0 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -128,12 +128,6 @@ int pvchange_single(struct physical_volume *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); if (*pv->vg_name) { if (!(fid->ops->vg_write(fid,vg))) { diff --git a/tools/pvcreate.c b/tools/pvcreate.c index 7a008fd02..3caa2594c 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -50,13 +50,6 @@ 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) { log_error("Can't initialize physical volume %s of " diff --git a/tools/pvscan.c b/tools/pvscan.c index 89fbb04c8..4d9580bf6 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -133,7 +133,6 @@ void pvscan_display_single(struct physical_volume *pv) { int vg_name_len = 0; - const char *active_str; char *s1, *s2; @@ -159,8 +158,6 @@ void pvscan_display_single(struct physical_volume *pv) 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; if (arg_count(uuid_ARG)) { @@ -173,7 +170,7 @@ void pvscan_display_single(struct physical_volume *pv) } 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, vg_max_name_len - 6, " ", (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) { strncpy(vg_name_this, pv->vg_name, vg_name_len); - log_print("%s PV %-*s is in EXPORTED VG %s [%s / %s free]", - active_str, pv_max_name_len, pv_tmp_name, + log_print("PV %-*s is in EXPORTED VG %s [%s / %s free]", + pv_max_name_len, pv_tmp_name, vg_name_this, (s1 = display_size(pv->pe_count * pv->pe_size / 2, @@ -198,7 +195,7 @@ void pvscan_display_single(struct physical_volume *pv) sprintf(vg_tmp_name, "%s", pv->vg_name); 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, (s1 = display_size(pv->pe_count * pv->pe_size / 2, SIZE_SHORT)), (s2 = diff --git a/tools/stub.h b/tools/stub.h index 5bf2e78d0..fa6e6e3a8 100644 --- a/tools/stub.h +++ b/tools/stub.h @@ -13,4 +13,5 @@ int vgexport(int argc, char **argv) {return 1;} int vgimport(int argc, char **argv) {return 1;} int vgmknodes(int argc, char **argv) {return 1;} int vgsplit(int argc, char **argv) {return 1;} +int vgcfgrestore(int argc, char **argv) {return 1;} diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c index c69974040..f6f450be0 100644 --- a/tools/vgcfgbackup.c +++ b/tools/vgcfgbackup.c @@ -35,9 +35,6 @@ static int vg_backup_single(const char *vg_name) return ECMD_FAILED; } - log_print("Found %sactive volume group %s", - (vg->status & ACTIVE) ? "" : "in", vg_name); - if (arg_count(file_ARG)) { _backup_to_file(arg_value(file_ARG), vg); diff --git a/tools/vgchange.c b/tools/vgchange.c index b7df02763..6d31b62dc 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -76,18 +76,8 @@ static int vgchange_single(const char *vg_name) void vgchange_available(struct volume_group *vg) { int lv_open, lv_active; - struct list *lvh; 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? */ if (!available && (lv_open = lvs_in_vg_opened(vg))) { 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 " "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))) log_verbose("Activated %d logical volumes in " "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); - if (vg->status & ACTIVE) { - log_error("MaxLogicalVolume can't be changed in " - "active volume group '%s'", vg->name); - return; - } - if (!(vg->status & RESIZEABLE_VG)) { log_error("Volume group '%s' must be resizeable " "to change MaxLogicalVolume", vg->name); diff --git a/tools/vgextend.c b/tools/vgextend.c index 59ac88e81..1938cb008 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -46,11 +46,6 @@ int vgextend(int argc, char **argv) return ECMD_FAILED; } -/******* Ignore active - if (!(vg->status & ACTIVE)) - log_error("Volume group '%s' is not active.", vg_name); -********/ - if (!(vg->status & RESIZEABLE_VG)) { log_error("Volume group '%s' is not resizeable.", vg_name); return ECMD_FAILED; diff --git a/tools/vgmerge.c b/tools/vgmerge.c index b9e963eb3..1461d5fc3 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -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 list *lvh1, *lvh2; + int active; if (!strcmp(vg_name_to, 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; } - /* FIXME status - confirm no active LVs? */ - if (vg_from->status & ACTIVE) { - log_error("Volume group %s must be inactive", vg_name_from); + if ((active = lvs_in_vg_activated(vg_from))) { + log_error("Logical volumes in %s must be inactive", + vg_name_from); return ECMD_FAILED; } diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 9e80dedc8..8fa6188a1 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -54,13 +54,6 @@ 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 & RESIZEABLE_VG)) { log_error("Volume group %s is not reducable", vg_name); return ECMD_FAILED; diff --git a/tools/vgremove.c b/tools/vgremove.c index d5dd8b481..8d9a4f1f3 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -40,13 +40,6 @@ 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)", vg_name, vg->lv_count); diff --git a/tools/vgrename.c b/tools/vgrename.c index 473732df5..b806a34b6 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -73,12 +73,14 @@ int vgrename(int argc, char **argv) return ECMD_FAILED; } - if (vg_old->status & ACTIVE) { - log_error("Volume group %s still active", vg_name_old); + if (lvs_in_vg_activated(vg_old)) { + log_error("Volume group %s still has active LVs", vg_name_old); +/***** FIXME Handle this with multiple LV renames! if (!force_ARG) { log_error("Use -f to force the rename"); return ECMD_FAILED; } +*****/ } log_verbose("Checking for new volume group %s", vg_name_new); diff --git a/tools/vgscan.c b/tools/vgscan.c index 5ca6999cd..97a328e36 100644 --- a/tools/vgscan.c +++ b/tools/vgscan.c @@ -50,23 +50,7 @@ static int vgscan_single(const char *vg_name) 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; - } - } -*********/ - - log_print("%d logical volumes in volume group %s activated", - activate_lvs_in_vg(vg), vg_name); + log_print("Found volume group %s", vg_name); return 0; }