[CRIU] [PATCH v4] IPC: collect and dump tunables sequentially
Kinsbursky Stanislav
skinsbursky at openvz.org
Wed Feb 8 04:13:38 EST 2012
v4: typos fixes
v3: cosmetic changes
v2: "TUN/tun" replaces by "VAR/var" respectively.
This patch removes collect stage and dumps tunables object right after
collect.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at parallels.com>
---
cr-show.c | 4 +-
crtools.c | 8 ++-
include/crtools.h | 6 +--
include/image.h | 5 +-
include/ipc_ns.h | 2 -
ipc_ns.c | 123 ++++++++++++++++++++++-------------------------------
6 files changed, 64 insertions(+), 84 deletions(-)
diff --git a/cr-show.c b/cr-show.c
index 6855b50..33e60b8 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -514,8 +514,8 @@ static int cr_parse_file(struct cr_options *opts)
case CREDS_MAGIC:
show_creds(fd);
break;
- case IPCNS_MAGIC:
- show_ipc_ns(fd);
+ case IPCNS_VAR_MAGIC:
+ show_ipc_var(fd);
break;
default:
pr_err("Unknown magic %x on %s\n", magic, opts->show_dump_file);
diff --git a/crtools.c b/crtools.c
index 5431443..8cfe866 100644
--- a/crtools.c
+++ b/crtools.c
@@ -111,10 +111,10 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
.magic = UTSNS_MAGIC,
},
- /* IPC namespace */
- [CR_FD_IPCNS] = {
- .fmt = FMT_FNAME_IPCNS,
- .magic = IPCNS_MAGIC,
+ /* IPC namespace variables */
+ [CR_FD_IPCNS_VAR] = {
+ .fmt = FMT_FNAME_IPCNS_VAR,
+ .magic = IPCNS_VAR_MAGIC,
},
};
diff --git a/include/crtools.h b/include/crtools.h
index 5a3c570..acb6a6d 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -37,7 +37,7 @@ enum {
CR_FD_PSTREE,
CR_FD_UTSNS,
- CR_FD_IPCNS,
+ CR_FD_IPCNS_VAR,
CR_FD_MAX
};
@@ -79,7 +79,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
#define FMT_FNAME_ITIMERS "itimers-%d.img"
#define FMT_FNAME_CREDS "creds-%d.img"
#define FMT_FNAME_UTSNS "utsns-%d.img"
-#define FMT_FNAME_IPCNS "ipcns-%d.img"
+#define FMT_FNAME_IPCNS_VAR "ipcns-var-%d.img"
extern int get_image_path(char *path, int size, const char *fmt, int pid);
@@ -111,7 +111,7 @@ struct cr_fdset {
CR_FD_DESC_USE(CR_FD_CREDS) )
#define CR_FD_DESC_NS (\
CR_FD_DESC_USE(CR_FD_UTSNS) |\
- CR_FD_DESC_USE(CR_FD_IPCNS) )
+ CR_FD_DESC_USE(CR_FD_IPCNS_VAR) )
#define CR_FD_DESC_NONE (0)
int cr_dump_tasks(pid_t pid, struct cr_options *opts);
diff --git a/include/image.h b/include/image.h
index 58b13fc..ca2a178 100644
--- a/include/image.h
+++ b/include/image.h
@@ -21,7 +21,7 @@
#define ITIMERS_MAGIC 0x57464056 /* Kostroma */
#define UTSNS_MAGIC 0x54473203 /* Smolensk */
#define CREDS_MAGIC 0x54023547 /* Kozelsk */
-#define IPCNS_MAGIC 0x53115007 /* Samara */
+#define IPCNS_VAR_MAGIC 0x53115007 /* Samara */
#define PIPEFS_MAGIC 0x50495045
@@ -105,7 +105,7 @@ struct vma_entry {
s64 fd;
} __packed;
-struct ipc_ns_entry {
+struct ipc_var_entry {
u32 sem_ctls[4];
u32 msg_ctlmax;
u32 msg_ctlmnb;
@@ -118,7 +118,6 @@ struct ipc_ns_entry {
u32 mq_queues_max;
u32 mq_msg_max;
u32 mq_msgsize_max;
- u32 in_use[3];
} __packed;
#define VMA_AREA_NONE (0 << 0)
diff --git a/include/ipc_ns.h b/include/ipc_ns.h
index 138b586..60fc1a2 100644
--- a/include/ipc_ns.h
+++ b/include/ipc_ns.h
@@ -3,7 +3,7 @@
#include "crtools.h"
-extern void show_ipc_ns(int fd);
+extern void show_ipc_var(int fd);
extern int dump_ipc_ns(int ns_pid, struct cr_fdset *fdset);
extern int prepare_ipc_ns(int pid);
diff --git a/ipc_ns.c b/ipc_ns.c
index 3336d8c..cc34a6a 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -13,15 +13,7 @@
#include "namespaces.h"
#include "sysctl.h"
-struct ipc_ns_data {
- struct ipc_ns_entry entry;
-};
-
-#define IPC_SEM_IDS 0
-#define IPC_MSG_IDS 1
-#define IPC_SHM_IDS 2
-
-static int ipc_sysctl_req(struct ipc_ns_entry *e, int op)
+static int ipc_sysctl_req(struct ipc_var_entry *e, int op)
{
struct sysctl_req req[] = {
{ "kernel/sem", e->sem_ctls, CTL_U32A(4) },
@@ -42,7 +34,7 @@ static int ipc_sysctl_req(struct ipc_ns_entry *e, int op)
return sysctl_op(req, op);
}
-static int collect_ipc_msg(void *data)
+static int dump_ipc_msg(void *data)
{
struct msginfo info;
int ret;
@@ -62,7 +54,7 @@ static int collect_ipc_msg(void *data)
return 0;
}
-static int collect_ipc_sem(void *data)
+static int dump_ipc_sem(void *data)
{
int ret;
struct seminfo info;
@@ -79,7 +71,7 @@ static int collect_ipc_sem(void *data)
return 0;
}
-static int collect_ipc_shm(void *data)
+static int dump_ipc_shm(void *data)
{
int fd;
int ret;
@@ -97,60 +89,53 @@ static int collect_ipc_shm(void *data)
return 0;
}
-static int collect_ipc_tun(struct ipc_ns_entry *e)
+static int dump_ipc_var(int fd)
{
- return ipc_sysctl_req(e, CTL_READ);
+ int ret;
+ struct ipc_var_entry var;
+
+ ret = ipc_sysctl_req(&var, CTL_READ);
+ if (ret < 0) {
+ pr_err("Failed to read IPC variables\n");
+ return ret;
+ }
+
+ ret = write_img(fd, &var);
+ if (ret < 0) {
+ pr_err("Failed to write IPC variables\n");
+ return ret;
+ }
+ return 0;
}
-static int collect_ipc_data(struct ipc_ns_data *ipc)
+static int dump_ipc_data(struct cr_fdset *fdset)
{
- int fd, ret;
- struct ipc_ns_entry *entry = &ipc->entry;
+ int ret;
- entry->in_use[IPC_MSG_IDS] = ret = collect_ipc_msg(NULL);
+ ret = dump_ipc_var(fdset->fds[CR_FD_IPCNS_VAR]);
if (ret < 0)
return ret;
- entry->in_use[IPC_SEM_IDS] = ret = collect_ipc_sem(NULL);
+ ret = dump_ipc_shm(0);
if (ret < 0)
return ret;
- entry->in_use[IPC_SHM_IDS] = ret = collect_ipc_shm(NULL);
+ ret = dump_ipc_msg(0);
if (ret < 0)
return ret;
- ret = collect_ipc_tun(entry);
+ ret = dump_ipc_sem(0);
if (ret < 0)
return ret;
-
- return 0;
-}
-
-static int dump_ipc_data(int fd, struct ipc_ns_data *ipc)
-{
- int err;
-
- err = write_img(fd, &ipc->entry);
- if (err < 0) {
- pr_err("Failed to write IPC namespace entry\n");
- return err;
- }
return 0;
}
int dump_ipc_ns(int ns_pid, struct cr_fdset *fdset)
{
int fd, ret;
- struct ipc_ns_data ipc;
ret = switch_ns(ns_pid, CLONE_NEWIPC, "ipc");
if (ret < 0)
return ret;
- ret = collect_ipc_data(&ipc);
- if (ret < 0) {
- pr_err("Failed to collect IPC namespace data\n");
- return ret;
- }
-
- ret = dump_ipc_data(fdset->fds[CR_FD_IPCNS], &ipc);
+ ret = dump_ipc_data(fdset);
if (ret < 0) {
pr_err("Failed to write IPC namespace data\n");
return ret;
@@ -158,59 +143,55 @@ int dump_ipc_ns(int ns_pid, struct cr_fdset *fdset)
return 0;
}
-static void show_ipc_entry(struct ipc_ns_entry *entry)
+static void show_var_entry(struct ipc_var_entry *entry)
{
ipc_sysctl_req(entry, CTL_PRINT);
}
-static void show_ipc_data(int fd)
+static void show_ipc_var_entry(int fd)
{
int ret;
- struct ipc_ns_entry entry;
+ struct ipc_var_entry var;
- ret = read_img_eof(fd, &entry);
+ ret = read_img_eof(fd, &var);
if (ret <= 0)
return;
- show_ipc_entry(&entry);
+ show_var_entry(&var);
}
-void show_ipc_ns(int fd)
+void show_ipc_var(int fd)
{
pr_img_head(CR_FD_IPCNS);
- show_ipc_data(fd);
+ show_ipc_var_entry(fd);
pr_img_tail(CR_FD_IPCNS);
}
-static int prepare_ipc_tun(struct ipc_ns_entry *e)
+static int prepare_ipc_var(int pid)
{
- return ipc_sysctl_req(e, CTL_WRITE);
-}
+ int fd, ret;
+ struct ipc_var_entry var;
-static int prepare_ipc_data(int fd)
-{
- int ret;
- struct ipc_ns_data ipc;
+ pr_info("Restoring IPC variables\n");
+ fd = open_image_ro(CR_FD_IPCNS_VAR, pid);
+ if (fd < 0)
+ return -1;
- ret = read_img(fd, &ipc);
+ ret = read_img(fd, &var);
if (ret <= 0)
return -EFAULT;
- ret = prepare_ipc_tun(&ipc.entry);
- if (ret < 0)
- return ret;
- return 0;
+
+ show_var_entry(&var);
+
+ return ipc_sysctl_req(&var, CTL_WRITE);
}
int prepare_ipc_ns(int pid)
{
- int fd, ret;
-
- fd = open_image_ro(CR_FD_IPCNS, pid);
- if (fd < 0)
- return -1;
-
- ret = prepare_ipc_data(fd);
+ int ret;
- close(fd);
- return ret;
+ pr_info("Restoring IPC namespace\n");
+ ret = prepare_ipc_var(pid);
+ if (ret < 0)
+ return ret;
+ return 0;
}
-
More information about the CRIU
mailing list