1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: allow deleting regions with dm_stats_delete_group()

Add a flag to dm_stats_delete_group() to allow optional deletion
of all regions belonging to the group being removed.
This commit is contained in:
Bryn M. Reeves 2016-07-01 13:14:41 +01:00
parent f1f2df7bc0
commit cda1622fef
3 changed files with 30 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.129 - Version 1.02.129 -
================================= =================================
Allow dm_stats_delete_group() to optionally delete all group members.
Add dm_stats_get_object_type() to return the type of object present. Add dm_stats_get_object_type() to return the type of object present.
Add dm_stats_walk_init() allowing control of objects visited by walks. Add dm_stats_walk_init() allowing control of objects visited by walks.
Add dm_stats_get_group_descriptor() to return the member list as a string. Add dm_stats_get_group_descriptor() to return the member list as a string.

View File

@ -1205,9 +1205,12 @@ int dm_stats_create_group(struct dm_stats *dms, const char *group,
const char *alias, uint64_t *group_id); const char *alias, uint64_t *group_id);
/* /*
* Remove the specified group_id. * Remove the specified group_id. If the remove argument is zero the
* group will be removed but the regions that it contained will remain.
* If remove is non-zero then all regions that belong to the group will
* also be removed.
*/ */
int dm_stats_delete_group(struct dm_stats *dms, uint64_t group_id); int dm_stats_delete_group(struct dm_stats *dms, uint64_t group_id, int remove);
/* /*
* Set an alias for this group or region. The alias will be returned * Set an alias for this group or region. The alias will be returned

View File

@ -1969,8 +1969,8 @@ static int _stats_remove_region_id_from_group(struct dm_stats *dms,
uint64_t region_id) uint64_t region_id)
{ {
struct dm_stats_region *region = &dms->regions[region_id]; struct dm_stats_region *region = &dms->regions[region_id];
dm_bitset_t regions = dms->groups[region_id].regions;
uint64_t group_id = region->group_id; uint64_t group_id = region->group_id;
dm_bitset_t regions = dms->groups[group_id].regions;
if (!_stats_region_is_grouped(dms, region_id)) if (!_stats_region_is_grouped(dms, region_id))
return_0; return_0;
@ -3770,8 +3770,13 @@ bad:
/* /*
* Remove the specified group_id. * Remove the specified group_id.
*/ */
int dm_stats_delete_group(struct dm_stats *dms, uint64_t group_id) int dm_stats_delete_group(struct dm_stats *dms, uint64_t group_id,
int remove_regions)
{ {
struct dm_stats_region *leader;
dm_bitset_t regions;
uint64_t i;
if (group_id > dms->max_region) { if (group_id > dms->max_region) {
log_error("Invalid group ID: " FMTu64, group_id); log_error("Invalid group ID: " FMTu64, group_id);
return 0; return 0;
@ -3782,11 +3787,27 @@ int dm_stats_delete_group(struct dm_stats *dms, uint64_t group_id)
return 0; return 0;
} }
regions = dms->groups[group_id].regions;
leader = &dms->regions[group_id];
/* delete all but the group leader */
for (i = (*regions - 1); i > leader->region_id; i--) {
if (dm_bit(regions, i)) {
dm_bit_clear(regions, i);
if (remove_regions && !dm_stats_delete_region(dms, i))
log_warn("Failed to delete region "
FMTu64 " on %s.", i, dms->name);
}
}
_stats_clear_group_regions(dms, group_id); _stats_clear_group_regions(dms, group_id);
_stats_group_destroy(&dms->groups[group_id]); _stats_group_destroy(&dms->groups[group_id]);
if (!_stats_set_aux(dms, group_id, dms->regions[group_id].aux_data)) if (remove_regions)
return dm_stats_delete_region(dms, group_id);
else if (!_stats_set_aux(dms, group_id, leader->aux_data))
return 0; return 0;
return 1; return 1;
} }