mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Refactor _lvcreate - move *_ARG into _lvcreate_params and get 'cmd' from 'vg'.
A couple simple refactorings of _lvcreate - should be no functional change. Move tags_ARG parsing into _lvcreate_params. Also use lp->voriginsize instread of arg_count(). These refactorings make it easier to move the bulk of _lvcreate into the library. Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
parent
c9b4604ba6
commit
9091827c46
@ -53,6 +53,7 @@ struct lvcreate_params {
|
|||||||
|
|
||||||
int pv_count;
|
int pv_count;
|
||||||
char **pvs;
|
char **pvs;
|
||||||
|
const char *tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int _lvcreate_name_params(struct lvcreate_params *lp,
|
static int _lvcreate_name_params(struct lvcreate_params *lp,
|
||||||
@ -525,6 +526,12 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg_count(cmd, addtag_ARG) &&
|
||||||
|
!(lp->tag = arg_str_value(cmd, addtag_ARG, NULL))) {
|
||||||
|
log_error("Failed to get tag");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lp->pv_count = argc;
|
lp->pv_count = argc;
|
||||||
lp->pvs = argv;
|
lp->pvs = argv;
|
||||||
|
|
||||||
@ -593,14 +600,14 @@ static struct logical_volume *_create_virtual_origin(struct cmd_context *cmd,
|
|||||||
return lv;
|
return lv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
static int _lvcreate(struct volume_group *vg,
|
||||||
struct lvcreate_params *lp)
|
struct lvcreate_params *lp)
|
||||||
{
|
{
|
||||||
|
struct cmd_context *cmd = vg->cmd;
|
||||||
uint32_t size_rest;
|
uint32_t size_rest;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
struct logical_volume *lv, *org = NULL;
|
struct logical_volume *lv, *org = NULL;
|
||||||
struct dm_list *pvh;
|
struct dm_list *pvh;
|
||||||
const char *tag = NULL;
|
|
||||||
int origin_active = 0;
|
int origin_active = 0;
|
||||||
char lv_name_buf[128];
|
char lv_name_buf[128];
|
||||||
const char *lv_name;
|
const char *lv_name;
|
||||||
@ -722,7 +729,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
/* Must zero cow */
|
/* Must zero cow */
|
||||||
status |= LVM_WRITE;
|
status |= LVM_WRITE;
|
||||||
|
|
||||||
if (arg_count(cmd, virtualsize_ARG))
|
if (lp->voriginsize)
|
||||||
origin_active = 1;
|
origin_active = 1;
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@ -806,12 +813,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
lv_name = &lv_name_buf[0];
|
lv_name = &lv_name_buf[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_count(cmd, addtag_ARG)) {
|
if (lp->tag) {
|
||||||
if (!(tag = arg_str_value(cmd, addtag_ARG, NULL))) {
|
|
||||||
log_error("Failed to get tag");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(vg->fid->fmt->features & FMT_TAGS)) {
|
if (!(vg->fid->fmt->features & FMT_TAGS)) {
|
||||||
log_error("Volume group %s does not support tags",
|
log_error("Volume group %s does not support tags",
|
||||||
vg->name);
|
vg->name);
|
||||||
@ -846,9 +848,9 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
lv->minor);
|
lv->minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag && !str_list_add(cmd->mem, &lv->tags, tag)) {
|
if (lp->tag && !str_list_add(cmd->mem, &lv->tags, lp->tag)) {
|
||||||
log_error("Failed to add tag %s to %s/%s",
|
log_error("Failed to add tag %s to %s/%s",
|
||||||
tag, lv->vg->name, lv->name);
|
lp->tag, lv->vg->name, lv->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +1002,7 @@ int lvcreate(struct cmd_context *cmd, int argc, char **argv)
|
|||||||
return ECMD_FAILED;
|
return ECMD_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_lvcreate(cmd, vg, &lp))
|
if (!_lvcreate(vg, &lp))
|
||||||
r = ECMD_FAILED;
|
r = ECMD_FAILED;
|
||||||
|
|
||||||
unlock_and_release_vg(cmd, vg, lp.vg_name);
|
unlock_and_release_vg(cmd, vg, lp.vg_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user