BurstFS_Server/burstfs_cmd_handler.c
int attach_to_shm(app_config_t *app_config, int app_id, int sock_id) {
		int ret = 0;
		char shm_name[GEN_STR_LEN] = {0};

		int client_side_id = app_config->client_ranks[sock_id];

		/* attach shared superblock,
		 * a superblock is created by each
		 * client to store the raw file data.
		 * The overflowed data are spilled to
		 * SSD.
		 * */
		sprintf(shm_name, "%d-super-%d", app_id, client_side_id);
		int tmp_fd = shm_open(shm_name,\
		    		MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd)) {
		    return ULFS_ERROR_SHMEM;
		}
		ret = ftruncate(tmp_fd, app_config->superblock_sz);
		if(-1 == ret) {
		    return ULFS_ERROR_SHMEM;
		}
		app_config->shm_superblock_fds[client_side_id] = tmp_fd;

		strcpy(app_config->super_buf_name[client_side_id], shm_name);
		app_config->shm_superblocks[client_side_id] =\
				mmap(NULL, app_config->superblock_sz, PROT_READ|PROT_WRITE,\
		    		MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_superblocks[client_side_id])
		{
			return ULFS_ERROR_SHMEM;
		}

		/* attach shared request buffer,
		 * a request buffer is created by each
		 * client to convey the client-side read
		 * request to the delegator
		 * */
		sprintf(shm_name, "%d-req-%d", app_id, client_side_id);
		tmp_fd = shm_open(shm_name, MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd)) {
		    	return ULFS_ERROR_SHMEM;
		}

		ret = ftruncate(tmp_fd, app_config->req_buf_sz);
		if(-1 == ret) {
			return ULFS_ERROR_SHMEM;
		}
		app_config->shm_req_fds[client_side_id] = tmp_fd;

		strcpy(app_config->req_buf_name[client_side_id], shm_name);
		app_config->shm_req_bufs[client_side_id] = mmap(NULL,\
				app_config->req_buf_sz, PROT_READ|PROT_WRITE,\
		    		MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_req_bufs[client_side_id]) {
			return ULFS_ERROR_SHMEM;
		}


		/* initialize shared receive buffer,
		 * a request buffer is created by each
		 * client for the delegator to
		 * temporarily buffer the received
		 * data for this client
		 *
		 * */
		sprintf(shm_name, "%d-recv-%d", app_id, client_side_id);

		tmp_fd = shm_open(shm_name, MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd))
		{
			return ULFS_ERROR_SHMEM;
		}
		ret = ftruncate(tmp_fd, app_config->recv_buf_sz);
		if(-1 == ret) {
			return ULFS_ERROR_SHMEM;
		}
		app_config->shm_recv_fds[client_side_id] = tmp_fd;

		strcpy(app_config->recv_buf_name[client_side_id], shm_name);
		app_config->shm_recv_bufs[client_side_id] =\
				mmap(NULL, app_config->recv_buf_sz, PROT_READ|PROT_WRITE,\
						MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_recv_bufs[client_side_id])
		{
			return ULFS_ERROR_SHMEM;
		}

	    return ULFS_SUCCESS;

	}
/**
* attach to the client-side shared memory
* @param app_config: application information
* @param app_id: the server-side
* @param sock_id: position in poll_set in burstfs_sock.h
* @return success/error code
*/
attach to the client-side shared memory
attach to the client - side shared memory
int attach_to_shm(app_config_t *app_config, int app_id, int sock_id) {
		int ret = 0;
		char shm_name[GEN_STR_LEN] = {0};
		int client_side_id = app_config->client_ranks[sock_id];
		sprintf(shm_name, "%d-super-%d", app_id, client_side_id);
		int tmp_fd = shm_open(shm_name,\
		    		MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd)) {
		    return ULFS_ERROR_SHMEM;
		}
		ret = ftruncate(tmp_fd, app_config->superblock_sz);
		if(-1 == ret) {
		    return ULFS_ERROR_SHMEM;
		}
		app_config->shm_superblock_fds[client_side_id] = tmp_fd;
		strcpy(app_config->super_buf_name[client_side_id], shm_name);
		app_config->shm_superblocks[client_side_id] =\
				mmap(NULL, app_config->superblock_sz, PROT_READ|PROT_WRITE,\
		    		MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_superblocks[client_side_id])
		{
			return ULFS_ERROR_SHMEM;
		}
		sprintf(shm_name, "%d-req-%d", app_id, client_side_id);
		tmp_fd = shm_open(shm_name, MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd)) {
		    	return ULFS_ERROR_SHMEM;
		}
		ret = ftruncate(tmp_fd, app_config->req_buf_sz);
		if(-1 == ret) {
			return ULFS_ERROR_SHMEM;
		}
		app_config->shm_req_fds[client_side_id] = tmp_fd;
		strcpy(app_config->req_buf_name[client_side_id], shm_name);
		app_config->shm_req_bufs[client_side_id] = mmap(NULL,\
				app_config->req_buf_sz, PROT_READ|PROT_WRITE,\
		    		MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_req_bufs[client_side_id]) {
			return ULFS_ERROR_SHMEM;
		}
		sprintf(shm_name, "%d-recv-%d", app_id, client_side_id);
		tmp_fd = shm_open(shm_name, MMAP_OPEN_FLAG, MMAP_OPEN_MODE);
		if(-1 == (ret = tmp_fd))
		{
			return ULFS_ERROR_SHMEM;
		}
		ret = ftruncate(tmp_fd, app_config->recv_buf_sz);
		if(-1 == ret) {
			return ULFS_ERROR_SHMEM;
		}
		app_config->shm_recv_fds[client_side_id] = tmp_fd;
		strcpy(app_config->recv_buf_name[client_side_id], shm_name);
		app_config->shm_recv_bufs[client_side_id] =\
				mmap(NULL, app_config->recv_buf_sz, PROT_READ|PROT_WRITE,\
						MAP_SHARED, tmp_fd, SEEK_SET);
		if(NULL == app_config->shm_recv_bufs[client_side_id])
		{
			return ULFS_ERROR_SHMEM;
		}
	    return ULFS_SUCCESS;
	}
