summaryrefslogtreecommitdiff
path: root/libdm/libdm-stats.c
Commit message (Collapse)AuthorAgeFilesLines
* libdm: convert FIEMAP buffer allocation from stack to dm_zallocBryn M. Reeves2016-10-031-6/+21
|
* libdm: fix dm_stats_delete_region() backwards compatBryn M. Reeves2016-09-271-9/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The dm_stats_delete_region() call removes a region from the bound device, and, if the region is grouped, from the group leader group descriptor stored in aux_data. To do this requires a listed handle: previous versions of the library do not since no dependencies exist between regions without grouping. This leads to strange behaviour when a command built against an old version of the library is used with one supporting groups. Deleting a region with dmstats succeeds, but logs errors: # dmstats list Name RgID RgSta RgSiz #Areas ArSize ProgID vg_hex-root 0 0 1.00g 1 1.00g dmstats vg_hex-root 1 1.00g 1.00g 1 1.00g dmstats vg_hex-root 2 2.00g 1.00g 1 1.00g dmstats # dmstats delete --regionid 2 vg_hex/root Region ID 2 does not exist Could not delete statistics region. Command failed # dmstats list Name RgID RgSta RgSiz #Areas ArSize ProgID vg_hex-root 0 0 1.00g 1 1.00g dmstats vg_hex-root 1 1.00g 1.00g 1 1.00g dmstats This happens because the call to dm_stats_delete_region() is inside a dm_stats_walk_*() iterator: upon entry to the call, the iterator is at its end conditions and about to terminate. Due to the call to dm_stats_list() inside the function, it returns with an iterator at the beginning of a walk and performs a further iteration before exiting. This final loop makes a further attempt to delete the (already deleted) region, leading to the confusing error messages.
* libdm: fix stats walk compatibility with older dmsetupBryn M. Reeves2016-09-271-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | The current dmsetup.c handles DR_STATS and DR_STATS_META reports separately in _display_info_cols(), meaning that the stats walk functions are never called for these report types. Versions before v2.02.159 have a loop using dm_stats_walk_do() and dm_stats_walk_while(), that executes once for non-stats reports, and once per region, or area, for DR_STATS/DR_STATS_META reports. This older behaviour relies on the documented behaviour that the walk functions will accept a NULL pointer as the struct dm_stats* argument. This was broken by commit f1f2df7b: the NULL test on dms and dms->regions were incorrectly moved from the dm_stats_walk_end() wrapper to the internal '_stats_walk_end()' helper. Since the pointer is dereferenced in between these points, using an older dmsetup with current libdm results in a segfault when running a non-stats report: # dmsetup info -c vg00/lvol0 Segmentation fault (core dumped) Restore the NULL checks to the wrapper function as intended.
* libdm: fix end-of-groups test in _stats_walk_end()Bryn M. Reeves2016-09-161-1/+1
|
* cleanup: clean gcc6 minor/major types warningsZdenek Kabelac2016-08-291-0/+1
| | | | | Put sys/sysmacros.h in front of sys/types.h header file as requested by gcc6.
* libdm: free hist_arg in _stats_create_file_regions() (Coverity)Bryn M. Reeves2016-07-181-0/+3
|
* libdm: add configure.in checks for fiemap.h and magic.hBryn M. Reeves2016-07-081-3/+26
|
* libdm: use 'goto_bad' if extent pool allocation failsBryn M. Reeves2016-07-081-2/+2
| | | | Generate a backtrace if unable to extend the extent table.
* libdm: use macro for boundary test in _stats_get_extents_for_file()Bryn M. Reeves2016-07-081-3/+7
|
* libdm: use a constant for FIEMAP buffer sizeBryn M. Reeves2016-07-081-1/+2
|
* libdm: use SECTOR_SHIFT constant in _stats_add_extent()Bryn M. Reeves2016-07-081-2/+4
|
* libdm: enable creation of filemap regions with histogramsBryn M. Reeves2016-07-081-9/+10
|
* libdm: allow regions with histograms in dm_stats_create_group()Bryn M. Reeves2016-07-081-5/+53
| | | | | Allow regions with histograms to be grouped if all histograms have the same number of bins and matching bounds.
* libdm: add aggregation support to dm_stats_get_histogram()Bryn M. Reeves2016-07-081-8/+126
| | | | | | | | | | | | Support aggregate group and region histograms by allocating a new histogram from the pool and populating it with a sum of the histogram data for the areas contained in the region or group. To avoid repeatedly summing the same histogram data, cache the pointer in the group and regions structs for subsequent access. The aggregate histograms are allocated from the same pool as the area histograms in the corresponding handle and will be discarded at each list or populate operation.
* libdm: add dm_stats_create_regions_from_fd()Bryn M. Reeves2016-07-081-1/+301
| | | | | | | | | | | | | | | | | Add a call to create dmstats regions that correspond to the extents present in a file descriptor open on a file in a local file system. The file must reside on a file system type that correctly supports physical extent location data in the FIEMAP ioctl. Regions are optionally placed into a group with a user-defined alias. File systems that do not support physical offsets in FIEMAP (btrfs currently) are detected via fstatfs() - although attempting to map a --filemap group on btrfs will fail anyway with the generic error "Not on a device-mapper device" this is confusing; the file system mount is on a device-mapper device, but btrfs' volume layer masks this in the returned st_dev field since the returned logical file extents may span multiple physical devices.
* libdm: fix group resource leak in dm_stats_delete_region()Bryn M. Reeves2016-07-081-1/+0
| | | | | | | | | | | | | | | | | | | | The function _stats_remove_region_id_from_group() incorecctly set the group_id to DM_STATS_GROUP_NOT_PRESENT _before_ the call to _stats_group_destroy(). This will cause the destroy function to return immediately without doing anything: 339 static void _stats_group_destroy(struct dm_stats_group *group) 340 { 341 if (!_stats_group_present(group)) 342 return; Invalidating the ID in _stats_region_region_id_from_group() is redundant anyway; it is rightly done as the last operation in _stats_group_destroy (and it is not possible for anything to see the old value between the two calls). Remove the change to group_id to ensure that the alias and bitset resources are correctly freed.
* libdm: improve comments in stats grouping functionsBryn M. Reeves2016-07-081-0/+10
| | | | | Add more detailed comments to dm_stats_create_group() and _stats_group_check_overlap().
* libdm: fix resource leak in dm_stats_set_alias()Bryn M. Reeves2016-07-081-0/+1
| | | | | When we fail to update aux_data the newly allocated group->alias must be freed before reinstating old_alias.
* libdm: check for empty aux_data in _parse_aux_data_group()Bryn M. Reeves2016-07-061-1/+1
| | | | | | If after extracting stats arguments and group tags nothing remains of aux_data but '-' set the region->aux_data field to the empty string to match behaviour for non-grouped regions.
* libdm: use log_err_once() for group histogram messageBryn M. Reeves2016-07-061-1/+1
|
* libdm: do not permit grouping regions with histogramsBryn M. Reeves2016-07-061-1/+5
| | | | | | Although not harmful do not allow a group containing regions with histograms since it is not currently possible to present histogram data aggregated for the group.
* libdm: check non-zero io count in _average_{rd,wr}_wait_time (Coverity)Bryn M. Reeves2016-07-061-3/+12
| | | | | | | Although a non-zero value for the number of ticks spent doing IO should imply a non-zero number of IOs in the interval test for this explicitly to avoid a divide-by-zero in the event of bad counter data.
* libdm: test for zero interval_ns in _utilization() (Coverity)Bryn M. Reeves2016-07-061-0/+9
| | | | | | It's possible for interval_ns to be zero if the interval is not set or the clock is misconfigured. Test for this before using the value as the divisor in the utilisation calculation.
* libdm: restore missing braces in _stats_walk_end_areasBryn M. Reeves2016-07-061-1/+2
| | | | | | Jumping to the end of the region table must only happen if there are no more present, non-skipped regions, and no group walk is configured to begin.
* libdm: cast walk flags to uint64_t when logging.Bryn M. Reeves2016-07-051-1/+1
| | | | | | | | Walk flags are ULL constants; cast the result to a uint64_t before logging with a FMTx64 format specifier to avoid a compiler warning: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘long long unsigned int’
* libdm: fix <backtrace> in dm_stats_populateBryn M. Reeves2016-07-051-1/+1
|
* libdm: fix <backtrace> in dm_stats_get_nr_regionsBryn M. Reeves2016-07-051-1/+5
|
* libdm: clarify library's use of aux_dataBryn M. Reeves2016-07-051-2/+2
| | | | | | | | Make it clear in libdevmapper.h, and in function argument names, that libdm-stats uses the aux_data field internally and that any values set for user_data are appended to the library values before being stored with a region, and similarly, that internal data fields will be stripped prior to returning any previously stored user_data.
* libdm: allow deleting regions with dm_stats_delete_group()Bryn M. Reeves2016-07-051-3/+24
| | | | | Add a flag to dm_stats_delete_group() to allow optional deletion of all regions belonging to the group being removed.
* libdm: add stats group and region iterators and propertiesBryn M. Reeves2016-07-051-60/+525
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support do dm_stats_walk*() to walk over the set of available groups using the cursor embedded in the dm_stats handle, and to obtain the type of the object at the current stats cursor location. A set of flags is introduced to control which objects are visited: DM_STATS_WALK_AREA DM_STATS_WALK_REGION DM_STATS_WALK_GROUP DM_STATS_WALK_ALL A final flag suppresses visits to regions that contain only a single area - since the aggregate of such a region is idential to the area it contains this allows these duplicates to be filtered out: DM_STATS_WALK_SKIP_SINGLE_AREA If flags are not initialised before beginning a walk the default set matches the behaviour of previous versions of the library. Also accept group identifiers as immediate arguments to the counter, metric, and property functions by adding control flags to the region and area identifiers passed in. Region and area properties are mapped to their equivalents for the group (for example: group size is reported as the sum of all regions contained in the group). Counter and metric values are aggregated for the region or group.
* libdm: use defined constants for buffer sizesBryn M. Reeves2016-07-051-13/+21
| | | | | | | Introduce constants for the buffer sizes that libdm-stats uses: one for messages sent to the kernel, one for rows of response data returned, and a pair for the "start+len" range and histogram bounds strings.
* libdm: add statistics groupsBryn M. Reeves2016-07-051-14/+866
| | | | | | | | | | | | | | | | | | | | | | | | Add a grouping facility to the libdm-stats library that allows the user to bind several regions together as a group. Groups may be used to aggregate data from several regions for reporting, or to select and sort among large sets of regions. A textual descriptor ("group tag") is associated with each group and is stored in the first group member's aux_data field. The tag contains the group member list and an optional alias for the group, allowing the user to assign meaningful names to groups of regions. These descriptors are parsed in @stats_list message responses and populate the resulting region and area tables with the group structure. Groups with overlapping regions are permitted but since this will result in some events being counted more than once a warning is printed in this case. Nested and overlapping groups are not currently supported and attempting to create these configurations results in error.
* libdm: rename 'region' to 'skip_region' in _stats_walk_nextBryn M. Reeves2016-07-051-4/+3
| | | | | In libdm-stats.c 'region' usually refers to a 'struct region*'. Rename the argument to _stats_walk_start to avoid confusion.
* libdm: add enum based counter and metric callsBryn M. Reeves2016-07-051-222/+345
| | | | | | | | | | | | | | | | | | Add a new enum based interface for accessing counter and metric values that uses a single function for each: uint64_t dm_stats_get_counter(const struct dm_stats *dms, dm_stats_counter_t counter uint64_t region_id, uint64_t area_id); int dm_stats_get_metric(const struct dm_stats *dms, int metric, uint64_t region_id, uint64_t area_id, double *value); This simplifies the implementation of value aggregation for groups of regions. The named function interface now calls the enum interface internally so that all new functionality is available regardless of the method used to retrieve values.
* libdm: cache dm name in stats handleBryn M. Reeves2016-07-051-0/+44
| | | | | | | | Cache the device-mapper name of a bound device in the dm_stats handle. This will be used by stats groups to report a device name or user defined alias for groups.
* libdm: rename dm_stats name, devno and uuid membersBryn M. Reeves2016-07-051-26/+26
| | | | | | | | | | | | | The device-mapper name, device numbers and uuid stored in the dm_stats handle are used only to bind the handle to a specific device in order to issue ioctls. Rename them to "bind_*" to reflect this usage in preparation for caching the device-mapper name of the bound device in the dm_stats handle. This will be used to allow optional aliases to be set for dmstats groups.
* libdm: fix histogram pool user-after-free (CWE-825)Bryn M. Reeves2016-07-051-2/+2
|
* libdm-stats: check for empty region and area listsBryn M. Reeves2016-04-221-0/+8
| | | | | | | | | | | | | Check that @stats_list and @stats_print returned data in the _stats_parse_list() and _stats_parse_region() functions before attempting to operate on region and area values. This avoids a coverity warning since fgets() could potentially return no data from the memory buffer returned by the ioctl. In both cases the ioctl would return an error, preventing these functions from running, however it is cleaner to test for the condition explicitly and fail in those cases.
* coverity: eliminate DEADCODEZdenek Kabelac2016-03-011-4/+2
| | | | | Coverity notice this cannot be NULL: cur = &dms->regions[*cur_r] so avoid NULL checking and simplify form.
* cleanup: use char arrays.Zdenek Kabelac2016-02-221-3/+3
|
* cleanup: libdm clang warningsZdenek Kabelac2016-02-221-2/+4
| | | | Add some extra clang pointer validation so we do not try deref NULL.
* libdm: grow with initialized struct contentZdenek Kabelac2016-02-221-5/+5
| | | | Coverity noticed struct hist has been copied uninitalized into mempool.
* doc: change fsf addressZdenek Kabelac2016-01-211-1/+1
| | | | | Hmm rpmlint suggest fsf is using a different address these days, so lets keep it up-to-date
* libdm: reorder error pathZdenek Kabelac2015-11-101-5/+4
| | | | | Coverity noticed recent fix of an error path missed to release 'dmt' - reoder code to ensure 'dmt' is released.
* cleanup: use code in placeZdenek Kabelac2015-11-091-7/+5
| | | | | Pass const strings to printf(), and use struct names directly instead of creating unused vars on stack.
* libdm: add test for dm_task_get_message_response()Zdenek Kabelac2015-11-091-1/+5
| | | | | Coverity notices dm_task_get_message_response() result should be checked for NULL which should not be passed to dm_pool_strdup().
* libdm: ensure vars are initializedZdenek Kabelac2015-11-091-1/+5
| | | | | Coverity found potential error path, where code could have used some unset variables.
* pre-releasev2_02_131Alasdair G Kergon2015-09-151-1/+1
|
* libdm: clean up stats local variable useBryn M. Reeves2015-09-071-40/+36
|
* libdm: fix display of nsec suffixes in histogram stringsBryn M. Reeves2015-09-071-0/+1
|