mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Move extents_from_size from lvcreate into internal library so we can reuse.
Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
parent
c42b235610
commit
9963d0710e
@ -495,6 +495,9 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
|
||||
int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
const char *new_name);
|
||||
|
||||
uint64_t extents_from_size(struct cmd_context *cmd, uint64_t size,
|
||||
uint32_t extent_size);
|
||||
|
||||
/* FIXME: refactor and reduce the size of this struct! */
|
||||
struct lvcreate_params {
|
||||
/* flags */
|
||||
|
@ -680,6 +680,28 @@ bad:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint64_t extents_from_size(struct cmd_context *cmd, uint64_t size,
|
||||
uint32_t extent_size)
|
||||
{
|
||||
if (size % extent_size) {
|
||||
size += extent_size - size % extent_size;
|
||||
log_print("Rounding up size to full physical extent %s",
|
||||
display_size(cmd, size));
|
||||
}
|
||||
|
||||
if (size > (uint64_t) UINT32_MAX * extent_size) {
|
||||
log_error("Volume too large (%s) for extent size %s. "
|
||||
"Upper limit is %s.",
|
||||
display_size(cmd, size),
|
||||
display_size(cmd, (uint64_t) extent_size),
|
||||
display_size(cmd, (uint64_t) UINT32_MAX *
|
||||
extent_size));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t) size / extent_size;
|
||||
}
|
||||
|
||||
static int _recalc_extents(uint32_t *extents, const char *desc1,
|
||||
const char *desc2, uint32_t old_size,
|
||||
uint32_t new_size)
|
||||
|
@ -25,9 +25,6 @@ struct lvcreate_cmdline_params {
|
||||
int pv_count;
|
||||
};
|
||||
|
||||
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)
|
||||
@ -136,12 +133,12 @@ static int _update_extents_params(struct volume_group *vg,
|
||||
uint32_t pv_extent_count;
|
||||
|
||||
if (lcp->size &&
|
||||
!(lp->extents = _extents_from_size(vg->cmd, lcp->size,
|
||||
!(lp->extents = extents_from_size(vg->cmd, lcp->size,
|
||||
vg->extent_size)))
|
||||
return_0;
|
||||
|
||||
if (lp->voriginsize &&
|
||||
!(lp->voriginextents = _extents_from_size(vg->cmd, lp->voriginsize,
|
||||
!(lp->voriginextents = extents_from_size(vg->cmd, lp->voriginsize,
|
||||
vg->extent_size)))
|
||||
return_0;
|
||||
|
||||
@ -573,28 +570,6 @@ static int _lvcreate_params(struct lvcreate_params *lp,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint64_t _extents_from_size(struct cmd_context *cmd, uint64_t size,
|
||||
uint32_t extent_size)
|
||||
{
|
||||
if (size % extent_size) {
|
||||
size += extent_size - size % extent_size;
|
||||
log_print("Rounding up size to full physical extent %s",
|
||||
display_size(cmd, size));
|
||||
}
|
||||
|
||||
if (size > (uint64_t) UINT32_MAX * extent_size) {
|
||||
log_error("Volume too large (%s) for extent size %s. "
|
||||
"Upper limit is %s.",
|
||||
display_size(cmd, size),
|
||||
display_size(cmd, (uint64_t) extent_size),
|
||||
display_size(cmd, (uint64_t) UINT32_MAX *
|
||||
extent_size));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t) size / extent_size;
|
||||
}
|
||||
|
||||
int lvcreate(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
int r = ECMD_PROCESSED;
|
||||
|
Loading…
Reference in New Issue
Block a user