[sheepdog] [PATCH 3/3] gateway: clean up gateway_read_obj()
Liu Yuan
namei.unix at gmail.com
Wed Sep 12 10:07:14 CEST 2012
From: Liu Yuan <tailai.ly at taobao.com>
- use gateway_init_fwd_hdr() to init forward header.
- move the initialization out of for loop
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/gateway.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/sheep/gateway.c b/sheep/gateway.c
index 3fd49a5..915fa09 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -15,6 +15,13 @@
#include "sheep_priv.h"
+static inline void gateway_init_fwd_hdr(struct sd_req *fwd, struct sd_req *hdr)
+{
+ memcpy(fwd, hdr, sizeof(*fwd));
+ fwd->opcode = gateway_to_peer_opcode(hdr->opcode);
+ fwd->proto_ver = SD_SHEEP_PROTO_VER;
+}
+
/*
* Try our best to read one copy and read local first.
*
@@ -50,6 +57,9 @@ int gateway_read_obj(struct request *req)
break;
}
+ gateway_init_fwd_hdr(&fwd_hdr, &req->rq);
+ wlen = 0;
+ rlen = fwd_hdr.data_length;
/*
* Read random copy from cluster for better load balance, useful for
* reading base VM's COW objects
@@ -62,15 +72,8 @@ int gateway_read_obj(struct request *req)
if (vnode_is_local(v))
continue;
- memcpy(&fwd_hdr, &req->rq, sizeof(fwd_hdr));
- fwd_hdr.opcode = SD_OP_READ_PEER;
- fwd_hdr.proto_ver = SD_SHEEP_PROTO_VER;
- 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;
@@ -213,13 +216,6 @@ write_info_advance(struct write_info *wi, struct node_id *nid,
wi->nr_sent++;
}
-static inline void gateway_init_fwd_hdr(struct sd_req *fwd, struct sd_req *hdr)
-{
- memcpy(fwd, hdr, sizeof(*fwd));
- fwd->opcode = gateway_to_peer_opcode(hdr->opcode);
- fwd->proto_ver = SD_SHEEP_PROTO_VER;
-}
-
static int init_target_nodes(struct request *req, bool all_node,
uint64_t oid, struct sd_node **target_nodes)
{
--
1.7.10.2
More information about the sheepdog
mailing list