diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2016-12-09 22:58:25 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-12-10 11:57:14 +0000 |
commit | 97c4490cc53157adde6da84933524f22149f449f (patch) | |
tree | b9576c474c6a495811d9d03bb4f65c819f644463 | |
parent | c459f23565e86eb9a8a116995cda7dcaed858b9f (diff) | |
download | lvm2-97c4490cc53157adde6da84933524f22149f449f.tar.gz |
libdm: split off internal _stats_delete_region()
Split dm_stats_delete_region() so that internal callers can manage
the handle state themselves.
dm_stats_delete_region() now just handles checking the state of the
handle, reporting validation errors, and calling dm_stats_list() if
necessary, before calling _stats_delete_region().
The new _stats_delete_region() function performs the actual group
member removal and region deletion, and requires a fully listed
handle to operate.
Callers that repeatedly delete regions can use a single listed
handle for many operations on the same device, avoiding one
message ioctl per region deleted: since @stats_list with many
regions is expensive, this yields large runtime improvements.
-rw-r--r-- | libdm/libdm-stats.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index 438a1ed9a..1cabd9a83 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -2018,10 +2018,34 @@ static int _stats_remove_region_id_from_group(struct dm_stats *dms, return _stats_set_aux(dms, group_id, dms->regions[group_id].aux_data); } -int dm_stats_delete_region(struct dm_stats *dms, uint64_t region_id) +static int _stats_delete_region(struct dm_stats *dms, uint64_t region_id) { char msg[STATS_MSG_BUF_LEN]; struct dm_task *dmt; + + if (_stats_region_is_grouped(dms, region_id)) + if (!_stats_remove_region_id_from_group(dms, region_id)) { + log_error("Could not remove region ID " FMTu64 " from " + "group ID " FMTu64, + region_id, dms->regions[region_id].group_id); + return 0; + } + + if (!dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id)) { + log_error("Could not prepare @stats_delete message."); + return 0; + } + + dmt = _stats_send_message(dms, msg); + if (!dmt) + return_0; + dm_task_destroy(dmt); + + return 1; +} + +int dm_stats_delete_region(struct dm_stats *dms, uint64_t region_id) +{ int listed = 0; if (!_stats_bound(dms)) @@ -2065,23 +2089,8 @@ int dm_stats_delete_region(struct dm_stats *dms, uint64_t region_id) goto bad; } - if(_stats_region_is_grouped(dms, region_id)) - if (!_stats_remove_region_id_from_group(dms, region_id)) { - log_error("Could not remove region ID " FMTu64 " from " - "group ID " FMTu64, - region_id, dms->regions[region_id].group_id); - goto bad; - } - - if (!dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id)) { - log_error("Could not prepare @stats_delete message."); + if (!_stats_delete_region(dms, region_id)) goto bad; - } - - dmt = _stats_send_message(dms, msg); - if (!dmt) - return_0; - dm_task_destroy(dmt); if (!listed) /* wipe region and mark as not present */ |