[7/7] remote: Combine check_pending_{reads,forwards}

Submitted by Radostin Stoyanov on July 8, 2018, 4:47 p.m.

Details

Message ID 20180708164711.857-8-rstoyanov1@gmail.com
State New
Series "Image-{cache,proxy} tweaks"
Headers show

Commit Message

Radostin Stoyanov July 8, 2018, 4:47 p.m.
Both functions check_pending_forwards() and check_pending_reads()
have very similar functionality. This patch aims to reduce the
duplication of code by merging both functions into check_pending()

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 criu/img-remote.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/img-remote.c b/criu/img-remote.c
index 3adb569d..264f49af 100644
--- a/criu/img-remote.c
+++ b/criu/img-remote.c
@@ -787,22 +787,7 @@  err:
 	free(rop);
 }
 
-void check_pending_forwards()
-{
-	struct roperation *rop = NULL;
-	struct rimage *rimg = NULL;
-
-	list_for_each_entry(rop, &rop_forwarding, l) {
-		rimg = get_rimg_by_name(rop->snapshot_id, rop->path);
-		if (rimg != NULL) {
-			rop_set_rimg(rop, rimg);
-			forward_remote_image(rop);
-			return;
-		}
-	}
-}
-
-void check_pending_reads()
+void check_pending()
 {
 	struct roperation *rop = NULL;
 	struct rimage *rimg = NULL;
@@ -811,7 +796,12 @@  void check_pending_reads()
 		rimg = get_rimg_by_name(rop->snapshot_id, rop->path);
 		if (rimg != NULL) {
 			rop_set_rimg(rop, rimg);
-			event_set(epoll_fd, EPOLL_CTL_ADD, rop->fd, EPOLLOUT, rop);
+			if (restoring) {
+				event_set(epoll_fd, EPOLL_CTL_ADD, rop->fd, EPOLLOUT, rop);
+			} else {
+				forward_remote_image(rop);
+				return;
+			}
 		}
 	}
 }
@@ -881,10 +871,8 @@  void accept_image_connections() {
 		}
 
 		// Check if there are any pending operations
-		if (restoring)
-			check_pending_reads();
-		else if (!forwarding)
-			check_pending_forwards();
+		if (restoring || !forwarding)
+			check_pending();
 
 		// Check if we can close the tcp socket (this will unblock the cache
 		// to answer "no image" to restore).