This patch adds a new parameter all_node to
gateway_forward_request(). When this parameter is 1,
gateway_forward_request() forwards a request to all other nodes
instead of vnodes which store the object.

Cc: MORITA Kazutaka <[email protected]>
Cc: Liu Yuan <[email protected]>
Signed-off-by: Hitoshi Mitake <[email protected]>
---
 sheep/gateway.c    |   58 ++++++++++++++++++++++++++++++++++------------------
 sheep/sheep_priv.h |    5 ++++
 2 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index 41d712b..98ba079 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -208,10 +208,10 @@ static inline void write_info_init(struct write_info *wi)
 }
 
 static inline void
-write_info_advance(struct write_info *wi, struct sd_vnode *v,
+write_info_advance(struct write_info *wi, struct node_id *nid,
                   struct sockfd *sfd)
 {
-       wi->ent[wi->nr_sent].nid = &v->nid;
+       wi->ent[wi->nr_sent].nid = nid;
        wi->ent[wi->nr_sent].pfd.fd = sfd->fd;
        wi->ent[wi->nr_sent].pfd.events = POLLIN;
        wi->ent[wi->nr_sent].sfd = sfd;
@@ -225,18 +225,20 @@ static inline void gateway_init_fwd_hdr(struct sd_req 
*fwd, struct sd_req *hdr)
        fwd->proto_ver = SD_SHEEP_PROTO_VER;
 }
 
-static int gateway_forward_request(struct request *req)
+static int gateway_forward_request(struct request *req, int all_node)
 {
        int i, err_ret = SD_RES_SUCCESS, ret, local = -1;
        unsigned wlen;
        struct sd_rsp *rsp = (struct sd_rsp *)&req->rp;
        struct sd_vnode *v;
+       struct sd_node *n;
        struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
        uint64_t oid = req->rq.obj.oid;
-       int nr_copies;
+       int nr_send;
        struct write_info wi;
        struct sd_op_template *op;
        struct sd_req hdr;
+       struct vnode_info *vinfo = NULL;
 
        dprintf("%"PRIx64"\n", oid);
 
@@ -245,20 +247,38 @@ static int gateway_forward_request(struct request *req)
 
        write_info_init(&wi);
        wlen = hdr.data_length;
-       nr_copies = get_req_copy_number(req);
-       oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes, oid,
-                     nr_copies, obj_vnodes);
+       if (all_node) {
+               vinfo = req->vinfo;
+               nr_send = vinfo->nr_nodes;
+       } else {
+               nr_send = get_req_copy_number(req);
+               oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes,
+                       oid, nr_send, obj_vnodes);
+       }
 
-       for (i = 0; i < nr_copies; i++) {
+       for (i = 0; i < nr_send; i++) {
                struct sockfd *sfd;
+               struct node_id *nid;
 
-               v = obj_vnodes[i];
-               if (vnode_is_local(v)) {
-                       local = i;
-                       continue;
+               if (all_node) {
+                       n = &vinfo->nodes[i];
+                       if (node_is_local(n)) {
+                               local = i;
+                               continue;
+                       }
+
+                       nid = &n->nid;
+               } else {
+                       v = obj_vnodes[i];
+                       if (vnode_is_local(v)) {
+                               local = i;
+                               continue;
+                       }
+
+                       nid = &v->nid;
                }
 
-               sfd = sheep_get_sockfd(&v->nid);
+               sfd = sheep_get_sockfd(nid);
                if (!sfd) {
                        err_ret = SD_RES_NETWORK_ERROR;
                        break;
@@ -266,17 +286,15 @@ static int gateway_forward_request(struct request *req)
 
                ret = send_req(sfd->fd, &hdr, req->data, &wlen);
                if (ret) {
-                       sheep_del_sockfd(&v->nid, sfd);
+                       sheep_del_sockfd(nid, sfd);
                        err_ret = SD_RES_NETWORK_ERROR;
                        dprintf("fail %d\n", ret);
                        break;
                }
-               write_info_advance(&wi, v, sfd);
+               write_info_advance(&wi, nid, sfd);
        }
 
        if (local != -1 && err_ret == SD_RES_SUCCESS) {
-               v = obj_vnodes[local];
-
                assert(op);
                ret = sheep_do_op_work(op, req);
 
@@ -301,7 +319,7 @@ int gateway_write_obj(struct request *req)
        if (sys->enable_write_cache && !req->local && !bypass_object_cache(req))
                return object_cache_handle_request(req);
 
-       return gateway_forward_request(req);
+       return gateway_forward_request(req, 0);
 }
 
 int gateway_create_and_write_obj(struct request *req)
@@ -309,10 +327,10 @@ int gateway_create_and_write_obj(struct request *req)
        if (sys->enable_write_cache && !req->local && !bypass_object_cache(req))
                return object_cache_handle_request(req);
 
-       return gateway_forward_request(req);
+       return gateway_forward_request(req, 0);
 }
 
 int gateway_remove_obj(struct request *req)
 {
-       return gateway_forward_request(req);
+       return gateway_forward_request(req, 0);
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index dce1ae5..a96b3c3 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -342,6 +342,11 @@ static inline int vnode_is_local(struct sd_vnode *v)
        return is_myself(v->nid.addr, v->nid.port);
 }
 
+static inline int node_is_local(struct sd_node *n)
+{
+       return is_myself(n->nid.addr, n->nid.port);
+}
+
 /* gateway operations */
 int gateway_read_obj(struct request *req);
 int gateway_write_obj(struct request *req);
-- 
1.7.5.1

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to