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

Robin Dong robin.k.dong at gmail.com
Wed Jan 29 10:15:05 CET 2014


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>
---
 sheep/http/kv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sheep/http/kv.c b/sheep/http/kv.c
index f896ab1..e7eb5f2 100644
--- a/sheep/http/kv.c
+++ b/sheep/http/kv.c
@@ -700,10 +700,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;
-- 
1.7.12.4




More information about the sheepdog mailing list