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

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).
This commit is contained in:
Zdenek Kabelac 2015-06-16 13:47:43 +02:00
parent a3e0d830bd
commit 438a65dfdb
3 changed files with 20 additions and 2 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.122 - Version 2.02.122 -
================================= =================================
Avoid allocation in display_lvname internal function.
Support thins with size of external origin unaligned with thin pool chunk. Support thins with size of external origin unaligned with thin pool chunk.
Allow to extend reduced thin volumes with external origins. Allow to extend reduced thin volumes with external origins.
Consider snapshot and origin LV as unusable if its component is suspended. Consider snapshot and origin LV as unusable if its component is suspended.

View File

@ -146,6 +146,8 @@ struct cmd_context {
char system_dir[PATH_MAX]; char system_dir[PATH_MAX];
char dev_dir[PATH_MAX]; char dev_dir[PATH_MAX];
char proc_dir[PATH_MAX]; char proc_dir[PATH_MAX];
char display_buffer[NAME_LEN * 10]; /* Ring buffer for upto 10 longest vg/lv names */
unsigned display_lvname_idx; /* Index to ring buffer */
}; };
/* /*

View File

@ -95,8 +95,23 @@ const char *get_percent_string(percent_type_t def)
const char *display_lvname(const struct logical_volume *lv) const char *display_lvname(const struct logical_volume *lv)
{ {
/* On allocation failure, just return the LV name. */ char *name;
return lv_fullname_dup(lv->vg->cmd->mem, lv) ? : lv->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 #define BASE_UNKNOWN 0