[CRIU] [PATCH v2 2/3] plugin: VZCT c/r core_pattern in CT
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Thu Feb 25 07:55:42 PST 2016
We have kernel.core_pattern virtualized per VZCT, that means:
each CT has own sysctl and coredumps are saved relative to VZCT fs
root accoring to that sysctl. Also coredump collector runs in
CTs usermodehelper. We need to c/r these sysctl, so:
Use POST_DUMP, POST_RESTORE plugin hooks, add separate VZCT image
for VZCT plugin and put there value of kernel.core_pattern sysctl
from CT. Use VZCT_ID environment variable of main criu process to
get id of c/r-ed container. Also add Makefile to compile plugin.
https://bugs.openvz.org/browse/OVZ-6696
https://jira.sw.ru/browse/PSBM-44145
v2: add bug links, use POST_DUMP, POST_RESTORE plugin hooks
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
criu/image-desc.c | 1 +
criu/include/image-desc.h | 2 +
criu/include/magic.h | 1 +
criu/include/protobuf-desc.h | 1 +
criu/protobuf-desc.c | 2 +
images/Makefile | 1 +
images/vzct.proto | 3 ++
test/vzct/Makefile | 4 ++
test/vzct/vzct.c | 105 +++++++++++++++++++++++++++++++++++++++++++
9 files changed, 120 insertions(+)
create mode 100644 images/vzct.proto
create mode 100644 test/vzct/Makefile
create mode 100644 test/vzct/vzct.c
diff --git a/criu/image-desc.c b/criu/image-desc.c
index de0fe93..6a08150 100644
--- a/criu/image-desc.c
+++ b/criu/image-desc.c
@@ -113,4 +113,5 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
.fmt = "filelocks-%d.img",
.magic = FILE_LOCKS_MAGIC,
},
+ FD_ENTRY(VZCT, "vzct"),
};
diff --git a/criu/include/image-desc.h b/criu/include/image-desc.h
index 532ced8..94c5db8 100644
--- a/criu/include/image-desc.h
+++ b/criu/include/image-desc.h
@@ -104,6 +104,8 @@ enum {
CR_FD_FANOTIFY_MARK,
CR_FD_EVENTPOLL_TFD,
+ CR_FD_VZCT,
+
CR_FD_MAX
};
diff --git a/criu/include/magic.h b/criu/include/magic.h
index b11a70e..47786c8 100644
--- a/criu/include/magic.h
+++ b/criu/include/magic.h
@@ -91,6 +91,7 @@
#define USERNS_MAGIC 0x55474906 /* Kazan */
#define SECCOMP_MAGIC 0x64413049 /* Kostomuksha */
#define BINFMT_MISC_MAGIC 0x67343323 /* Apatity */
+#define VZCT_MAGIC 0x60033780 /* Belozersk */
#define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define ROUTE_MAGIC RAW_IMAGE_MAGIC
diff --git a/criu/include/protobuf-desc.h b/criu/include/protobuf-desc.h
index bb66a86..20991f2 100644
--- a/criu/include/protobuf-desc.h
+++ b/criu/include/protobuf-desc.h
@@ -68,6 +68,7 @@ enum {
PB_SK_QUEUES,
PB_IPCNS_MSG,
PB_IPCNS_MSG_ENT,
+ PB_VZCT,
PB_MAX,
};
diff --git a/criu/protobuf-desc.c b/criu/protobuf-desc.c
index 511d349..2616289 100644
--- a/criu/protobuf-desc.c
+++ b/criu/protobuf-desc.c
@@ -63,6 +63,7 @@
#include "images/userns.pb-c.h"
#include "images/seccomp.pb-c.h"
#include "images/binfmt-misc.pb-c.h"
+#include "images/vzct.pb-c.h"
struct cr_pb_message_desc cr_pb_descs[PB_MAX];
@@ -98,6 +99,7 @@ void cr_pb_init(void)
CR_PB_DESC(IPCNS_MSG_ENT, IpcMsg, ipc_msg);
CR_PB_DESC(REMAP_FPATH, RemapFilePath, remap_file_path);
CR_PB_DESC(NETDEV, NetDevice, net_device);
+ CR_PB_DESC(VZCT, Vzct, vzct);
CR_PB_MDESC_INIT(cr_pb_descs[PB_PAGEMAP_HEAD], PagemapHead, pagemap_head);
#include "protobuf-desc-gen.h"
diff --git a/images/Makefile b/images/Makefile
index 16ecb6a..1978d26 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -58,6 +58,7 @@ proto-obj-y += opts.o
proto-obj-y += seccomp.o
proto-obj-y += binfmt-misc.o
proto-obj-y += time.o
+proto-obj-y += vzct.o
CFLAGS += -iquote $(obj)/
diff --git a/images/vzct.proto b/images/vzct.proto
new file mode 100644
index 0000000..27121cb
--- /dev/null
+++ b/images/vzct.proto
@@ -0,0 +1,3 @@
+message vzct_entry {
+ required string core_pattern = 1;
+}
diff --git a/test/vzct/Makefile b/test/vzct/Makefile
new file mode 100644
index 0000000..0e1625d
--- /dev/null
+++ b/test/vzct/Makefile
@@ -0,0 +1,4 @@
+all: vzct.so
+
+vzct.so: vzct.c
+ gcc -g -Werror -Wall -shared -nostartfiles vzct.c -o vzct.so -iquote ../../criu/include -iquote ../../ -iquote ../../criu/arch/x86/include -fPIC
diff --git a/test/vzct/vzct.c b/test/vzct/vzct.c
new file mode 100644
index 0000000..c31f967
--- /dev/null
+++ b/test/vzct/vzct.c
@@ -0,0 +1,105 @@
+#include "protobuf.h"
+#include "image.h"
+#include "protobuf-desc.h"
+#include "image-desc.h"
+#include "images/vzct.pb-c.h"
+
+#include "criu-plugin.h"
+
+#define VZCT_ID_ENV "VZCT_ID"
+#define VZCTL_GET_CORE_PATTERN "vzctl exec %s cat /proc/sys/kernel/core_pattern"
+#define VZCTL_SET_CORE_PATTERN "vzctl exec %s echo \"%s\" > /proc/sys/kernel/core_pattern"
+#define MAX_LEN 200
+
+static int dump_vzct()
+{
+ FILE *vzctl_cmd;
+ int ret;
+ char core_pattern[MAX_LEN];
+ char *ctid;
+ char cmd[MAX_LEN];
+ struct cr_img *img;
+ VzctEntry vzct = VZCT_ENTRY__INIT;
+
+ ctid = getenv(VZCT_ID_ENV);
+ if (!ctid) {
+ perror("No VZCT_ID env");
+ return -1;
+ }
+
+ sprintf(cmd, VZCTL_GET_CORE_PATTERN, ctid);
+
+ vzctl_cmd = popen(cmd, "r");
+ if (vzctl_cmd == NULL) {
+ perror("Failed to popen command");
+ return -1;
+ }
+
+ if (fgets(core_pattern, MAX_LEN, vzctl_cmd) == NULL) {
+ perror("Failed to read command output");
+ goto err;
+ }
+ vzct.core_pattern = core_pattern;
+
+ img = open_image_at(criu_get_image_dir(), CR_FD_VZCT, O_RDWR | O_CREAT | O_TRUNC);
+ if (!img) {
+ perror("Failed to open image");
+ goto err;
+ }
+
+ ret = pb_write_one(img, &vzct, PB_VZCT);
+ if (ret) {
+ perror("Failed to write to image");
+ goto errimg;
+ }
+
+ close_image(img);
+ pclose(vzctl_cmd);
+ return 0;
+errimg:
+ close_image(img);
+err:
+ pclose(vzctl_cmd);
+ return -1;
+}
+
+static int restore_vzct()
+{
+ int ret;
+ char *ctid;
+ char cmd[MAX_LEN];
+ struct cr_img *img;
+ VzctEntry *vzct;
+
+ ctid = getenv(VZCT_ID_ENV);
+ if (!ctid) {
+ perror("No VZCT_ID env");
+ return -1;
+ }
+
+ img = open_image_at(criu_get_image_dir(), CR_FD_VZCT, O_RDONLY);
+ if (!img)
+ return 0;
+
+ ret = pb_read_one(img, &vzct, PB_VZCT);
+ if (ret < 0) {
+ perror("Failed to read from image");
+ goto errimg;
+ }
+
+ sprintf(cmd, VZCTL_SET_CORE_PATTERN, ctid, vzct->core_pattern);
+
+ ret = system(cmd);
+ if (ret == -1) {
+ perror("Failed to run command");
+ goto errimg;
+ }
+
+errimg:
+ close_image(img);
+ return ret;
+}
+
+CR_PLUGIN_REGISTER_DUMMY("trivial")
+CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__POST_DUMP, dump_vzct)
+CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__POST_RESTORE, restore_vzct)
--
1.9.3
More information about the CRIU
mailing list