[Devel,criu-stable] mount: Enter/exit VE while mounting CR-time binfmt_misc

Submitted by Kirill Tkhai on Sept. 19, 2016, 3:05 p.m.

Details

Message ID 147429751368.8940.17970628907293304739.stgit@pro
State New
Series "mount: Enter/exit VE while mounting CR-time binfmt_misc"
Headers show

Commit Message

Kirill Tkhai Sept. 19, 2016, 3:05 p.m.
Since mounted binfmt_misc partition is per-VE, we should
enter it for normal mount resolution.

https://jira.sw.ru/browse/PSBM-52320

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/mount.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index 0f81891..6a4a161 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1350,6 +1350,28 @@  static int mount_cr_time_mount(struct ns_id *ns, unsigned int *s_dev, const char
 {
 	int mnt_fd, ret, exit_code = 0;
 	struct stat st;
+	int ve0_fd = -1, veX_fd = -1, len = -1;
+	char buf[PATH_MAX];
+
+	snprintf(buf, PATH_MAX, "/sys/fs/cgroup/ve/tasks");
+	ret = ve0_fd = open(buf, O_WRONLY);
+	if (ret < 0) {
+		pr_perror("Can't open %s", buf);
+		goto out;
+	}
+	snprintf(buf, PATH_MAX, "/sys/fs/cgroup/ve/%s/tasks", getenv("VEID"));
+	ret = veX_fd = open(buf, O_WRONLY);
+	if (ret < 0) {
+		pr_perror("Can't open %s", buf);
+		goto out;
+	}
+
+	len = sprintf(buf, "%d", getpid());
+	if (len <= 0 || write(veX_fd, buf, len) != len) {
+		pr_perror("Can't enter VE cgroup (len=%d)", len);
+		len = ret = -1;
+		goto out;
+	}
 
 	ret = switch_ns(ns->ns_pid, &mnt_ns_desc, &mnt_fd);
 	if (ret < 0) {
@@ -1374,6 +1396,12 @@  static int mount_cr_time_mount(struct ns_id *ns, unsigned int *s_dev, const char
 restore_ns:
 	ret = restore_ns(mnt_fd, &mnt_ns_desc);
 out:
+	if (len > 0 && write(ve0_fd, buf, len) != len) {
+		pr_perror("Can't restore VE\n");
+		ret = -1;
+	}
+	close(ve0_fd);
+	close(veX_fd);
 	return ret < 0 ? 0 : exit_code;
 }