adapt to libfastcommon 1.70 and libserverframe 1.2.0

use_libfastcommon1.70
YuQing 2023-10-12 17:55:11 +08:00
parent 4b42ed9fe2
commit e7caa614cf
9 changed files with 542 additions and 533 deletions

View File

@ -1,11 +1,13 @@
Version 6.10.0 2023-09-07
* use libfastcommon V1.70 and libserverframe 1.2.0
Version 6.9.5 2023-06-05 Version 6.9.5 2023-06-05
* fix possible out-of-bounds issues with array access * fix possible out-of-bounds issues with array access
* fix realloc mistakes to avoid memory leaks * fix realloc mistakes to avoid memory leaks
* add ExecStartPost=/bin/sleep 0.1 to systemd service files * add ExecStartPost=/bin/sleep 0.1 to systemd service files
* fdht_client/fdht_func.c: fixed compile error * fdht_client/fdht_func.c: fixed compile error
Version 6.9.4 2023-02-15 Version 6.9.4 2023-02-15
* use epoll edge trigger to resolve github issues #608 * use epoll edge trigger to resolve github issues #608
* bugfixed: report connections' current_count and max_count correctly * bugfixed: report connections' current_count and max_count correctly

View File

@ -250,7 +250,7 @@ int dio_discard_file(struct fast_task_info *pTask)
StorageFileContext *pFileContext; StorageFileContext *pFileContext;
pFileContext = &(((StorageClientInfo *)pTask->arg)->file_context); pFileContext = &(((StorageClientInfo *)pTask->arg)->file_context);
pFileContext->offset += pTask->length - pFileContext->buff_offset; pFileContext->offset += pTask->recv.ptr->length - pFileContext->buff_offset;
if (pFileContext->offset >= pFileContext->end) if (pFileContext->offset >= pFileContext->end)
{ {
pFileContext->done_callback(pTask, 0); pFileContext->done_callback(pTask, 0);
@ -331,16 +331,16 @@ int dio_read_file(struct fast_task_info *pTask)
} }
remain_bytes = pFileContext->end - pFileContext->offset; remain_bytes = pFileContext->end - pFileContext->offset;
capacity_bytes = pTask->size - pTask->length; capacity_bytes = pTask->send.ptr->size - pTask->send.ptr->length;
read_bytes = (capacity_bytes < remain_bytes) ? \ read_bytes = (capacity_bytes < remain_bytes) ? \
capacity_bytes : remain_bytes; capacity_bytes : remain_bytes;
/* /*
logInfo("###before dio read bytes: %d, pTask->length=%d, file offset=%ld", \ logInfo("###before dio read bytes: %d, pTask->length=%d, file offset=%ld", \
read_bytes, pTask->length, pFileContext->offset); read_bytes, pTask->send.ptr->length, pFileContext->offset);
*/ */
if (fc_safe_read(pFileContext->fd, pTask->data + pTask->length, \ if (fc_safe_read(pFileContext->fd, pTask->send.ptr->data + pTask->send.ptr->length, \
read_bytes) != read_bytes) read_bytes) != read_bytes)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
@ -364,17 +364,17 @@ int dio_read_file(struct fast_task_info *pTask)
if (pFileContext->calc_crc32) if (pFileContext->calc_crc32)
{ {
pFileContext->crc32 = CRC32_ex(pTask->data + pTask->length, pFileContext->crc32 = CRC32_ex(pTask->send.ptr->data + pTask->send.ptr->length,
read_bytes, pFileContext->crc32); read_bytes, pFileContext->crc32);
} }
pTask->length += read_bytes; pTask->send.ptr->length += read_bytes;
pFileContext->offset += read_bytes; pFileContext->offset += read_bytes;
/* /*
logInfo("###after dio read bytes: %d, pTask->length=%d, " logInfo("###after dio read bytes: %d, pTask->length=%d, "
"file offset=%"PRId64", file size: %"PRId64, read_bytes, "file offset=%"PRId64", file size: %"PRId64, read_bytes,
pTask->length, pFileContext->offset, pFileContext->end); pTask->send.ptr->length, pFileContext->offset, pFileContext->end);
*/ */
if (pFileContext->offset < pFileContext->end) if (pFileContext->offset < pFileContext->end)
@ -441,8 +441,8 @@ int dio_write_file(struct fast_task_info *pTask)
} }
} }
pDataBuff = pTask->data + pFileContext->buff_offset; pDataBuff = pTask->recv.ptr->data + pFileContext->buff_offset;
write_bytes = pTask->length - pFileContext->buff_offset; write_bytes = pTask->recv.ptr->length - pFileContext->buff_offset;
if (fc_safe_write(pFileContext->fd, pDataBuff, write_bytes) != write_bytes) if (fc_safe_write(pFileContext->fd, pDataBuff, write_bytes) != write_bytes)
{ {
result = errno != 0 ? errno : EIO; result = errno != 0 ? errno : EIO;
@ -488,7 +488,7 @@ int dio_write_file(struct fast_task_info *pTask)
/* /*
logInfo("###dio fd: %d, write bytes: %d, pTask->length=%d, " logInfo("###dio fd: %d, write bytes: %d, pTask->length=%d, "
"buff_offset=%d", pFileContext->fd, write_bytes, "buff_offset=%d", pFileContext->fd, write_bytes,
pTask->length, pFileContext->buff_offset); pTask->recv.ptr->length, pFileContext->buff_offset);
*/ */
pFileContext->offset += write_bytes; pFileContext->offset += write_bytes;

View File

@ -365,7 +365,7 @@ static int fdfs_dump_storage_stat(char *buff, const int buffSize)
"last_synced_timestamp=%s\n" "last_synced_timestamp=%s\n"
"last_heart_beat_time=%s\n", "last_heart_beat_time=%s\n",
g_stat_change_count, g_sync_change_count, g_stat_change_count, g_sync_change_count,
free_queue_alloc_connections(), free_queue_alloc_connections(&g_sf_context.free_queue),
SF_G_CONN_CURRENT_COUNT, SF_G_CONN_CURRENT_COUNT,
SF_G_CONN_MAX_COUNT, SF_G_CONN_MAX_COUNT,
g_storage_stat.total_upload_count, g_storage_stat.total_upload_count,

View File

@ -1403,6 +1403,7 @@ static int init_my_result_per_tracker()
int storage_func_init(const char *filename) int storage_func_init(const char *filename)
{ {
const int fixed_buffer_size = 0;
const int task_buffer_extra_size = 0; const int task_buffer_extra_size = 0;
const bool need_set_run_by = false; const bool need_set_run_by = false;
char *pGroupName; char *pGroupName;
@ -1439,11 +1440,11 @@ int storage_func_init(const char *filename)
sf_set_current_time(); sf_set_current_time();
SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, &iniContext, SF_SET_CONTEXT_INI_CONFIG_EX(config, fc_comm_type_sock, filename,
NULL, FDFS_STORAGE_SERVER_DEF_PORT, &iniContext, NULL, FDFS_STORAGE_SERVER_DEF_PORT,
FDFS_STORAGE_SERVER_DEF_PORT, DEFAULT_WORK_THREADS, FDFS_STORAGE_SERVER_DEF_PORT, DEFAULT_WORK_THREADS,
"buff_size"); "buff_size");
if ((result=sf_load_config_ex("storaged", &config, if ((result=sf_load_config_ex("storaged", &config, fixed_buffer_size,
task_buffer_extra_size, need_set_run_by)) != 0) task_buffer_extra_size, need_set_run_by)) != 0)
{ {
return result; return result;

View File

@ -423,11 +423,11 @@ static void storage_sync_delete_file_done_callback( \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader),
pHeader->pkg_len); pHeader->pkg_len);
sf_nio_notify(pTask, SF_NIO_STAGE_SEND); sf_nio_notify(pTask, SF_NIO_STAGE_SEND);
@ -463,8 +463,8 @@ static void storage_sync_truncate_file_done_callback( \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -569,8 +569,8 @@ static void storage_sync_copy_file_done_callback(struct fast_task_info *pTask, \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -645,8 +645,8 @@ static void storage_sync_modify_file_done_callback( \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -666,9 +666,9 @@ static void storage_get_metadata_done_callback(struct fast_task_info *pTask,
if (err_no != 0) if (err_no != 0)
{ {
__sync_add_and_fetch(&g_storage_stat.total_get_meta_count, 1); __sync_add_and_fetch(&g_storage_stat.total_get_meta_count, 1);
if (pTask->length == sizeof(TrackerHeader)) //never response if (pTask->send.ptr->length == sizeof(TrackerHeader)) //never response
{ {
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = err_no; pHeader->status = err_no;
sf_nio_notify(pTask, SF_NIO_STAGE_SEND); sf_nio_notify(pTask, SF_NIO_STAGE_SEND);
} }
@ -703,9 +703,9 @@ static void storage_download_file_done_callback( \
__sync_add_and_fetch(&g_storage_stat.total_download_bytes, __sync_add_and_fetch(&g_storage_stat.total_download_bytes,
pFileContext->offset - pFileContext->start); pFileContext->offset - pFileContext->start);
if (pTask->length == sizeof(TrackerHeader)) //never response if (pTask->send.ptr->length == sizeof(TrackerHeader)) //never response
{ {
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = err_no; pHeader->status = err_no;
sf_nio_notify(pTask, SF_NIO_STAGE_SEND); sf_nio_notify(pTask, SF_NIO_STAGE_SEND);
} }
@ -1078,8 +1078,8 @@ static void storage_delete_fdfs_file_done_callback( \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -1149,7 +1149,7 @@ static void storage_upload_file_done_callback(struct fast_task_info *pTask, \
filename_len = strlen(pFileContext->fname2log); filename_len = strlen(pFileContext->fname2log);
pClientInfo->total_length = sizeof(TrackerHeader) + \ pClientInfo->total_length = sizeof(TrackerHeader) + \
FDFS_GROUP_NAME_MAX_LEN + filename_len; FDFS_GROUP_NAME_MAX_LEN + filename_len;
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
memcpy(p, pFileContext->extra_info.upload.group_name, \ memcpy(p, pFileContext->extra_info.upload.group_name, \
FDFS_GROUP_NAME_MAX_LEN); FDFS_GROUP_NAME_MAX_LEN);
p += FDFS_GROUP_NAME_MAX_LEN; p += FDFS_GROUP_NAME_MAX_LEN;
@ -1170,9 +1170,9 @@ static void storage_upload_file_done_callback(struct fast_task_info *pTask, \
STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_UPLOAD_FILE, result); STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_UPLOAD_FILE, result);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -1240,7 +1240,7 @@ static void storage_trunk_create_link_file_done_callback( \
filename_len = strlen(pFileContext->fname2log); filename_len = strlen(pFileContext->fname2log);
pClientInfo->total_length = sizeof(TrackerHeader) + \ pClientInfo->total_length = sizeof(TrackerHeader) + \
FDFS_GROUP_NAME_MAX_LEN + filename_len; FDFS_GROUP_NAME_MAX_LEN + filename_len;
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
memcpy(p, pFileContext->extra_info.upload.group_name, \ memcpy(p, pFileContext->extra_info.upload.group_name, \
FDFS_GROUP_NAME_MAX_LEN); FDFS_GROUP_NAME_MAX_LEN);
p += FDFS_GROUP_NAME_MAX_LEN; p += FDFS_GROUP_NAME_MAX_LEN;
@ -1258,9 +1258,9 @@ static void storage_trunk_create_link_file_done_callback( \
if (pCreateLinkArg->need_response) if (pCreateLinkArg->need_response)
{ {
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -1327,9 +1327,9 @@ static void storage_append_file_done_callback(struct fast_task_info *pTask, \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(0, pHeader->pkg_len); long2buff(0, pHeader->pkg_len);
@ -1396,9 +1396,9 @@ static void storage_modify_file_done_callback(struct fast_task_info *pTask, \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(0, pHeader->pkg_len); long2buff(0, pHeader->pkg_len);
@ -1459,9 +1459,9 @@ static void storage_do_truncate_file_done_callback(struct fast_task_info *pTask,
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(0, pHeader->pkg_len); long2buff(0, pHeader->pkg_len);
@ -1513,8 +1513,8 @@ static void storage_set_metadata_done_callback( \
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -1544,7 +1544,7 @@ int storage_set_body_length(struct fast_task_info *pTask)
if (pClientInfo->total_length == 0) //header if (pClientInfo->total_length == 0) //header
{ {
total_length = buff2long(((TrackerHeader *) total_length = buff2long(((TrackerHeader *)
pTask->data)->pkg_len); pTask->recv.ptr->data)->pkg_len);
if (total_length < 0) if (total_length < 0)
{ {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
@ -1554,13 +1554,14 @@ int storage_set_body_length(struct fast_task_info *pTask)
} }
pClientInfo->total_length = total_length + sizeof(TrackerHeader); pClientInfo->total_length = total_length + sizeof(TrackerHeader);
if (pClientInfo->total_length > pTask->size) if (pClientInfo->total_length > pTask->recv.ptr->size)
{ {
pTask->length = pTask->size - sizeof(TrackerHeader); pTask->recv.ptr->length = pTask->recv.ptr->size -
sizeof(TrackerHeader);
} }
else else
{ {
pTask->length = total_length; pTask->recv.ptr->length = total_length;
} }
} }
@ -1595,8 +1596,8 @@ static int sock_send_done_callback(struct fast_task_info *pTask,
pClientInfo->total_offset += length; pClientInfo->total_offset += length;
if (pClientInfo->total_offset >= pClientInfo->total_length) if (pClientInfo->total_offset >= pClientInfo->total_length)
{ {
if (pClientInfo->total_length == sizeof(TrackerHeader) if (pClientInfo->total_length == sizeof(TrackerHeader) &&
&& ((TrackerHeader *)pTask->data)->status == EINVAL) ((TrackerHeader *)pTask->send.ptr->data)->status == EINVAL)
{ {
logDebug("file: "__FILE__", line: %d, " logDebug("file: "__FILE__", line: %d, "
"close conn: #%d, client ip: %s", "close conn: #%d, client ip: %s",
@ -2424,16 +2425,16 @@ static int storage_nio_notify(struct fast_task_info *pTask, const int stage)
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
if (stage == SF_NIO_STAGE_RECV) if (stage == SF_NIO_STAGE_RECV)
{ {
pTask->offset = 0; pTask->recv.ptr->offset = 0;
remain_bytes = pClientInfo->total_length - remain_bytes = pClientInfo->total_length -
pClientInfo->total_offset; pClientInfo->total_offset;
if (remain_bytes > pTask->size) if (remain_bytes > pTask->recv.ptr->size)
{ {
pTask->length = pTask->size; pTask->recv.ptr->length = pTask->recv.ptr->size;
} }
else else
{ {
pTask->length = remain_bytes; pTask->recv.ptr->length = remain_bytes;
} }
} }
@ -2443,7 +2444,7 @@ static int storage_nio_notify(struct fast_task_info *pTask, const int stage)
static int calc_crc32_continue_callback(struct fast_task_info *pTask, static int calc_crc32_continue_callback(struct fast_task_info *pTask,
const int stage) const int stage)
{ {
pTask->length = 0; pTask->send.ptr->length = 0;
return storage_dio_queue_push(pTask); return storage_dio_queue_push(pTask);
} }
@ -2509,27 +2510,27 @@ static int storage_trunk_create_link(struct fast_task_info *pTask, \
return result; return result;
} }
pTask->length = pTask->size; pTask->send.ptr->length = pTask->send.ptr->size;
p = pTask->data + (pTask->length - sizeof(TrunkCreateLinkArg) \ p = pTask->send.ptr->data + (pTask->send.ptr->length -
- file_bytes); sizeof(TrunkCreateLinkArg) - file_bytes);
if (p < pTask->data + sizeof(TrackerHeader)) if (p < pTask->send.ptr->data + sizeof(TrackerHeader))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"task buffer size: %d is too small", \ "task buffer size: %d is too small", \
__LINE__, pTask->size); __LINE__, pTask->send.ptr->size);
return ENOSPC; return ENOSPC;
} }
pCreateLinkArg = (TrunkCreateLinkArg *)p; pCreateLinkArg = (TrunkCreateLinkArg *)p;
memcpy(&(pCreateLinkArg->src_file_info), pSourceFileInfo, \ memcpy(&(pCreateLinkArg->src_file_info), pSourceFileInfo,
sizeof(SourceFileInfo)); sizeof(SourceFileInfo));
pCreateLinkArg->need_response = bNeedReponse; pCreateLinkArg->need_response = bNeedReponse;
pClientInfo->extra_arg = (void *)pCreateLinkArg; pClientInfo->extra_arg = (void *)pCreateLinkArg;
p += sizeof(TrunkCreateLinkArg); p += sizeof(TrunkCreateLinkArg);
memcpy(p, src_filename, file_bytes); memcpy(p, src_filename, file_bytes);
storage_trunk_do_create_link(pTask, file_bytes, p - pTask->data, \ storage_trunk_do_create_link(pTask, file_bytes, p - pTask->send.ptr->data,
dio_check_trunk_file_when_upload, \ dio_check_trunk_file_when_upload,
storage_trunk_create_link_file_done_callback); storage_trunk_create_link_file_done_callback);
return TASK_STATUS_CONTINUE; return TASK_STATUS_CONTINUE;
} }
@ -2925,20 +2926,18 @@ static int storage_server_set_metadata(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
if (nInPackLen + sizeof(TrackerHeader) >= pTask->size) if (pClientInfo->total_length >= pTask->recv.ptr->size)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, "
"cmd=%d, client ip: %s, package size " \ "cmd=%d, client ip: %s, package size "
"%"PRId64" is not correct, " \ "%"PRId64" is not correct, "
"expect length < %d", \ "expect length < %d", __LINE__,
__LINE__, STORAGE_PROTO_CMD_SET_METADATA, \ STORAGE_PROTO_CMD_SET_METADATA, pTask->client_ip,
pTask->client_ip, nInPackLen, \ pClientInfo->total_length, pTask->recv.ptr->size);
pTask->size - (int)sizeof(TrackerHeader));
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename_len = buff2long(p); filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
meta_bytes = buff2long(p); meta_bytes = buff2long(p);
@ -3069,7 +3068,7 @@ static int storage_server_report_server_id(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
storage_server_id = pTask->data + sizeof(TrackerHeader); storage_server_id = pTask->recv.ptr->data + sizeof(TrackerHeader);
*(storage_server_id + (FDFS_STORAGE_ID_MAX_SIZE - 1)) = '\0'; *(storage_server_id + (FDFS_STORAGE_ID_MAX_SIZE - 1)) = '\0';
if (*storage_server_id == '\0') if (*storage_server_id == '\0')
{ {
@ -3130,7 +3129,7 @@ static int storage_server_trunk_sync_binlog(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
binlog_buff = pTask->data + sizeof(TrackerHeader); binlog_buff = pTask->send.ptr->data + sizeof(TrackerHeader);
return trunk_binlog_write_buffer(binlog_buff, nInPackLen); return trunk_binlog_write_buffer(binlog_buff, nInPackLen);
} }
@ -3139,7 +3138,7 @@ static int query_file_info_response(struct fast_task_info *pTask,
{ {
char *p; char *p;
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
long2buff(finfo->fsize, p); long2buff(finfo->fsize, p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
long2buff(finfo->mtime, p); long2buff(finfo->mtime, p);
@ -3174,7 +3173,7 @@ static int query_file_info_response(struct fast_task_info *pTask,
} }
p += IP_ADDRESS_SIZE; p += IP_ADDRESS_SIZE;
((StorageClientInfo *)pTask->arg)->total_length = p - pTask->data; ((StorageClientInfo *)pTask->arg)->total_length = p - pTask->send.ptr->data;
return 0; return 0;
} }
@ -3205,12 +3204,12 @@ static void calc_crc32_done_callback_for_query_finfo(
fast_mblock_free_object(&finfo_for_crc32_allocator, crc32_file_info); fast_mblock_free_object(&finfo_for_crc32_allocator, crc32_file_info);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pTask->length - sizeof(TrackerHeader), pHeader->pkg_len); long2buff(pTask->send.ptr->length - sizeof(TrackerHeader), pHeader->pkg_len);
STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_QUERY_FILE, result); STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_QUERY_FILE, result);
sf_nio_notify(pTask, SF_NIO_STAGE_SEND); sf_nio_notify(pTask, SF_NIO_STAGE_SEND);
@ -3342,14 +3341,14 @@ static int storage_server_query_file_info(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
in_buff = pTask->data + sizeof(TrackerHeader); in_buff = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename = in_buff + FDFS_GROUP_NAME_MAX_LEN; filename = in_buff + FDFS_GROUP_NAME_MAX_LEN;
*(filename + filename_len) = '\0'; *(filename + filename_len) = '\0';
STORAGE_ACCESS_STRCPY_FNAME2LOG(filename, filename_len, \ STORAGE_ACCESS_STRCPY_FNAME2LOG(filename, filename_len, \
pClientInfo); pClientInfo);
bSilence = ((TrackerHeader *)pTask->data)->status != 0; bSilence = ((TrackerHeader *)pTask->recv.ptr->data)->status != 0;
memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
if (strcmp(group_name, g_group_name) != 0) if (strcmp(group_name, g_group_name) != 0)
@ -3551,7 +3550,7 @@ static int storage_server_trunk_alloc_space(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
in_buff = pTask->data + sizeof(TrackerHeader); in_buff = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
if (strcmp(group_name, g_group_name) != 0) if (strcmp(group_name, g_group_name) != 0)
@ -3588,7 +3587,7 @@ static int storage_server_trunk_alloc_space(struct fast_task_info *pTask)
return result; return result;
} }
pApplyBody = (FDFSTrunkInfoBuff *)(pTask->data+sizeof(TrackerHeader)); pApplyBody = (FDFSTrunkInfoBuff *)(pTask->send.ptr->data+sizeof(TrackerHeader));
pApplyBody->store_path_index = trunkInfo.path.store_path_index; pApplyBody->store_path_index = trunkInfo.path.store_path_index;
pApplyBody->sub_path_high = trunkInfo.path.sub_path_high; pApplyBody->sub_path_high = trunkInfo.path.sub_path_high;
pApplyBody->sub_path_low = trunkInfo.path.sub_path_low; pApplyBody->sub_path_low = trunkInfo.path.sub_path_low;
@ -3596,7 +3595,7 @@ static int storage_server_trunk_alloc_space(struct fast_task_info *pTask)
int2buff(trunkInfo.file.offset, pApplyBody->offset); int2buff(trunkInfo.file.offset, pApplyBody->offset);
int2buff(trunkInfo.file.size, pApplyBody->size); int2buff(trunkInfo.file.size, pApplyBody->size);
pClientInfo->total_length = sizeof(TrackerHeader) + \ pClientInfo->total_length = sizeof(TrackerHeader) +
sizeof(FDFSTrunkInfoBuff); sizeof(FDFSTrunkInfoBuff);
return 0; return 0;
} }
@ -3616,7 +3615,7 @@ static int storage_server_trunk_get_binlog_size(struct fast_task_info *pTask)
struct stat file_stat; struct stat file_stat;
int64_t nInPackLen; int64_t nInPackLen;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->recv.ptr->data;
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader); nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader);
@ -3650,7 +3649,7 @@ static int storage_server_trunk_get_binlog_size(struct fast_task_info *pTask)
return errno != 0 ? errno : ENOENT; return errno != 0 ? errno : ENOENT;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
long2buff(file_stat.st_size, p); long2buff(file_stat.st_size, p);
pClientInfo->total_length = sizeof(TrackerHeader) pClientInfo->total_length = sizeof(TrackerHeader)
@ -3664,7 +3663,7 @@ static int storage_server_trunk_truncate_binlog_file(struct fast_task_info *pTas
TrackerHeader *pHeader; TrackerHeader *pHeader;
int64_t nInPackLen; int64_t nInPackLen;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->recv.ptr->data;
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader); nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader);
pClientInfo->total_length = sizeof (TrackerHeader); pClientInfo->total_length = sizeof (TrackerHeader);
@ -3706,7 +3705,7 @@ static int storage_server_trunk_delete_binlog_marks(struct fast_task_info *pTask
int64_t nInPackLen; int64_t nInPackLen;
int result; int result;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->recv.ptr->data;
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader); nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader);
pClientInfo->total_length = sizeof (TrackerHeader); pClientInfo->total_length = sizeof (TrackerHeader);
@ -3767,7 +3766,7 @@ static int storage_server_trunk_confirm_or_free(struct fast_task_info *pTask)
FDFSTrunkFullInfo trunkInfo; FDFSTrunkFullInfo trunkInfo;
int64_t nInPackLen; int64_t nInPackLen;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->recv.ptr->data;
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader); nInPackLen = pClientInfo->total_length - sizeof(TrackerHeader);
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
@ -3785,7 +3784,7 @@ static int storage_server_trunk_confirm_or_free(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
in_buff = pTask->data + sizeof(TrackerHeader); in_buff = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
if (strcmp(group_name, g_group_name) != 0) if (strcmp(group_name, g_group_name) != 0)
@ -3862,7 +3861,7 @@ static int storage_server_fetch_one_path_binlog_dealer(
store_path_index = pFileContext->extra_info.upload.trunk_info. store_path_index = pFileContext->extra_info.upload.trunk_info.
path.store_path_index; path.store_path_index;
pBasePath = g_fdfs_store_paths.paths[store_path_index].path; pBasePath = g_fdfs_store_paths.paths[store_path_index].path;
pOutBuff = pTask->data; pOutBuff = pTask->send.ptr->data;
bLast = false; bLast = false;
sprintf(diskLogicPath, "%c"FDFS_STORAGE_DATA_DIR_FORMAT, sprintf(diskLogicPath, "%c"FDFS_STORAGE_DATA_DIR_FORMAT,
@ -4034,7 +4033,7 @@ static int storage_server_fetch_one_path_binlog_dealer(
paths[store_path_index].path_len + 6); paths[store_path_index].path_len + 6);
} }
if (pTask->size - (pOutBuff - pTask->data) < if (pTask->send.ptr->size - (pOutBuff - pTask->send.ptr->data) <
STORAGE_BINLOG_LINE_SIZE + FDFS_PROTO_PKG_LEN_SIZE) STORAGE_BINLOG_LINE_SIZE + FDFS_PROTO_PKG_LEN_SIZE)
{ {
break; break;
@ -4055,14 +4054,14 @@ static int storage_server_fetch_one_path_binlog_dealer(
return result; return result;
} }
pTask->length = pOutBuff - pTask->data; pTask->send.ptr->length = pOutBuff - pTask->send.ptr->data;
if (bLast) if (bLast)
{ {
pkg_len = pClientInfo->total_offset + pTask->length - pkg_len = pClientInfo->total_offset + pTask->send.ptr->length -
sizeof(TrackerHeader); sizeof(TrackerHeader);
long2buff(pkg_len, pOutBuff); long2buff(pkg_len, pOutBuff);
pTask->length += FDFS_PROTO_PKG_LEN_SIZE; pTask->send.ptr->length += FDFS_PROTO_PKG_LEN_SIZE;
pClientInfo->total_length = pkg_len + FDFS_PROTO_PKG_LEN_SIZE pClientInfo->total_length = pkg_len + FDFS_PROTO_PKG_LEN_SIZE
+ STORAGE_LAST_AHEAD_BYTES; + STORAGE_LAST_AHEAD_BYTES;
} }
@ -4151,8 +4150,8 @@ static int storage_server_do_fetch_one_path_binlog(
pClientInfo->total_length = INFINITE_FILE_SIZE + pClientInfo->total_length = INFINITE_FILE_SIZE +
sizeof(TrackerHeader); sizeof(TrackerHeader);
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = sizeof(TrackerHeader); pTask->send.ptr->length = sizeof(TrackerHeader);
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = 0; pHeader->status = 0;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), long2buff(pClientInfo->total_length - sizeof(TrackerHeader),
@ -4189,7 +4188,7 @@ static int storage_server_fetch_one_path_binlog(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
in_buff = pTask->data + sizeof(TrackerHeader); in_buff = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, in_buff, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
if (strcmp(group_name, g_group_name) != 0) if (strcmp(group_name, g_group_name) != 0)
@ -4255,7 +4254,7 @@ static int storage_upload_file(struct fast_task_info *pTask, bool bAppenderFile)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
store_path_index = *p++; store_path_index = *p++;
if (store_path_index == -1) if (store_path_index == -1)
@ -4404,9 +4403,9 @@ static int storage_upload_file(struct fast_task_info *pTask, bool bAppenderFile)
} }
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, file_offset, file_bytes, \ return storage_write_to_file(pTask, file_offset, file_bytes,
p - pTask->data, dio_write_file, \ p - pTask->recv.ptr->data, dio_write_file,
storage_upload_file_done_callback, \ storage_upload_file_done_callback,
clean_func, store_path_index); clean_func, store_path_index);
} }
@ -4527,7 +4526,7 @@ static void calc_crc32_done_callback_for_regenerate(
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
pFileContext = &(pClientInfo->file_context); pFileContext = &(pClientInfo->file_context);
crc32_file_info = (StorageFileInfoForCRC32 *)pClientInfo->extra_arg; crc32_file_info = (StorageFileInfoForCRC32 *)pClientInfo->extra_arg;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
if (err_no == 0) if (err_no == 0)
{ {
@ -4587,7 +4586,7 @@ static void calc_crc32_done_callback_for_regenerate(
pClientInfo->total_length = sizeof(TrackerHeader) + pClientInfo->total_length = sizeof(TrackerHeader) +
FDFS_GROUP_NAME_MAX_LEN + filename_len; FDFS_GROUP_NAME_MAX_LEN + filename_len;
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
memcpy(p, g_group_name, FDFS_GROUP_NAME_MAX_LEN); memcpy(p, g_group_name, FDFS_GROUP_NAME_MAX_LEN);
p += FDFS_GROUP_NAME_MAX_LEN; p += FDFS_GROUP_NAME_MAX_LEN;
memcpy(p, return_filename, filename_len); memcpy(p, return_filename, filename_len);
@ -4615,11 +4614,11 @@ static void calc_crc32_done_callback_for_regenerate(
} }
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pTask->length - sizeof(TrackerHeader), pHeader->pkg_len); long2buff(pTask->send.ptr->length - sizeof(TrackerHeader), pHeader->pkg_len);
STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_RENAME_FILE, result); STORAGE_ACCESS_LOG(pTask, ACCESS_LOG_ACTION_RENAME_FILE, result);
sf_nio_notify(pTask, SF_NIO_STAGE_SEND); sf_nio_notify(pTask, SF_NIO_STAGE_SEND);
@ -4657,7 +4656,7 @@ static int storage_server_regenerate_appender_filename(struct fast_task_info *pT
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(appender_filename, p, appender_filename_len); memcpy(appender_filename, p, appender_filename_len);
*(appender_filename + appender_filename_len) = '\0'; *(appender_filename + appender_filename_len) = '\0';
@ -4720,7 +4719,7 @@ static int storage_append_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
appender_filename_len = buff2long(p); appender_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -4784,7 +4783,7 @@ static int storage_append_file(struct fast_task_info *pTask)
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, stat_buf.st_size, file_bytes, return storage_write_to_file(pTask, stat_buf.st_size, file_bytes,
p - pTask->data, dio_write_file, p - pTask->recv.ptr->data, dio_write_file,
storage_append_file_done_callback, storage_append_file_done_callback,
dio_append_finish_clean_up, store_path_index); dio_append_finish_clean_up, store_path_index);
} }
@ -4827,7 +4826,7 @@ static int storage_modify_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
appender_filename_len = buff2long(p); appender_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -4913,7 +4912,7 @@ static int storage_modify_file(struct fast_task_info *pTask)
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, file_offset, file_bytes, return storage_write_to_file(pTask, file_offset, file_bytes,
p - pTask->data, dio_write_file, p - pTask->recv.ptr->data, dio_write_file,
storage_modify_file_done_callback, storage_modify_file_done_callback,
dio_modify_finish_clean_up, store_path_index); dio_modify_finish_clean_up, store_path_index);
} }
@ -4956,7 +4955,7 @@ static int storage_do_truncate_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
appender_filename_len = buff2long(p); appender_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -5142,7 +5141,7 @@ static int storage_upload_slave_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
master_filename_len = buff2long(p); master_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -5323,8 +5322,8 @@ static int storage_upload_slave_file(struct fast_task_info *pTask)
| g_extra_open_file_flags; | g_extra_open_file_flags;
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, 0, file_bytes, p - pTask->data, \ return storage_write_to_file(pTask, 0, file_bytes, p - pTask->recv.
dio_write_file, storage_upload_file_done_callback, \ ptr->data, dio_write_file, storage_upload_file_done_callback,
dio_write_finish_clean_up, store_path_index); dio_write_finish_clean_up, store_path_index);
} }
@ -5372,7 +5371,7 @@ static int storage_sync_copy_file(struct fast_task_info *pTask, \
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename_len = buff2long(p); filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -5412,7 +5411,7 @@ static int storage_sync_copy_file(struct fast_task_info *pTask, \
return EINVAL; return EINVAL;
} }
have_file_content = ((TrackerHeader *)pTask->data)->status == 0; have_file_content = ((TrackerHeader *)pTask->recv.ptr->data)->status == 0;
if (have_file_content) if (have_file_content)
{ {
if (file_bytes != nInPackLen - (2*FDFS_PROTO_PKG_LEN_SIZE + \ if (file_bytes != nInPackLen - (2*FDFS_PROTO_PKG_LEN_SIZE + \
@ -5632,9 +5631,9 @@ static int storage_sync_copy_file(struct fast_task_info *pTask, \
if (have_file_content) if (have_file_content)
{ {
return storage_write_to_file(pTask, file_offset, file_bytes, \ return storage_write_to_file(pTask, file_offset, file_bytes,
p - pTask->data, deal_func, \ p - pTask->recv.ptr->data, deal_func,
storage_sync_copy_file_done_callback, \ storage_sync_copy_file_done_callback,
clean_func, store_path_index); clean_func, store_path_index);
} }
else else
@ -5687,7 +5686,7 @@ static int storage_sync_append_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename_len = buff2long(p); filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -5859,9 +5858,9 @@ static int storage_sync_append_file(struct fast_task_info *pTask)
pFileContext->extra_info.upload.before_close_callback = NULL; pFileContext->extra_info.upload.before_close_callback = NULL;
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, start_offset, append_bytes, \ return storage_write_to_file(pTask, start_offset, append_bytes,
p - pTask->data, deal_func, \ p - pTask->recv.ptr->data, deal_func,
storage_sync_modify_file_done_callback, \ storage_sync_modify_file_done_callback,
dio_append_finish_clean_up, store_path_index); dio_append_finish_clean_up, store_path_index);
} }
@ -5909,7 +5908,7 @@ static int storage_sync_modify_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename_len = buff2long(p); filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -6054,9 +6053,9 @@ static int storage_sync_modify_file(struct fast_task_info *pTask)
pFileContext->extra_info.upload.before_close_callback = NULL; pFileContext->extra_info.upload.before_close_callback = NULL;
pFileContext->continue_callback = storage_nio_notify; pFileContext->continue_callback = storage_nio_notify;
return storage_write_to_file(pTask, start_offset, modify_bytes, \ return storage_write_to_file(pTask, start_offset, modify_bytes,
p - pTask->data, deal_func, \ p - pTask->recv.ptr->data, deal_func,
storage_sync_modify_file_done_callback, \ storage_sync_modify_file_done_callback,
dio_modify_finish_clean_up, store_path_index); dio_modify_finish_clean_up, store_path_index);
} }
@ -6101,7 +6100,7 @@ static int storage_sync_truncate_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
filename_len = buff2long(p); filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -6281,7 +6280,7 @@ static int storage_do_sync_link_file(struct fast_task_info *pTask)
do do
{ {
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
dest_filename_len = buff2long(p); dest_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -6402,19 +6401,20 @@ static int storage_do_sync_link_file(struct fast_task_info *pTask)
formatted_ext_name, \ formatted_ext_name, \
destTrunkHeader.formatted_ext_name); destTrunkHeader.formatted_ext_name);
pTask->length = pTask->size; pTask->send.ptr->length = pTask->send.ptr->size;
p = pTask->data + (pTask->length - src_filename_len); p = pTask->send.ptr->data + (pTask->send.
if (p < pTask->data + sizeof(TrackerHeader)) ptr->length - src_filename_len);
if (p < pTask->send.ptr->data + sizeof(TrackerHeader))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"task buffer size: %d is too small", \ "task buffer size: %d is too small", \
__LINE__, pTask->size); __LINE__, pTask->send.ptr->size);
break; break;
} }
memcpy(p, src_filename, src_filename_len); memcpy(p, src_filename, src_filename_len);
result = storage_trunk_do_create_link(pTask, \ result = storage_trunk_do_create_link(pTask, \
src_filename_len, p - pTask->data, \ src_filename_len, p - pTask->send.ptr->data, \
dio_check_trunk_file_when_sync, NULL); dio_check_trunk_file_when_sync, NULL);
if (result != 0) if (result != 0)
{ {
@ -6466,8 +6466,8 @@ static int storage_do_sync_link_file(struct fast_task_info *pTask)
CHECK_AND_WRITE_TO_STAT_FILE1 CHECK_AND_WRITE_TO_STAT_FILE1
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -6508,7 +6508,7 @@ static int storage_sync_link_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
dest_filename_len = buff2long(p); dest_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -6609,7 +6609,7 @@ static int storage_sync_rename_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
dest_filename_len = buff2long(p); dest_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -6742,19 +6742,18 @@ static int storage_server_get_metadata(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
if (nInPackLen >= pTask->size) if (pClientInfo->total_length >= pTask->recv.ptr->size)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, "
"cmd=%d, client ip: %s, package size " \ "cmd=%d, client ip: %s, package size "
"%"PRId64" is too large, " \ "%"PRId64" is too large, "
"expect length should < %d", __LINE__, \ "expect length should < %d", __LINE__,
STORAGE_PROTO_CMD_GET_METADATA, \ STORAGE_PROTO_CMD_GET_METADATA, pTask->client_ip,
pTask->client_ip, \ pClientInfo->total_length, pTask->recv.ptr->size);
nInPackLen, pTask->size);
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
@ -6869,19 +6868,19 @@ static int storage_server_download_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
if (nInPackLen >= pTask->size) if (pClientInfo->total_length >= pTask->recv.ptr->size)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, "
"cmd=%d, client ip: %s, package size " \ "cmd=%d, client ip: %s, package size "
"%"PRId64" is too large, " \ "%"PRId64" is too large, "
"expect length should < %d", __LINE__, \ "expect length should < %d", __LINE__,
STORAGE_PROTO_CMD_DOWNLOAD_FILE, \ STORAGE_PROTO_CMD_DOWNLOAD_FILE,
pTask->client_ip, \ pTask->client_ip, pClientInfo->total_length,
nInPackLen, pTask->size); pTask->recv.ptr->size);
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
file_offset = buff2long(p); file_offset = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
@ -7058,9 +7057,9 @@ static int storage_read_from_file(struct fast_task_info *pTask, \
pTask, store_path_index, pFileContext->op); pTask, store_path_index, pFileContext->op);
pFileContext->done_callback = done_callback; pFileContext->done_callback = done_callback;
pTask->length = sizeof(TrackerHeader); pTask->send.ptr->length = sizeof(TrackerHeader);
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = 0; pHeader->status = 0;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(download_bytes, pHeader->pkg_len); long2buff(download_bytes, pHeader->pkg_len);
@ -7171,18 +7170,19 @@ static int storage_sync_delete_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
if (nInPackLen >= pTask->size) if (pClientInfo->total_length >= pTask->recv.ptr->size)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, "
"cmd=%d, client ip: %s, package size " \ "cmd=%d, client ip: %s, package size "
"%"PRId64" is too large, " \ "%"PRId64" is too large, "
"expect length should < %d", __LINE__, \ "expect length should < %d", __LINE__,
STORAGE_PROTO_CMD_SYNC_DELETE_FILE, \ STORAGE_PROTO_CMD_SYNC_DELETE_FILE,
pTask->client_ip, nInPackLen, pTask->size); pTask->client_ip, pClientInfo->total_length,
pTask->recv.ptr->size);
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
pFileContext->timestamp2log = buff2int(p); pFileContext->timestamp2log = buff2int(p);
p += 4; p += 4;
memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN);
@ -7297,18 +7297,19 @@ static int storage_server_delete_file(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
if (nInPackLen >= pTask->size) if (pClientInfo->total_length >= pTask->recv.ptr->size)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, "
"cmd=%d, client ip: %s, package size " \ "cmd=%d, client ip: %s, package size "
"%"PRId64" is too large, " \ "%"PRId64" is too large, "
"expect length should < %d", __LINE__, \ "expect length should < %d", __LINE__,
STORAGE_PROTO_CMD_DELETE_FILE, \ STORAGE_PROTO_CMD_DELETE_FILE,
pTask->client_ip, nInPackLen, pTask->size); pTask->client_ip, pClientInfo->total_length,
pTask->recv.ptr->size);
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN); memcpy(group_name, p, FDFS_GROUP_NAME_MAX_LEN);
*(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0'; *(group_name + FDFS_GROUP_NAME_MAX_LEN) = '\0';
p += FDFS_GROUP_NAME_MAX_LEN; p += FDFS_GROUP_NAME_MAX_LEN;
@ -7722,7 +7723,7 @@ static int storage_do_create_link(struct fast_task_info *pTask)
break; break;
} }
p = pTask->data + sizeof(TrackerHeader); p = pTask->recv.ptr->data + sizeof(TrackerHeader);
master_filename_len = buff2long(p); master_filename_len = buff2long(p);
p += FDFS_PROTO_PKG_LEN_SIZE; p += FDFS_PROTO_PKG_LEN_SIZE;
src_filename_len = buff2long(p); src_filename_len = buff2long(p);
@ -7858,14 +7859,14 @@ static int storage_do_create_link(struct fast_task_info *pTask)
if (result == 0) if (result == 0)
{ {
pClientInfo->total_length += FDFS_GROUP_NAME_MAX_LEN + filename_len; pClientInfo->total_length += FDFS_GROUP_NAME_MAX_LEN + filename_len;
p = pTask->data + sizeof(TrackerHeader); p = pTask->send.ptr->data + sizeof(TrackerHeader);
memcpy(p, g_group_name, FDFS_GROUP_NAME_MAX_LEN); memcpy(p, g_group_name, FDFS_GROUP_NAME_MAX_LEN);
memcpy(p + FDFS_GROUP_NAME_MAX_LEN, filename, filename_len); memcpy(p + FDFS_GROUP_NAME_MAX_LEN, filename, filename_len);
} }
pClientInfo->total_offset = 0; pClientInfo->total_offset = 0;
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \
@ -7907,7 +7908,7 @@ static int storage_create_link(struct fast_task_info *pTask)
return EINVAL; return EINVAL;
} }
p = pTask->data + sizeof(TrackerHeader) + FDFS_PROTO_PKG_LEN_SIZE; p = pTask->recv.ptr->data + sizeof(TrackerHeader) + FDFS_PROTO_PKG_LEN_SIZE;
src_filename_len = buff2long(p); src_filename_len = buff2long(p);
if (src_filename_len <= 0 || src_filename_len >= \ if (src_filename_len <= 0 || src_filename_len >= \
sizeof(src_filename)) sizeof(src_filename))
@ -7985,15 +7986,14 @@ static int storage_deal_task(struct fast_task_info *pTask, const int stage)
int result; int result;
pClientInfo = (StorageClientInfo *)pTask->arg; pClientInfo = (StorageClientInfo *)pTask->arg;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->recv.ptr->data;
if (pClientInfo->total_offset == 0) if (pClientInfo->total_offset == 0)
{ {
pClientInfo->total_offset = pTask->length; pClientInfo->total_offset = pTask->send.ptr->length;
} }
else else
{ {
pClientInfo->total_offset += pTask->length; pClientInfo->total_offset += pTask->send.ptr->length;
/* continue write to file */ /* continue write to file */
return storage_dio_queue_push(pTask); return storage_dio_queue_push(pTask);
@ -8164,12 +8164,12 @@ static int storage_deal_task(struct fast_task_info *pTask, const int stage)
{ {
pClientInfo->total_length = sizeof(TrackerHeader); pClientInfo->total_length = sizeof(TrackerHeader);
} }
pTask->length = pClientInfo->total_length; pTask->send.ptr->length = pClientInfo->total_length;
pHeader = (TrackerHeader *)pTask->data; pHeader = (TrackerHeader *)pTask->send.ptr->data;
pHeader->status = result; pHeader->status = result;
pHeader->cmd = STORAGE_PROTO_CMD_RESP; pHeader->cmd = STORAGE_PROTO_CMD_RESP;
long2buff(pClientInfo->total_length - sizeof(TrackerHeader), \ long2buff(pClientInfo->total_length - sizeof(TrackerHeader),
pHeader->pkg_len); pHeader->pkg_len);
sf_send_add_event(pTask); sf_send_add_event(pTask);
return result; return result;

View File

@ -2314,7 +2314,7 @@ static int tracker_heart_beat(ConnectionInfo *pTrackerServer,
pStatBuff = (FDFSStorageStatBuff *)( \ pStatBuff = (FDFSStorageStatBuff *)( \
out_buff + sizeof(TrackerHeader)); out_buff + sizeof(TrackerHeader));
int2buff(free_queue_alloc_connections(), int2buff(free_queue_alloc_connections(&g_sf_context.free_queue),
pStatBuff->connection.sz_alloc_count); pStatBuff->connection.sz_alloc_count);
int2buff(SF_G_CONN_CURRENT_COUNT, int2buff(SF_G_CONN_CURRENT_COUNT,
pStatBuff->connection.sz_current_count); pStatBuff->connection.sz_current_count);

View File

@ -126,6 +126,7 @@ static int tracker_load_storage_id_info(const char *config_filename, \
int tracker_load_from_conf_file(const char *filename) int tracker_load_from_conf_file(const char *filename)
{ {
const int fixed_buffer_size = 0;
const int task_buffer_extra_size = 0; const int task_buffer_extra_size = 0;
const bool need_set_run_by = false; const bool need_set_run_by = false;
char *pSlotMinSize; char *pSlotMinSize;
@ -171,11 +172,11 @@ int tracker_load_from_conf_file(const char *filename)
sf_set_current_time(); sf_set_current_time();
SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, &iniContext, SF_SET_CONTEXT_INI_CONFIG_EX(config, fc_comm_type_sock, filename,
NULL, FDFS_TRACKER_SERVER_DEF_PORT, &iniContext, NULL, FDFS_TRACKER_SERVER_DEF_PORT,
FDFS_TRACKER_SERVER_DEF_PORT, DEFAULT_WORK_THREADS, FDFS_TRACKER_SERVER_DEF_PORT, DEFAULT_WORK_THREADS,
"buff_size"); "buff_size");
if ((result=sf_load_config_ex("trackerd", &config, if ((result=sf_load_config_ex("trackerd", &config, fixed_buffer_size,
task_buffer_extra_size, need_set_run_by)) != 0) task_buffer_extra_size, need_set_run_by)) != 0)
{ {
return result; return result;

View File

@ -26,12 +26,13 @@
int fdfs_set_body_length(struct fast_task_info *pTask) int fdfs_set_body_length(struct fast_task_info *pTask)
{ {
pTask->length = buff2long(((TrackerHeader *)pTask->data)->pkg_len); pTask->recv.ptr->length = buff2long(((TrackerHeader *)
if (pTask->length < 0) pTask->recv.ptr->data)->pkg_len);
if (pTask->recv.ptr->length < 0)
{ {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
"client ip: %s, pkg length: %d < 0", "client ip: %s, pkg length: %d < 0", __LINE__,
__LINE__, pTask->client_ip, pTask->length); pTask->client_ip, pTask->recv.ptr->length);
return EINVAL; return EINVAL;
} }

File diff suppressed because it is too large Load Diff