]> sourceware.org Git - lvm2.git/commitdiff
Replace dynamic buffer allocations for PATH_MAX
authorZdenek Kabelac <zkabelac@redhat.com>
Fri, 18 Nov 2011 19:31:09 +0000 (19:31 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 18 Nov 2011 19:31:09 +0000 (19:31 +0000)
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.

WHATS_NEW
lib/activate/activate.c
lib/activate/fs.c
lib/commands/toolcontext.c
lib/format_text/format-text.c
lib/metadata/metadata.c

index 169beee2ee43b9bdf748b7eeca288d59bce6264e..eed8ec5eeeabf3647f782ae40f519995e42e4a95 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 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.
index 0541c55930db997539100441f6bf9c50d3834188..c0e8beae86786e3825cb7ef7d8b675ccffab2e0d 100644 (file)
@@ -38,7 +38,7 @@
 
 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) {
@@ -294,7 +294,7 @@ static int _passes_activation_filter(struct cmd_context *cmd,
        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 "
index f9eb28081fdf0b041d91d0a8a3991b97f660d448..2edd81e62da6d6eae6dd0d7fc53b58d17f0f867b 100644 (file)
@@ -36,7 +36,7 @@ static int _fs_create = 0;
 
 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",
@@ -67,7 +67,7 @@ static int _mk_dir(const char *dev_dir, const char *vg_name)
 
 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) {
@@ -87,7 +87,7 @@ static int _rm_dir(const char *dev_dir, const char *vg_name)
 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;
@@ -124,8 +124,8 @@ static void _rm_blks(const char *dir)
 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",
@@ -226,7 +226,7 @@ static int _rm_link(const char *dev_dir, const char *vg_name,
                    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) {
index ec6e40011ce1935ed70e19a35577924432a019a1..8b6ad3b63f7d77f145446497c54286e89151169d 100644 (file)
@@ -477,7 +477,7 @@ static int _init_tags(struct cmd_context *cmd, struct dm_config_tree *cft)
 
 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;
@@ -786,10 +786,10 @@ err:
 
 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;
 
@@ -1138,8 +1138,8 @@ static int _init_hostname(struct cmd_context *cmd)
 
 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]) {
index 5e1db36eded327fafc74a5c13f0fb401d8881797..df3c870d7dfd0048a89eb6930c904549ead444ed 100644 (file)
@@ -1791,6 +1791,7 @@ static void *_create_text_context(struct dm_pool *mem, struct text_context *tc)
 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;
@@ -1798,7 +1799,6 @@ static int _create_vg_text_instance(struct format_instance *fid,
        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;
index 7ab06c0bdc1eeba22d44476f895a61fdbf9945da..8528d27edab977600d346cc2000264aefed3d396 100644 (file)
@@ -452,12 +452,12 @@ int move_pvs_used_by_lv(struct volume_group *vg_from,
 
 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;
@@ -4201,7 +4201,7 @@ static int _convert_key_to_string(const char *key, size_t key_len,
 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);
 
@@ -4212,7 +4212,7 @@ int fid_add_mda(struct format_instance *fid, struct metadata_area *mda,
        /* 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,
@@ -4246,13 +4246,13 @@ struct metadata_area *fid_get_mda_indexed(struct format_instance *fid,
                                          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);
@@ -4266,8 +4266,8 @@ struct metadata_area *fid_get_mda_indexed(struct format_instance *fid,
 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)
@@ -4287,7 +4287,7 @@ int fid_remove_mda(struct format_instance *fid, struct metadata_area *mda,
 
                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);
This page took 0.04734 seconds and 5 git commands to generate.