[sheepdog] [PATCH 5/9] gateway: support forward read request

Liu Yuan namei.unix at gmail.com
Thu Sep 19 12:42:49 CEST 2013


Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/gateway.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index fd71b4a..38db79f 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -97,6 +97,7 @@ struct forward_info_entry {
 	struct pollfd pfd;
 	const struct node_id *nid;
 	struct sockfd *sfd;
+	void *buf;
 };
 
 struct forward_info {
@@ -124,6 +125,17 @@ static inline void finish_one_entry_err(struct forward_info *fi, int i)
 	forward_info_update(fi, i);
 }
 
+static inline struct forward_info_entry *
+forward_info_find(struct forward_info *fi, int fd)
+{
+	for (int i = 0; i < fi->nr_sent; i++)
+		if (fi->ent[i].pfd.fd == fd)
+			return &fi->ent[i];
+
+	panic("can't find entry for %d", fd);
+	return NULL;
+}
+
 struct pfd_info {
 	struct pollfd pfds[SD_MAX_NODES];
 	int nr;
@@ -200,6 +212,19 @@ again:
 			goto out;
 		}
 
+		if (rsp->data_length) {
+			struct forward_info_entry *ent;
+
+			ent = forward_info_find(fi, pi.pfds[i].fd);
+			if (do_read(pi.pfds[i].fd, ent->buf, rsp->data_length,
+				    sheep_need_retry, req->rq.epoch,
+				    MAX_RETRY_COUNT)) {
+				sd_err("remote node might have gone away");
+				err_ret = SD_RES_NETWORK_ERROR;
+				finish_one_entry_err(fi, i);
+				goto out;
+			}
+		}
 		ret = rsp->result;
 		if (ret != SD_RES_SUCCESS) {
 			sd_err("fail %"PRIx64", %s", req->rq.obj.oid,
-- 
1.7.9.5




More information about the sheepdog mailing list