diff options
author | Dave Wysochanski <dwysocha@redhat.com> | 2007-09-20 21:39:08 +0000 |
---|---|---|
committer | Dave Wysochanski <dwysocha@redhat.com> | 2007-09-20 21:39:08 +0000 |
commit | dfef7f6942cc1b2988e73cb2e7086a452bee6516 (patch) | |
tree | 2f966ad8925af4a2a11a4c841528392a61a4727c /tools | |
parent | d6e11b43fd608b1c071e2eb13a557fa0e2f0e58c (diff) | |
download | lvm2-dfef7f6942cc1b2988e73cb2e7086a452bee6516.tar.gz lvm2-dfef7f6942cc1b2988e73cb2e7086a452bee6516.tar.xz lvm2-dfef7f6942cc1b2988e73cb2e7086a452bee6516.zip |
Add %PVS extents option to lvresize, lvextend, and lvcreate.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/commands.h | 6 | ||||
-rw-r--r-- | tools/lvcreate.c | 13 | ||||
-rw-r--r-- | tools/lvmcmdline.c | 3 | ||||
-rw-r--r-- | tools/lvresize.c | 31 | ||||
-rw-r--r-- | tools/tools.h | 3 |
5 files changed, 45 insertions, 11 deletions
diff --git a/tools/commands.h b/tools/commands.h index 1ab5e380..cebb3060 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -144,7 +144,7 @@ xx(lvcreate, "\t[-d|--debug]\n" "\t[-h|-?|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" - "\t{-l|--extents LogicalExtentsNumber[%{VG|LV|FREE}] |\n" + "\t{-l|--extents LogicalExtentsNumber[%{VG|LV|PVS|FREE}] |\n" "\t -L|--size LogicalVolumeSize[kKmMgGtTpPeE]}\n" "\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n" "\t[-n|--name LogicalVolumeName]\n" @@ -209,7 +209,7 @@ xx(lvextend, "\t[-d|--debug]\n" "\t[-h|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" - "\t{-l|--extents [+]LogicalExtentsNumber[%{VG|FREE}] |\n" + "\t{-l|--extents [+]LogicalExtentsNumber[%{VG|PVS|FREE}] |\n" "\t -L|--size [+]LogicalVolumeSize[kKmMgGtTpPeE]}\n" "\t[-m|--mirrors Mirrors]\n" "\t[-n|--nofsck]\n" @@ -323,7 +323,7 @@ xx(lvresize, "\t[-d|--debug]\n" "\t[-h|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" - "\t{-l|--extents [+|-]LogicalExtentsNumber[%{VG|LV|FREE}] |\n" + "\t{-l|--extents [+|-]LogicalExtentsNumber[%{VG|LV|PVS|FREE}] |\n" "\t -L|--size [+|-]LogicalVolumeSize[kKmMgGtTpPeE]}\n" "\t[-n|--nofsck]\n" "\t[-r|--resizefs]\n" diff --git a/tools/lvcreate.c b/tools/lvcreate.c index bf990722..9986be22 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -490,6 +490,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) char lv_name_buf[128]; const char *lv_name; struct lvinfo info; + uint32_t pv_extent_count; status |= lp->permission | VISIBLE_LV; @@ -574,8 +575,18 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp) case PERCENT_FREE: lp->extents = lp->extents * vg->free_count / 100; break; + case PERCENT_PVS: + if (!lp->pv_count) { + log_error("Please specify physical volume(s) " + "with %%PVS"); + return 0; + } + pv_extent_count = pv_list_extents_free(pvh); + lp->extents = lp->extents * pv_extent_count / 100; + break; case PERCENT_LV: - log_error("Please express size as %%VG or %%FREE."); + log_error("Please express size as %%VG, %%PVS, or " + "%%FREE."); return 0; case PERCENT_NONE: break; diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index b5e2e444..0f5cc085 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -269,6 +269,9 @@ int int_arg_with_sign_and_percent(struct cmd_context *cmd __attribute((unused)), a->percent = PERCENT_VG; else if (!strcasecmp(ptr, "L") || !strcasecmp(ptr, "LV")) a->percent = PERCENT_LV; + else if (!strcasecmp(ptr, "P") || !strcasecmp(ptr, "PV") || + !strcasecmp(ptr, "PVS")) + a->percent = PERCENT_PVS; else if (!strcasecmp(ptr, "F") || !strcasecmp(ptr, "FR") || !strcasecmp(ptr, "FREE")) a->percent = PERCENT_FREE; diff --git a/tools/lvresize.c b/tools/lvresize.c index 7c17b392..e69c8dd4 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -182,8 +182,20 @@ static int _lvresize_params(struct cmd_context *cmd, int argc, char **argv, if (!strcmp(cmd_name, "lvextend")) lp->resize = LV_EXTEND; - if (arg_count(cmd, extents_ARG) + arg_count(cmd, size_ARG) != 1) { - log_error("Please specify either size or extents (not both)"); + /* + * Allow omission of extents and size if the user has given us + * one or more PVs. Most likely, the intent was "resize this + * LV the best you can with these PVs" + */ + if ((arg_count(cmd, extents_ARG) + arg_count(cmd, size_ARG) == 0) && + (argc >= 2)) { + lp->extents = 100; + lp->percent = PERCENT_PVS; + lp->sign = SIGN_PLUS; + } else if ((arg_count(cmd, extents_ARG) + + arg_count(cmd, size_ARG) != 1)) { + log_error("Please specify either size or extents but not " + "both."); return 0; } @@ -246,6 +258,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) uint32_t seg_mirrors = 0; uint32_t extents_used = 0; uint32_t size_rest; + uint32_t pv_extent_count = 0; alloc_policy_t alloc; struct logical_volume *lock_lv; struct lv_list *lvl; @@ -319,6 +332,12 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) lp->extents = lp->size / vg->extent_size; } + if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc, + lp->argv, 1) : &vg->pvs)) { + stack; + return ECMD_FAILED; + } + switch(lp->percent) { case PERCENT_VG: lp->extents = lp->extents * vg->extent_count / 100; @@ -329,6 +348,10 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) case PERCENT_LV: lp->extents = lp->extents * lv->le_count / 100; break; + case PERCENT_PVS: + pv_extent_count = pv_list_extents_free(pvh); + lp->extents = lp->extents * pv_extent_count / 100; + break; case PERCENT_NONE: break; } @@ -539,10 +562,6 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp) if (lp->resize == LV_REDUCE) { if (lp->argc) log_warn("Ignoring PVs on command line when reducing"); - } else if (!(pvh = lp->argc ? create_pv_list(cmd->mem, vg, lp->argc, - lp->argv, 1) : &vg->pvs)) { - stack; - return ECMD_FAILED; } if (lp->resize == LV_REDUCE || lp->resizefs) { diff --git a/tools/tools.h b/tools/tools.h index d0d3d300..436cc9c5 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -83,7 +83,8 @@ typedef enum { PERCENT_NONE = 0, PERCENT_VG, PERCENT_FREE, - PERCENT_LV + PERCENT_LV, + PERCENT_PVS } percent_t; enum { |