[CRIU] [PATCH 3/8] compel: Routine to open proc files

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 21 10:26:15 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

Yet again -- CRIU has an optimized openat()-based engine that
is slightly faster for opening "/proc" files rather than plain
open(). The latter is provided by default by compel.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 compel/src/lib/infect.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index 98f1c80ca8bf..a834f76b6fb9 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -961,6 +961,21 @@ out:
 	return ret;
 }
 
+static int simple_open_proc(int pid, int mode, const char *fmt, ...)
+{
+	int l;
+	char path[128];
+	va_list args;
+
+	l = sprintf(path, "/proc/%d/", pid);
+
+	va_start(args, fmt);
+	vsnprintf(path + l, sizeof(path) - l, fmt, args);
+	va_end(args);
+
+	return open(path, mode);
+}
+
 struct parasite_ctl *compel_prepare(int pid)
 {
 	struct parasite_ctl *ctl;
@@ -972,6 +987,7 @@ struct parasite_ctl *compel_prepare(int pid)
 
 	ictx = &ctl->ictx;
 	ictx->task_size = task_size();
+	ictx->open_proc = simple_open_proc;
 	ictx->syscall_ip = find_executable_area(pid);
 	if (ictx->syscall_ip == (unsigned long)MAP_FAILED)
 		goto err;
-- 
2.7.4



More information about the CRIU mailing list