Fix lv_count & max_lv problems in lvm2
cover Fix lv_count & max_lv problems in lvm2
LVM2 allows setting of maximal logical count in metadata.
Logically, the maximal count of LVs should be count of user-visible LVs.
Curently there are several problems:
- we have several variables and code paths counts visible/diplayable LVs not consistently
- some code paths violates these restrictions
- there are situations when code allows creating new LV, but then during metadata loading the VG is not read (because of violating limits)
Only possible fix if this happen is to restore metadata from backup an manualy edit max_lv (or remove some volume). (vgchange -l doesn't work too here)
This patchset tries to consistenly use visible LV count and fixes all code paths which are temporarily violating the restrictions.
See also bug https://bugzilla.redhat.com/show_bug.cgi?id=490298
(with reproducer)
Milan Broz (7):
Fix snapshot segment import to not use duplicate segments & replace. Never set mirror log and images directly visible in metadata. Remove snapshot_count from VG and use function instead. Introduce vg_add_lc and vg_remove_lv functions.
Introduce lv_set_visible & lv_set_hidden and use lv_is_visible
always.
Merge lv_is_displayable and lv_is_visible.
Remove import paramater from lv_create_empty.
lib/activate/activate.c | 6 +- lib/display/display.c | 4 +- lib/format1/disk-rep.h | 3 +- lib/format1/import-export.c | 28 ++++----- lib/format_pool/format_pool.c | 1 - lib/format_pool/import_export.c | 15 +---- lib/format_text/export.c | 4 +- lib/format_text/import_vsn1.c | 22 +------ lib/metadata/lv_manip.c | 127 +++++++++++++++++++++++-------------- lib/metadata/metadata-exported.h | 20 +++--- lib/metadata/metadata.c | 35 +++++------ lib/metadata/metadata.h | 4 +- lib/metadata/mirror.c | 20 +++---- lib/metadata/snapshot_manip.c | 44 ++++++------- lib/report/columns.h | 4 +- lib/report/report.c | 22 +++--- lib/snapshot/snapshot.c | 19 +++++- test/t-lvcreate-usage.sh | 22 ++++++- test/test-utils.sh | 1 + tools/lvchange.c | 2 +- tools/lvconvert.c | 3 +- tools/lvcreate.c | 6 +- tools/lvdisplay.c | 2 +- tools/lvscan.c | 2 +- tools/pvmove.c | 2 +- tools/reporter.c | 4 +- tools/vgmerge.c | 2 - tools/vgsplit.c | 5 +- 28 files changed, 221 insertions(+), 208 deletions(-)
PATCH 1/7 Fix snapshot segment import to not use duplicate segments & replace.
The snapshot segment (snapshotX) is created twice during the text metadata segment processing.
This can cause temporary violation of max_lv count.
Simplify the code, snapshot segment is properly initialized in text_import function now and do not need to be replaced by vg_add_snapshot call.
The vg_add_snapshot() is now usefull only for adding new snapshot. The name is always gewerated, remove it from function call.
--- lib/format1/import-export.c | 2 +- lib/format_text/import_vsn1.c | 10 ---------- lib/metadata/metadata-exported.h | 3 +-- lib/metadata/snapshot_manip.c | 4 ++-- lib/snapshot/snapshot.c | 23 ++++++++++++++++++++--- tools/lvconvert.c | 3 +-- tools/lvcreate.c | 2 +- 7 files changed, 26 insertions(+), 21 deletions(-)
lib/format1/import-export.c +1 -1
@@ -616,7 +616,7 @@ int import_snapshots(struct dm_pool *mem __attribute((unused)), struct volume_grcontinue ;/* insert the snapshot */ -if (!vg_add_snapshot (NULL , org, cow,NULL , +if (!vg_add_snapshot (org, cow,NULL , org->le_count, lvd->lv_chunk_size)) {log_err ("Couldn't add snapshot." );
lib/format_text/import_vsn1.c +0 -10
@@ -603,16 +603,6 @@ static int _read_lvsegs(struct format_instance *fid __attribute((unused)), lv->size = (uint64_t ) lv->le_count * (uint64_t ) vg->extent_size; -/* -* FIXME We now have 2 LVs for each snapshot. The real one was -* created by vg_add_snapshot from the segment text_import. -*/ -if (lv->status &SNAPSHOT ) { - vg->lv_count--; -dm_list_del (&lvl->list); -return 1 ; - } - lv->minor =-1 ;if ((lv->status &FIXED_MINOR ) && !_read_int32 (lvn,"minor" , &lv->minor)) {
lib/metadata/metadata-exported.h +1 -2
@@ -547,8 +547,7 @@ struct lv_segment *find_cow(const struct logical_volume *lv);/* Given a cow LV, return its origin */ struct logical_volume *origin_from_cow (const struct logical_volume *lv); -int vg_add_snapshot (const char *name, -struct logical_volume *origin,struct logical_volume *cow, +int vg_add_snapshot (struct logical_volume *origin,struct logical_volume *cow,union lvid *lvid,uint32_t extent_count,uint32_t chunk_size);
lib/metadata/snapshot_manip.c +2 -2
@@ -62,7 +62,7 @@ struct logical_volume *origin_from_cow(const struct logical_volume *lv)return lv->snapshot->origin; } -int vg_add_snapshot (const char *name,struct logical_volume *origin, +int vg_add_snapshot (struct logical_volume *origin,struct logical_volume *cow,union lvid *lvid,uint32_t extent_count,uint32_t chunk_size) {
@@ -88,7 +88,7 @@ int vg_add_snapshot(const char *name, struct logical_volume *origin,*/ origin->vg->lv_count--; -if (!(snap =lv_create_empty (name ? name :"snapshot%d" , +if (!(snap =lv_create_empty ("snapshot%d" , lvid,LVM_READ |LVM_WRITE |VISIBLE_LV ,ALLOC_INHERIT ,1 , origin->vg))) { origin->vg->lv_count++;
lib/snapshot/snapshot.c +20 -3
@@ -74,9 +74,26 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *sreturn 0 ; } -if (!vg_add_snapshot (seg->lv->name, org, cow, - &seg->lv->lvid, seg->len, chunk_size)) - return_0; + seg->chunk_size = chunk_size; + seg->origin = org; + seg->cow = cow; + +// FIXME: direct count manipulation to be removed later + cow->status &= ~VISIBLE_LV ; + cow->vg->lv_count--; + cow->snapshot = seg; + + org->origin_count++; + org->vg->lv_count--; + org->vg->snapshot_count++; + +/* FIXME Assumes an invisible origin belongs to a sparse device */ +if (!lv_is_visible (org)) + org->status |=VIRTUAL_ORIGIN ; + + seg->lv->status |=VIRTUAL ; + +dm_list_add (&org->snapshot_segs, &seg->origin_list);return 1 ; }
tools/lvconvert.c +1 -2
@@ -760,8 +760,7 @@ static int lvconvert_snapshot(struct cmd_context *cmd,return 0 ; } -if (!vg_add_snapshot (NULL , org, lv,NULL , org->le_count, - lp->chunk_size)) { +if (!vg_add_snapshot (org, lv,NULL , org->le_count, lp->chunk_size)) {log_error ("Couldn't create snapshot." );return 0 ; }
tools/lvcreate.c +1 -1
@@ -918,7 +918,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,/* cow LV remains active and becomes snapshot LV */ -if (!vg_add_snapshot (NULL , org, lv,NULL , +if (!vg_add_snapshot (org, lv,NULL , org->le_count, lp->chunk_size)) {log_error ("Couldn't create snapshot." ); goto deactivate_and_revert_new_lv;
Signature · 1 line
1.6.2.4
PATCH 1/7 Fix snapshot segment import to not use duplicate segments & replace.
Quoted 3 lines · Milan Broz
Simplify the code, snapshot segment is properly initialized in
text_importfunction now and do not need to be replaced byvg_add_snapshotcall.
Looks OK, although it does duplicate part of the code. Nevertheless, seems like a better compromise than the previous one. Also, the ugly part of the code where lv_count is fiddled manually is fixed by a later patch.
Quoted 2 lines
The
vg_add_snapshot()is now usefull only for adding new snapshot. The name is always gewerated, remove it from function call.
Ack.
Quoted 1 line
Signed-off-by Milan Broz <[email protected]>
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 1/7 Fix snapshot segment import to not use duplicate segments & replace.
Quoted 5 lines · Peter Rockai
Quoted 3 lines · Milan Broz
Simplify the code, snapshot segment is properly initialized in
text_importfunction now and do not need to be replaced byvg_add_snapshotcall.Looks OK, although it does duplicate part of the code.
Indeed - please avoid duplicating that code.
Alasdair
PATCH 2/7 Never set mirror log and images directly visible in metadata.
In reply to Milan BrozMirror creation and conversion force set mirror log and images to be visible. This can violate VG max_lv restriction on LV.
There is no need to set these volumes visible, even during mirror images conversion.
The log must be cleared, but the requested symlink is created if the volume is manipulated directly.
[Is it true for udev?]
[Is there some side effect on cluster with this patch?]
--- lib/metadata/mirror.c | 14 +++++--------- 1 files changed, 5 insertions(+), 9 deletions(-)
lib/metadata/mirror.c +5 -9
@@ -259,9 +259,6 @@ static int _init_mirror_log(struct cmd_context *cmd, was_active =1 ; } -/* Temporary make it visible for set_lv() */ - log_lv->status |=VISIBLE_LV ; -/* Temporary tag mirror log for activation */ dm_list_iterate_items(sl, tags)if (!str_list_add (cmd->mem, &log_lv->tags, sl->str)) {
@@ -275,6 +272,10 @@ static int _init_mirror_log(struct cmd_context *cmd,backup (log_lv->vg); +/* +* Directly activating log_lv will create symlink for set_lv, +* even then log_lv is never directly visible +*/ if (!activate_lv (cmd, log_lv)) {log_error ("Aborting. Failed to activate mirror log." ); goto revert_new_lv;
@@ -303,8 +304,6 @@ static int _init_mirror_log(struct cmd_context *cmd,return 0 ; } - log_lv->status &= ~VISIBLE_LV ; -if (was_active && !activate_lv (cmd, log_lv)) return_0;
@@ -410,7 +409,6 @@ struct logical_volume *detach_mirror_log(struct lv_segment *mirrored_seg) log_lv = mirrored_seg->log_lv; mirrored_seg->log_lv =NULL ; - log_lv->status |=VISIBLE_LV ; log_lv->status &= ~MIRROR_LOG ;remove_seg_from_segs_using_this_lv (log_lv, mirrored_seg);
@@ -536,7 +534,6 @@ static int _remove_mirror_images(struct logical_volume *lv,dm_list_init (&tmp_orphan_lvs);for (m = new_area_count; m < mirrored_seg->area_count; m++) {seg_lv (mirrored_seg, m)->status &= ~MIRROR_IMAGE ; -seg_lv (mirrored_seg, m)->status |=VISIBLE_LV ;if (!(lvl =dm_pool_alloc (lv->vg->cmd->mem,sizeof (*lvl)))) {log_error ("lv_list alloc failed" );return 0 ;
@@ -554,7 +551,6 @@ static int _remove_mirror_images(struct logical_volume *lv,if (new_area_count ==1 && !is_temporary_mirror_layer (lv)) { lv1 =seg_lv (mirrored_seg,0 ); lv1->status &= ~MIRROR_IMAGE ; - lv1->status |=VISIBLE_LV ; detached_log_lv =detach_mirror_log (mirrored_seg);if (!remove_layer_from_lv (lv, lv1)) return_0;
@@ -1265,7 +1261,7 @@ static struct logical_volume *_create_mirror_log(struct logical_volume *lv, }if (!(log_lv =lv_create_empty (log_name,NULL , -VISIBLE_LV |LVM_READ |LVM_WRITE , +LVM_READ |LVM_WRITE , alloc,0 , lv->vg))) return_NULL;
Signature · 1 line
1.6.2.4
PATCH 2/7 Never set mirror log and images directly visible in metadata.
Quoted 5 lines · Milan Broz
Mirror creation and conversion force set mirror log and images to be visible. This can violate VG
max_lvrestriction on LV.There is no need to set these volumes visible, even during mirror images conversion.
Well, I believe the use-case is that when the operation fails halfway (which happens from time to time -- more often than would be comfortable, even), you can clean up by hand, since those offending LVs became visible. If there is a reasonable procedure that the admins can follow to get rid of the junk LVs in those scenarios, I'm fine.
(The whole non-atomicity of those mirror operation is very unfortunate for other reasons, but I didn't yet have time to investigate how hard it would be to make those really atomic.)
Other than that, I have reviewed the patch, and it does what the description advertises, so (bar the above issue) it is good to go, IMHO.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 2/7 Never set mirror log and images directly visible in metadata.
Quoted 11 lines · Petr Rockai
Quoted 5 lines · Milan Broz
Mirror creation and conversion force set mirror log and images to be visible. This can violate VG
max_lvrestriction on LV.There is no need to set these volumes visible, even during mirror images conversion.
Well, I believe the use-case is that when the operation fails halfway (which happens from time to time -- more often than would be comfortable, even), you can clean up by hand, since those offending LVs became visible. If there is a reasonable procedure that the admins can follow to get rid of the junk LVs in those scenarios, I'm fine.
Maybe we should display these "invisible" LVs to user (in reporting commands) if no visible LV references them (I mean _mimage, _mlog & Co. devices)
Admin can remove these insvible LV even now (lvremove works), but must run "lvs -a" to found them first...
Milan
PATCH 2/7 Never set mirror log and images directly visible in metadata.
Quoted 9 lines · Milan Broz
Quoted 5 lines · Petr Rockai
Well, I believe the use-case is that when the operation fails halfway (which happens from time to time -- more often than would be comfortable, even), you can clean up by hand, since those offending LVs became visible. If there is a reasonable procedure that the admins can follow to get rid of the junk LVs in those scenarios, I'm fine.
Maybe we should display these "invisible" LVs to user (in reporting commands) if no visible LV references them (I mean
_mimage,_mlog& Co. devices)
Sounds like a decent solution to me.
Quoted 2 lines
Admin can remove these insvible LV even now (lvremove works), but must run "lvs -a" to found them first...
Ok.
Yours,
Petr.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 2/7 Never set mirror log and images directly visible in metadata.
Quoted 4 lines · Peter Rockai
Quoted 2 lines · Milan Broz
Maybe we should display these "invisible" LVs to user (in reporting commands) if no visible LV references them (I mean
_mimage,_mlog& Co. devices)Sounds like a decent solution to me.
But then - what's our definition of visible? - and we're back to the original counting problem with multiple confusing definitions.
Can we really not consolidate this into a single definition?
(BTW max_lv etc. is not a factor that skew other policy decisions - it's an unimportant feature.)
Alasdair
PATCH 2/7 Never set mirror log and images directly visible in metadata.
In reply to Petr RockaiQuoted 3 lines · Peter Rockai
(The whole non-atomicity of those mirror operation is very unfortunate for other reasons, but I didn't yet have time to investigate how hard it would be to make those really atomic.)
We've two factors here:
All single-VG command-line-level changes must have a single commit
point with no chance of data/metadata corruption. (See Rik's lvconvert bug report.) pvmove offers a model.
Not all lvm2 code does everything possible to clean up after an
operation fails. More code could take the trouble to undo operations rather than logging error messages telling the admin to remove something by hand. More code could detect things left behind by an earlier failed operation and clean them up transparently.
Alasdair
PATCH 2/7 Never set mirror log and images directly visible in metadata.
In reply to Milan BrozQuoted 1 line · Milan Broz
This can violate VG
max_lvrestriction on LV.
I'm not bothered if the code exceeds max_lv temporarily.
I mean, does anyone have a real-world use case for that parameter? (Perhaps make it so VGs exceeding that limit can still be manipulated internally, but users cannot add new LVs until it drops below the limit i.e. a soft limit enforced on the user.)
This comes back to whether we actually need the distinction between TOPLEVEL (nothing in lvm uses the LV) and VISIBLE (it's for users/tools to open) or not, a distinction we've been eliminating I think.
(If we got automatic clean-up of incomplete multi-step operations wouldn't the problem go away? Might be as simple as flagging LVs as temporary/uncommitted in the metadata and having them deleted next time the VG lock is taken in the same way as we deal with multiple metadata sequence numbers in different VG mdas.)
Alasdair
PATCH 2/7 Never set mirror log and images directly visible in metadata.
Quoted 4 lines · Alasdair G Kergon
Quoted 1 line · Milan Broz
This can violate VG
max_lvrestriction on LV.I'm not bothered if the code exceeds
max_lvtemporarily.
It is not temporarily, it is stored in metadata on disk in this case.
That's why I do not want to store VISIBLE flag there.
Even without mentioning max_lv, the proper solution should be properly revert these invisible volumes if operation fails in the middle.
Quoted 1 line
I mean, does anyone have a real-world use case for that parameter?
That parameter is mistake for text metadata format IMHO.
The only real use is to downconvert to lvm1 format (which has limited LVs)
But we have it documented, "supported" so removing it is probably not good way.
Quoted 3 lines
(Perhaps make it so VGs exceeding that limit can still be manipulated internally, but users cannot add new LVs until it drops below the limit i.e. a soft limit enforced on the user.)
What the internally means here? Not stored in persistent metadata? Or stored with an internal/temporary flag?
Quoted 3 lines
This comes back to whether we actually need the distinction between TOPLEVEL (nothing in lvm uses the LV) and VISIBLE (it's for users/tools to open) or not, a distinction we've been eliminating I think.
Which will probably re-complicate again when replicator & crypto segments/LVs are introduced...
Quoted 5 lines
(If we got automatic clean-up of incomplete multi-step operations wouldn't the problem go away? Might be as simple as flagging LVs as temporary/uncommitted in the metadata and having them deleted next time the VG lock is taken in the same way as we deal with multiple metadata sequence numbers in different VG mdas.)
Is this possible without breaking compatibility with old versions? (new LV flag?)
Milan
PATCH 3/7 Remove snapshot_count from VG and use function instead.
In reply to Milan Broz--- lib/format1/import-export.c | 2 +- lib/format_pool/format_pool.c | 1 - lib/metadata/metadata-exported.h | 8 ++------ lib/metadata/metadata.c | 18 ++++++++++++++---- lib/metadata/metadata.h | 5 +++++ lib/metadata/snapshot_manip.c | 2 -- lib/report/columns.h | 2 +- lib/report/report.c | 12 ++++++++++++ lib/snapshot/snapshot.c | 1 - tools/vgmerge.c | 2 -- tools/vgsplit.c | 5 +---- 11 files changed, 36 insertions(+), 22 deletions(-)
lib/format1/import-export.c +1 -1
@@ -282,7 +282,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg) vgd->vg_status |=VG_EXTENDABLE ; vgd->lv_max = vg->max_lv; - vgd->lv_cur = vg->lv_count + vg->snapshot_count; + vgd->lv_cur = vg->lv_count +snapshot_lvs_in_vg (vg); vgd->pv_max = vg->max_pv; vgd->pv_cur = vg->pv_count;
lib/format_pool/format_pool.c +0 -1
@@ -120,7 +120,6 @@ static struct volume_group *_build_vg_from_pds(struct format_instance vg->extent_count =0 ; vg->pv_count =0 ; vg->lv_count =0 ; - vg->snapshot_count =0 ; vg->seqno =1 ; vg->system_id =NULL ;dm_list_init (&vg->pvs);
lib/metadata/metadata-exported.h +2 -6
@@ -236,15 +236,12 @@ struct volume_group {struct dm_list pvs;/* -* logical volumes -* The following relationship should always hold: -* dm_list_size(lvs) = lv_count + 2 * snapshot_count +* logical volumes count * * Snapshots consist of 2 instances of "struct logical_volume": * - cow (lv_name is visible to the user) * - snapshot (lv_name is 'snapshotN') -* Neither of these instances is reflected in lv_count, but we -* multiply the snapshot_count by 2. +* Neither of these instances is reflected in lv_count. * * Mirrors consist of multiple instances of "struct logical_volume": * - one for the mirror log
@@ -253,7 +250,6 @@ struct volume_group {* all of the instances are reflected in lv_count. */ uint32_t lv_count; -uint32_t snapshot_count;struct dm_list lvs;struct dm_list tags;
lib/metadata/metadata.c +14 -4
@@ -574,8 +574,6 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name, vg->lv_count =0 ;dm_list_init (&vg->lvs); - vg->snapshot_count =0 ; -dm_list_init (&vg->tags); if (!(vg->fid = cmd->fmt->ops->create_instance(cmd->fmt, vg_name,
@@ -1155,6 +1153,18 @@ unsigned displayable_lvs_in_vg(const struct volume_group *vg)return lv_count; } +unsigned snapshot_lvs_in_vg (const struct volume_group *vg) +{ +struct lv_list *lvl; +unsigned lv_count =0 ; + + dm_list_iterate_items(lvl, &vg->lvs) +if (lv_is_cow (lvl->lv)) + lv_count++; + +return lv_count; +} +/* * Determine whether two vgs are compatible for merging. */
@@ -1445,11 +1455,11 @@ int vg_validate(struct volume_group *vg) }if ((lv_count = (uint32_t )dm_list_size (&vg->lvs)) != - vg->lv_count +2 * vg->snapshot_count) { + vg->lv_count +2 *snapshot_lvs_in_vg (vg)) {log_error ("Internal error: #internal LVs (%u) != #LVs (%" PRIu32") + 2 * #snapshots (%" PRIu32") in VG %s" ,dm_list_size (&vg->lvs), vg->lv_count, - vg->snapshot_count, vg->name); +snapshot_lvs_in_vg (vg), vg->name); r =0 ; }
lib/metadata/metadata.h +5 -0
@@ -345,6 +345,11 @@ struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv);unsigned displayable_lvs_in_vg (const struct volume_group *vg);/* +* Count snapshot LVs. +*/ +unsigned snapshot_lvs_in_vg (const struct volume_group *vg); + +/* * For internal metadata caching. */ int export_vg_to_buffer (struct volume_group *vg,char **buf);
lib/metadata/snapshot_manip.c +0 -2
@@ -106,7 +106,6 @@ int vg_add_snapshot(struct logical_volume *origin, seg->lv->status |=SNAPSHOT ; origin->origin_count++; - origin->vg->snapshot_count++; cow->snapshot = seg; cow->status &= ~VISIBLE_LV ;
@@ -133,7 +132,6 @@ int vg_remove_snapshot(struct logical_volume *cow) cow->snapshot =NULL ; - cow->vg->snapshot_count--; cow->vg->lv_count++; cow->status |=VISIBLE_LV ;
lib/report/columns.h +1 -1
@@ -105,7 +105,7 @@ FIELD(VGS, vg, NUM, "MaxLV", max_lv, 5, uint32, "max_lv", "Maximum number of LVs FIELD(VGS, vg, NUM, "MaxPV", max_pv, 5, uint32, "max_pv", "Maximum number of PVs allowed in VG or 0 if unlimited.") FIELD(VGS, vg, NUM, "#PV", pv_count, 3, uint32, "pv_count", "Number of PVs.") FIELD(VGS, vg, NUM, "#LV", cmd, 3, lvcount, "lv_count", "Number of LVs.") -FIELD(VGS, vg, NUM, "#SN", snapshot_count, 3, uint32, "snap_count", "Number of snapshots.") +FIELD(VGS, vg, NUM, "#SN", cmd, 3, snapcount, "snap_count", "Number of snapshots.") FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno", "Revision number of internal metadata. Incremented whenever it changes.") FIELD(VGS, vg, STR, "VG Tags", tags, 7, tags, "vg_tags", "Tags, if any.")FIELD (VGS , vg,NUM ,"#VMda" , cmd,5 , vgmdas,"vg_mda_count" ,"Number of metadata areas in use by this VG." )
lib/report/report.c +12 -0
@@ -991,6 +991,18 @@ static int _lvsegcount_disp(struct dm_report *rh, struct dm_pool *mem,return _uint32_disp (rh, mem, field, &count, private); } +static int _snapcount_disp (struct dm_report *rh,struct dm_pool *mem, +struct dm_report_field *field, +const void *data,void *private) +{ +const struct volume_group *vg = (const struct volume_group *) data; +uint32_t count; + + count =snapshot_lvs_in_vg (vg); + +return _uint32_disp (rh, mem, field, &count, private); +} +static int _snpercent_disp (struct dm_report *rh __attribute((unused)),struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private __attribute((unused)))
lib/snapshot/snapshot.c +0 -1
@@ -85,7 +85,6 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *s org->origin_count++; org->vg->lv_count--; - org->vg->snapshot_count++;/* FIXME Assumes an invisible origin belongs to a sparse device */ if (!lv_is_visible (org))
tools/vgmerge.c +0 -2
@@ -102,8 +102,6 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, } vg_to->lv_count += vg_from->lv_count; - vg_to->snapshot_count += vg_from->snapshot_count; - vg_to->extent_count += vg_from->extent_count; vg_to->free_count += vg_from->free_count;
tools/vgsplit.c +1 -4
@@ -106,10 +106,7 @@ static int _move_one_lv(struct volume_group *vg_from,return 0 ; } -if (lv->status &SNAPSHOT ) { - vg_from->snapshot_count--; - vg_to->snapshot_count++; - }else if (!lv_is_cow (lv)) { +if (!(lv->status &SNAPSHOT ) && !lv_is_cow (lv)) { vg_from->lv_count--; vg_to->lv_count++; }
Signature · 1 line
1.6.2.4
PATCH 3/7 Remove snapshot_count from VG and use function instead.
Patch looks good. Good to get rid of redundant counter, which is prone to getting out of sync. I would, however, propose to rename "snapshot_lvs_in_vg" to "vg_snapshot_lv_count" -- we already have "vg_missing_pv_count" as a precedent for that naming scheme.
Yours,
Petr.
PS: I would welcome a similar approach to removing lv_count as well (and other redundant counters), since the counting function's implementation clearly defines what gets counted in the given counter (vg_lv_count, say), *and* it never gets out of sync. In other words, I believe this approach is much more transparent, albeit a little less efficient -- however, I don't believe such counting function is going to show up on any profile of any LVM2 command whatsoever.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 3/7 Remove snapshot_count from VG and use function instead.
Quoted 4 lines · Peter Rockai
Patch looks good. Good to get rid of redundant counter, which is prone to getting out of sync. I would, however, propose to rename "
snapshot_lvs_in_vg" to "vg_snapshot_lv_count" -- we already have "vg_missing_pv_count" as a precedent for that naming scheme.
Ack.
Quoted 7 lines
PS: I would welcome a similar approach to removing
lv_countas well (and other redundant counters), since the counting function's implementation clearly defines what gets counted in the given counter (vg_lv_count, say), *and* it never gets out of sync. In other words, I believe this approach is much more transparent, albeit a little less efficient -- however, I don't believe such counting function is going to show up on any profile of any LVM2 command whatsoever.
If it ever did, we could just optimise things by putting it back in:-) It's only needed for display tools (and there are caching tricks we could use there but don't) and the tiny subset of people these days who found a use for max_lv (or don't need it but are running systems that inherited it from LVM1).
Alasdair
PATCH 3/7 Remove snapshot_count from VG and use function instead.
In reply to Milan Brozlib/metadata/metadata-exported.h struct volume_group { · line 239
Quoted 3 lines · Milan Broz
lib/metadata/metadata-exported.h +1
-2-* The following relationship should always hold: -* dm_list_size(lvs) = lv_count + 2 * snapshot_count +* logical volumes count
Please leave the description of dm_list_size(lvs).
"Number of snapshots" instead of snapshot_count? (Or the new function?)
lib/metadata/metadata.c unsigned displayable_lvs_in_vg(const struct volume_group *vg) · line 1159
Quoted 4 lines
lib/metadata/metadata.c +4
-0+unsigned snapshot_lvs_in_vg (const struct volume_group *vg) +{ +struct lv_list *lvl; +unsigned lv_count =0 ;
A confusing alternative use for a variable called lv_count? 'unsigned snapshot_count'?
Ack.
Alasdair.
PATCH 4/7 Introduce vg_add_lc and vg_remove_lv functions.
In reply to Milan Brozvg_add_lv and vg_remove_lv are the only functions for adding/removing logical volume into volume group.
Only these function should manipulate with vg->lvs list and (together with following patches) will update VG logical volume counter (vg->lv_count).
--- lib/format1/disk-rep.h | 3 +- lib/format1/import-export.c | 24 +++++------- lib/format_pool/import_export.c | 15 +------ lib/format_text/import_vsn1.c | 12 +----- lib/metadata/lv_manip.c | 81 ++++++++++++++++++++++--------------- lib/metadata/metadata-exported.h | 3 + 6 files changed, 67 insertions(+), 71 deletions(-)
lib/format1/disk-rep.h +2 -1
@@ -215,7 +215,8 @@ int import_vg(struct dm_pool *mem, struct volume_group *vg, struct disk_list *dl);int export_vg (struct vg_disk *vgd,struct volume_group *vg); -int import_lv (struct dm_pool *mem,struct logical_volume *lv,struct lv_disk *lvd); +int import_lv (struct cmd_context *cmd,struct dm_pool *mem, +struct logical_volume *lv,struct lv_disk *lvd);int import_extents (struct cmd_context *cmd,struct volume_group *vg,struct dm_list *pvds);
lib/format1/import-export.c +10 -14
@@ -294,10 +294,9 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)return 1 ; } -int import_lv (struct dm_pool *mem,struct logical_volume *lv,struct lv_disk *lvd) +int import_lv (struct cmd_context *cmd,struct dm_pool *mem, +struct logical_volume *lv,struct lv_disk *lvd) { -lvid_from_lvnum (&lv->lvid, &lv->vg->id, lvd->lv_number); -if (!(lv->name =_create_lv_name (mem, (char *)lvd->lv_name))) return_0;
@@ -331,7 +330,7 @@ int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv lv->alloc =ALLOC_NORMAL ;if (!lvd->lv_read_ahead) - lv->read_ahead = lv->vg->cmd->default_settings.read_ahead; + lv->read_ahead = cmd->default_settings.read_ahead;else lv->read_ahead = lvd->lv_read_ahead;
@@ -456,22 +455,19 @@ static struct logical_volume *_add_lv(struct dm_pool *mem,struct volume_group *vg, struct lv_disk *lvd) { - struct lv_list *ll; struct logical_volume *lv; -if (!(ll =dm_pool_zalloc (mem,sizeof (*ll))) || - !(ll->lv =dm_pool_zalloc (mem,sizeof (*ll->lv)))) +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) return_NULL; - lv = ll->lv; - lv->vg = vg; -if (!import_lv (mem, lv, lvd)) - return_NULL; +lvid_from_lvnum (&lv->lvid, &vg->id, lvd->lv_number); -dm_list_add (&vg->lvs, &ll->list); - vg->lv_count++; +if (!import_lv (vg->cmd, mem, lv, lvd)) { +dm_pool_free (mem, lv); + return_NULL; + } -return lv; +return vg_add_lv (vg, lv) ? lv :NULL ; }int import_lvs (struct dm_pool *mem,struct volume_group *vg,struct dm_list *pvds)
lib/format_pool/import_export.c +2 -13
@@ -58,22 +58,14 @@ int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_listint import_pool_lvs (struct volume_group *vg,struct dm_pool *mem,struct dm_list *pls) {struct pool_list *pl; -struct lv_list *lvl =dm_pool_zalloc (mem,sizeof (*lvl));struct logical_volume *lv; -if (!lvl) { -log_error ("Unable to allocate lv list structure" ); -return 0 ; - } - -if (!(lvl->lv =dm_pool_zalloc (mem,sizeof (*lvl->lv)))) { +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) {log_error ("Unable to allocate logical volume structure" );return 0 ; } - lv = lvl->lv; lv->status =0 ; - lv->vg = vg; lv->alloc =ALLOC_NORMAL ; lv->size =0 ; lv->name =NULL ;
@@ -115,11 +107,8 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list } lv->le_count = lv->size /POOL_PE_SIZE ; - lvl->lv = lv; -dm_list_add (&vg->lvs, &lvl->list); - vg->lv_count++; -return 1 ; +return vg_add_lv (vg, lv); } int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
lib/format_text/import_vsn1.c +2 -10
@@ -495,15 +495,11 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)), struct dm_hash_table *pv_hash __attribute((unused))) {struct logical_volume *lv; -struct lv_list *lvl;struct config_node *cn; -if (!(lvl =dm_pool_zalloc (mem,sizeof (*lvl))) || - !(lvl->lv =dm_pool_zalloc (mem,sizeof (*lvl->lv)))) +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) return_0; - lv = lvl->lv; -if (!(lv->name =dm_pool_strdup (mem, lvn->key))) return_0;
@@ -561,11 +557,7 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)),return 0 ; } - lv->vg = vg; - vg->lv_count++; -dm_list_add (&vg->lvs, &lvl->list); - -return 1 ; +return vg_add_lv (vg, lv); } static int _read_lvsegs(struct format_instance *fid __attribute((unused)),
lib/metadata/lv_manip.c +48 -33
123 lines not on this page · raw message
lib/metadata/metadata-exported.h +3 -0
@@ -367,6 +367,9 @@ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, int warnings, int scan_label_only);struct dm_list *get_pvs (struct cmd_context *cmd); +int vg_add_lv (struct volume_group *vg,struct logical_volume *lv); +int vg_remove_lv (struct logical_volume *lv); +/* Set full_scan to 1 to re-read every (filtered) device label */ struct dm_list *get_vgnames (struct cmd_context *cmd,int full_scan);struct dm_list *get_vgids (struct cmd_context *cmd,int full_scan);
Signature · 1 line
1.6.2.4
PATCH 4/7 Introduce vg_add_lc and vg_remove_lv functions.
Quoted 2 lines · Milan Broz
vg_add_lvandvg_remove_lvare the only functions for adding/removing logical volume into volume group.
Another good refactor.
Quoted 2 lines
Only these function should manipulate with
vg->lvslist and (together with following patches) will update VG logical volume counter (vg->lv_count).
I guess there's no easy way in C to enforce this? (vg->lvs is only ever touched by vg_add_lv, vg_remove_lv). Not necessary, but would be nice to have.
Btw., would vg_link_lv and vg_unlink_lv describe better what these two functions do? It seems a little easy to confuse _add_lv and vg_add_lv, while the two do quite a different thing.
(Detailed review comments inline.)
LVM1 format
-----------
Quoted 32 lines
lib/format1/disk-rep.h +2
-1@@ -215,7 +215,8 @@ int import_vg(struct dm_pool *mem, struct volume_group *vg, struct disk_list *dl);int export_vg (struct vg_disk *vgd,struct volume_group *vg); -int import_lv (struct dm_pool *mem,struct logical_volume *lv,struct lv_disk *lvd); +int import_lv (struct cmd_context *cmd,struct dm_pool *mem, +struct logical_volume *lv,struct lv_disk *lvd);int import_extents (struct cmd_context *cmd,struct volume_group *vg,struct dm_list *pvds);lib/format1/import-export.c +2
-3@@ -294,10 +294,9 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)return 1 ; } -int import_lv (struct dm_pool *mem,struct logical_volume *lv,struct lv_disk *lvd) +int import_lv (struct cmd_context *cmd,struct dm_pool *mem, +struct logical_volume *lv,struct lv_disk *lvd) { -lvid_from_lvnum (&lv->lvid, &lv->vg->id, lvd->lv_number); -if (!(lv->name =_create_lv_name (mem, (char *)lvd->lv_name))) return_0;
lib/format1/import-export.c int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv · line 336
Quoted 8 lines
lib/format1/import-export.c +1
-1@@ -331,7 +330,7 @@ int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv lv->alloc =ALLOC_NORMAL ;if (!lvd->lv_read_ahead) - lv->read_ahead = lv->vg->cmd->default_settings.read_ahead; + lv->read_ahead = cmd->default_settings.read_ahead;else lv->read_ahead = lvd->lv_read_ahead;
I'm not sure why is this change needed? (Adding cmd_context parameter to import_lv.)
Quoted 18 lines
lib/format1/import-export.c +2
-7@@ -456,22 +455,19 @@ static struct logical_volume *_add_lv(struct dm_pool *mem,struct volume_group *vg, struct lv_disk *lvd) { - struct lv_list *ll; struct logical_volume *lv; -if (!(ll =dm_pool_zalloc (mem,sizeof (*ll))) || - !(ll->lv =dm_pool_zalloc (mem,sizeof (*ll->lv)))) +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) return_NULL; - lv = ll->lv; - lv->vg = vg; -if (!import_lv (mem, lv, lvd)) - return_NULL; +lvid_from_lvnum (&lv->lvid, &vg->id, lvd->lv_number);
lib/format1/import-export.c static struct logical_volume *_add_lv(struct dm_pool *mem, · line 471
Quoted 10 lines
lib/format1/import-export.c +5
-3-dm_list_add (&vg->lvs, &ll->list); - vg->lv_count++; +if (!import_lv (vg->cmd, mem, lv, lvd)) { +dm_pool_free (mem, lv); + return_NULL; + } -return lv; +return vg_add_lv (vg, lv) ? lv :NULL ; }
Does not change what the code does, just shuffles the lines somewhat. It does change semantics of import_lv, but that function is never used outside _add_lv anyway (would it make sense to make it static _import_lv, in a separate patch?).
Pool Format
-----------
Quoted 29 lines
lib/format_pool/import_export.c +1
-9@@ -58,22 +58,14 @@ int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_listint import_pool_lvs (struct volume_group *vg,struct dm_pool *mem,struct dm_list *pls) {struct pool_list *pl; -struct lv_list *lvl =dm_pool_zalloc (mem,sizeof (*lvl));struct logical_volume *lv; -if (!lvl) { -log_error ("Unable to allocate lv list structure" ); -return 0 ; - } - -if (!(lvl->lv =dm_pool_zalloc (mem,sizeof (*lvl->lv)))) { +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) {log_error ("Unable to allocate logical volume structure" );return 0 ; } - lv = lvl->lv; lv->status =0 ; - lv->vg = vg; lv->alloc =ALLOC_NORMAL ; lv->size =0 ; lv->name =NULL ;
lib/format_pool/import_export.c int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list · line 112
Quoted 10 lines
lib/format_pool/import_export.c +1
-4@@ -115,11 +107,8 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list } lv->le_count = lv->size /POOL_PE_SIZE ; - lvl->lv = lv; -dm_list_add (&vg->lvs, &lvl->list); - vg->lv_count++; -return 1 ; +return vg_add_lv (vg, lv); }
Again, harmless reordering of code. As a side-effect, unifies the error handling code with other instances of similar code.
Text (LVM2) format
------------------
Quoted 22 lines
lib/format_text/import_vsn1.c +1
-5@@ -495,15 +495,11 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)), struct dm_hash_table *pv_hash __attribute((unused))) {struct logical_volume *lv; -struct lv_list *lvl;struct config_node *cn; -if (!(lvl =dm_pool_zalloc (mem,sizeof (*lvl))) || - !(lvl->lv =dm_pool_zalloc (mem,sizeof (*lvl->lv)))) +if (!(lv =dm_pool_zalloc (mem,sizeof (*lv)))) return_0; - lv = lvl->lv; -if (!(lv->name =dm_pool_strdup (mem, lvn->key))) return_0;
lib/format_text/import_vsn1.c static int _read_lvnames(struct format_instance *fid __attribute((unused)), · line 561
Quoted 10 lines
lib/format_text/import_vsn1.c +1
-5@@ -561,11 +557,7 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)),return 0 ; } - lv->vg = vg; - vg->lv_count++; -dm_list_add (&vg->lvs, &lvl->list); - -return 1 ; +return vg_add_lv (vg, lv); }
The new code is equivalent to the older version, just the ordering is (harmlessly) different.
General metadata code
---------------------
Quoted 17 lines
lib/metadata/lv_manip.c +0
-2@@ -402,7 +402,6 @@ static int _lv_segment_reduce(struct lv_segment *seg, uint32_t reduction)*/ static int _lv_reduce (struct logical_volume *lv,uint32_t extents,int delete) { -struct lv_list *lvl;struct lv_segment *seg;uint32_t count = extents;uint32_t reduction;@@ -434,13 +433,11 @@ static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete)/* Remove the LV if it is now empty */ if (!lv->le_count) { -if (!(lvl =find_lv_in_vg (lv->vg, lv->name)))
lib/metadata/lv_manip.c static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete) · line 440
Quoted 10 lines
lib/metadata/lv_manip.c +4
-5+if (!vg_remove_lv (lv)) return_0; - -dm_list_del (&lvl->list); - -if (!(lv->status &SNAPSHOT )) - lv->vg->lv_count--; +//FIXME: cow still in VG, fix count, remove this later +if (lv->status &SNAPSHOT ) + lv->vg->lv_count++;
^^ This is indeed ugly (see also my previous mail: it might be worth getting rid of lv_count altogether) ... although this patch is a definite improvement, it is still suboptimal in this respect.
Quoted 15 lines
lib/metadata/lv_manip.c +0
-2}else if (lv->vg->fid->fmt->ops->lv_setup && !lv->vg->fid->fmt->ops->lv_setup (lv->vg->fid, lv)) return_0;@@ -1822,8 +1819,6 @@ struct logical_volume *lv_create_empty(const char *name, struct volume_group *vg) {struct format_instance *fi = vg->fid; -struct cmd_context *cmd = vg->cmd; -struct lv_list *ll =NULL ;struct logical_volume *lv;char dname[NAME_LEN ];@@ -1843,23 +1838,11 @@ struct logical_volume *lv_create_empty(const char *name,if (!import)log_verbose ("Creating logical volume %s" , name);
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1842
Quoted 10 lines
lib/metadata/lv_manip.c +2
-7-if (!(ll =dm_pool_zalloc (cmd->mem,sizeof (*ll))) || - !(ll->lv =dm_pool_zalloc (cmd->mem,sizeof (*ll->lv)))) { -log_error ("lv_list allocation failed" ); -if (ll) -dm_pool_free (cmd->mem, ll); -return NULL ; - } +if (!(lv =dm_pool_zalloc (vg->vgmem,sizeof (*lv)))) + return_NULL;
.
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1845
Quoted 12 lines
lib/metadata/lv_manip.c +2
-9- lv = ll->lv; - lv->vg = vg; - -if (!(lv->name =dm_pool_strdup (cmd->mem, name))) { -log_error ("lv name strdup failed" ); -if (ll) -dm_pool_free (cmd->mem, ll); -return NULL ; - } +if (!(lv->name =dm_pool_strdup (vg->vgmem, name))) + goto_bad;
.
Quoted 4 lines
lib/metadata/lv_manip.c +0
-0lv->status = status; lv->alloc = alloc;
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1864
Quoted 10 lines
lib/metadata/lv_manip.c +2
-5@@ -1877,18 +1860,20 @@ struct logical_volume *lv_create_empty(const char *name,if (lvid) lv->lvid = *lvid; -if (fi->fmt->ops->lv_setup && !fi->fmt->ops->lv_setup (fi, lv)) { -if (ll) -dm_pool_free (cmd->mem, ll); - return_NULL; - } +if (!vg_add_lv (vg, lv)) + goto_bad;
.
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1871
Quoted 10 lines
lib/metadata/lv_manip.c +5
-3-if (!import) - vg->lv_count++; +if (fi->fmt->ops->lv_setup && !fi->fmt->ops->lv_setup (fi, lv)) + goto_bad; -dm_list_add (&vg->lvs, &ll->list); +//FIXME: remove that +if (import) + vg->lv_count--;
The same about the FIXME, see above.
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1877
Quoted 6 lines
lib/metadata/lv_manip.c +3
-0return lv; +bad: +dm_pool_free (vg->vgmem, lv); + return_NULL; }
Other than that, the code looks equivalent to me, although there's a fair amount of logic shuffling. It goes to a great length to make the function less tangled though, so I guess it's a good thing (for example it gets rid of the repeated error handler by using goto_bad instead).
Quoted 24 lines
lib/metadata/lv_manip.c +19
-0static int _add_pvs(struct cmd_context *cmd, struct pv_segment *peg,@@ -1957,6 +1942,36 @@ struct dm_list *build_parallel_areas_from_lv(struct cmd_context *cmd,return parallel_areas; } +int vg_add_lv (struct volume_group *vg,struct logical_volume *lv) +{ +struct lv_list *lvl; + +if (!(lvl =dm_pool_zalloc (vg->vgmem,sizeof (*lvl)))) + return_0; + + lvl->lv = lv; + lv->vg = vg; +dm_list_add (&vg->lvs, &lvl->list); + + vg->lv_count++; + +return 1 ; +} + +int vg_remove_lv (struct logical_volume *lv) +{ +struct lv_list *lvl;
lib/metadata/lv_manip.c struct dm_list *build_parallel_areas_from_lv(struct cmd_context *cmd, · line 1973
Quoted 10 lines
lib/metadata/lv_manip.c +10
-0+ +if (!(lvl =find_lv_in_vg (lv->vg, lv->name))) + return_0; + +dm_list_del (&lvl->list); + + lvl->lv->vg->lv_count--; + +return 1 ; +}
These two look good, and are implemented in accord with how they are used in the code above.
Yours,
Petr.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 4/7 Introduce vg_add_lc and vg_remove_lv functions.
Quoted 3 lines · Petr Rockai
Btw., would
vg_link_lvandvg_unlink_lvdescribe better what these two functions do? It seems a little easy to confuse_add_lvandvg_add_lv, while the two do quite a different thing.
yes, renamed
Quoted 11 lines
lib/format1/import-export.c int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv · line 336
Quoted 9 lines
lib/format1/import-export.c +1
-1@@ -331,7 +330,7 @@ int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv lv->alloc =ALLOC_NORMAL ;if (!lvd->lv_read_ahead) - lv->read_ahead = lv->vg->cmd->default_settings.read_ahead; + lv->read_ahead = cmd->default_settings.read_ahead;else lv->read_ahead = lvd->lv_read_ahead;I'm not sure why is this change needed? (Adding
cmd_contextparameter toimport_lv.)
just code shuffle, because lv->vg is initialized later in vg_add_lv and we need cmd for default settings.
(probably explains some code shuffle later too)
Quoted 4 lines
Does not change what the code does, just shuffles the lines somewhat. It does change semantics of
import_lv, but that function is never used outside_add_lvanyway (would it make sense to make it static_import_lv, in a separate patch?).
ok, I'll move it to separate patch
Quoted 6 lines
lib/metadata/lv_manip.c static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete) · line 440
Quoted 3 lines
lib/metadata/lv_manip.c +3
-0+//FIXME: cow still in VG, fix count, remove this later +if (lv->status &SNAPSHOT ) + lv->vg->lv_count++;^^ This is indeed ugly (see also my previous mail: it might be worth getting rid of
lv_countaltogether) ... although this patch is a definite improvement, it is still suboptimal in this respect.
later patch removes that, I keep it here just that every separate patch can pass full testing.
Milan
PATCH 5/7 Introduce lv_set_visible & lv_set_hidden and use lv_is_visible always.
In reply to Milan BrozThe vg->lv_count parameter now includes always number of visible logical volumes.
Note that virtual snapshot volume (snapshotX) is never visible, but it is stored in metadata with visible flag, so code use exception here.
--- lib/activate/activate.c | 4 +- lib/metadata/lv_manip.c | 45 ++++++++++++++++++++++++++----------- lib/metadata/metadata-exported.h | 2 + lib/metadata/metadata.c | 16 ++++++++----- lib/metadata/mirror.c | 2 +- lib/metadata/snapshot_manip.c | 28 +++++++++++++++-------- lib/snapshot/snapshot.c | 9 ++----- tools/vgsplit.c | 2 +- 8 files changed, 68 insertions(+), 40 deletions(-)
lib/activate/activate.c +2 -2
@@ -647,7 +647,7 @@ static int _lvs_in_vg_activated(struct volume_group *vg, unsigned by_uuid_only)return 0 ; dm_list_iterate_items(lvl, &vg->lvs) { -if (lvl->lv->status &VISIBLE_LV ) +if (lv_is_visible (lvl->lv)) count += (_lv_active (vg->cmd, lvl->lv, by_uuid_only) ==1 ); }
@@ -996,7 +996,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s) goto out; } -if (info.open_count && (lv->status &VISIBLE_LV )) { +if (info.open_count &&lv_is_visible (lv)) {log_error ("LV %s/%s in use: not deactivating" , lv->vg->name, lv->name); goto out;
lib/metadata/lv_manip.c +31 -14
79 lines not on this page · raw message
lib/metadata/metadata-exported.h +2 -0
@@ -369,6 +369,8 @@ struct dm_list *get_pvs(struct cmd_context *cmd);int vg_add_lv (struct volume_group *vg,struct logical_volume *lv);int vg_remove_lv (struct logical_volume *lv); +void lv_set_visible (struct logical_volume *lv); +void lv_set_hidden (struct logical_volume *lv);/* Set full_scan to 1 to re-read every (filtered) device label */ struct dm_list *get_vgnames (struct cmd_context *cmd,int full_scan);
lib/metadata/metadata.c +10 -6
@@ -1454,12 +1454,16 @@ int vg_validate(struct volume_group *vg) r =0 ; } -if ((lv_count = (uint32_t )dm_list_size (&vg->lvs)) != - vg->lv_count +2 *snapshot_lvs_in_vg (vg)) { -log_error ("Internal error: #internal LVs (%u) != #LVs (%" - PRIu32") + 2 * #snapshots (%" PRIu32") in VG %s" , -dm_list_size (&vg->lvs), vg->lv_count, -snapshot_lvs_in_vg (vg), vg->name); + lv_count =0 ; + dm_list_iterate_items(lvl, &vg->lvs) +if (lv_is_visible (lvl->lv)) + lv_count++; + +if (lv_count != vg->lv_count) { +log_error ("Internal error: #internal visible LVs (%u) != " +"visible #LVs (%u of %" PRIu32") in VG %s" , + lv_count, vg->lv_count,dm_list_size (&vg->lvs), + vg->name); r =0 ; }
lib/metadata/mirror.c +1 -1
@@ -1336,7 +1336,7 @@ int attach_mirror_log(struct lv_segment *seg, struct logical_volume *log_lv) { seg->log_lv = log_lv; log_lv->status |=MIRROR_LOG ; - log_lv->status &= ~VISIBLE_LV ; +lv_set_hidden (log_lv);return add_seg_to_segs_using_this_lv (log_lv, seg); }
lib/metadata/snapshot_manip.c +18 -10
@@ -30,8 +30,11 @@ int lv_is_cow(const struct logical_volume *lv)int lv_is_visible (const struct logical_volume *lv) { +if (lv->status &SNAPSHOT ) +return 0 ; +if (lv_is_cow (lv)) -return lv_is_visible (find_cow (lv)->lv); +return lv_is_visible (origin_from_cow (lv));return lv->status &VISIBLE_LV ?1 :0 ; }
@@ -83,15 +86,15 @@ int vg_add_snapshot(struct logical_volume *origin, }/* -* Set origin lv count in advance to prevent fail because +* Remove COW from visible volumes in advance to prevent fail because * of temporary violation of LV limits. */ - origin->vg->lv_count--; +lv_set_hidden (cow);if (!(snap =lv_create_empty ("snapshot%d" , lvid,LVM_READ |LVM_WRITE |VISIBLE_LV ,ALLOC_INHERIT ,1 , origin->vg))) { - origin->vg->lv_count++; +lv_set_visible (cow); return_0; }
@@ -108,11 +111,11 @@ int vg_add_snapshot(struct logical_volume *origin, origin->origin_count++; cow->snapshot = seg; - cow->status &= ~VISIBLE_LV ; -/* FIXME Assumes an invisible origin belongs to a sparse device */ -if (!lv_is_visible (origin)) +if (!lv_is_visible (origin)) { + origin->vg->lv_count--; origin->status |=VIRTUAL_ORIGIN ; + }dm_list_add (&origin->snapshot_segs, &seg->origin_list);
@@ -130,10 +133,15 @@ int vg_remove_snapshot(struct logical_volume *cow)return 0 ; } - cow->snapshot =NULL ; +/* +* Virtual snapshot volume was removed +* LV count must be fixed... +*/ +if (!lv_is_virtual_origin (cow->snapshot->origin)) + cow->vg->lv_count--; - cow->vg->lv_count++; - cow->status |=VISIBLE_LV ; +lv_set_visible (cow); + cow->snapshot =NULL ;return 1 ; }
lib/snapshot/snapshot.c +3 -6
@@ -78,17 +78,14 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *s seg->origin = org; seg->cow = cow; -// FIXME: direct count manipulation to be removed later - cow->status &= ~VISIBLE_LV ; - cow->vg->lv_count--; cow->snapshot = seg; - org->origin_count++; - org->vg->lv_count--;/* FIXME Assumes an invisible origin belongs to a sparse device */ -if (!lv_is_visible (org)) +if (!lv_is_visible (org)) { + org->vg->lv_count--; org->status |=VIRTUAL_ORIGIN ; + } seg->lv->status |=VIRTUAL ;
tools/vgsplit.c +1 -1
@@ -106,7 +106,7 @@ static int _move_one_lv(struct volume_group *vg_from,return 0 ; } -if (!(lv->status &SNAPSHOT ) && !lv_is_cow (lv)) { +if (lv_is_visible (lv)) { vg_from->lv_count--; vg_to->lv_count++; }
Signature · 1 line
1.6.2.4
PATCH 5/7 Introduce lv_set_visible & lv_set_hidden and use lv_is_visible always.
This patch does improve upon the previous one with regards to the consistency of lv_count handling (to the point of addressing most of my concerns with previous).
Quoted 2 lines · Milan Broz
The
vg->lv_countparameter now includes always number of visible logical volumes.
The patch does as advertised.
Quoted 3 lines
Note that virtual snapshot volume (snapshotX) is never visible, but it is stored in metadata with visible flag, so code use exception here.
The & SNAPSHOT logic is a little dubious, but seems to be a sufficient solution to the issue at hand.
Overall, seems good enough to me,
Quoted 7 lines
lib/metadata/snapshot_manip.c +0
-0@@ -30,8 +30,11 @@ int lv_is_cow(const struct logical_volume *lv)int lv_is_visible (const struct logical_volume *lv)
lib/metadata/snapshot_manip.c int lv_is_cow(const struct logical_volume *lv) · line 40
Quoted 10 lines
lib/metadata/snapshot_manip.c +4
-1{ +if (lv->status &SNAPSHOT ) +return 0 ; +if (lv_is_cow (lv)) -return lv_is_visible (find_cow (lv)->lv); +return lv_is_visible (origin_from_cow (lv));return lv->status &VISIBLE_LV ?1 :0 ; }
Why is the latter change included here? Doesn't seem to be directly related to the rest of the patch (although I might just be missing something).
Quoted 10 lines
/* FIXME Assumes an invisible origin belongs to a sparse device */lib/metadata/snapshot_manip.c +3
-1-if (!lv_is_visible (origin)) +if (!lv_is_visible (origin)) { + origin->vg->lv_count--; origin->status |=VIRTUAL_ORIGIN ; + }dm_list_add (&origin->snapshot_segs, &seg->origin_list);
lib/metadata/snapshot_manip.c int vg_remove_snapshot(struct logical_volume *cow) · line 141
Quoted 10 lines
lib/metadata/snapshot_manip.c +6
-1@@ -130,10 +133,15 @@ int vg_remove_snapshot(struct logical_volume *cow)return 0 ; } - cow->snapshot =NULL ; +/* +* Virtual snapshot volume was removed +* LV count must be fixed... +*/ +if (!lv_is_virtual_origin (cow->snapshot->origin)) + cow->vg->lv_count--;
These two are ugly hacks again, and spill the lv_count manipulation (and knowledge) out of the supposed keeper functions (set visible/hidden, vg add/remove). Nevertheless, it's hard to tell how to fix this more cleanly.
Quoted 10 lines
lib/snapshot/snapshot.c +0
-2@@ -78,17 +78,14 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *s seg->origin = org; seg->cow = cow; -// FIXME: direct count manipulation to be removed later - cow->status &= ~VISIBLE_LV ;
lib/snapshot/snapshot.c static int _snap_text_import(struct lv_segment *seg, const struct config_node *s · line 86
Quoted 10 lines
lib/snapshot/snapshot.c +2
-4- cow->vg->lv_count--; cow->snapshot = seg; - org->origin_count++; - org->vg->lv_count--;/* FIXME Assumes an invisible origin belongs to a sparse device */ -if (!lv_is_visible (org)) +if (!lv_is_visible (org)) { + org->vg->lv_count--;
Same as above.
lib/snapshot/snapshot.c static int _snap_text_import(struct lv_segment *seg, const struct config_node *s · line 88
Quoted 2 lines
lib/snapshot/snapshot.c +1
-0org->status |=VIRTUAL_ORIGIN ; + }
Yours,
Petr.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 5/7 Introduce lv_set_visible & lv_set_hidden and use lv_is_visible always.
Quoted 15 lines · Petr Rockai
Quoted 15 lines
lib/metadata/snapshot_manip.c +4
-1@@ -30,8 +30,11 @@ int lv_is_cow(const struct logical_volume *lv)int lv_is_visible (const struct logical_volume *lv) { +if (lv->status &SNAPSHOT ) +return 0 ; +if (lv_is_cow (lv)) -return lv_is_visible (find_cow (lv)->lv); +return lv_is_visible (origin_from_cow (lv));
Quoted 4 lines
lib/metadata/snapshot_manip.c int lv_is_cow(const struct logical_volume *lv) · line 40
Quoted 2 lines
lib/metadata/snapshot_manip.c +0
-0return lv->status &VISIBLE_LV ?1 :0 ; }Why is the latter change included here? Doesn't seem to be directly related to the rest of the patch (although I might just be missing something).
This is kind of bugfix, I'll move it to separate patch.
If the query LV is COW, ut returns visibility status of its origin because the virtual LV (which find_cow(lv)->lv points to) is never set visible in metadata.
But with virtual origin is this assumption wrong, I'll fix it somehow.
Milan
PATCH 6/7 Merge lv_is_displayable and lv_is_visible.
In reply to Milan BrozDisplayable and visible is the same thing, stored
in lv_count volume group attribute.
--- lib/activate/activate.c | 2 +- lib/display/display.c | 4 ++-- lib/format_text/export.c | 4 ++-- lib/metadata/lv_manip.c | 2 +- lib/metadata/metadata-exported.h | 3 +-- lib/metadata/metadata.c | 25 ++++--------------------- lib/metadata/metadata.h | 5 ----- lib/metadata/snapshot_manip.c | 8 -------- lib/report/columns.h | 2 +- lib/report/report.c | 14 +------------- tools/lvchange.c | 2 +- tools/lvdisplay.c | 2 +- tools/lvscan.c | 2 +- tools/reporter.c | 4 ++-- 14 files changed, 18 insertions(+), 61 deletions(-)
lib/activate/activate.c +1 -1
@@ -673,7 +673,7 @@ int lvs_in_vg_opened(const struct volume_group *vg)return 0 ; dm_list_iterate_items(lvl, &vg->lvs) { -if (lv_is_displayable (lvl->lv)) +if (lv_is_visible (lvl->lv)) count += (_lv_open_count (vg->cmd, lvl->lv) >0 ); }
lib/display/display.c +2 -2
@@ -606,7 +606,7 @@ void vgdisplay_full(const struct volume_group *vg) }log_print ("MAX LV %u" , vg->max_lv); -log_print ("Cur LV %u" ,displayable_lvs_in_vg (vg)); +log_print ("Cur LV %u" , vg->lv_count);log_print ("Open LV %u" ,lvs_in_vg_opened (vg));/****** FIXME Max LV Size log_print ( "MAX LV Size %s",
@@ -681,7 +681,7 @@ void vgdisplay_colons(const struct volume_group *vg) vg->status,/* internal volume group number; obsolete */ vg->max_lv, -displayable_lvs_in_vg (vg), + vg->lv_count,lvs_in_vg_opened (vg),/* FIXME: maximum logical volume size */ vg->max_pv,
lib/format_text/export.c +2 -2
@@ -592,14 +592,14 @@ static int _print_lvs(struct formatter *f, struct volume_group *vg)* Write visible LVs first */ dm_list_iterate_items(lvl, &vg->lvs) { -if (!(lv_is_displayable (lvl->lv))) +if (!(lv_is_visible (lvl->lv)))continue ;if (!_print_lv (f, lvl->lv)) return_0; } dm_list_iterate_items(lvl, &vg->lvs) { -if ((lv_is_displayable (lvl->lv))) +if ((lv_is_visible (lvl->lv)))continue ;if (!_print_lv (f, lvl->lv)) return_0;
lib/metadata/lv_manip.c +1 -1
@@ -1732,7 +1732,7 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,int r =0 ;/* rename is not allowed on sub LVs */ -if (!lv_is_displayable (lv)) { +if (!lv_is_visible (lv)) {log_error ("Cannot rename internal LV \"%s\"." , lv->name);return 0 ; }
lib/metadata/metadata-exported.h +1 -2
@@ -535,10 +535,9 @@ struct lv_segment *first_seg(const struct logical_volume *lv);int lv_is_origin (const struct logical_volume *lv);int lv_is_virtual_origin (const struct logical_volume *lv);int lv_is_cow (const struct logical_volume *lv); -int lv_is_visible (const struct logical_volume *lv);/* Test if given LV is visible from user's perspective */ -int lv_is_displayable (const struct logical_volume *lv); +int lv_is_visible (const struct logical_volume *lv);int pv_is_in_vg (struct volume_group *vg,struct physical_volume *pv);
lib/metadata/metadata.c +4 -21
@@ -362,7 +362,6 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name, {struct physical_volume *pv;struct pv_list *pvl; -unsigned lv_count;int ret =1 ;if (!vg || !consistent ||vg_missing_pv_count (vg)) {
@@ -376,14 +375,12 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,if (!vg_check_status (vg,EXPORTED_VG ))return 0 ; - lv_count =displayable_lvs_in_vg (vg); - -if (lv_count) { +if (vg->lv_count) {if ((force ==PROMPT ) && (yes_no_prompt ("Do you really want to remove volume " "group \"%s\" containing %u " "logical volumes? [y/n]: " , - vg_name, lv_count) =='n' )) { + vg_name, vg->lv_count) =='n' )) {log_print ("Volume group \"%s\" not removed" , vg_name);return 0 ; }
@@ -391,11 +388,9 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,return 0 ; } - lv_count =displayable_lvs_in_vg (vg); - -if (lv_count) { +if (vg->lv_count) {log_error ("Volume group \"%s\" still contains %u " -"logical volume(s)" , vg_name, lv_count); +"logical volume(s)" , vg_name, vg->lv_count);return 0 ; }
@@ -1141,18 +1136,6 @@ int vg_remove(struct volume_group *vg)return 1 ; } -unsigned displayable_lvs_in_vg (const struct volume_group *vg) -{ -struct lv_list *lvl; -unsigned lv_count =0 ; - - dm_list_iterate_items(lvl, &vg->lvs) -if (lv_is_displayable (lvl->lv)) - lv_count++; - -return lv_count; -} -unsigned snapshot_lvs_in_vg (const struct volume_group *vg) {struct lv_list *lvl;
lib/metadata/metadata.h +0 -5
@@ -340,11 +340,6 @@ int remove_seg_from_segs_using_this_lv(struct logical_volume *lv, struct lv_segmstruct lv_segment *get_only_segment_using_this_lv (struct logical_volume *lv);/* -* Count LVs that are visible from user's perspective. -*/ -unsigned displayable_lvs_in_vg (const struct volume_group *vg); - -/* * Count snapshot LVs. */ unsigned snapshot_lvs_in_vg (const struct volume_group *vg);
lib/metadata/snapshot_manip.c +0 -8
@@ -39,14 +39,6 @@ int lv_is_visible(const struct logical_volume *lv)return lv->status &VISIBLE_LV ?1 :0 ; } -int lv_is_displayable (const struct logical_volume *lv) -{ -if (lv->status &SNAPSHOT ) -return 0 ; - -return (lv->status &VISIBLE_LV ) ||lv_is_cow (lv) ?1 :0 ; -} -int lv_is_virtual_origin (const struct logical_volume *lv) {return (lv->status &VIRTUAL_ORIGIN ) ?1 :0 ;
lib/report/columns.h +1 -1
@@ -104,7 +104,7 @@ FIELD(VGS, vg, NUM, "Free", free_count, 4, uint32, "vg_free_count", "Total numbe FIELD(VGS, vg, NUM, "MaxLV", max_lv, 5, uint32, "max_lv", "Maximum number of LVs allowed in VG or 0 if unlimited.") FIELD(VGS, vg, NUM, "MaxPV", max_pv, 5, uint32, "max_pv", "Maximum number of PVs allowed in VG or 0 if unlimited.") FIELD(VGS, vg, NUM, "#PV", pv_count, 3, uint32, "pv_count", "Number of PVs.") -FIELD(VGS, vg, NUM, "#LV", cmd, 3, lvcount, "lv_count", "Number of LVs.") +FIELD(VGS, vg, NUM, "#LV", lv_count, 3, uint32, "lv_count", "Number of LVs.") FIELD(VGS, vg, NUM, "#SN", cmd, 3, snapcount, "snap_count", "Number of snapshots.") FIELD(VGS, vg, NUM, "Seq", seqno, 3, uint32, "vg_seqno", "Revision number of internal metadata. Incremented whenever it changes.")FIELD (VGS , vg,STR ,"VG Tags" , tags,7 , tags,"vg_tags" ,"Tags, if any." )
lib/report/report.c +1 -13
@@ -497,7 +497,7 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,char *repstr, *lvname;size_t len; -if (lv_is_displayable (lv)) { +if (lv_is_visible (lv)) { repstr = lv->name;return dm_report_field_string (rh, field, (const char **) &repstr); }
@@ -967,18 +967,6 @@ static int _vgmdafree_disp(struct dm_report *rh, struct dm_pool *mem,return _size64_disp (rh, mem, field, &freespace, private); } -static int _lvcount_disp (struct dm_report *rh,struct dm_pool *mem, -struct dm_report_field *field, -const void *data,void *private) -{ -const struct volume_group *vg = (const struct volume_group *) data; -uint32_t count; - - count =displayable_lvs_in_vg (vg); - -return _uint32_disp (rh, mem, field, &count, private); -} -static int _lvsegcount_disp (struct dm_report *rh,struct dm_pool *mem,struct dm_report_field *field,const void *data,void *private)
tools/lvchange.c +1 -1
@@ -584,7 +584,7 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,return ECMD_FAILED ; } -if (!(lv_is_displayable (lv))) { +if (!(lv_is_visible (lv))) {log_error ("Unable to change internal LV %s directly" , lv->name);return ECMD_FAILED ;
tools/lvdisplay.c +1 -1
@@ -18,7 +18,7 @@static int _lvdisplay_single (struct cmd_context *cmd,struct logical_volume *lv,void *handle) { -if (!arg_count (cmd, all_ARG) && !lv_is_displayable (lv)) +if (!arg_count (cmd, all_ARG) && !lv_is_visible (lv))return ECMD_PROCESSED ;if (arg_count (cmd, colon_ARG))
tools/lvscan.c +1 -1
@@ -27,7 +27,7 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,const char *active_str, *snapshot_str; -if (!arg_count (cmd, all_ARG) && !lv_is_displayable (lv)) +if (!arg_count (cmd, all_ARG) && !lv_is_visible (lv))return ECMD_PROCESSED ; inkernel =lv_info (cmd, lv, &info,1 ,0 ) && info.exists;
tools/reporter.c +2 -2
@@ -36,7 +36,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute((unused)),static int _lvs_single (struct cmd_context *cmd,struct logical_volume *lv,void *handle) { -if (!arg_count (cmd, all_ARG) && !lv_is_displayable (lv)) +if (!arg_count (cmd, all_ARG) && !lv_is_visible (lv))return ECMD_PROCESSED ;if (!report_object (handle, lv->vg, lv,NULL ,NULL ,NULL ))
@@ -113,7 +113,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,static int _lvsegs_single (struct cmd_context *cmd,struct logical_volume *lv,void *handle) { -if (!arg_count (cmd, all_ARG) && !lv_is_displayable (lv)) +if (!arg_count (cmd, all_ARG) && !lv_is_visible (lv))return ECMD_PROCESSED ;return process_each_segment_in_lv (cmd, lv, handle, _segs_single);
Signature · 1 line
1.6.2.4
PATCH 6/7 Merge lv_is_displayable and lv_is_visible.
Looks good, no obvious regressions, simplifies code.
Quoted 1 line · Milan Broz
Signed-off-by Milan Broz <[email protected]>
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 7/7 Remove import paramater from lv_create_empty.
In reply to Milan BrozNow the max_lv check is performed in vg_add_lv and import parameter in lv_create_empty has no use.
Patch also adds simple max_lv tests into testsuite
--- lib/metadata/lv_manip.c | 17 ++++++++--------- lib/metadata/metadata-exported.h | 1 - lib/metadata/mirror.c | 4 ++-- lib/metadata/snapshot_manip.c | 2 +- test/t-lvcreate-usage.sh | 22 ++++++++++++++++++++-- test/test-utils.sh | 1 + tools/lvcreate.c | 4 ++-- tools/pvmove.c | 2 +- 8 files changed, 35 insertions(+), 18 deletions(-)
lib/metadata/lv_manip.c +8 -9
@@ -1811,19 +1811,12 @@ struct logical_volume *lv_create_empty(const char *name,union lvid *lvid, uint32_t status, alloc_policy_t alloc, - int import, struct volume_group *vg) { struct format_instance *fi = vg->fid;struct logical_volume *lv;char dname[NAME_LEN ]; -if (vg->max_lv && (vg->max_lv == vg->lv_count)) { -log_error ("Maximum number of logical volumes (%u) reached " -"in volume group %s" , vg->max_lv, vg->name); -return NULL ; - } -if (strstr (name,"%d" ) && !(name =generate_lv_name (vg, name, dname,sizeof (dname)))) { log_error("Failed to generate unique name for the new "
@@ -1831,7 +1824,7 @@ struct logical_volume *lv_create_empty(const char *name,return NULL ; } -if (!import) +if (status &VISIBLE_LV )log_verbose ("Creating logical volume %s" , name);if (!(lv =dm_pool_zalloc (vg->vgmem,sizeof (*lv))))
@@ -1938,6 +1931,12 @@ int vg_add_lv(struct volume_group *vg, struct logical_volume *lv) {struct lv_list *lvl; +if (lv_is_visible (lv) && vg->max_lv && vg->max_lv <= vg->lv_count) { +log_error ("Maximum number of logical volumes (%u) reached " +"in volume group %s" , vg->max_lv, vg->name); +return 0 ; + } +if (!(lvl =dm_pool_zalloc (vg->vgmem,sizeof (*lvl)))) return_0;
@@ -2426,7 +2425,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd, }if (!(layer_lv =lv_create_empty (name,NULL ,LVM_READ |LVM_WRITE , -ALLOC_INHERIT ,0 , lv_where->vg))) { +ALLOC_INHERIT , lv_where->vg))) {log_error ("Creation of layer LV failed" );return NULL ; }
lib/metadata/metadata-exported.h +0 -1
@@ -446,7 +446,6 @@ struct logical_volume *lv_create_empty(const char *name,union lvid *lvid, uint32_t status, alloc_policy_t alloc, - int import, struct volume_group *vg);/* Write out LV contents */
lib/metadata/mirror.c +2 -2
@@ -928,7 +928,7 @@ static int _create_mimage_lvs(struct alloc_handle *ah,for (m =0 ; m < num_mirrors; m++) {if (!(img_lvs[m] =lv_create_empty (img_name,NULL ,LVM_READ |LVM_WRITE , -ALLOC_INHERIT ,0 , lv->vg))) { +ALLOC_INHERIT , lv->vg))) {log_error ("Aborting. Failed to create mirror image LV. " "Remove new LV and retry." );return 0 ;
@@ -1262,7 +1262,7 @@ static struct logical_volume *_create_mirror_log(struct logical_volume *lv,if (!(log_lv =lv_create_empty (log_name,NULL ,LVM_READ |LVM_WRITE , - alloc,0 , lv->vg))) + alloc, lv->vg))) return_NULL;if (!lv_add_log_segment (ah, log_lv))
lib/metadata/snapshot_manip.c +1 -1
@@ -85,7 +85,7 @@ int vg_add_snapshot(struct logical_volume *origin,if (!(snap =lv_create_empty ("snapshot%d" , lvid,LVM_READ |LVM_WRITE |VISIBLE_LV , -ALLOC_INHERIT ,1 , origin->vg))) { +ALLOC_INHERIT , origin->vg))) {lv_set_visible (cow); return_0; }
test/t-lvcreate-usage.sh +20 -2
@@ -13,7 +13,7 @@ . ./test-utils.sh -aux prepare_pvs 2 +aux prepare_pvs 4 aux pvcreate --metadatacopies 0 $dev1 vgcreate -cn $vg $devs
@@ -59,11 +59,29 @@ grep "^ Invalid stripe size 3\.00 KB\$" err case $(lvdisplay $vg) in "") true ;; *) false ;; esac # Setting max_lv works. (bz490298) -vgchange -l 4 $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 +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
test/test-utils.sh +1 -0
@@ -128,6 +128,7 @@ prepare_devs() { lv1=LV1 lv2=LV2 lv3=LV3 + lv4=LV4 } disable_dev() {
tools/lvcreate.c +2 -2
@@ -577,7 +577,7 @@ static struct logical_volume *_create_virtual_origin(struct cmd_context *cmd, }if (!(lv =lv_create_empty (vorigin_name,NULL , permission, -ALLOC_INHERIT ,0 , vg))) +ALLOC_INHERIT , vg))) return_0; if (!lv_extend(lv, segtype, 1, 0, 1, voriginextents, NULL, 0u, 0u,
@@ -824,7 +824,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg, }if (!(lv =lv_create_empty (lv_name ? lv_name :"lvol%d" ,NULL , - status, lp->alloc,0 , vg))) + status, lp->alloc, vg))) return_0;if (lp->read_ahead) {
tools/pvmove.c +1 -1
@@ -191,7 +191,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,/* FIXME Cope with non-contiguous => splitting existing segments */ if (!(lv_mirr =lv_create_empty ("pvmove%d" ,NULL ,LVM_READ |LVM_WRITE , -ALLOC_CONTIGUOUS ,0 , vg))) { +ALLOC_CONTIGUOUS , vg))) {log_error ("Creation of temporary pvmove LV failed" );return NULL ; }
Signature · 1 line
1.6.2.4
PATCH 7/7 Remove import paramater from lv_create_empty.
Quoted 2 lines · Milan Broz
Now the
max_lvcheck is performed invg_add_lvand import parameter inlv_create_emptyhas no use.
Indeed -- and good riddance, too.
Quoted 1 line
Patch also adds simple
max_lvtests into testsuite
Good.
Quoted 1 line
Signed-off-by Milan Broz <[email protected]>
lib/metadata/lv_manip.c struct logical_volume *lv_create_empty(const char *name, · line 1828
Quoted 3 lines
lib/metadata/lv_manip.c +1
-1-if (!import) +if (status &VISIBLE_LV )log_verbose ("Creating logical volume %s" , name);
Would it make sense to use lv_is_visible there? It's just a verbose log message, so I guess it wouldn't matter much?
Yours,
Petr.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentation