1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 01:55:10 +03:00

Check max_lv on only place and force the check only for new volume.

We can temporarily violate max_lv during mirror conversion etc.

(If the operation fails, orphan mirror images are visible to administrator
for manual remove for example. Not that this should ever happen:-)

Force limit only for lvcreate (and vg merge) command.

Patch also adds simple max_lv tests into testsuite
This commit is contained in:
Milan Broz 2009-05-13 21:29:10 +00:00
parent 82cf926094
commit 970f241c52
7 changed files with 56 additions and 12 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.46 -
================================
Force max_lv restriction only for newly created LV.
Remove unneeded import parameter from lv_create_empty.
Merge lv_is_displayable and lv_is_visible functions.
Introduce lv_set_visible & lv_set_invisible functions.

View File

@ -1804,6 +1804,20 @@ char *generate_lv_name(struct volume_group *vg, const char *format,
return buffer;
}
int vg_max_lv_reached(struct volume_group *vg)
{
if (!vg->max_lv)
return 0;
if (vg->max_lv > vg_visible_lvs(vg))
return 0;
log_verbose("Maximum number of logical volumes (%u) reached "
"in volume group %s", vg->max_lv, vg->name);
return 1;
}
/*
* Create a new empty LV.
*/
@ -1817,11 +1831,8 @@ struct logical_volume *lv_create_empty(const char *name,
struct logical_volume *lv;
char dname[NAME_LEN];
if (vg->max_lv && (vg->max_lv == vg_visible_lvs(vg))) {
log_error("Maximum number of logical volumes (%u) reached "
"in volume group %s", vg->max_lv, vg->name);
return NULL;
}
if (vg_max_lv_reached(vg))
stack;
if (strstr(name, "%d") &&
!(name = generate_lv_name(vg, name, dname, sizeof(dname)))) {
@ -1936,6 +1947,9 @@ int link_lv_to_vg(struct volume_group *vg, struct logical_volume *lv)
{
struct lv_list *lvl;
if (vg_max_lv_reached(vg))
stack;
if (!(lvl = dm_pool_zalloc(vg->vgmem, sizeof(*lvl))))
return_0;

View File

@ -564,6 +564,11 @@ int vg_check_status(const struct volume_group *vg, uint32_t status);
*/
unsigned vg_visible_lvs(const struct volume_group *vg);
/*
* Check if the VG reached maximal LVs count (if set)
*/
int vg_max_lv_reached(struct volume_group *vg);
/*
* Mirroring functions
*/

View File

@ -1528,12 +1528,8 @@ int vg_validate(struct volume_group *vg)
r = 0;
}
if (vg->max_lv && (vg->max_lv < vg_visible_lvs(vg))) {
log_error("Internal error: Volume group %s contains %u volumes"
" but the limit is set to %u.",
vg->name, vg_visible_lvs(vg), vg->max_lv);
r = 0;
}
if (vg_max_lv_reached(vg))
stack;
return r;
}

View File

@ -55,12 +55,33 @@ grep "^ Invalid stripe size 3\.00 KB\$" err
case $(lvdisplay $vg) in "") true ;; *) false ;; esac
# Setting max_lv works. (bz490298)
vgchange -l 4 $vg
lvremove -ff $vg
vgchange -l 3 $vg
lvcreate -l1 -n $lv1 $vg
lvcreate -l1 -s -n $lv2 $vg/$lv1
lvcreate -l1 -n $lv3 $vg
not lvcreate -l1 -n $lv4 $vg
lvremove -ff $vg/$lv3
lvcreate -l1 -s -n $lv3 $vg/$lv1
not lvcreate -l1 -n $lv4 $vg
not lvcreate -l1 -m1 -n $lv4 $vg
lvremove -ff $vg/$lv3
lvcreate -l1 -m1 -n $lv3 $vg
lvs
vgs -o +max_lv
not lvcreate -l1 -n $lv4 $vg
not lvcreate -l1 -m1 -n $lv4 $vg
lvconvert -m0 $vg/$lv3
lvconvert -m2 -i 1 $vg/$lv3
lvconvert -m1 $vg/$lv3
not vgchange -l 2
vgchange -l 4
vgs $vg
lvremove -ff $vg
vgchange -l 0 $vg

View File

@ -130,6 +130,7 @@ prepare_devs() {
lv1=LV1
lv2=LV2
lv3=LV3
lv4=LV4
}
disable_dev() {

View File

@ -613,6 +613,12 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
return 0;
}
if (vg_max_lv_reached(vg)) {
log_error("Maximum number of logical volumes (%u) reached "
"in volume group %s", vg->max_lv, vg->name);
return 0;
}
if (lp->mirrors > 1 && !(vg->fid->fmt->features & FMT_SEGMENTS)) {
log_error("Metadata does not support mirroring.");
return 0;