Use static buffer instead of stack allocated buffer.
This reduces stack size usage of lvm tool and the
change is very simple.
Since the whole library is not thread safe - it should not
add any new problems - and if there will be some conversion
it's easy to convert this to use some preallocated buffer.
Version 2.02.89 -
==================================
+ Reduce stack allocation of some PATH_MAX sized char buffers.
Unlock memory before writing metadata.
Add query before removing snapshots when inactive snapshot origin is removed.
Allow changing availability state of snapshots.
int lvm1_present(struct cmd_context *cmd)
{
- char path[PATH_MAX];
+ static char path[PATH_MAX];
if (dm_snprintf(path, sizeof(path), "%s/lvm/global", cmd->proc_dir)
< 0) {
const struct dm_config_node *cn;
const struct dm_config_value *cv;
const char *str;
- char path[PATH_MAX];
+ static char path[PATH_MAX];
if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
log_verbose("activation/volume_list configuration setting "
static int _mk_dir(const char *dev_dir, const char *vg_name)
{
- char vg_path[PATH_MAX];
+ static char vg_path[PATH_MAX];
mode_t old_umask;
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
static int _rm_dir(const char *dev_dir, const char *vg_name)
{
- char vg_path[PATH_MAX];
+ static char vg_path[PATH_MAX];
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
dev_dir, vg_name) == -1) {
static void _rm_blks(const char *dir)
{
const char *name;
- char path[PATH_MAX];
+ static char path[PATH_MAX];
struct dirent *dirent;
struct stat buf;
DIR *d;
static int _mk_link(const char *dev_dir, const char *vg_name,
const char *lv_name, const char *dev, int check_udev)
{
- char lv_path[PATH_MAX], link_path[PATH_MAX], lvm1_group_path[PATH_MAX];
- char vg_path[PATH_MAX];
+ static char lv_path[PATH_MAX], link_path[PATH_MAX], lvm1_group_path[PATH_MAX];
+ static char vg_path[PATH_MAX];
struct stat buf, buf_lp;
if (dm_snprintf(vg_path, sizeof(vg_path), "%s%s",
const char *lv_name, int check_udev)
{
struct stat buf;
- char lv_path[PATH_MAX];
+ static char lv_path[PATH_MAX];
if (dm_snprintf(lv_path, sizeof(lv_path), "%s%s/%s",
dev_dir, vg_name, lv_name) == -1) {
static int _load_config_file(struct cmd_context *cmd, const char *tag)
{
- char config_file[PATH_MAX] = "";
+ static char config_file[PATH_MAX] = "";
const char *filler = "";
struct stat info;
struct config_tree_list *cfl;
static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
{
+ static char cache_file[PATH_MAX];
const char *dev_cache = NULL, *cache_dir, *cache_file_prefix;
struct dev_filter *f3, *f4;
struct stat st;
- char cache_file[PATH_MAX];
cmd->dump_filter = 0;
static int _init_backup(struct cmd_context *cmd)
{
+ static char default_dir[PATH_MAX];
uint32_t days, min;
- char default_dir[PATH_MAX];
const char *dir;
if (!cmd->system_dir[0]) {
static int _create_vg_text_instance(struct format_instance *fid,
const struct format_instance_ctx *fic)
{
+ static char path[PATH_MAX];
uint32_t type = fic->type;
struct text_fid_context *fidtc;
struct metadata_area *mda;
struct dir_list *dl;
struct raw_list *rl;
struct dm_list *dir_list, *raw_list;
- char path[PATH_MAX];
struct text_context tc;
struct lvmcache_vginfo *vginfo;
struct lvmcache_info *info;
static int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name)
{
- char vg_path[PATH_MAX];
+ static char vg_path[PATH_MAX];
if (!validate_name(vg_name))
return_0;
- snprintf(vg_path, PATH_MAX, "%s%s", cmd->dev_dir, vg_name);
+ snprintf(vg_path, sizeof(vg_path), "%s%s", cmd->dev_dir, vg_name);
if (path_exists(vg_path)) {
log_error("%s: already exists in filesystem", vg_path);
return 0;
int fid_add_mda(struct format_instance *fid, struct metadata_area *mda,
const char *key, size_t key_len, const unsigned sub_key)
{
- char full_key[PATH_MAX];
+ static char full_key[PATH_MAX];
dm_list_add(mda_is_ignored(mda) ? &fid->metadata_areas_ignored :
&fid->metadata_areas_in_use, &mda->list);
/* Add metadata area to index. */
if (fid->type & FMT_INSTANCE_VG) {
if (!_convert_key_to_string(key, key_len, sub_key,
- full_key, PATH_MAX))
+ full_key, sizeof(full_key)))
return_0;
dm_hash_insert(fid->metadata_areas_index.hash,
const char *key, size_t key_len,
const unsigned sub_key)
{
- char full_key[PATH_MAX];
+ static char full_key[PATH_MAX];
struct metadata_area *mda = NULL;
if (fid->type & FMT_INSTANCE_VG) {
if (!_convert_key_to_string(key, key_len, sub_key,
- full_key, PATH_MAX))
+ full_key, sizeof(full_key)))
return_NULL;
mda = (struct metadata_area *) dm_hash_lookup(fid->metadata_areas_index.hash,
full_key);
int fid_remove_mda(struct format_instance *fid, struct metadata_area *mda,
const char *key, size_t key_len, const unsigned sub_key)
{
+ static char full_key[PATH_MAX];
struct metadata_area *mda_indexed = NULL;
- char full_key[PATH_MAX];
/* At least one of mda or key must be specified. */
if (!mda && !key)
if (fid->type & FMT_INSTANCE_VG) {
if (!_convert_key_to_string(key, key_len, sub_key,
- full_key, PATH_MAX))
+ full_key, sizeof(full_key)))
return_0;
dm_hash_remove(fid->metadata_areas_index.hash, full_key);