コード例 #1
0
ファイル: gateway.c プロジェクト: shenyibin/sheepdog
int gateway_create_and_write_obj(struct request *req)
{
	if (is_object_cache_enabled() && !req->local && !bypass_object_cache(req))
		return object_cache_handle_request(req);

	return gateway_forward_request(req, false);
}
コード例 #2
0
ファイル: gateway.c プロジェクト: shenyibin/sheepdog
/*
 * Try our best to read one copy and read local first.
 *
 * Return success if any read succeed. We don't call gateway_forward_request()
 * because we only read once.
 */
int gateway_read_obj(struct request *req)
{
	int i, ret = SD_RES_SUCCESS;
	unsigned wlen, rlen;
	struct sd_req fwd_hdr;
	struct sd_rsp *rsp = (struct sd_rsp *)&fwd_hdr;
	struct sd_vnode *v;
	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
	uint64_t oid = req->rq.obj.oid;
	int nr_copies, j;

	if (is_object_cache_enabled() && !req->local && !bypass_object_cache(req))
		return object_cache_handle_request(req);

	nr_copies = get_req_copy_number(req);
	oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes, oid,
		      nr_copies, obj_vnodes);
	for (i = 0; i < nr_copies; i++) {
		v = obj_vnodes[i];
		if (!vnode_is_local(v))
			continue;
		ret = peer_read_obj(req);
		if (ret == SD_RES_SUCCESS)
			return ret;

		eprintf("local read fail %x\n", ret);
		break;
	}

	/*
	 * Read random copy from cluster for better load balance, useful for
	 * reading base VM's COW objects
	 */
	j = random();
	for (i = 0; i < nr_copies; i++) {
		int idx = (i + j) % nr_copies;

		v = obj_vnodes[idx];
		if (vnode_is_local(v))
			continue;
		/*
		 * We need to re-init it because rsp and req share the same
		 * structure.
		 */
		gateway_init_fwd_hdr(&fwd_hdr, &req->rq);
		wlen = 0;
		rlen = fwd_hdr.data_length;
		ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data, &wlen,
				     &rlen);
		if (ret != SD_RES_SUCCESS)
			continue;

		/* Read success */
		memcpy(&req->rp, rsp, sizeof(*rsp));
		break;
	}
	return ret;
}
コード例 #3
0
ファイル: plain_store.c プロジェクト: hungld/sheepdog
int default_format(void)
{
	unsigned ret;

	sd_dprintf("try get a clean store\n");
	ret = rmdir_r(obj_path);
	if (ret && ret != -ENOENT) {
		sd_eprintf("failed to remove %s: %s\n",
			obj_path, strerror(-ret));
		return SD_RES_EIO;
	}
	if (mkdir(obj_path, def_dmode) < 0) {
		sd_eprintf("%m\n");
		return SD_RES_EIO;
	}
	if (is_object_cache_enabled())
		object_cache_format();

	return SD_RES_SUCCESS;
}