[sheepdog] [PATCH 3/3] gateway: refactor write and remove functions

Christoph Hellwig hch at infradead.org
Sun Jul 8 19:35:31 CEST 2012


On Sun, Jul 08, 2012 at 01:02:39PM +0800, Liu Yuan wrote:
> From: Liu Yuan <tailai.ly at taobao.com>
> 
> They share almost the same logic, so let's extract the core out and wrap it a
> stand-alone function.
> 
> - add sheep_do_op_work()

I thought about that and it sounds fine to me, but two little caveats:

 - I think gateway_read_obj should grow a comment explaining why we
   can't use the new helper (because we only need to read things once)
 - I would rename it to gateway_forward_operation or similar to make
   clear it's a) a gateway helper and b) that it forwards a request.

>  
> +static int do_gateway_write_obj(struct request *req, bool create)
> +{
> +	struct sd_req hdr;
> +
> +	if (sys->enable_write_cache && !req->local && !bypass_object_cache(req))
> +		return object_cache_handle_request(req);
> +
> +	memcpy(&hdr, &req->rq, sizeof(hdr));
> +	if (create)
> +		hdr.opcode = SD_OP_CREATE_AND_WRITE_PEER;
> +	else
> +		hdr.opcode = SD_OP_WRITE_PEER;
> +	hdr.proto_ver = SD_SHEEP_PROTO_VER;
> +
> +	return do_request(req, &hdr);
> +}

I would probably remove this helper in favour of opencoding it in the
two callers.

Maybe we also want an

static inline void sd_init_fwd_req(struct sd_req *fwd_hdr, struct sd_req *hdr)
{
	memcpy(fwd_hdr, hdr, sizeof(*fwd_hdr));
	fwd_hdr->opcode = sd_fwd_tbl[hdr->opcode);
	fwd_hdr->proto_ver = SD_SHEEP_PROTO_VER;
}

where sd_fwd_tbl is a simple lookup table for guest vs peer operations.




More information about the sheepdog mailing list