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

Radostin Stoyanov rstoyanov1 at gmail.com
Sun Jul 8 19:47:11 MSK 2018


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 at gmail.com>
---
 criu/img-remote.c | 30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

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).
-- 
2.17.1



More information about the CRIU mailing list