Linux Container Development
 help / color / mirror / Atom feed
From: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 3/3] Stub implementation of IPC namespace c/r (v2)
Date: Tue, 31 Mar 2009 13:58:27 -0700	[thread overview]
Message-ID: <1238533107-11796-4-git-send-email-danms@us.ibm.com> (raw)
In-Reply-To: <1238533107-11796-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Changes:
 - Update to match UTS changes

Signed-off-by: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
 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

  parent reply	other threads:[~2009-03-31 20:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-31 20:58 c/r: Add UTS support Dan Smith
     [not found] ` <1238533107-11796-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-03-31 20:58   ` [PATCH 1/3] Make cr_may_checkpoint_task() check each namespace individually Dan Smith
     [not found]     ` <1238533107-11796-2-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 17:50       ` Serge E. Hallyn
2009-03-31 20:58   ` [PATCH 2/3] c/r: Add UTS support (v6) Dan Smith
     [not found]     ` <1238533107-11796-3-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 17:44       ` Serge E. Hallyn
2009-04-02 17:54         ` Dan Smith
     [not found]           ` <87wsa32b7h.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>
2009-04-06  2:33             ` Oren Laadan
2009-04-02 17:48       ` Serge E. Hallyn
2009-04-02 17:58       ` Serge E. Hallyn
     [not found]         ` <20090402175804.GC21178-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 18:06           ` Dan Smith
2009-04-02 18:09       ` Serge E. Hallyn
     [not found]         ` <20090402180936.GE21178-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 18:10           ` Dan Smith
2009-03-31 20:58   ` Dan Smith [this message]
     [not found]     ` <1238533107-11796-4-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 18:06       ` [PATCH 3/3] Stub implementation of IPC namespace c/r (v2) Serge E. Hallyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1238533107-11796-4-git-send-email-danms@us.ibm.com \
    --to=danms-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox