[sheepdog] [PATCH v2 2/2] sheep/http: add check for return value of http_request_read()

Robin Dong robin.k.dong at gmail.com
Tue Feb 11 08:22:51 CET 2014


From: Robin Dong <sanbai at taobao.com>

When users kill the curl which is uploading large files, the http_request_read()
will return 0 and lead to dead loop, so we should check it.
We also add code to free space of alloc after error happens.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
v1-->v2:
  1. swift_get_object() will handle SD_RES_EIO.

 sheep/http/kv.c    | 11 +++++++++++
 sheep/http/swift.c |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index de8c6af..0c54340 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -671,10 +671,21 @@ static int onode_populate_extents(struct kv_onode *onode,
 	total = req->data_length;
 	while (done < total) {
 		size = http_request_read(req, data_buf, write_buffer_size);
+		if (size <= 0) {
+			sd_err("Failed to read http request: %ld", size);
+			sys->cdrv->lock(data_vid);
+			oalloc_free(data_vid, start, count);
+			sys->cdrv->unlock(data_vid);
+			ret = SD_RES_EIO;
+			goto out;
+		}
 		ret = vdi_read_write(data_vid, data_buf, size, offset, false);
 		if (ret != SD_RES_SUCCESS) {
 			sd_err("Failed to write data object for %s, %s",
 			       onode->name, sd_strerror(ret));
+			sys->cdrv->lock(data_vid);
+			oalloc_free(data_vid, start, count);
+			sys->cdrv->unlock(data_vid);
 			goto out;
 		}
 		done += size;
diff --git a/sheep/http/swift.c b/sheep/http/swift.c
index 9d9ecfe..7b9685a 100644
--- a/sheep/http/swift.c
+++ b/sheep/http/swift.c
@@ -232,6 +232,9 @@ static void swift_get_object(struct http_request *req, const char *account,
 	case SD_RES_INVALID_PARMS:
 		http_response_header(req, REQUEST_RANGE_NOT_SATISFIABLE);
 		break;
+	case SD_RES_EIO:
+		http_response_header(req, PARTIAL_CONTENT);
+		break;
 	default:
 		http_response_header(req, INTERNAL_SERVER_ERROR);
 		break;
-- 
1.7.12.4



More information about the sheepdog mailing list