From af4f0754e482ff882294f6d045887546542eefb5 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sun, 17 Nov 2019 19:21:55 +0800 Subject: [PATCH] code refine: extent struct FDFSStorePathInfo --- HISTORY | 6 +- storage/storage_disk_recovery.c | 15 +++-- storage/storage_dump.c | 6 +- storage/storage_func.c | 25 ++----- storage/storage_global.c | 1 - storage/storage_global.h | 9 --- storage/storage_service.c | 108 +++++++++++++++---------------- storage/storage_sync.c | 12 ++-- storage/tracker_client_thread.c | 16 ++--- storage/trunk_mgr/trunk_mem.c | 4 +- storage/trunk_mgr/trunk_shared.c | 90 ++++++++++++++------------ storage/trunk_mgr/trunk_shared.h | 20 +++++- tracker/tracker_types.h | 5 -- 13 files changed, 155 insertions(+), 162 deletions(-) diff --git a/HISTORY b/HISTORY index a34d1ae..a09218c 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 6.03 2019-11-16 +Version 6.03 2019-11-17 * dual IPs support two different types of inner (intranet) IPs * storage server request tracker server to change it's status to that of tracker leader when the storage server found @@ -7,7 +7,9 @@ Version 6.03 2019-11-16 * bugfix: fdfs_monitor fix get index of the specified tracker server * storage server write to data_init_flag and mark file safely (write to temp file then rename) - + * code refine: combine g_fdfs_store_paths and g_path_space_list, + and extent struct FDFSStorePathInfo + NOTE: the tracker and storage server must upgrade together Version 6.02 2019-11-12 diff --git a/storage/storage_disk_recovery.c b/storage/storage_disk_recovery.c index 1c4c7bd..4cf8096 100644 --- a/storage/storage_disk_recovery.c +++ b/storage/storage_disk_recovery.c @@ -30,6 +30,7 @@ #include "tracker_types.h" #include "tracker_proto.h" #include "storage_global.h" +#include "trunk_mgr/trunk_shared.h" #include "storage_func.h" #include "storage_sync.h" #include "tracker_client.h" @@ -65,7 +66,7 @@ static int storage_do_fetch_binlog(ConnectionInfo *pSrcStorage, \ int64_t file_bytes; int result; - pBasePath = g_fdfs_store_paths.paths[store_path_index]; + pBasePath = g_fdfs_store_paths.paths[store_path_index].path; recovery_get_binlog_filename(pBasePath, full_binlog_filename); memset(out_buff, 0, sizeof(out_buff)); @@ -534,7 +535,7 @@ static int recovery_download_file_to_local(StorageBinLogRecord *pRecord, { bTrunkFile = false; sprintf(local_filename, "%s/data/%s", - g_fdfs_store_paths.paths[pRecord->store_path_index], + g_fdfs_store_paths.paths[pRecord->store_path_index].path, pRecord->true_filename); } @@ -684,7 +685,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead break; } sprintf(local_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ record.true_filename); if ((result=storage_split_filename_ex( \ @@ -695,7 +696,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead break; } sprintf(src_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ record.true_filename); if (symlink(src_filename, local_filename) == 0) { @@ -916,7 +917,7 @@ static int storage_do_split_trunk_binlog(const int store_path_index, int record_length; int result; - pBasePath = g_fdfs_store_paths.paths[store_path_index]; + pBasePath = g_fdfs_store_paths.paths[store_path_index].path; recovery_get_full_filename(pBasePath, \ RECOVERY_BINLOG_FILENAME".tmp", tmpFullFilename); fp = fopen(tmpFullFilename, "w"); @@ -1087,7 +1088,7 @@ static int storage_disk_recovery_split_trunk_binlog(const int store_path_index) StorageBinLogReader reader; int result; - pBasePath = g_fdfs_store_paths.paths[store_path_index]; + pBasePath = g_fdfs_store_paths.paths[store_path_index].path; if ((result=recovery_reader_init(pBasePath, &reader)) != 0) { storage_reader_destroy(&reader); @@ -1107,7 +1108,7 @@ int storage_disk_recovery_start(const int store_path_index) int result; char *pBasePath; - pBasePath = g_fdfs_store_paths.paths[store_path_index]; + pBasePath = g_fdfs_store_paths.paths[store_path_index].path; if ((result=recovery_init_mark_file(pBasePath, false)) != 0) { return result; diff --git a/storage/storage_dump.c b/storage/storage_dump.c index c7707d7..badefef 100644 --- a/storage/storage_dump.c +++ b/storage/storage_dump.c @@ -246,9 +246,9 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize) total_len += snprintf(buff + total_len, buffSize - total_len, "\tg_fdfs_store_paths.paths[%d]=%s, " \ "total=%d MB, free=%d MB\n", i, \ - g_fdfs_store_paths.paths[i], \ - g_path_space_list[i].total_mb, \ - g_path_space_list[i].free_mb); + g_fdfs_store_paths.paths[i].path, \ + g_fdfs_store_paths.paths[i].total_mb, \ + g_fdfs_store_paths.paths[i].free_mb); } if (total_len < buffSize - 1) diff --git a/storage/storage_func.c b/storage/storage_func.c index fdf39ab..53d8977 100644 --- a/storage/storage_func.c +++ b/storage/storage_func.c @@ -842,7 +842,7 @@ static int storage_check_and_make_data_dirs() for (i=0; ifilename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ true_filename); } @@ -2012,15 +2012,15 @@ int storage_get_storage_path_index(int *store_path_index) *store_path_index = 0; } - if (!storage_check_reserved_space_path(g_path_space_list \ - [*store_path_index].total_mb, g_path_space_list \ + if (!storage_check_reserved_space_path(g_fdfs_store_paths.paths \ + [*store_path_index].total_mb, g_fdfs_store_paths.paths \ [*store_path_index].free_mb, g_avg_storage_reserved_mb)) { for (i=0; ifilename, sizeof(pFileContext->filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[master_store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[master_store_path_index].path, \ filename); sprintf(pFileContext->fname2log, \ "%c"FDFS_STORAGE_DATA_DIR_FORMAT"/%s", \ @@ -2878,12 +2878,12 @@ static int storage_service_do_create_link(struct fast_task_info *pTask, \ else { sprintf(full_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ filename); } sprintf(src_full_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ pSrcFileInfo->src_true_filename); if (symlink(src_full_filename, full_filename) != 0) { @@ -3337,7 +3337,7 @@ static int storage_server_set_metadata(struct fast_task_info *pTask) pFileContext->timestamp2log = g_current_time; sprintf(pFileContext->filename, "%s/data/%s%s", \ - g_fdfs_store_paths.paths[store_path_index], true_filename, \ + g_fdfs_store_paths.paths[store_path_index].path, true_filename, \ FDFS_STORAGE_META_FILE_EXT); sprintf(pFileContext->fname2log,"%s%s", \ filename, FDFS_STORAGE_META_FILE_EXT); @@ -3595,7 +3595,7 @@ static int query_file_info_deal_response(struct fast_task_info *pTask, snprintf(pFileContext->fname2log, sizeof(pFileContext->fname2log), "%s", filename); snprintf(pFileContext->filename, sizeof(pFileContext->filename), - "%s/data/%s", g_fdfs_store_paths.paths[store_path_index], + "%s/data/%s", g_fdfs_store_paths.paths[store_path_index].path, true_filename); return push_calc_crc32_to_dio_queue(pTask, @@ -3772,7 +3772,7 @@ static int storage_server_query_file_info(struct fast_task_info *pTask) { char full_filename[MAX_PATH_SIZE + 128]; sprintf(full_filename, "%s/data/%s", - g_fdfs_store_paths.paths[store_path_index], + g_fdfs_store_paths.paths[store_path_index].path, true_filename); if ((len=readlink(full_filename, src_filename, \ sizeof(src_filename))) < 0) @@ -4156,7 +4156,6 @@ static int storage_server_fetch_one_path_binlog_dealer( \ char *pBasePath; int result; int record_len; - int base_path_len; int len; int store_path_index; struct stat stat_buf; @@ -4180,8 +4179,7 @@ static int storage_server_fetch_one_path_binlog_dealer( \ store_path_index = pFileContext->extra_info.upload.trunk_info. \ path.store_path_index; - pBasePath = g_fdfs_store_paths.paths[store_path_index]; - base_path_len = strlen(pBasePath); + pBasePath = g_fdfs_store_paths.paths[store_path_index].path; pOutBuff = pTask->data; bLast = false; @@ -4202,7 +4200,8 @@ static int storage_server_fetch_one_path_binlog_dealer( \ break; } - if (g_fdfs_store_paths.paths[record.store_path_index] != pBasePath) + if (g_fdfs_store_paths.paths[record.store_path_index]. + path != pBasePath) { continue; } @@ -4231,7 +4230,7 @@ static int storage_server_fetch_one_path_binlog_dealer( \ else { snprintf(full_filename, sizeof(full_filename), "%s/data/%s", - g_fdfs_store_paths.paths[record.store_path_index], + g_fdfs_store_paths.paths[record.store_path_index].path, record.true_filename); if (lstat(full_filename, &stat_buf) != 0) { @@ -4326,7 +4325,7 @@ static int storage_server_fetch_one_path_binlog_dealer( \ break; } - if (len <= base_path_len) + if (len <= g_fdfs_store_paths.paths[store_path_index].path_len) { logWarning("file: "__FILE__", line: %d, " \ "invalid symbol link file: %s, " \ @@ -4346,11 +4345,11 @@ static int storage_server_fetch_one_path_binlog_dealer( \ } //full filename format: ${base_path}/data/filename - pOutBuff += sprintf(pOutBuff, "%d %c %s %s/%s\n", \ - (int)record.timestamp, \ - record.op_type, record.filename, \ - diskLogicPath, \ - src_filename + base_path_len + 6); + pOutBuff += sprintf(pOutBuff, "%d %c %s %s/%s\n", + (int)record.timestamp, + record.op_type, record.filename, + diskLogicPath, src_filename + g_fdfs_store_paths. + paths[store_path_index].path_len + 6); } if (pTask->size - (pOutBuff - pTask->data) < @@ -4663,8 +4662,8 @@ static int storage_upload_file(struct fast_task_info *pTask, bool bAppenderFile) { char reserved_space_str[32]; - if (!storage_check_reserved_space_path(g_path_space_list \ - [store_path_index].total_mb, g_path_space_list \ + if (!storage_check_reserved_space_path(g_fdfs_store_paths.paths \ + [store_path_index].total_mb, g_fdfs_store_paths.paths \ [store_path_index].free_mb - (file_bytes/FDFS_ONE_MB), \ g_avg_storage_reserved_mb)) { @@ -4672,12 +4671,12 @@ static int storage_upload_file(struct fast_task_info *pTask, bool bAppenderFile) "no space to upload file, " "free space: %d MB is too small, file bytes: " \ "%"PRId64", reserved space: %s", \ - __LINE__, g_path_space_list[store_path_index].\ + __LINE__, g_fdfs_store_paths.paths[store_path_index].\ free_mb, file_bytes, \ fdfs_storage_reserved_space_to_string_ex( \ g_storage_reserved_space.flag, \ g_avg_storage_reserved_mb, \ - g_path_space_list[store_path_index]. \ + g_fdfs_store_paths.paths[store_path_index]. \ total_mb, g_storage_reserved_space.rs.ratio,\ reserved_space_str)); return ENOSPC; @@ -4758,7 +4757,7 @@ static int storage_server_check_appender_file(struct fast_task_info *pTask, } snprintf(pFileContext->filename, sizeof(pFileContext->filename), - "%s/data/%s", g_fdfs_store_paths.paths[*store_path_index], + "%s/data/%s", g_fdfs_store_paths.paths[*store_path_index].path, true_filename); if (lstat(pFileContext->filename, stat_buf) == 0) { @@ -5517,8 +5516,8 @@ static int storage_upload_slave_file(struct fast_task_info *pTask) return result; } - if (!storage_check_reserved_space_path(g_path_space_list \ - [store_path_index].total_mb, g_path_space_list \ + if (!storage_check_reserved_space_path(g_fdfs_store_paths.paths \ + [store_path_index].total_mb, g_fdfs_store_paths.paths \ [store_path_index].free_mb - (file_bytes / FDFS_ONE_MB), \ g_avg_storage_reserved_mb)) { @@ -5526,11 +5525,11 @@ static int storage_upload_slave_file(struct fast_task_info *pTask) "no space to upload file, " "free space: %d MB is too small, file bytes: " \ "%"PRId64", reserved space: %s", __LINE__,\ - g_path_space_list[store_path_index].free_mb, \ + g_fdfs_store_paths.paths[store_path_index].free_mb, \ file_bytes, fdfs_storage_reserved_space_to_string_ex(\ g_storage_reserved_space.flag, \ g_avg_storage_reserved_mb, \ - g_path_space_list[store_path_index].total_mb, \ + g_fdfs_store_paths.paths[store_path_index].total_mb, \ g_storage_reserved_space.rs.ratio, \ reserved_space_str)); return ENOSPC; @@ -5573,7 +5572,7 @@ static int storage_upload_slave_file(struct fast_task_info *pTask) } snprintf(pFileContext->filename, sizeof(pFileContext->filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[store_path_index], filename); + "%s/data/%s", g_fdfs_store_paths.paths[store_path_index].path, filename); if (fileExists(pFileContext->filename)) { logError("file: "__FILE__", line: %d, " \ @@ -5871,7 +5870,7 @@ static int storage_sync_copy_file(struct fast_task_info *pTask, \ sprintf(pFileContext->filename, "%s/data/.cp" \ "%"PRId64".tmp", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ temp_file_sequence++); pthread_mutex_unlock(&g_storage_thread_lock); @@ -6732,11 +6731,11 @@ static int storage_do_sync_link_file(struct fast_task_info *pTask) else { snprintf(pFileContext->filename, sizeof(pFileContext->filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[dest_store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[dest_store_path_index].path, \ dest_true_filename); snprintf(src_full_filename, sizeof(src_full_filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[src_store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[src_store_path_index].path, \ src_true_filename); if (symlink(src_full_filename, pFileContext->filename) != 0) { @@ -7106,7 +7105,7 @@ static int storage_server_get_metadata(struct fast_task_info *pTask) } sprintf(pFileContext->filename, "%s/data/%s%s", \ - g_fdfs_store_paths.paths[store_path_index], \ + g_fdfs_store_paths.paths[store_path_index].path, \ true_filename, FDFS_STORAGE_META_FILE_EXT); if (lstat(pFileContext->filename, &stat_buf) == 0) { @@ -7308,7 +7307,7 @@ static int storage_server_download_file(struct fast_task_info *pTask) else { sprintf(pFileContext->filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], true_filename); + g_fdfs_store_paths.paths[store_path_index].path, true_filename); } pFileContext->calc_crc32 = false; @@ -7560,7 +7559,7 @@ static int storage_sync_delete_file(struct fast_task_info *pTask) { pClientInfo->deal_func = dio_delete_normal_file; sprintf(pFileContext->filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], true_filename); + g_fdfs_store_paths.paths[store_path_index].path, true_filename); } strcpy(pFileContext->fname2log, filename); @@ -7695,7 +7694,7 @@ static int storage_server_delete_file(struct fast_task_info *pTask) { pClientInfo->deal_func = dio_delete_normal_file; sprintf(pFileContext->filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], true_filename); + g_fdfs_store_paths.paths[store_path_index].path, true_filename); } if ((pFileContext->extra_info.upload.file_type & _FILE_TYPE_LINK) && \ @@ -7706,12 +7705,11 @@ static int storage_server_delete_file(struct fast_task_info *pTask) char src_fname2log[128]; char *src_true_filename; int src_filename_len; - int base_path_len; int src_store_path_index; int i; sprintf(full_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[store_path_index], true_filename); + g_fdfs_store_paths.paths[store_path_index].path, true_filename); do { if ((src_filename_len=readlink(full_filename, \ @@ -7742,11 +7740,11 @@ static int storage_server_delete_file(struct fast_task_info *pTask) return result; } - base_path_len = strlen(g_fdfs_store_paths.paths \ - [store_path_index]); - if (src_filename_len > base_path_len && memcmp( \ - src_filename, g_fdfs_store_paths.paths \ - [store_path_index], base_path_len) == 0) + if (src_filename_len > g_fdfs_store_paths.paths + [store_path_index].path_len && memcmp( + src_filename, g_fdfs_store_paths.paths + [store_path_index].path, g_fdfs_store_paths. + paths[store_path_index].path_len) == 0) { src_store_path_index = store_path_index; } @@ -7755,10 +7753,9 @@ static int storage_server_delete_file(struct fast_task_info *pTask) src_store_path_index = -1; for (i=0; i base_path_len && \ - memcmp(src_filename, g_fdfs_store_paths.paths\ - [i], base_path_len) == 0) + if (src_filename_len > g_fdfs_store_paths.paths[i].path_len && + memcmp(src_filename, g_fdfs_store_paths.paths + [i].path, g_fdfs_store_paths.paths[i].path_len) == 0) { src_store_path_index = i; break; @@ -7774,8 +7771,9 @@ static int storage_server_delete_file(struct fast_task_info *pTask) } } - src_true_filename = src_filename + (base_path_len + \ - (sizeof("/data/") -1)); + src_true_filename = src_filename + (g_fdfs_store_paths. + paths[src_store_path_index].path_len + + (sizeof("/data/") -1)); snprintf(src_fname2log, sizeof(src_fname2log), \ "%c"FDFS_STORAGE_DATA_DIR_FORMAT"/%s", \ FDFS_STORAGE_STORE_PATH_PREFIX_CHAR, \ @@ -7916,7 +7914,7 @@ static int storage_create_link_core(struct fast_task_info *pTask, \ } snprintf(full_filename, sizeof(full_filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[store_path_index].path, \ filename); if (fileExists(full_filename)) { diff --git a/storage/storage_sync.c b/storage/storage_sync.c index 6f10608..1265640 100644 --- a/storage/storage_sync.c +++ b/storage/storage_sync.c @@ -185,7 +185,7 @@ static int storage_sync_copy_file(ConnectionInfo *pStorageServer, \ { file_offset = 0; sprintf(full_filename, "%s/data/%s", \ - g_fdfs_store_paths.paths[pRecord->store_path_index], \ + g_fdfs_store_paths.paths[pRecord->store_path_index].path, \ pRecord->true_filename); } @@ -350,7 +350,7 @@ static int storage_sync_modify_file(ConnectionInfo *pStorageServer, \ } snprintf(full_filename, sizeof(full_filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index].path, \ pRecord->true_filename); if (lstat(full_filename, &stat_buf) != 0) { @@ -520,7 +520,7 @@ static int storage_sync_truncate_file(ConnectionInfo *pStorageServer, \ } snprintf(full_filename, sizeof(full_filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index].path, \ pRecord->true_filename); if (lstat(full_filename, &stat_buf) != 0) { @@ -841,7 +841,7 @@ static int storage_sync_link_file(ConnectionInfo *pStorageServer, \ int src_filename_len; snprintf(full_filename, sizeof(full_filename), \ - "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index], \ + "%s/data/%s", g_fdfs_store_paths.paths[pRecord->store_path_index].path, \ pRecord->true_filename); src_filename_len = readlink(full_filename, src_full_filename, \ sizeof(src_full_filename) - 1); @@ -884,7 +884,7 @@ static int storage_sync_link_file(ConnectionInfo *pStorageServer, \ src_path_index++) { if (strcmp(src_full_filename, \ - g_fdfs_store_paths.paths[src_path_index]) == 0) + g_fdfs_store_paths.paths[src_path_index].path) == 0) { break; } @@ -998,7 +998,7 @@ static int storage_sync_rename_file(ConnectionInfo *pStorageServer, } snprintf(full_filename, sizeof(full_filename), "%s/data/%s", - g_fdfs_store_paths.paths[pRecord->store_path_index], + g_fdfs_store_paths.paths[pRecord->store_path_index].path, pRecord->true_filename); if (lstat(full_filename, &stat_buf) != 0) { diff --git a/storage/tracker_client_thread.c b/storage/tracker_client_thread.c index 096c558..0133e08 100644 --- a/storage/tracker_client_thread.c +++ b/storage/tracker_client_thread.c @@ -2203,7 +2203,7 @@ static int tracker_report_df_stat(ConnectionInfo *pTrackerServer, for (i=0; isz_total_mb); - long2buff(g_path_space_list[i].free_mb, pStatBuff->sz_free_mb); + long2buff(g_fdfs_store_paths.paths[i].total_mb, pStatBuff->sz_total_mb); + long2buff(g_fdfs_store_paths.paths[i].free_mb, pStatBuff->sz_free_mb); pStatBuff++; } @@ -2235,12 +2235,12 @@ static int tracker_report_df_stat(ConnectionInfo *pTrackerServer, store_path_index = -1; for (i=0; i \ + if (g_fdfs_store_paths.paths[i].free_mb > \ g_avg_storage_reserved_mb \ - && g_path_space_list[i].free_mb > max_free_mb) + && g_fdfs_store_paths.paths[i].free_mb > max_free_mb) { store_path_index = i; - max_free_mb = g_path_space_list[i].free_mb; + max_free_mb = g_fdfs_store_paths.paths[i].free_mb; } } if (g_store_path_index != store_path_index) diff --git a/storage/trunk_mgr/trunk_mem.c b/storage/trunk_mgr/trunk_mem.c index ce301a3..5aa8812 100644 --- a/storage/trunk_mgr/trunk_mem.c +++ b/storage/trunk_mgr/trunk_mem.c @@ -1953,8 +1953,8 @@ int trunk_create_trunk_file_advance(void *args) free_mb_sum = 0; for (i=0; ipaths[pTrunkInfo->path.store_path_index]; + pStorePath = pStorePaths->paths[pTrunkInfo->path.store_path_index].path; TRUNK_GET_FILENAME(pTrunkInfo->file.id, short_filename); snprintf(full_filename, buff_size, \ @@ -547,7 +551,7 @@ int trunk_file_do_lstat_func_ex(const FDFSStorePaths *pStorePaths, \ if (filename_len != FDFS_TRUNK_FILENAME_LENGTH) //not trunk file { snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ - pStorePaths->paths[store_path_index], true_filename); + pStorePaths->paths[store_path_index].path, true_filename); if (stat_func == FDFS_STAT_FUNC_STAT) { @@ -576,7 +580,7 @@ int trunk_file_do_lstat_func_ex(const FDFSStorePaths *pStorePaths, \ if (!IS_TRUNK_FILE(file_size)) //slave file { snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ - pStorePaths->paths[store_path_index], true_filename); + pStorePaths->paths[store_path_index].path, true_filename); if (stat_func == FDFS_STAT_FUNC_STAT) { diff --git a/storage/trunk_mgr/trunk_shared.h b/storage/trunk_mgr/trunk_shared.h index db2513c..9fcab70 100644 --- a/storage/trunk_mgr/trunk_shared.h +++ b/storage/trunk_mgr/trunk_shared.h @@ -48,6 +48,20 @@ #define TRUNK_GET_FILENAME(file_id, filename) \ sprintf(filename, "%06d", file_id) +typedef struct +{ + int total_mb; //total spaces + int free_mb; //free spaces + int path_len; //the length of store path + char *path; //file store path + char *mark; //path mark to avoid confusion +} FDFSStorePathInfo; + +typedef struct { + int count; //store path count + FDFSStorePathInfo *paths; //file store paths +} FDFSStorePaths; + #ifdef __cplusplus extern "C" { #endif @@ -84,9 +98,9 @@ typedef struct tagFDFSTrunkFullInfo { FDFSTrunkFileInfo file; } FDFSTrunkFullInfo; -char **storage_load_paths_from_conf_file_ex(IniContext *pItemContext, \ - const char *szSectionName, const bool bUseBasePath, \ - int *path_count, int *err_no); +FDFSStorePathInfo *storage_load_paths_from_conf_file_ex( + IniContext *pItemContext, const char *szSectionName, + const bool bUseBasePath, int *path_count, int *err_no); int storage_load_paths_from_conf_file(IniContext *pItemContext); void trunk_shared_init(); diff --git a/tracker/tracker_types.h b/tracker/tracker_types.h index 3974f2c..8e7bb75 100644 --- a/tracker/tracker_types.h +++ b/tracker/tracker_types.h @@ -464,11 +464,6 @@ typedef struct { } rs; } FDFSStorageReservedSpace; -typedef struct { - int count; //store path count - char **paths; //file store paths -} FDFSStorePaths; - typedef struct { TrackerServerInfo *pTrackerServer; int running_time; //running seconds, more means higher weight