diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/metadata/lv_manip.c | 88 | ||||
-rw-r--r-- | lib/metadata/metadata-exported.h | 1 |
2 files changed, 52 insertions, 37 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index d11b1259f..022bb1f9d 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -5130,38 +5130,8 @@ static int _lvresize_volume(struct logical_volume *lv, struct volume_group *vg = lv->vg; struct cmd_context *cmd = vg->cmd; uint32_t old_extents; - int status; alloc_policy_t alloc = lp->alloc ? : lv->alloc; - if ((lp->resize == LV_REDUCE) && (pvh != &vg->pvs)) - log_print_unless_silent("Ignoring PVs on command line when reducing."); - - /* Request confirmation before operations that are often mistakes. */ - if ((lp->resizefs || (lp->resize == LV_REDUCE)) && - !_request_confirmation(lv, lp)) - return_0; - - if (lp->resizefs) { - if (!lp->nofsck && - !_fsadm_cmd(FSADM_CMD_CHECK, lv, 0, lp->force, &status)) { - if (status != FSADM_CHECK_FAILS_FOR_MOUNTED) { - log_error("Filesystem check failed."); - return 0; - } - /* some filesystems support online resize */ - } - - /* FIXME forks here */ - if ((lp->resize == LV_REDUCE) && - !_fsadm_cmd(FSADM_CMD_RESIZE, lv, lp->extents, lp->force, NULL)) { - log_error("Filesystem resize failed."); - return 0; - } - } - - if (!archive(vg)) - return_0; - old_extents = lv->le_count; log_verbose("%sing logical volume %s to %s%s", (lp->resize == LV_REDUCE) ? "Reduc" : "Extend", @@ -5187,11 +5157,13 @@ static int _lvresize_volume(struct logical_volume *lv, log_print_unless_silent("Size of logical volume %s unchanged from %s (%" PRIu32 " extents).", display_lvname(lv), display_size(cmd, (uint64_t) old_extents * vg->extent_size), old_extents); - else + else { + lp->size_changed = 1; log_print_unless_silent("Size of logical volume %s changed from %s (%" PRIu32 " extents) to %s (%" PRIu32 " extents).", display_lvname(lv), display_size(cmd, (uint64_t) old_extents * vg->extent_size), old_extents, display_size(cmd, (uint64_t) lv->le_count * vg->extent_size), lv->le_count); + } return 1; } @@ -5211,10 +5183,10 @@ static int _lvresize_prepare(struct logical_volume **lv, else if (lp->extents && !_lvresize_extents_from_percent(*lv, lp, pvh)) return_0; - if (lp->extents && !_lvresize_adjust_extents(*lv, lp, pvh)) + if (!_lvresize_adjust_extents(*lv, lp, pvh)) return_0; - if (lp->extents && !_lvresize_check_type(*lv, lp)) + if (!_lvresize_check_type(*lv, lp)) return_0; return 1; @@ -5246,6 +5218,7 @@ int lv_resize(struct logical_volume *lv, struct lvresize_params aux_lp; int activated = 0; int ret = 0; + int status; if (!_lvresize_check(lv, lp)) return_0; @@ -5271,8 +5244,8 @@ int lv_resize(struct logical_volume *lv, } } else if (lp->poolmetadata_size) { if (!lp->extents && !lp->size) { - /* When only --poolmetadatasize give and not --size - * swith directly to resize metadata LV */ + /* When only --poolmetadatasize given and not --size + * switch directly to resize metadata LV */ lv = first_seg(lv)->metadata_lv; lp->size = lp->poolmetadata_size; lp->sign = lp->poolmetadata_sign; @@ -5287,9 +5260,44 @@ int lv_resize(struct logical_volume *lv, if (aux_lv && !_lvresize_prepare(&aux_lv, &aux_lp, pvh)) return_0; + /* Always should have lp->size or lp->extents */ if (!_lvresize_prepare(&lv, lp, pvh)) return_0; + if (((lp->resize == LV_REDUCE) || + (aux_lv && aux_lp.resize == LV_REDUCE)) && + (pvh != &vg->pvs)) + log_print_unless_silent("Ignoring PVs on command line when reducing."); + + /* Request confirmation before operations that are often mistakes. */ + /* aux_lv never resize fs */ + if ((lp->resizefs || (lp->resize == LV_REDUCE)) && + !_request_confirmation(lv, lp)) + return_0; + + if (lp->resizefs) { + if (!lp->nofsck && + !_fsadm_cmd(FSADM_CMD_CHECK, lv, 0, lp->force, &status)) { + if (status != FSADM_CHECK_FAILS_FOR_MOUNTED) { + log_error("Filesystem check failed."); + return 0; + } + /* some filesystems support online resize */ + } + + /* FIXME forks here */ + if ((lp->resize == LV_REDUCE) && + !_fsadm_cmd(FSADM_CMD_RESIZE, lv, lp->extents, lp->force, NULL)) { + log_error("Filesystem resize failed."); + return 0; + } + } + + if (!lp->extents && (!aux_lv || !aux_lp.extents)) { + lp->extents = lv->le_count; + goto out; /* Nothing to do */ + } + if (lv_is_thin_pool(lock_lv) && /* Lock holder is thin-pool */ !lv_is_active(lock_lv)) { @@ -5322,12 +5330,15 @@ int lv_resize(struct logical_volume *lv, if (!lockd_lv(cmd, lock_lv, "ex", 0)) return_0; + if (!archive(vg)) + return_0; + if (aux_lv) { if (!_lvresize_volume(aux_lv, &aux_lp, pvh)) goto_bad; /* store vg on disk(s) */ - if (!lv_update_and_reload(lock_lv)) + if (aux_lp.size_changed && !lv_update_and_reload(lock_lv)) goto_bad; } @@ -5335,6 +5346,9 @@ int lv_resize(struct logical_volume *lv, goto_bad; /* store vg on disk(s) */ + if (!lp->size_changed) + goto out; /* No table reload needed */ + if (!lv_update_and_reload(lock_lv)) goto_bad; @@ -5349,7 +5363,7 @@ int lv_resize(struct logical_volume *lv, backup(vg); } - +out: log_print_unless_silent("Logical volume %s successfully resized.", display_lvname(lv)); diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 7765d23ae..84b510b59 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -637,6 +637,7 @@ struct lvresize_params { int approx_alloc; int extents_are_pes; /* Is 'extents' counting PEs or LEs? */ + int size_changed; /* Was there actually a size change */ }; void pvcreate_params_set_defaults(struct pvcreate_params *pp); |