Exemple #1
0
Master::node_t Master::_send_request_to_IOnodes(const char *file_path, ssize_t file_no, int flag, size_t& file_length,size_t& block_size)throw(std::invalid_argument)
{
	int fd=open(file_path, flag);
	
	if(-1 == fd)
	{
		throw std::invalid_argument("file can not open");
	}

	struct stat file_stat;
	fstat(fd, &file_stat);
	file_length=file_stat.st_size;
	block_size=_get_block_size(file_length); 
	close(fd);
	// send node number
	node_t nodes=_select_IOnode(file_length, block_size);
	for(node_t::const_iterator it=nodes.begin(); 
			nodes.end()!=it; ++it)
	{
		//send read request to each IOnode
		//buffer requset
		//file_no
		//file_path
		//start_point
		//block_size
		int socket=_registed_IOnodes.at(it->second).socket;
		Send(socket, OPEN_FILE);
		Send(socket, file_no); 
		Send(socket, flag);
		Sendv(socket, file_path, strlen(file_path));
		Send(socket, it->first); 
		Send(socket, block_size); 
	}
	return nodes; 
}
Exemple #2
0
static int _aligned_io(struct device_area *where, void *buffer,
		       int should_write)
{
	void *bounce;
	unsigned int block_size = 0;
	uintptr_t mask;
	struct device_area widened;

	if (!(where->dev->flags & DEV_REGULAR) &&
	    !_get_block_size(where->dev, &block_size))
		return_0;

	if (!block_size)
		block_size = lvm_getpagesize();

	_widen_region(block_size, where, &widened);

	/* Do we need to use a bounce buffer? */
	mask = block_size - 1;
	if (!memcmp(where, &widened, sizeof(widened)) &&
	    !((uintptr_t) buffer & mask))
		return _io(where, buffer, should_write);

	/* Allocate a bounce buffer with an extra block */
	if (!(bounce = alloca((size_t) widened.size + block_size))) {
		log_error("Bounce buffer alloca failed");
		return 0;
	}

	/*
	 * Realign start of bounce buffer (using the extra sector)
	 */
	if (((uintptr_t) bounce) & mask)
		bounce = (void *) ((((uintptr_t) bounce) + mask) & ~mask);

	/* channel the io through the bounce buffer */
	if (!_io(&widened, bounce, 0)) {
		if (!should_write)
			return_0;
		/* FIXME pre-extend the file */
		memset(bounce, '\n', widened.size);
	}

	if (should_write) {
		memcpy(bounce + (where->start - widened.start), buffer,
		       (size_t) where->size);

		/* ... then we write */
		return _io(&widened, bounce, 1);
	}

	memcpy(buffer, bounce + (where->start - widened.start),
	       (size_t) where->size);

	return 1;
}
Exemple #3
0
int Master::_parse_write_file(int clientfd, std::string& ip)
{
	fprintf(stderr, "request for writing ip=%s\n",ip.c_str());
	ssize_t file_no;
	size_t size, block_size;
	off_t start_point;
	Recv(clientfd, file_no);
	Recv(clientfd, start_point);
	Recv(clientfd, size);
	int fd=open(_buffered_files.at(file_no).path.c_str(), O_CREAT, S_IRUSR|S_IWUSR);
	if(-1 == fd)
	{
		fprintf(stderr, "file create error\n");
		return FAILURE;
	}
	close(fd);
	try
	{
		file_info &file=_buffered_files.at(file_no);
		block_size=_get_block_size(size);
		file.block_size=block_size;
		if(0 == file.size)
		{
			file.size=size;
		}
		node_t nodes=_select_IOnode(size, block_size);
		for(node_t::const_iterator it=nodes.begin(); 
				nodes.end()!=it; ++it)
		{
			//send read request to each IOnode
			//buffer requset
			//file_no
			//file_path
			//start_point
			//block_size
			int socket=_registed_IOnodes.at(it->second).socket;
			size_t my_block_size=it->first+block_size > file.size?file.size-it->first:block_size;
			Send(socket, WRITE_FILE);
			Send(socket, file_no);
			Sendv(socket, file.path.c_str(), file.path.size());
			Send(socket, it->first); 
			Send(socket, my_block_size); 
		}
		file.p_node=nodes;
		for(node_t::const_iterator it=file.p_node.begin();
				it !=file.p_node.end();++it)
		{
			file.nodes.insert(it->second);
		}
		Send(clientfd, SUCCESS);	
		Send(clientfd, static_cast<int>(file.p_node.size()));
		Send(clientfd, file.size);
		Send(clientfd, file.block_size);
		for(node_t::const_iterator it=file.p_node.begin(); it!=file.p_node.end(); ++it)
		{
			Send(clientfd, it->first);
			const std::string& ip=_registed_IOnodes.at(it->second).ip; 
			Sendv(clientfd, ip.c_str(), ip.size());
		}
		close(clientfd);
		return SUCCESS;
	}
	catch(std::out_of_range &e)
	{
		Send(clientfd, FAILURE);	
		close(clientfd);
		return FAILURE;
	}
}