summaryrefslogtreecommitdiff
path: root/lib/display
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2015-06-16 13:47:43 +0200
committerZdenek Kabelac <zkabelac@redhat.com>2015-06-18 18:50:37 +0200
commit438a65dfdb13abd10b3311e96786770d70868de1 (patch)
tree8ed610843d0a9ebd1e577f3611c6ca5751be4ed0 /lib/display
parenta3e0d830bde952a83da3ba60936fff2fa7b40966 (diff)
downloadlvm2-438a65dfdb13abd10b3311e96786770d70868de1.tar.gz
display: drop allocation from display_lvname
Use of display_lvname() in plain log_debug() may accumulate memory in command context mempool. Use instead small ringbuffer which allows to store cuple (10 ATM) names so upto 10 full names can be used at one. We are not keeping full VG/LV names as it may eventually consume larger amount of RAM resouces if vgname is longer and lots of LVs are in use. Note: if there would be ever needed for displaing more names at once, the limit should be raised (e.g. log_debug() would need to print more then 10 LVs on a single line).
Diffstat (limited to 'lib/display')
-rw-r--r--lib/display/display.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/display/display.c b/lib/display/display.c
index 2cc5d27d8..8f075d910 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -95,8 +95,23 @@ const char *get_percent_string(percent_type_t def)
const char *display_lvname(const struct logical_volume *lv)
{
- /* On allocation failure, just return the LV name. */
- return lv_fullname_dup(lv->vg->cmd->mem, lv) ? : lv->name;
+ char *name;
+ int r;
+
+ if ((lv->vg->cmd->display_lvname_idx + NAME_LEN) >= sizeof((lv->vg->cmd->display_buffer)))
+ lv->vg->cmd->display_lvname_idx = 0;
+
+ name = lv->vg->cmd->display_buffer + lv->vg->cmd->display_lvname_idx;
+ r = dm_snprintf(name, NAME_LEN, "%s/%s", lv->vg->name, lv->name);
+
+ if (r < 0) {
+ log_error("Full LV name \"%s/%s\" is too long.", lv->vg->name, lv->name);
+ return NULL;
+ }
+
+ lv->vg->cmd->display_lvname_idx += r;
+
+ return name;
}
#define BASE_UNKNOWN 0