Exemple #1
0
static int object_create_entry(const char *entry, const char *url)
{
	struct strbuf buf = STRBUF_INIT;
	char *args[3], path[PATH_MAX];
	int nr, ret = -EINVAL;
	uint64_t size;

	nr = split_path(entry, ARRAY_SIZE(args), args);
	if (nr != ARRAY_SIZE(args)) {
		sheepfs_pr("Invalid argument %d, %s", nr, entry);
		goto out;
	}

	strbuf_addf(&buf, "%s", PATH_HTTP);
	for (int i = 0; i < nr; i++) {
		strbuf_addf(&buf, "/%s", args[i]);
		snprintf(path, sizeof(path), "%.*s", (int)buf.len, buf.buf);
		if (i == (nr - 1)) {
			if (shadow_file_create(path) < 0) {
				sheepfs_pr("Create file %s fail", path);
				goto out;
			}
			size = curl_get_object_size(url);
			if (size <= 0) {
				sheepfs_pr("Failed to get size of object");
				shadow_file_delete(path);
				goto out;
			}
			if (shadow_file_setxattr(path, HTTP_SIZE_NAME, &size,
						 HTTP_SIZE_SIZE) < 0) {
				sheepfs_pr("Failed to setxattr for %s",
				       HTTP_SIZE_NAME);
				shadow_file_delete(path);
				goto out;
			}
			if (sheepfs_set_op(path, OP_OBJECT) < 0) {
				sheepfs_pr("Set_op %s fail", path);
				shadow_file_delete(path);
				goto out;
			}
		} else {
			if (shadow_dir_create(path) < 0) {
				sheepfs_pr("Create dir %s fail", path);
				goto out;
			}
			if (sheepfs_set_op(path, OP_CONTAINER) < 0) {
				sheepfs_pr("Set_op %s fail", path);
				shadow_dir_delete(path);
				goto out;
			}
		}
	}
	ret = 0;
out:
	for (int i = 0; i < ARRAY_SIZE(args); i++)
		free(args[i]);
	strbuf_release(&buf);
	return ret;
}
Exemple #2
0
int create_node_layout(void)
{
	if (shadow_dir_create(PATH_NODE) < 0)
		return -1;

	if (shadow_file_create(PATH_NODE_INFO) < 0)
		return -1;
	if (sheepfs_set_op(PATH_NODE_INFO, OP_NODE_INFO) < 0)
		return -1;

	if (shadow_file_create(PATH_NODE_LIST) < 0)
		return -1;
	if (sheepfs_set_op(PATH_NODE_LIST, OP_NODE_LIST) < 0)
		return -1;

	return 0;
}
Exemple #3
0
int create_http_layout(void)
{
	if (shadow_dir_create(PATH_HTTP) < 0)
		return -1;

	if (shadow_file_create(PATH_HTTP_ADDRESS) < 0)
		return -1;
	if (sheepfs_set_op(PATH_HTTP_ADDRESS, OP_HTTP_ADDRESS) < 0)
		return -1;

	if (shadow_file_create(PATH_HTTP_OBJECT) < 0)
		return -1;
	if (sheepfs_set_op(PATH_HTTP_OBJECT, OP_HTTP_OBJECT) < 0)
		return -1;

	return 0;
}
Exemple #4
0
int create_vdi_layout(void)
{
	if (shadow_dir_create(PATH_VDI) < 0)
		return -1;

	if (shadow_file_create(PATH_VDI_LIST) < 0)
		return -1;
	if (sheepfs_set_op(PATH_VDI_LIST, OP_VDI_LIST) < 0)
		return -1;

	if (shadow_file_create(PATH_VDI_MOUNT) < 0)
		return -1;
	if (sheepfs_set_op(PATH_VDI_MOUNT, OP_VDI_MOUNT) < 0)
		return -1;

	if (shadow_file_create(PATH_VDI_UNMOUNT) < 0)
		return -1;
	if (sheepfs_set_op(PATH_VDI_UNMOUNT, OP_VDI_UNMOUNT) < 0)
		return -1;

	return 0;
}
Exemple #5
0
int create_config_layout(void)
{
	if (shadow_dir_create(PATH_CONFIG) < 0)
		return -1;

	if (shadow_file_create(PATH_CONFIG_PCACHE) < 0)
		return -1;
	if (sheepfs_set_op(PATH_CONFIG_PCACHE, OP_CONFIG_PCACHE) < 0)
		return -1;

	if (shadow_file_create(PATH_CONFIG_OCACHE) < 0)
		return -1;
	if (sheepfs_set_op(PATH_CONFIG_OCACHE, OP_CONFIG_OCACHE) < 0)
		return -1;

	if (shadow_file_create(PATH_CONFIG_SHEEP) < 0)
		return -1;
	if (sheepfs_set_op(PATH_CONFIG_SHEEP, OP_CONFIG_SHEEP) < 0)
		return -1;

	return 0;
}