public inbox for lvm2-cvs@sourceware.org help / color / mirror / Atom feed
From: wysochanski@sourceware.org To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org Subject: LVM2/tools lvcreate.c Date: Sun, 26 Jul 2009 02:31:00 -0000 [thread overview] Message-ID: <20090726023118.15809.qmail@sourceware.org> (raw) CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2009-07-26 02:31:18 Modified files: tools : lvcreate.c Log message: Refactor extents calculations / updates in _lvcreate. Move extents calculation adjustments into their own local functions right after we read the vg. This calculation really is not part of the LV create function but is rather an adjustment to the parameters based on what is given on the cmdline. So we move it outside the main _lvcreate. Should be no functional change. Author: Dave Wysochanski <dwysocha@redhat.com> Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvcreate.c.diff?cvsroot=lvm2&r1=1.200&r2=1.201 --- LVM2/tools/lvcreate.c 2009/07/26 02:30:57 1.200 +++ LVM2/tools/lvcreate.c 2009/07/26 02:31:18 1.201 @@ -18,6 +18,7 @@ #include <fcntl.h> +/* FIXME: refactor and reduce the size of this struct! */ struct lvcreate_params { /* flags */ int snapshot; @@ -46,6 +47,7 @@ uint32_t voriginextents; uint64_t voriginsize; percent_t percent; + struct dm_list *pvh; uint32_t permission; uint32_t read_ahead; @@ -56,6 +58,9 @@ const char *tag; }; +static uint64_t _extents_from_size(struct cmd_context *cmd, uint64_t size, + uint32_t extent_size); + static int _lvcreate_name_params(struct lvcreate_params *lp, struct cmd_context *cmd, int *pargc, char ***pargv) @@ -151,6 +156,64 @@ return 1; } +/* + * Update extents parameters based on other parameters which affect the size + * calcuation. + * NOTE: We must do this here because of the percent_t typedef and because we + * need the vg. + */ +static int _update_extents_params(struct volume_group *vg, + struct lvcreate_params *lp) +{ + uint32_t pv_extent_count; + + if (lp->size && + !(lp->extents = _extents_from_size(vg->cmd, lp->size, + vg->extent_size))) + return_0; + + if (lp->voriginsize && + !(lp->voriginextents = _extents_from_size(vg->cmd, lp->voriginsize, + vg->extent_size))) + return_0; + + /* + * Create the pv list before we parse lp->percent - might be + * PERCENT_PVSs + */ + if (lp->pv_count) { + if (!(lp->pvh = create_pv_list(vg->cmd->mem, vg, + lp->pv_count, lp->pvs, 1))) + return_0; + } else + lp->pvh = &vg->pvs; + + switch(lp->percent) { + case PERCENT_VG: + lp->extents = lp->extents * vg->extent_count / 100; + break; + 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(lp->pvh); + lp->extents = lp->extents * pv_extent_count / 100; + break; + case PERCENT_LV: + log_error("Please express size as %%VG, %%PVS, or " + "%%FREE."); + return 0; + case PERCENT_NONE: + break; + } + return 1; +} + static int _read_size_params(struct lvcreate_params *lp, struct cmd_context *cmd) { @@ -607,12 +670,10 @@ uint32_t size_rest; uint32_t status = 0; struct logical_volume *lv, *org = NULL; - struct dm_list *pvh; int origin_active = 0; char lv_name_buf[128]; const char *lv_name; struct lvinfo info; - uint32_t pv_extent_count; if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) { log_error("Logical volume \"%s\" already exists in " @@ -656,49 +717,6 @@ return 0; } - if (lp->size && - !(lp->extents = _extents_from_size(cmd, lp->size, vg->extent_size))) - return_0; - - if (lp->voriginsize && - !(lp->voriginextents = _extents_from_size(cmd, lp->voriginsize, - vg->extent_size))) - return_0; - - /* - * Create the pv list. - */ - if (lp->pv_count) { - if (!(pvh = create_pv_list(cmd->mem, vg, - lp->pv_count, lp->pvs, 1))) - return_0; - } else - pvh = &vg->pvs; - - switch(lp->percent) { - case PERCENT_VG: - lp->extents = lp->extents * vg->extent_count / 100; - break; - 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, %%PVS, or " - "%%FREE."); - return 0; - case PERCENT_NONE: - break; - } - if ((size_rest = lp->extents % lp->stripes)) { log_print("Rounding size (%d extents) up to stripe boundary " "size (%d extents)", lp->extents, @@ -782,10 +800,10 @@ return 0; } - if (lp->stripes > dm_list_size(pvh) && lp->alloc != ALLOC_ANYWHERE) { + if (lp->stripes > dm_list_size(lp->pvh) && lp->alloc != ALLOC_ANYWHERE) { log_error("Number of stripes (%u) must not exceed " "number of physical volumes (%d)", lp->stripes, - dm_list_size(pvh)); + dm_list_size(lp->pvh)); return 0; } @@ -855,7 +873,7 @@ } if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size, - 1, lp->extents, NULL, 0u, 0u, pvh, lp->alloc)) + 1, lp->extents, NULL, 0u, 0u, lp->pvh, lp->alloc)) return_0; if (lp->mirrors > 1) { @@ -864,7 +882,7 @@ vg->extent_size, lv->le_count, lp->region_size), - lp->corelog ? 0U : 1U, pvh, lp->alloc, + lp->corelog ? 0U : 1U, lp->pvh, lp->alloc, MIRROR_BY_LV | (lp->nosync ? MIRROR_SKIP_INIT_SYNC : 0))) { stack; @@ -1002,6 +1020,9 @@ return ECMD_FAILED; } + if (!_update_extents_params(vg, &lp)) + return ECMD_FAILED; + if (!_lvcreate(vg, &lp)) r = ECMD_FAILED;
next reply other threads:[~2009-07-26 2:31 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-07-26 2:31 wysochanski [this message] -- strict thread matches above, loose matches on Subject: below -- 2012-03-02 20:18 zkabelac 2012-02-01 1:54 agk 2011-11-10 12:40 zkabelac 2011-11-10 12:39 zkabelac 2011-09-27 12:37 agk 2011-09-07 9:25 zkabelac 2011-09-06 15:35 agk 2011-03-25 21:56 jbrassow 2010-10-25 12:05 zkabelac 2010-05-11 21:40 jbrassow 2009-07-26 2:32 wysochanski 2009-07-26 2:32 wysochanski 2009-07-26 2:32 wysochanski 2009-07-26 2:31 wysochanski 2009-07-26 2:30 wysochanski 2009-06-06 22:06 mbroz 2009-05-27 13:07 agk 2009-04-26 8:12 prajnoha 2008-07-17 15:19 wysochanski 2008-01-16 15:26 agk 2007-10-01 15:01 wysochanski 2007-09-24 13:29 wysochanski 2006-10-16 16:47 agk 2005-11-12 22:00 agk 2005-10-28 14:38 agk 2005-09-30 22:20 agk
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090726023118.15809.qmail@sourceware.org \ --to=wysochanski@sourceware.org \ --cc=lvm-devel@redhat.com \ --cc=lvm2-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).