Changes:
 - Update to match UTS changes

Signed-off-by: Dan Smith <[email protected]>
---
 checkpoint/checkpoint.c        |   26 +++++++++++++++++++++
 checkpoint/objhash.c           |    7 +++++
 checkpoint/restart.c           |   49 ++++++++++++++++++++++++++++++++++++++++
 include/linux/checkpoint.h     |    1 +
 include/linux/checkpoint_hdr.h |    6 +++++
 5 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/checkpoint/checkpoint.c b/checkpoint/checkpoint.c
index 5f83e83..e20eff3 100644
--- a/checkpoint/checkpoint.c
+++ b/checkpoint/checkpoint.c
@@ -240,6 +240,21 @@ static int cr_write_utsns(struct cr_ctx *ctx, struct 
new_utsname *name)
        return ret;
 }
 
+static int cr_write_ipcns(struct cr_ctx *ctx, struct ipc_namespace *ipc)
+{
+       struct cr_hdr h;
+       struct cr_hdr_ipcns *hh = cr_hbuf_get(ctx, sizeof(*hh));
+       int ret;
+
+       h.type = CR_HDR_IPCNS;
+       h.len = sizeof(*hh);
+
+       ret = cr_write_obj(ctx, &h, hh);
+       cr_hbuf_put(ctx, sizeof(*hh));
+
+       return ret;
+}
+
 static int cr_write_namespaces(struct cr_ctx *ctx, struct task_struct *t)
 {
        struct cr_hdr h;
@@ -247,6 +262,7 @@ static int cr_write_namespaces(struct cr_ctx *ctx, struct 
task_struct *t)
        struct nsproxy *nsp = t->nsproxy;
        int ret;
        int uts;
+       int ipc;
 
        h.type = CR_HDR_NS;
        h.len = sizeof(*hh);
@@ -255,6 +271,10 @@ static int cr_write_namespaces(struct cr_ctx *ctx, struct 
task_struct *t)
        if (uts < 0)
                goto out;
 
+       ipc = cr_obj_add_ptr(ctx, nsp->ipc_ns, &hh->ipc_ref, CR_OBJ_IPCNS, 0);
+       if (ipc < 0)
+               goto out;
+
        ret = cr_write_obj(ctx, &h, hh);
        if (ret)
                goto out;
@@ -265,6 +285,12 @@ static int cr_write_namespaces(struct cr_ctx *ctx, struct 
task_struct *t)
                        goto out;
        }
 
+       if (ipc) {
+               ret = cr_write_ipcns(ctx, nsp->ipc_ns);
+               if (ret < 0)
+                       goto out;
+       }
+
        /* FIXME: Write other namespaces here */
  out:
        cr_hbuf_put(ctx, sizeof(*hh));
diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c
index c6ae7c1..b04f8df 100644
--- a/checkpoint/objhash.c
+++ b/checkpoint/objhash.c
@@ -13,6 +13,7 @@
 #include <linux/hash.h>
 #include <linux/checkpoint.h>
 #include <linux/utsname.h>
+#include <linux/ipc_namespace.h>
 
 struct cr_objref {
        int objref;
@@ -42,6 +43,9 @@ static void cr_obj_ref_drop(struct cr_objref *obj)
        case CR_OBJ_UTSNS:
                put_uts_ns((struct uts_namespace *) obj->ptr);
                break;
+       case CR_OBJ_IPCNS:
+               put_ipc_ns((struct ipc_namespace *) obj->ptr);
+               break;
        default:
                BUG();
        }
@@ -62,6 +66,9 @@ static int cr_obj_ref_grab(struct cr_objref *obj)
        case CR_OBJ_UTSNS:
                get_uts_ns((struct uts_namespace *) obj->ptr);
                break;
+       case CR_OBJ_IPCNS:
+               get_ipc_ns((struct ipc_namespace *) obj->ptr);
+               break;
        default:
                BUG();
        }
