Use a trivial completion hanlder for peer I/O requests and a slightly more
complicated one for gateway requests instead of interwinding the two.


Signed-off-by: Christoph Hellwig <hch@lst.de>

diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 266a733..da346aa 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -116,6 +116,26 @@ static void check_object_consistency(struct sd_req *hdr)
 static void io_op_done(struct work *work)
 {
 	struct request *req = container_of(work, struct request, work);
+
+	list_del(&req->request_list);
+
+	if (req->rp.result == SD_RES_EIO) {
+		req->rp.result = SD_RES_NETWORK_ERROR;
+
+		eprintf("leaving sheepdog cluster\n");
+		leave_cluster();
+	}
+
+	resume_pending_requests();
+	resume_recovery_work();
+
+	req_done(req);
+	return;
+}
+
+static void gateway_op_done(struct work *work)
+{
+	struct request *req = container_of(work, struct request, work);
 	struct sd_req *hdr = &req->rq;
 
 	list_del(&req->request_list);
@@ -126,25 +146,18 @@ static void io_op_done(struct work *work)
 	case SD_RES_NETWORK_ERROR:
 	case SD_RES_WAIT_FOR_JOIN:
 	case SD_RES_WAIT_FOR_FORMAT:
-		if (!(req->rq.flags & SD_FLAG_CMD_IO_LOCAL)) {
-			if (req->rp.epoch > sys->epoch &&
-			    req->rp.result == SD_RES_OLD_NODE_VER) {
-				list_add_tail(&req->request_list,
-						&sys->wait_rw_queue);
-			} else
-				goto retry;
+		if (req->rp.epoch > sys->epoch &&
+		    req->rp.result == SD_RES_OLD_NODE_VER) {
+			list_add_tail(&req->request_list,
+					&sys->wait_rw_queue);
+		} else {
+			goto retry;
 		}
-		break;
 	case SD_RES_EIO:
 		if (is_access_local(req, hdr->obj.oid)) {
 			eprintf("leaving sheepdog cluster\n");
 			leave_cluster();
-
-			if (!(req->rq.flags & SD_FLAG_CMD_IO_LOCAL))
-				goto retry;
-
-			/* hack to retry */
-			req->rp.result = SD_RES_NETWORK_ERROR;
+			goto retry;
 		}
 		break;
 	case SD_RES_SUCCESS:
@@ -364,7 +377,7 @@ static void queue_gateway_request(struct request *req)
 		set_consistency_check(req);
 
 	req->work.fn = do_gateway_request;
-	req->work.done = io_op_done;
+	req->work.done = gateway_op_done;
 	queue_work(sys->gateway_wqueue, &req->work);
 }
 


