[CRIU] [PATCH 7/9] compel: plugins -- Add shmem plugin

Cyrill Gorcunov gorcunov at openvz.org
Wed Aug 24 09:47:37 PDT 2016


From: Dmitry Safonov <dsafonov at virtuozzo.com>

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 compel/include/shmem.h                     | 10 ++++++++
 compel/plugins/Makefile                    |  7 ++++++
 compel/plugins/include/std-priv.h          |  6 +++++
 compel/plugins/include/uapi/plugin-shmem.h | 17 +++++++++++++
 compel/plugins/shmem/shmem.c               | 38 ++++++++++++++++++++++++++++++
 5 files changed, 78 insertions(+)
 create mode 100644 compel/include/shmem.h
 create mode 100644 compel/plugins/include/std-priv.h
 create mode 100644 compel/plugins/include/uapi/plugin-shmem.h
 create mode 100644 compel/plugins/shmem/shmem.c

diff --git a/compel/include/shmem.h b/compel/include/shmem.h
new file mode 100644
index 000000000000..b6f994617e75
--- /dev/null
+++ b/compel/include/shmem.h
@@ -0,0 +1,10 @@
+#ifndef __COMPEL_PLUGIN_SHMEM_PRIV_H__
+#define __COMPEL_PLUGIN_SHMEM_PRIV_H__
+
+struct shmem_plugin_msg {
+	unsigned long start;
+	unsigned long len;
+};
+
+#endif /* __COMPEL_PLUGIN_SHMEM_PRIV_H__ */
+
diff --git a/compel/plugins/Makefile b/compel/plugins/Makefile
index 3743f3a9ca29..9480264bdd57 100644
--- a/compel/plugins/Makefile
+++ b/compel/plugins/Makefile
@@ -2,6 +2,9 @@
 
 ARCH_DIR		:= compel/arch/$(ARCH)/plugins
 
+#
+# CFLAGS, ASFLAGS, LDFLAGS
+
 # General compel includes
 ccflags-y		+= -iquote $(SRC_DIR)/compel/include
 
@@ -20,6 +23,10 @@ asflags-y		+= -iquote $(SRC_DIR)/$(ARCH_DIR)
 asflags-y		+= -Wstrict-prototypes -Wa,--noexecstack
 asflags-y		+= -D__ASSEMBLY__ -nostdlib -fomit-frame-pointer
 
+#
+# Shmem plugin
+target			+= shmem
+shmem-obj-y		+= shmem/shmem.o
 
 #
 # STD plugin
diff --git a/compel/plugins/include/std-priv.h b/compel/plugins/include/std-priv.h
new file mode 100644
index 000000000000..3fc3041c036f
--- /dev/null
+++ b/compel/plugins/include/std-priv.h
@@ -0,0 +1,6 @@
+#ifndef __COMPEL_PLUGIN_STD_PRIV_H__
+#define __COMPEL_PLUGIN_STD_PRIV_H__
+
+extern int std_ctl_sock(void);
+
+#endif /* __COMPEL_PLUGIN_STD_PRIV_H__ */
diff --git a/compel/plugins/include/uapi/plugin-shmem.h b/compel/plugins/include/uapi/plugin-shmem.h
new file mode 100644
index 000000000000..7e5850953a6b
--- /dev/null
+++ b/compel/plugins/include/uapi/plugin-shmem.h
@@ -0,0 +1,17 @@
+#ifndef __COMPEL_PLUGIN_SHMEM_H__
+#define __COMPEL_PLUGIN_SHMEM_H__
+
+/*
+ * Creates local shmem mapping and announces it
+ * to the peer. Peer can later "receive" one. The
+ * local area should be munmap()-ed at the end.
+ */
+extern void *shmem_create(unsigned long size);
+/*
+ * "Receives" shmem from peer and maps it. The
+ * locally mapped area should be munmap()-ed at
+ * the end
+ */
+extern void *shmem_receive(unsigned long *size);
+
+#endif /* __COMPEL_PLUGIN_SHMEM_H__ */
diff --git a/compel/plugins/shmem/shmem.c b/compel/plugins/shmem/shmem.c
new file mode 100644
index 000000000000..9ded93fb3e3d
--- /dev/null
+++ b/compel/plugins/shmem/shmem.c
@@ -0,0 +1,38 @@
+#include <sys/mman.h>
+
+#include "uapi/plugins.h"
+#include "uapi/plugin-shmem.h"
+#include "uapi/std/syscall.h"
+#include "shmem.h"
+#include "std-priv.h"
+
+void *shmem_create(unsigned long size)
+{
+	int ret;
+	void *mem;
+	struct shmem_plugin_msg spi;
+
+	mem = (void *)sys_mmap(NULL, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | MAP_ANON, 0, 0);
+	if (mem == MAP_FAILED)
+		return NULL;
+
+	spi.start = (unsigned long)mem;
+	spi.len = size;
+
+	ret = sys_write(std_ctl_sock(), &spi, sizeof(spi));
+	if (ret != sizeof(spi)) {
+		sys_munmap(mem, size);
+		return NULL;
+	}
+
+	return mem;
+}
+
+void *shmem_receive(unsigned long *size)
+{
+	/* master -> parasite not implemented yet */
+	return NULL;
+}
+
+PLUGIN_REGISTER_DUMMY(shmem)
-- 
2.7.4



More information about the CRIU mailing list