[sheepdog] [PATCH 1/4] sheep: don't send unnecessary data against read requests
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Sun Sep 9 18:13:15 CEST 2012
This will save network traffic.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/gateway.c | 11 ++++++++---
sheep/ops.c | 17 ++++++++++++-----
sheep/request.c | 2 ++
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/sheep/gateway.c b/sheep/gateway.c
index 3e8e673..2ed53d4 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -32,8 +32,10 @@ int gateway_read_obj(struct request *req)
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);
+ if (is_object_cache_enabled() && !req->local && !bypass_object_cache(req)) {
+ ret = object_cache_handle_request(req);
+ goto out;
+ }
nr_copies = get_req_copy_number(req);
oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes, oid,
@@ -44,7 +46,7 @@ int gateway_read_obj(struct request *req)
continue;
ret = peer_read_obj(req);
if (ret == SD_RES_SUCCESS)
- return ret;
+ goto out;
eprintf("local read fail %x\n", ret);
break;
@@ -95,6 +97,9 @@ int gateway_read_obj(struct request *req)
sheep_put_sockfd(&v->nid, sfd);
}
}
+out:
+ if (ret != SD_RES_SUCCESS)
+ req->rp.data_length = 0;
return ret;
}
diff --git a/sheep/ops.c b/sheep/ops.c
index 4c0426f..472fb00 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -401,8 +401,9 @@ static int local_get_store_list(struct request *req)
strbuf_addf(&buf, "%s ", driver->name);
}
strbuf_copyout(&buf, req->data, req->data_length);
-
strbuf_release(&buf);
+
+ req->rp.data_length = strlen(req->data) + 1;
return SD_RES_SUCCESS;
}
@@ -676,12 +677,16 @@ static int local_get_snap_file(struct request *req)
int ret;
struct siocb iocb = { .buf = req->data };
- if (sd_store->get_snap_file) {
+ if (sd_store->get_snap_file)
ret = sd_store->get_snap_file(&iocb);
- req->rp.data_length = iocb.length;
- } else
+ else
ret = SD_RES_NO_SUPPORT;
+ if (ret == SD_RES_SUCCESS)
+ req->rp.data_length = iocb.length;
+ else
+ req->rp.data_length = 0;
+
return ret;
}
@@ -731,8 +736,10 @@ static int local_trace_read_buf(struct request *request)
int ret;
ret = trace_buffer_pop(request->data, req->data_length);
- if (ret == -1)
+ if (ret == -1) {
+ rsp->data_length = 0;
return SD_RES_AGAIN;
+ }
rsp->data_length = ret;
dprintf("%u\n", rsp->data_length);
diff --git a/sheep/request.c b/sheep/request.c
index ae12bd3..40a49fc 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -123,6 +123,7 @@ static int check_request_epoch(struct request *req)
/* ask gateway to retry. */
req->rp.result = SD_RES_OLD_NODE_VER;
req->rp.epoch = sys->epoch;
+ req->rp.data_length = 0;
put_request(req);
return -1;
} else if (after(req->rq.epoch, sys->epoch)) {
@@ -394,6 +395,7 @@ static void queue_request(struct request *req)
return;
done:
+ rsp->data_length = 0;
put_request(req);
}
--
1.7.2.5
More information about the sheepdog
mailing list