c/r: Add UTS support
This is the latest version of my UTS patch. I think I integrated all necessary feedback in the flurry of recent discussion. My apologies if I missed something.
This also adds the stub IPC namespace implementation, which right now just writes an empty record. Matching userspace support to follow.
A message that is not in the archive (sent off-list or not yet received): 1237836743-20262-1-git-send-email-danms-r/[email protected]
PATCH 1/2 c/r: Add UTS support (v5)
This patch adds a "phase" of checkpoint that saves out information about any namespaces the task(s) may have. Do this by tracking the namespace objects of the tasks and making sure that tasks with the same namespace that follow get properly referenced in the checkpoint stream. Note that for now, we refuse to checkpoint if all tasks in the set don't share the same set of *all* namespaces.
Restart is handled in userspace by reading the UTS record(s), calling unshare() and setting the hostname accordingly. See my changes to mktree.c for details.
I tested this with single and multiple task restore, on top of Oren's v13 tree.
Changes:
- Remove the kernel restore path
- Punt on nested namespaces
- Use __NEW_UTS_LEN in nodename and domainname buffers
- Add a note to Documentation/checkpoint/internals.txt to indicate where in the save/restore process the UTS information is kept
- Store (and track) the objref of the namespace itself instead of the nsproxy (based on comments from Dave on IRC)
- Remove explicit check for non-root nsproxy
- Store the nodename and domainname lengths and use cr_write_string() to store the actual name strings
- Catch failure of cr_obj_add_ptr() in cr_write_namespaces()
- Remove "types" bitfield and use the "is this new" flag to determine whether or not we should write out a new ns descriptor
--- Documentation/checkpoint/internals.txt | 2 + checkpoint/checkpoint.c | 80 ++++++++++++++++++++++++++++++++ checkpoint/objhash.c | 7 +++ checkpoint/restart.c | 1 + include/linux/checkpoint.h | 1 + include/linux/checkpoint_hdr.h | 13 +++++ 6 files changed, 104 insertions(+), 0 deletions(-)
Documentation/checkpoint/internals.txt +2 -0
@@ -12,6 +12,8 @@ The order of operations, both save and restore, is as follows: * Process forest: [TBD] tasks and their relationships +* Namespace section: per-container namespace information + * Per task data (for each task): -> task state: elements of task_struct -> thread state: elements of thread_struct and thread_info
checkpoint/checkpoint.c +80 -0
92 lines not on this page · raw message
checkpoint/objhash.c +7 -0
@@ -12,6 +12,7 @@#include <linux/file.h> #include <linux/hash.h> #include <linux/checkpoint.h> +#include <linux/utsname.h> struct cr_objref {int objref;
@@ -35,6 +36,9 @@ static void cr_obj_ref_drop(struct cr_objref *obj)case CR_OBJ_FILE :fput ((struct file *) obj->ptr);break ; +case CR_OBJ_UTSNS : +put_uts_ns ((struct uts_namespace *) obj->ptr); +break ;default :BUG (); }
@@ -46,6 +50,9 @@ static void cr_obj_ref_grab(struct cr_objref *obj)case CR_OBJ_FILE :get_file ((struct file *) obj->ptr);break ; +case CR_OBJ_UTSNS : +get_uts_ns ((struct uts_namespace *) obj->ptr); +break ;default :BUG (); }
checkpoint/restart.c +1 -0
@@ -15,6 +15,7 @@#include <linux/magic.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h> +#include <linux/utsname.h> #include "checkpoint_arch.h"
include/linux/checkpoint.h +1 -0
@@ -75,6 +75,7 @@ extern void cr_ctx_put(struct cr_ctx *ctx);enum {CR_OBJ_FILE =1 , +CR_OBJ_UTSNS ,CR_OBJ_MAX };
include/linux/checkpoint_hdr.h +13 -0
@@ -49,6 +49,8 @@ enum {CR_HDR_TASK ,CR_HDR_THREAD ,CR_HDR_CPU , +CR_HDR_NS , +CR_HDR_UTSNS ,CR_HDR_MM =201 , CR_HDR_VMA,
@@ -156,4 +158,15 @@ struct cr_hdr_fd_data {__u64 f_version; } __attribute__((aligned(8))); +#define CR_NS_UTS 1 + +struct cr_hdr_namespaces { +__u32 uts_ref;/* Objref of matching UTS namespace */ +}; + +struct cr_hdr_utsns { +__u32 nodename_len; +__u32 domainname_len; +}; +#endif /* _CHECKPOINT_CKPT_HDR_H_ */
Signature · 1 line
1.5.6.3
PATCH 2/2 c/r: Add (dummy) IPC support
In reply to a message not in the archiveBased on Serge's suggestion, this is a stub implementation of IPC support. It defines the header object for the c/r stream and the bits in cr_write_namespaces() to do the work. It just needs someone to fill in the details.
--- checkpoint/checkpoint.c | 28 ++++++++++++++++++++++++++++ checkpoint/objhash.c | 7 +++++++ include/linux/checkpoint.h | 1 + include/linux/checkpoint_hdr.h | 6 ++++++ 4 files changed, 42 insertions(+), 0 deletions(-)
checkpoint/checkpoint.c +28 -0
@@ -222,6 +222,23 @@ static int cr_write_ns_uts(struct cr_ctx *ctx, struct task_struct *t)return ret; } +static int cr_write_ns_ipc (struct cr_ctx *ctx,struct task_struct *t) +{ +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); + h.parent =0 ; + + 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;
@@ -229,6 +246,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);
@@ -238,6 +256,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;
@@ -248,6 +270,12 @@ static int cr_write_namespaces(struct cr_ctx *ctx, struct task_struct *t) goto out; } +if (ipc) { + ret =cr_write_ns_ipc (ctx, t); +if (ret <0 ) + goto out; + } +/* FIXME: Write other namespaces here */ out:cr_hbuf_put (ctx,sizeof (*hh));
checkpoint/objhash.c +7 -0
@@ -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;
@@ -39,6 +40,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 (); }
@@ -53,6 +57,9 @@ static void 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 (); }
include/linux/checkpoint.h +1 -0
@@ -76,6 +76,7 @@ extern void cr_ctx_put(struct cr_ctx *ctx);enum {CR_OBJ_FILE =1 ,CR_OBJ_UTSNS , +CR_OBJ_IPCNS ,CR_OBJ_MAX };
include/linux/checkpoint_hdr.h +6 -0
@@ -51,6 +51,7 @@ enum {CR_HDR_CPU ,CR_HDR_NS ,CR_HDR_UTSNS , +CR_HDR_IPCNS ,CR_HDR_MM =201 , CR_HDR_VMA,
@@ -159,9 +160,11 @@ struct cr_hdr_fd_data { } __attribute__((aligned(8)));#define CR_NS_UTS 1 +#define CR_NS_IPC 2struct cr_hdr_namespaces {__u32 uts_ref;/* Objref of matching UTS namespace */ +__u32 ipc_ref;/* Objref of matching IPC namespace */ };struct cr_hdr_utsns {
@@ -169,4 +172,7 @@ struct cr_hdr_utsns { __u32 domainname_len; }; +struct cr_hdr_ipcns { +}; +#endif /* _CHECKPOINT_CKPT_HDR_H_ */
Signature · 1 line
1.5.6.3