⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage_func.c

📁 文件系统源代码!!!!! 文件系统源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			break;		}		memset(g_tracker_servers, 0, \			sizeof(TrackerServerInfo) * g_tracker_server_count); 		if ((result=copy_tracker_servers(filename, \				ppTrackerServers)) != 0)		{			free(g_tracker_servers);			g_tracker_servers = NULL;			break;		}		g_sync_wait_usec = iniGetIntValue("sync_wait_msec",\			 items, nItemCount, STORAGE_DEF_SYNC_WAIT_MSEC);		if (g_sync_wait_usec <= 0)		{			g_sync_wait_usec = STORAGE_DEF_SYNC_WAIT_MSEC;		}		g_sync_wait_usec *= 1000;		g_sync_interval = iniGetIntValue("sync_interval",\			 items, nItemCount, 0);		if (g_sync_interval < 0)		{			g_sync_interval = 0;		}		g_sync_interval *= 1000;		if ((result=storage_get_time(items, nItemCount, \			"sync_start_time", &g_sync_start_time, 0, 0)) != 0)		{			break;		}		if ((result=storage_get_time(items, nItemCount, \			"sync_end_time", &g_sync_end_time, 23, 59)) != 0)		{			break;		}		g_sync_part_time = !((g_sync_start_time.hour == 0 && \				g_sync_start_time.minute == 0) && \				(g_sync_end_time.hour == 23 && \				g_sync_end_time.minute == 59));		g_max_connections = iniGetIntValue("max_connections", \				items, nItemCount, DEFAULT_MAX_CONNECTONS);		if (g_max_connections <= 0)		{			g_max_connections = DEFAULT_MAX_CONNECTONS;		}		if ((result=set_rlimit(RLIMIT_NOFILE, g_max_connections)) != 0)		{			break;		}			pRunByGroup = iniGetStrValue("run_by_group", \						items, nItemCount);		pRunByUser = iniGetStrValue("run_by_user", \						items, nItemCount);		if ((result=set_run_by(pRunByGroup, pRunByUser)) != 0)		{			return result;		}		if ((result=load_allow_hosts(items, nItemCount, \                	 &g_allow_ip_addrs, &g_allow_ip_count)) != 0)		{			return result;		}		g_file_distribute_path_mode = iniGetIntValue( \			"file_distribute_path_mode", items, nItemCount, \			FDFS_FILE_DIST_PATH_ROUND_ROBIN);		g_file_distribute_rotate_count = iniGetIntValue( \			"file_distribute_rotate_count", items, nItemCount, \			FDFS_FILE_DIST_DEFAULT_ROTATE_COUNT);		if (g_file_distribute_rotate_count <= 0)		{			g_file_distribute_rotate_count = \				FDFS_FILE_DIST_DEFAULT_ROTATE_COUNT;		}		pFsyncAfterWrittenBytes = iniGetStrValue( \			"fsync_after_written_bytes", items, nItemCount);		if (pFsyncAfterWrittenBytes == NULL)		{			fsync_after_written_bytes = 0;		}		else if ((result=parse_bytes(pFsyncAfterWrittenBytes, 1, \				&fsync_after_written_bytes)) != 0)		{			return result;		}		g_fsync_after_written_bytes = fsync_after_written_bytes;		g_sync_log_buff_interval = iniGetIntValue( \				"sync_log_buff_interval", items, nItemCount, \				SYNC_LOG_BUFF_DEF_INTERVAL);		if (g_sync_log_buff_interval <= 0)		{			g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL;		}		logInfo("FastDFS v%d.%d, base_path=%s, store_path_count=%d, " \			"subdir_count_per_path=%d, group_name=%s, " \			"network_timeout=%ds, "\			"port=%d, bind_addr=%s, " \			"max_connections=%d, "    \			"heart_beat_interval=%ds, " \			"stat_report_interval=%ds, tracker_server_count=%d, " \			"sync_wait_msec=%dms, sync_interval=%dms, " \			"sync_start_time=%02d:%02d, sync_end_time: %02d:%02d, "\			"allow_ip_count=%d, " \			"file_distribute_path_mode=%d, " \			"file_distribute_rotate_count=%d, " \			"fsync_after_written_bytes=%d, " \			"sync_log_buff_interval=%ds", \			g_version.major, g_version.minor, \			g_base_path, g_path_count, g_subdir_count_per_path, \			g_group_name, g_network_timeout, \			g_server_port, bind_addr, g_max_connections, \			g_heart_beat_interval, g_stat_report_interval, \			g_tracker_server_count, g_sync_wait_usec / 1000, \			g_sync_interval / 1000, \			g_sync_start_time.hour, g_sync_start_time.minute, \			g_sync_end_time.hour, g_sync_end_time.minute, \			g_allow_ip_count, g_file_distribute_path_mode, \			g_file_distribute_rotate_count, \			g_fsync_after_written_bytes, g_sync_log_buff_interval);		break;	}	/*	if ((result=init_pthread_lock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"init_pthread_lock fail, program exit!", __LINE__);		return result;	}	if ((result=init_fsync_pthread_cond()) != 0)	{		return result;	}	*/	iniFreeItems(items);	if ((result=storage_check_and_make_data_dirs()) != 0)	{		logCrit("file: "__FILE__", line: %d, " \			"storage_check_and_make_data_dirs fail, " \			"program exit!", __LINE__);		return result;	}	if (result == 0)	{		return storage_open_storage_stat();	}	else	{		return result;	}}int storage_func_destroy(){	int i;	if (g_store_paths != NULL)	{		for (i=0; i<g_path_count; i++)		{			if (g_store_paths[i] != NULL)			{				free(g_store_paths[i]);				g_store_paths[i] = NULL;			}		}		g_store_paths = NULL;	}	if (g_tracker_servers != NULL)	{		free(g_tracker_servers);		g_tracker_servers = NULL;	}	return storage_close_storage_stat();}int storage_split_filename(const char *logic_filename, \		int *filename_len, \		char *true_filename, char **ppStorePath){	char buff[3];	int store_path_index;	char *pEnd;	if (*filename_len <= FDFS_FILE_PATH_LEN)	{		logError("file: "__FILE__", line: %d, " \			"filename_len: %d is invalid, <= %d", \			__LINE__, *filename_len, FDFS_FILE_PATH_LEN);		return EINVAL;	}	if (*logic_filename != STORAGE_STORE_PATH_PREFIX_CHAR)	{ //version < V1.12		memcpy(true_filename, logic_filename, (*filename_len)+1);		*ppStorePath = g_store_paths[0];		return 0;	}	if (*(logic_filename + 3) != '/')	{		logError("file: "__FILE__", line: %d, " \			"filename: %s is invalid", \			__LINE__, logic_filename);		return EINVAL;	}	*buff = *(logic_filename+1);	*(buff+1) = *(logic_filename+2);	*(buff+2) = '\0';	pEnd = NULL;	store_path_index = strtol(buff, &pEnd, 16);	if (pEnd != NULL && *pEnd != '\0')	{		logError("file: "__FILE__", line: %d, " \			"filename: %s is invalid", \			__LINE__, logic_filename);		return EINVAL;	}	if (store_path_index < 0 || store_path_index >= g_path_count)	{		logError("file: "__FILE__", line: %d, " \			"filename: %s is invalid, invalid store path index: %d",			__LINE__, logic_filename, store_path_index);		return EINVAL;	}	*filename_len -= 4;	memcpy(true_filename, logic_filename + 4, (*filename_len) + 1);	*ppStorePath = g_store_paths[store_path_index];	return 0;}/*int write_serialized(int fd, const char *buff, size_t count, const bool bSync){	int result;	int fsync_ret;	if ((result=pthread_mutex_lock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_lock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));		return result;	}	while (fsync_thread_count >= g_max_write_thread_count)	{		if ((result=pthread_cond_wait(&fsync_thread_cond, \				&fsync_thread_mutex)) != 0)		{			logError("file: "__FILE__", line: %d, " \				"pthread_cond_wait failed, " \				"errno: %d, error info: %s", \				__LINE__, result, strerror(result));			return result;		}	}	fsync_thread_count++;	if ((result=pthread_mutex_unlock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_unlock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	if (write(fd, buff, count) == count)	{		if (bSync && fsync(fd) != 0)		{			fsync_ret = errno != 0 ? errno : EIO;			logError("file: "__FILE__", line: %d, " \				"call fsync fail, " \				"errno: %d, error info: %s", \				__LINE__, fsync_ret, strerror(fsync_ret));		}		else		{			fsync_ret = 0;		}	}	else	{		fsync_ret = errno != 0 ? errno : EIO;		logError("file: "__FILE__", line: %d, " \			"call write fail, " \			"errno: %d, error info: %s", \			__LINE__, fsync_ret, strerror(fsync_ret));	}	if ((result=pthread_mutex_lock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_lock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	fsync_thread_count--;	if ((result=pthread_mutex_unlock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_unlock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	if ((result=pthread_cond_signal(&fsync_thread_cond)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"pthread_cond_signal failed, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	return fsync_ret;}int fsync_serialized(int fd){	int result;	int fsync_ret;	if ((result=pthread_mutex_lock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_lock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));		return result;	}	while (fsync_thread_count >= g_max_write_thread_count)	{		if ((result=pthread_cond_wait(&fsync_thread_cond, \				&fsync_thread_mutex)) != 0)		{			logError("file: "__FILE__", line: %d, " \				"pthread_cond_wait failed, " \				"errno: %d, error info: %s", \				__LINE__, result, strerror(result));			return result;		}	}	fsync_thread_count++;	if ((result=pthread_mutex_unlock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_unlock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	if (fsync(fd) == 0)	{		fsync_ret = 0;	}	else	{		fsync_ret = errno != 0 ? errno : EIO;		logError("file: "__FILE__", line: %d, " \			"call fsync fail, " \			"errno: %d, error info: %s", \			__LINE__, fsync_ret, strerror(fsync_ret));	}	if ((result=pthread_mutex_lock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_lock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	fsync_thread_count--;	if ((result=pthread_mutex_unlock(&fsync_thread_mutex)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"call pthread_mutex_unlock fail, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	if ((result=pthread_cond_signal(&fsync_thread_cond)) != 0)	{		logError("file: "__FILE__", line: %d, " \			"pthread_cond_signal failed, " \			"errno: %d, error info: %s", \			__LINE__, result, strerror(result));	}	return fsync_ret;}int recv_file_serialized(int sock, const char *filename, \		const int64_t file_bytes){	int fd;	char buff[FDFS_WRITE_BUFF_SIZE];	int64_t remain_bytes;	int recv_bytes;	int result;	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);	if (fd < 0)	{		return errno != 0 ? errno : EACCES;	}	remain_bytes = file_bytes;	while (remain_bytes > 0)	{		if (remain_bytes > sizeof(buff))		{			recv_bytes = sizeof(buff);		}		else		{			recv_bytes = remain_bytes;		}		if ((result=tcprecvdata(sock, buff, recv_bytes, \				g_network_timeout)) != 0)		{			close(fd);			unlink(filename);			return result;		}		if (recv_bytes == remain_bytes)  //last buff		{			if (write_serialized(fd, buff, recv_bytes, true) != 0)			{				result = errno != 0 ? errno : EIO;				close(fd);				unlink(filename);				return result;			}		}		else		{			if (write_serialized(fd, buff, recv_bytes, false) != 0)			{				result = errno != 0 ? errno : EIO;				close(fd);				unlink(filename);				return result;			}			if ((result=fsync_serialized(fd)) != 0)			{				close(fd);				unlink(filename);				return result;			}		}		remain_bytes -= recv_bytes;	}	close(fd);	return 0;}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -