[02/22] unix: Move stale unlink into post-prep

Submitted by Pavel Emelianov on June 30, 2017, 10:56 a.m.

Details

Message ID e3b98839-be84-1fb3-c7d2-27d4829edb10@virtuozzo.com
State Accepted
Series "Merge images with different files into one"
Headers show

Commit Message

Pavel Emelianov June 30, 2017, 10:56 a.m.
The call to unlink() should happen in root task context,
while the collection stage is about to be moved into the
crtools, so keep the stale-unlink piece in post-prep
for a socket.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/sk-unix.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 7c71448..69c1d14 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1390,7 +1390,19 @@  static void unlink_stale(struct unix_sk_info *ui)
 	revert_unix_sk_cwd(&cwd_fd, &root_fd);
 }
 
-static int resolve_unix_peer(struct pprep_head *ph);
+static int resolve_unix_peer(struct unix_sk_info *ui);
+
+static int post_prepare_unix_sk(struct pprep_head *ph)
+{
+	struct unix_sk_info *ui;
+
+	ui = container_of(ph, struct unix_sk_info, peer_resolve);
+	if (ui->ue->peer && resolve_unix_peer(ui))
+		return -1;
+	if (ui->name)
+		unlink_stale(ui);
+	return 0;
+}
 
 static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
 {
@@ -1401,11 +1413,6 @@  static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
 	ui->ue = pb_msg(base, UnixSkEntry);
 	ui->name_dir = (void *)ui->ue->name_dir;
 
-	if (ui->ue->peer) {
-		ui->peer_resolve.actor = resolve_unix_peer;
-		add_post_prepare_cb(&ui->peer_resolve);
-	}
-
 	if (ui->ue->name.len) {
 		if (ui->ue->name.len > UNIX_PATH_MAX) {
 			pr_err("Bad unix name len %d\n", (int)ui->ue->name.len);
@@ -1413,8 +1420,6 @@  static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
 		}
 
 		ui->name = (void *)ui->ue->name.data;
-
-		unlink_stale(ui);
 	} else
 		ui->name = NULL;
 
@@ -1452,6 +1457,11 @@  static int collect_one_unixsk(void *o, ProtobufCMessage *base, struct cr_img *i)
 		prefix, ulen, uname,
 		ui->name_dir ? ui->name_dir : "-");
 
+	if (ui->ue->peer || ui->name) {
+		ui->peer_resolve.actor = post_prepare_unix_sk;
+		add_post_prepare_cb(&ui->peer_resolve);
+	}
+
 	list_add_tail(&ui->list, &unix_sockets);
 	return file_desc_add(&ui->d, ui->ue->id, &unix_desc_ops);
 }
@@ -1490,11 +1500,10 @@  static void interconnected_pair(struct unix_sk_info *ui, struct unix_sk_info *pe
 	}
 }
 
-static int resolve_unix_peer(struct pprep_head *ph)
+static int resolve_unix_peer(struct unix_sk_info *ui)
 {
-	struct unix_sk_info *ui, *peer;
+	struct unix_sk_info *peer;
 
-	ui = container_of(ph, struct unix_sk_info, peer_resolve);
 	if (ui->peer)
 		goto out;