From ecb83990050247782d2ebea4f7e588eac8e0a14f Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 15 Apr 2024 00:31:30 +0200 Subject: [PATCH] lvm: use configure proc dir in lvm.conf Update some code parts to use configurer /proc from lvm.conf (so i.e. our testing can use some fake values) --- lib/metadata/thin_manip.c | 5 +++-- lib/metadata/vdo_manip.c | 9 ++++++--- tools/lvconvert.c | 12 +++++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c index fb6e99821..90544bb55 100644 --- a/lib/metadata/thin_manip.c +++ b/lib/metadata/thin_manip.c @@ -459,7 +459,7 @@ int thin_pool_prepare_metadata(struct logical_volume *metadata_lv, uint64_t data_length) { struct cmd_context *cmd = metadata_lv->vg->cmd; - char lv_path[PATH_MAX], md_path[64], buffer[512]; + char lv_path[PATH_MAX], md_path[PATH_MAX], buffer[512]; const char *argv[DEFAULT_MAX_EXEC_ARGS + 7] = { find_config_tree_str_allow_empty(cmd, global_thin_restore_executable_CFG, NULL) }; @@ -490,7 +490,8 @@ int thin_pool_prepare_metadata(struct logical_volume *metadata_lv, } /* Build path for 'thin_restore' app with this 'hidden/deleted' tmpfile */ - (void) dm_snprintf(md_path, sizeof(md_path), "/proc/%u/fd/%u", getpid(), fileno(f)); + (void) dm_snprintf(md_path, sizeof(md_path), "%s/%u/fd/%u", + cmd->proc_dir, getpid(), fileno(f)); argv[++args] = "-i"; argv[++args] = md_path; diff --git a/lib/metadata/vdo_manip.c b/lib/metadata/vdo_manip.c index 6668fe45a..acb12bdf8 100644 --- a/lib/metadata/vdo_manip.c +++ b/lib/metadata/vdo_manip.c @@ -653,7 +653,7 @@ static int _compare_mem_table_s(const void *a, const void *b){ return strcmp(((const mem_table_t*)a)->name, ((const mem_table_t*)b)->name); } -static int _get_memory_info(uint64_t *total_mb, uint64_t *available_mb) +static int _get_memory_info(struct cmd_context *cmd, uint64_t *total_mb, uint64_t *available_mb) { uint64_t anon_pages = 0, mem_available = 0, mem_free = 0, mem_total = 0, shmem = 0, swap_free = 0; uint64_t can_swap; @@ -667,11 +667,14 @@ static int _get_memory_info(uint64_t *total_mb, uint64_t *available_mb) }; char line[128], namebuf[32], *e, *tail; + char proc_meminfo[PATH_MAX]; FILE *fp; mem_table_t findme = { namebuf, NULL }; mem_table_t *found; - if (!(fp = fopen("/proc/meminfo", "r"))) + if ((dm_snprintf(proc_meminfo, sizeof(proc_meminfo), + "%s/meminfo", cmd->proc_dir) < 0) || + !(fp = fopen(proc_meminfo, "r"))) return _get_sysinfo_memory(total_mb, available_mb); while (fgets(line, sizeof(line), fp)) { @@ -760,7 +763,7 @@ int check_vdo_constrains(struct cmd_context *cmd, const struct vdo_pool_size_con // total required memory for VDO target req_mb = 38 + cfg->index_memory_size_mb + virt_mb + phy_mb + cache_mb; - _get_memory_info(&total_mb, &available_mb); + _get_memory_info(cmd, &total_mb, &available_mb); has_cnt = cnt = (phy_mb ? 1 : 0) + (virt_mb ? 1 : 0) + diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 52c7cb9c2..b848a895b 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -6139,8 +6139,18 @@ static int _check_writecache_memory(struct cmd_context *cmd, struct logical_volu uint64_t need_mem_gb; uint64_t proc_mem_gb; unsigned long long proc_mem_kb = 0; + char proc_meminfo[PATH_MAX]; - if (!(fp = fopen("/proc/meminfo", "r"))) + if (*cmd->proc_dir) + goto skip_proc; + + if (dm_snprintf(proc_meminfo, sizeof(proc_meminfo), + "%s/meminfo", cmd->proc_dir) < 0) { + stack; + goto skip_proc; + } + + if (!(fp = fopen(proc_meminfo, "r"))) goto skip_proc; while (fgets(line, sizeof(line), fp)) {