restore: Factor out thread core opening

Submitted by Pavel Emelianov on May 23, 2016, 7:13 p.m.

Details

Message ID 57435648.30105@virtuozzo.com
State Accepted
Series "restore: Factor out thread core opening"
Commit 03b6a8512c4f3368074bdfa4525199587c7fc4a7
Headers show

Commit Message

Pavel Emelianov May 23, 2016, 7:13 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/cr-restore.c | 46 ++++++++++++++++++++--------------------------
 1 file changed, 20 insertions(+), 26 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index e05deb7..083e722 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -401,6 +401,23 @@  static int collect_zombie_pids()
 	return collect_child_pids(TASK_DEAD, &n_zombies);
 }
 
+static int open_core(int pid, CoreEntry **pcore)
+{
+	int ret;
+	struct cr_img *img;
+
+	img = open_image(CR_FD_CORE, O_RSTR, pid);
+	if (!img) {
+		pr_err("Can't open core data for %d", pid);
+		return -1;
+	}
+
+	ret = pb_read_one(img, pcore, PB_CORE);
+	close_image(img);
+
+	return ret <= 0 ? -1 : 0;
+}
+
 static int open_cores(int pid, CoreEntry *leader_core)
 {
 	int i, tpid;
@@ -415,22 +432,8 @@  static int open_cores(int pid, CoreEntry *leader_core)
 
 		if (tpid == pid)
 			cores[i] = leader_core;
-		else {
-			struct cr_img *img;
-
-			img = open_image(CR_FD_CORE, O_RSTR, tpid);
-			if (!img) {
-				pr_err("Can't open core data for thread %d\n", tpid);
-				goto err;
-			}
-
-			if (pb_read_one(img, &cores[i], PB_CORE) <= 0) {
-				close_image(img);
-				goto err;
-			}
-
-			close_image(img);
-		}
+		else if (open_core(tpid, &cores[i]))
+			goto err;
 	}
 
 	current->core = cores;
@@ -780,16 +783,7 @@  static inline int fork_with_pid(struct pstree_item *item)
 	pid_t pid = item->pid.virt;
 
 	if (item->pid.state != TASK_HELPER) {
-		struct cr_img *img;
-
-		img = open_image(CR_FD_CORE, O_RSTR, pid);
-		if (!img)
-			return -1;
-
-		ret = pb_read_one(img, &ca.core, PB_CORE);
-		close_image(img);
-
-		if (ret < 0)
+		if (open_core(pid, &ca.core))
 			return -1;
 
 		if (check_core(ca.core, item))