[sheepdog] [PATCH] sheep: send only header on failure

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Sep 8 11:44:58 CEST 2012


We don't need to send useless data to client when a read request
fails.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/ops.c     |    8 ++------
 sheep/request.c |    5 +++++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 4c0426f..23f514a 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -499,10 +499,8 @@ static int local_get_epoch(struct request *req)
 	dprintf("%d\n", epoch);
 
 	nr_nodes = epoch_log_read(epoch, req->data, req->rq.data_length);
-	if (nr_nodes == -1) {
-		req->rp.data_length = 0;
+	if (nr_nodes == -1)
 		return SD_RES_NO_TAG;
-	}
 
 	req->rp.data_length = nr_nodes * sizeof(struct sd_node) + sizeof(time_t);
 	return SD_RES_SUCCESS;
@@ -861,10 +859,8 @@ int peer_read_obj(struct request *req)
 	iocb.length = hdr->data_length;
 	iocb.offset = hdr->obj.offset;
 	ret = sd_store->read(hdr->obj.oid, &iocb);
-	if (ret != SD_RES_SUCCESS) {
-		rsp->data_length = 0;
+	if (ret != SD_RES_SUCCESS)
 		goto out;
-	}
 
 	rsp->data_length = hdr->data_length;
 	if (hdr->obj.copies)
diff --git a/sheep/request.c b/sheep/request.c
index ae12bd3..7e05c06 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -505,6 +505,11 @@ void put_request(struct request *req)
 	if (uatomic_sub_return(&req->refcnt, 1) > 0)
 		return;
 
+	/* We don't need to send useless data on failure */
+	if (!(req->rq.flags & SD_FLAG_CMD_WRITE) &&
+	    req->rp.result != SD_RES_SUCCESS)
+		req->rp.data_length = 0;
+
 	if (req->local) {
 		req->done = 1;
 		eventfd_write(req->wait_efd, value);
-- 
1.7.2.5




More information about the sheepdog mailing list