Exemplo n.º 1
0
void add_to_cache(cache *c_cache, char *query, char *q_data, unsigned int q_size){
	if (!(q_size > MAX_OBJECT_SIZE)){
		pthread_rwlock_wrlock(&lock);
		// printf("%s:%s\n", "Adding to cache", query);
		cache_node *to_add = Calloc(1, sizeof(cache_node));
		to_add->url = Calloc(strlen(query) + 1, sizeof(char));
		strcpy(to_add->url, query);
		to_add->data = Malloc(q_size);
		memcpy(to_add->data, q_data, q_size);
		to_add->data_size = q_size;
		if (c_cache->start == NULL){
			to_add->prev = NULL;
			to_add->next = NULL;
			c_cache->start = to_add;
			c_cache->end = to_add;
		}
		else {
			to_add->prev = NULL;
			to_add->next = c_cache->start;
			c_cache->start->prev = to_add;
			c_cache->start = to_add;
		}
		c_cache->cache_size += q_size;
		while (c_cache->cache_size > MAX_CACHE_SIZE){
			delete_from_cache(c_cache);
		}
		pthread_rwlock_unlock(&lock);
	}
}
Exemplo n.º 2
0
int _rfs_link(struct rfs_instance *instance, const char *path, const char *target)
{
	if (instance->sendrecv.socket == -1)
	{
		return -ECONNABORTED;
	}

	uint32_t path_len = strlen(path) + 1;
	unsigned target_len = strlen(target) + 1;

	unsigned overall_size = sizeof(path_len) + path_len + target_len;

	struct rfs_command cmd = { cmd_link, overall_size };

	char *buffer = malloc(cmd.data_len);

	pack(target, target_len, 
	pack(path, path_len, 
	pack_32(&path_len, buffer
	)));

	send_token_t token = { 0 };
	if (do_send(&instance->sendrecv, 
		queue_data(buffer, overall_size, 
		queue_cmd(&cmd, &token))) < 0)
	{
		free(buffer);
		return -ECONNABORTED;
	}

	free(buffer);

	struct rfs_answer ans = { 0 };

	if (rfs_receive_answer(&instance->sendrecv, &ans) == -1)
	{
		return -ECONNABORTED;
	}

	if (ans.command != cmd_link 
	|| ans.data_len != 0)
	{
		return cleanup_badmsg(instance, &ans);
	}
	
	if (ans.ret == 0)
	{
		delete_from_cache(&instance->attr_cache, path);
	}

	return ans.ret == -1 ? -ans.ret_errno : ans.ret;
}
Exemplo n.º 3
0
static void id_cache_delete(struct messaging_context *msg_ctx,
			    void *private_data,
			    uint32_t msg_type,
			    struct server_id server_id,
			    DATA_BLOB* data)
{
	const char *msg = (data && data->data) ? (const char *)data->data : "<NULL>";
	struct id_cache_ref id;

	if (!id_cache_ref_parse(msg, &id)) {
		DEBUG(0, ("Invalid ?ID: %s\n", msg));
		return;
	}

	delete_from_cache(&id);
}
Exemplo n.º 4
0
int _rfs_open(struct rfs_instance *instance, const char *path, int flags, uint64_t *desc)
{
	if (instance->sendrecv.socket == -1)
	{
		return -ECONNABORTED;
	}

	unsigned path_len = strlen(path) + 1;
	uint16_t fi_flags = rfs_file_flags(flags);
	
	unsigned overall_size = sizeof(fi_flags) + path_len;

	struct rfs_command cmd = { cmd_open, overall_size };

	char *buffer = malloc(cmd.data_len);

	pack(path, path_len, 
	pack_16(&fi_flags, buffer
	));

	send_token_t token = { 0 };
	if (do_send(&instance->sendrecv, 
		queue_data(buffer, overall_size, 
		queue_cmd(&cmd, &token))) < 0)
	{
		free(buffer);
		return -ECONNABORTED;
	}

	free(buffer);

	struct rfs_answer ans = { 0 };

	if (rfs_receive_answer(&instance->sendrecv, &ans) == -1)
	{
		return -ECONNABORTED;
	}

	if (ans.command != cmd_open)
	{
		return cleanup_badmsg(instance, &ans);
	}

	if (ans.ret == -1)
	{
		if (ans.ret_errno == -ENOENT)
		{
			delete_from_cache(&instance->attr_cache, path);
		}

		return -ans.ret_errno;
	}

	uint32_t stat_failed = 0;
	uint32_t user_len = 0;
	uint32_t group_len = 0;

#define ans_buffer_size sizeof(*desc) \
+ sizeof(stat_failed) + STAT_BLOCK_SIZE + sizeof(user_len) + sizeof(group_len) \
+ (MAX_SUPPORTED_NAME_LEN + 1) + (MAX_SUPPORTED_NAME_LEN + 1)

	char ans_buffer[ans_buffer_size]  = { 0 };
	
	if (ans.data_len > sizeof(ans_buffer))
	{
		return cleanup_badmsg(instance, &ans);
	}
#undef ans_buffer_size
	
	if (rfs_receive_data(&instance->sendrecv, ans_buffer, ans.data_len) == -1)
	{
		return -ECONNABORTED;
	}

	struct stat stbuf = { 0 };

	const char *user = 
	unpack_32(&group_len, 
	unpack_32(&user_len, 
	unpack_stat(&stbuf, 
	unpack_32(&stat_failed, 
	unpack_64(desc, ans_buffer
	)))));
	const char *group = user + user_len;

	DEBUG("handle: %llu\n", (long long unsigned)(*desc));

	stbuf.st_uid = resolve_username(instance, user);
	stbuf.st_gid = resolve_groupname(instance, group, user);

	if (ans.ret_errno == 0)
	{
		if (stat_failed == 0)
		{
			cache_file(&instance->attr_cache, path, &stbuf);
		}
		
		resume_add_file_to_open_list(&instance->resume.open_files, path, flags, *desc);
	}
	else
	{
		delete_from_cache(&instance->attr_cache, path);
	}
	
	return ans.ret == -1 ? -ans.ret_errno : ans.ret;
}