Skip to contentSkip to conversation

Protect the invariants

PATCH In review Pete Zaitcev 1 participant 1 message May 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 2/6 Protect the invariants

I am unable to ensure that the invariants such as having something in write_q upon restart are not violated, ever. So, let's rearrange the code a little bit to make sure.

[Before sending I noticed that this patch included a piece of other, unrelated patch. However, this passed tests on its own (because cli_wr_set_poll never returns an error). So in the interests of not screwing up further, sending as-is.]

---
 server/object.c |    6 ++++++
 server/server.c |    9 ++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

commit 75d01d61e9ca55d244120cbbd7f338f07f03e9b6

Author: Master <[email protected]>
Date:   Thu May 20 21:26:55 2010 -0600

Protect the invariants.

server/object.c +6 -0
index 40ef4c4..7f6341a 100644
@@ -342,6 +342,12 @@ bool object_get(struct client *cli, bool want_body)
 		goto start_write;
 	}
 
+	if (!cli->in_len) {
+		applog(LOG_INFO, "zero-sized object");
+		cli_in_end(cli);
+		goto start_write;
+	}
+
 	if (!object_read_bytes(cli)) {
 		cli_in_end(cli);
 		return cli_err(cli, err, false);
server/server.c +4 -5
index 07d0375..de9e6a8 100644
@@ -529,14 +529,13 @@ do_write:
 
 	cli_wr_completed(cli, rc, &more_work);
 
-	if (more_work)
-		goto restart;
-
 	/* if we emptied the queue, clear write notification */
 	if (list_empty(&cli->write_q)) {
 		cli->writing = false;
-		if (!cli_wr_set_poll(cli, false))
-			goto err_out;
+		cli_wr_set_poll(cli, false);
+	} else {
+		if (more_work)
+			goto restart;
 	}
 
 	return;