diff --git a/checkpoint/restart.c b/checkpoint/restart.c
index f42d549..803816a 100644
--- a/checkpoint/restart.c
+++ b/checkpoint/restart.c
@@ -16,6 +16,7 @@
 #include <linux/checkpoint.h>
 #include <linux/checkpoint_hdr.h>
 #include <linux/utsname.h>
+#include <linux/ipc_namespace.h>
 #include <linux/syscalls.h>
 
 #include "checkpoint_arch.h"
@@ -315,6 +316,49 @@ static int cr_restore_utsns(struct cr_ctx *ctx, int ref)
        return 0;
 }
 
+static int cr_read_ipcns(struct cr_ctx *ctx, struct task_struct *t)
+{
+       struct cr_hdr_ipcns hh;
+       int ret;
+
+       ret = cr_read_obj_type(ctx, &hh, sizeof(hh), CR_HDR_IPCNS);
+       if (ret < 0)
+               return ret;
+
+       /* FIXME: Implement this */
+
+       return 0;
+}
+
+static int cr_restore_ipcns(struct cr_ctx *ctx, int ref)
+{
+       struct ipc_namespace *ipc;
+       int ret;
+
+       ipc = cr_obj_get_by_ref(ctx, ref, CR_OBJ_IPCNS);
+       if (ipc == NULL) {
+               ret = cr_read_ipcns(ctx, current);
+               if (ret < 0)
+                       return ret;
+
+               return cr_obj_add_ref(ctx, current->nsproxy->ipc_ns,
+                                     ref, CR_OBJ_IPCNS, 0);
+       } else if (IS_ERR(ipc)) {
+               cr_debug("Failed to get IPC ns from objhash\n");
+               return PTR_ERR(ipc);
+       }
+
+       ret = copy_namespaces(CLONE_NEWIPC, current);
+       if (ret < 0)
+               return ret;
+
+       put_ipc_ns(current->nsproxy->ipc_ns);
+       get_ipc_ns(ipc);
+       current->nsproxy->ipc_ns = ipc;
+
+       return 0;
+}
+
 static int cr_read_namespaces(struct cr_ctx *ctx)
 {
        struct cr_hdr_namespaces hh;
@@ -329,6 +373,11 @@ static int cr_read_namespaces(struct cr_ctx *ctx)
        if (ret < 0)
                return ret;
 
+       ret = cr_restore_ipcns(ctx, hh.ipc_ref);
+       cr_debug("ipc ns: %d\n", ret);
+       if (ret < 0)
+               return ret;
+
        /* FIXME: Add more namespaces here */
 
        return 0;
diff --git a/include/linux/checkpoint.h b/include/linux/checkpoint.h
index cb62716..2fc39fb 100644
--- a/include/linux/checkpoint.h
+++ b/include/linux/checkpoint.h
@@ -76,6 +76,7 @@ enum {
        CR_OBJ_FILE = 1,
        CR_OBJ_INODE,
        CR_OBJ_UTSNS,
+       CR_OBJ_IPCNS,
        CR_OBJ_MAX
 };
 
diff --git a/include/linux/checkpoint_hdr.h b/include/linux/checkpoint_hdr.h
index 6f29a72..9d5d935 100644
--- a/include/linux/checkpoint_hdr.h
+++ b/include/linux/checkpoint_hdr.h
@@ -50,6 +50,7 @@ enum {
        CR_HDR_CPU,
        CR_HDR_NS,
        CR_HDR_UTSNS,
+       CR_HDR_IPCNS,
 
        CR_HDR_MM = 201,
        CR_HDR_VMA,
@@ -181,6 +182,7 @@ struct cr_hdr_fd_pipe {
 
 struct cr_hdr_namespaces {
        __u32 uts_ref;
+       __u32 ipc_ref;
 };
 
 struct cr_hdr_utsns {
@@ -188,4 +190,8 @@ struct cr_hdr_utsns {
        __u32 domainname_len;
 };
 
+struct cr_hdr_ipcns {
+       /* FIXME: Fill this in */
+};
+
 #endif /* _CHECKPOINT_CKPT_HDR_H_ */
-- 
1.5.6.3

_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers

_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel

Reply via email to