diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2016-10-03 14:42:30 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-10-03 15:14:33 +0100 |
commit | e95a2529748c3047f1af33678c74114d71994e05 (patch) | |
tree | ce97bdd48531b02c3d53f0674d5288419a65f28a | |
parent | 49a1c4d4b0f2c5fbc83a1ad4bfde59a366049b2a (diff) | |
download | lvm2-e95a2529748c3047f1af33678c74114d71994e05.tar.gz |
libdm: convert FIEMAP buffer allocation from stack to dm_zalloc
-rw-r--r-- | libdm/libdm-stats.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index a033861ea..3cddae449 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -4195,9 +4195,9 @@ static int _stats_add_extent(struct dm_pool *mem, struct fiemap_extent *fm_ext, static struct _extent *_stats_get_extents_for_file(struct dm_pool *mem, int fd, uint64_t *count) { - uint64_t buf[STATS_FIE_BUF_LEN]; - struct fiemap *fiemap = (struct fiemap *)buf; - struct fiemap_extent *fm_ext = &fiemap->fm_extents[0]; + uint64_t *buf; + struct fiemap *fiemap = NULL; + struct fiemap_extent *fm_ext = NULL; struct fiemap_extent fm_last = {0}; struct _extent *extents; unsigned long long expected = 0; @@ -4208,10 +4208,18 @@ static struct _extent *_stats_get_extents_for_file(struct dm_pool *mem, int fd, int last = 0; int rc; - memset(buf, 0, sizeof(buf)); + buf = dm_zalloc(STATS_FIE_BUF_LEN); + if (!buf) { + log_error("Could not allocate memory for FIEMAP buffer."); + return NULL; + } + + /* initialise pointers into the ioctl buffer. */ + fiemap = (struct fiemap *) buf; + fm_ext = &fiemap->fm_extents[0]; /* space available per ioctl */ - *count = (sizeof(buf) - sizeof(*fiemap)) + *count = (STATS_FIE_BUF_LEN - sizeof(*fiemap)) / sizeof(struct fiemap_extent); /* grow temporary extent table in the pool */ @@ -4277,9 +4285,16 @@ static struct _extent *_stats_get_extents_for_file(struct dm_pool *mem, int fd, /* return total number of extents */ *count = tot_extents; - return dm_pool_end_object(mem); + extents = dm_pool_end_object(mem); + + /* free FIEMAP buffer. */ + dm_free(buf); + + return extents; + bad: dm_pool_abandon_object(mem); + dm_free(buf); return NULL; } |