int attach_to_shm ( app_config_t * app_config , int app_id , int sock_id ) { int ret = 0 ; char shm_name [ GEN_STR_LEN ] = { 0 } ; int client_side_id = app_config -> client_ranks [ sock_id ] ; sprintf ( shm_name , " " , app_id , client_side_id ) ; int tmp_fd = shm_open ( shm_name , MMAP_OPEN_FLAG , MMAP_OPEN_MODE ) ; if ( -1 == ( ret = tmp_fd ) ) { return ULFS_ERROR_SHMEM ; } ret = ftruncate ( tmp_fd , app_config -> superblock_sz ) ; if ( -1 == ret ) { return ULFS_ERROR_SHMEM ; } app_config -> shm_superblock_fds [ client_side_id ] = tmp_fd ; strcpy ( app_config -> super_buf_name [ client_side_id ] , shm_name ) ; app_config -> shm_superblocks [ client_side_id ] = mmap ( NULL , app_config -> superblock_sz , PROT_READ | PROT_WRITE , MAP_SHARED , tmp_fd , SEEK_SET ) ; if ( NULL == app_config -> shm_superblocks [ client_side_id ] ) { return ULFS_ERROR_SHMEM ; } sprintf ( shm_name , " " , app_id , client_side_id ) ; tmp_fd = shm_open ( shm_name , MMAP_OPEN_FLAG , MMAP_OPEN_MODE ) ; if ( -1 == ( ret = tmp_fd ) ) { return ULFS_ERROR_SHMEM ; } ret = ftruncate ( tmp_fd , app_config -> req_buf_sz ) ; if ( -1 == ret ) { return ULFS_ERROR_SHMEM ; } app_config -> shm_req_fds [ client_side_id ] = tmp_fd ; strcpy ( app_config -> req_buf_name [ client_side_id ] , shm_name ) ; app_config -> shm_req_bufs [ client_side_id ] = mmap ( NULL , app_config -> req_buf_sz , PROT_READ | PROT_WRITE , MAP_SHARED , tmp_fd , SEEK_SET ) ; if ( NULL == app_config -> shm_req_bufs [ client_side_id ] ) { return ULFS_ERROR_SHMEM ; } sprintf ( shm_name , " " , app_id , client_side_id ) ; tmp_fd = shm_open ( shm_name , MMAP_OPEN_FLAG , MMAP_OPEN_MODE ) ; if ( -1 == ( ret = tmp_fd ) ) { return ULFS_ERROR_SHMEM ; } ret = ftruncate ( tmp_fd , app_config -> recv_buf_sz ) ; if ( -1 == ret ) { return ULFS_ERROR_SHMEM ; } app_config -> shm_recv_fds [ client_side_id ] = tmp_fd ; strcpy ( app_config -> recv_buf_name [ client_side_id ] , shm_name ) ; app_config -> shm_recv_bufs [ client_side_id ] = mmap ( NULL , app_config -> recv_buf_sz , PROT_READ | PROT_WRITE , MAP_SHARED , tmp_fd , SEEK_SET ) ; if ( NULL == app_config -> shm_recv_bufs [ client_side_id ] ) { return ULFS_ERROR_SHMEM ; } return ULFS_SUCCESS ; }
attach to the client-side shared memory
attach to the client - side shared memory
/* attach shared superblock,
		 * a superblock is created by each
		 * client to store the raw file data.
		 * The overflowed data are spilled to
		 * SSD.
		 * */ /* attach shared request buffer,
		 * a request buffer is created by each
		 * client to convey the client-side read
		 * request to the delegator
		 * */ /* initialize shared receive buffer,
		 * a request buffer is created by each
		 * client for the delegator to
		 * temporarily buffer the received
		 * data for this client
		 *
		 * */