diff --git a/src/common/wr_filesystem.c b/src/common/wr_filesystem.c index 122ced26fb227118242d23e301b92326b8324c02..f6793c823a30c3f4c7f06781ff9a22960909b0f0 100644 --- a/src/common/wr_filesystem.c +++ b/src/common/wr_filesystem.c @@ -40,7 +40,7 @@ errno_t iret_snprintf = 0; #define WR_FS_GET_PATH(name) ({ \ static char path[WR_FILE_PATH_MAX_LENGTH]; \ iret_snprintf = snprintf_s(path, WR_FILE_PATH_MAX_LENGTH, WR_FILE_PATH_MAX_LENGTH - 1, \ - "%s/%s", g_inst_cfg->data_dir, (name)); \ + "%s/%s", g_inst_cfg->params.data_file_path, (name)); \ WR_SECUREC_SS_RETURN_IF_ERROR(iret_snprintf, CM_ERROR); \ path; \ }) diff --git a/src/params/wr_param.c b/src/params/wr_param.c index 5affa25ee8fbeb4820769a752648a6bac2d05f59..42c2df58a47e305dc76417b6532f6959e539c975 100644 --- a/src/params/wr_param.c +++ b/src/params/wr_param.c @@ -147,6 +147,8 @@ static config_item_t g_wr_params[] = { EFFECT_REBOOT, CFG_INS, NULL, NULL, NULL, NULL}, {"LISTEN_ADDR", CM_TRUE, ATTR_READONLY, "127.0.0.1:1622", NULL, NULL, "-", "-", "GS_TYPE_VARCHAR", NULL, 62, EFFECT_REBOOT, CFG_INS, NULL, NULL, NULL, NULL}, + {"DATA_FILE_PATH", CM_TRUE, ATTR_READONLY, "/tmp", NULL, NULL, "-", "-", "GS_TYPE_VARCHAR", NULL, 24, + EFFECT_REBOOT, CFG_INS, NULL, NULL, NULL, NULL}, }; static const char *g_wr_config_file = (const char *)"wr_inst.ini"; @@ -208,6 +210,22 @@ static status_t wr_load_disk_lock_file_path(wr_config_t *inst_cfg) return CM_SUCCESS; } +static status_t wr_load_data_file_path(wr_config_t *inst_cfg) +{ + int32 ret; + char *value = cm_get_config_value(&inst_cfg->config, "DATA_FILE_PATH"); + status_t status = wr_verify_lock_file_path(value); + WR_RETURN_IFERR2( + status, WR_THROW_ERROR(ERR_WR_INVALID_PARAM, "failed to load params, invalid DATA_FILE_PATH")); + ret = snprintf_s(inst_cfg->params.data_file_path, WR_UNIX_PATH_MAX, WR_UNIX_PATH_MAX - 1, "%s", value); + if (ret == -1) { + WR_RETURN_IFERR2( + CM_ERROR, WR_THROW_ERROR(ERR_WR_INVALID_PARAM, "failed to load params, invalid DATA_FILE_PATH")); + } + + return CM_SUCCESS; +} + static status_t wr_load_storage_mode(wr_config_t *inst_cfg) { char *value = cm_get_config_value(&inst_cfg->config, "STORAGE_MODE"); @@ -579,10 +597,6 @@ status_t wr_set_cfg_dir(const char *home, wr_config_t *inst_cfg) int32 iret_snprintf = snprintf_s(inst_cfg->home, WR_MAX_PATH_BUFFER_SIZE, WR_MAX_PATH_BUFFER_SIZE - 1, "%s", is_home_empty ? home_realpath : home); WR_SECUREC_SS_RETURN_IF_ERROR(iret_snprintf, CM_ERROR); - - iret_snprintf = snprintf_s(inst_cfg->data_dir, WR_MAX_PATH_BUFFER_SIZE, WR_MAX_PATH_BUFFER_SIZE - 1, "%s/data", - is_home_empty ? home_realpath : home); - WR_SECUREC_SS_RETURN_IF_ERROR(iret_snprintf, CM_ERROR); g_inst_cfg = inst_cfg; return CM_SUCCESS; } @@ -745,7 +759,7 @@ status_t wr_load_config(wr_config_t *inst_cfg) CM_RETURN_IFERR(wr_load_enable_core_state_collect(inst_cfg)); CM_RETURN_IFERR(wr_load_delay_clean_interval(inst_cfg)); CM_RETURN_IFERR(wr_load_space_usage(inst_cfg)); - + CM_RETURN_IFERR(wr_load_data_file_path(inst_cfg)); return CM_SUCCESS; } diff --git a/src/params/wr_param.h b/src/params/wr_param.h index b83abb6ebe4b267cb39283adcd304d48bd0b8d8e..0436624398f56fee19283c11d9b1e2d4b42288ad 100644 --- a/src/params/wr_param.h +++ b/src/params/wr_param.h @@ -72,6 +72,7 @@ typedef struct st_wr_params { char *root_name; // root volume name int64 inst_id; char disk_lock_file_path[WR_UNIX_PATH_MAX]; + char data_file_path[WR_UNIX_PATH_MAX]; int32 wr_mode; uint32 cfg_session_num; int32 lock_interval; @@ -103,7 +104,6 @@ typedef struct st_wr_params { typedef struct st_wr_config { char home[WR_MAX_PATH_BUFFER_SIZE]; - char data_dir[WR_MAX_PATH_BUFFER_SIZE]; config_t config; wr_params_t params; } wr_config_t;