c/r: Add UTS support (v3)
PATCH 1/1 c/r: Add UTS support (v3)
This patch adds a "phase" of checkpoint that saves out information about any namespaces the task(s) may have. Do this by tracking the nsproxy of the first task and making sure that the tasks that follow get hooked back to share the same one on restart.
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
--- 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 | 15 ++++++ 6 files changed, 106 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_NSP : +put_nsproxy ((struct nsproxy *) 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_NSP : +get_nsproxy ((struct nsproxy *) 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_NSP ,CR_OBJ_MAX };
include/linux/checkpoint_hdr.h +15 -0
@@ -49,6 +49,8 @@ enum {CR_HDR_TASK ,CR_HDR_THREAD ,CR_HDR_CPU , +CR_HDR_NSP , +CR_HDR_UTSNS ,CR_HDR_MM =201 , CR_HDR_VMA,
@@ -156,4 +158,17 @@ struct cr_hdr_fd_data {__u64 f_version; } __attribute__((aligned(8))); +#define CR_NSP_UTS 1 + +struct cr_hdr_nsproxy { +__u32 objref; +__u32 types; +}; + +struct cr_hdr_utsns { +/* Both of these fields are defined as 65-chars long */ +char nodename[__NEW_UTS_LEN+1 ]; +char domainname[__NEW_UTS_LEN+1 ]; +}; +#endif /* _CHECKPOINT_CKPT_HDR_H_ */
Signature · 1 line
1.5.6.3
A message that is not in the archive (sent off-list or not yet received): 1237306139-23075-1-git-send-email-danms-r/[email protected]
Quoted 11 lines · Dan Smith
This patch adds a "phase" of checkpoint that saves out information about any namespaces the task(s) may have. Do this by tracking the nsproxy of the first task and making sure that the tasks that follow get hooked back to share the same one on restart.
Restart is handled in userspace by reading the UTS record(s), calling
unshare()and setting the hostname accordingly. See my changes tomktree.cfor details.I tested this with single and multiple task restore, on top of Oren's v13 tree.
Thanks, Dan.
[..]
Quoted 12 lines
checkpoint/checkpoint.c +4
-0@@ -193,6 +193,82 @@ static int cr_write_tail(struct cr_ctx *ctx)return ret; } +static int cr_write_ns_uts (struct cr_ctx *ctx,struct task_struct *t) +{ +struct cr_hdr h; +struct cr_hdr_utsns *hh =cr_hbuf_get (ctx,sizeof (*hh));
checkpoint/checkpoint.c static int cr_write_tail(struct cr_ctx *ctx) · line 209
Quoted 10 lines
checkpoint/checkpoint.c +10
-0+struct new_utsname *n = &t->nsproxy->uts_ns->name; +int ret; + + h.type =CR_HDR_UTSNS ; + h.len =sizeof (*hh); + h.parent =0 ; + +memcpy (hh->nodename, n->nodename,sizeof (n->nodename)); +memcpy (hh->domainname, n->domainname,sizeof (n->domainname)); +
The length of ->nodename etc may change in the future. It's probably safer to also add the length of the field as well (see for instance how task->comm is saved).
Quoted 5 lines
checkpoint/checkpoint.c +5
-0+ ret =cr_write_obj (ctx, &h, hh); +cr_hbuf_put (ctx,sizeof (*hh)); + +return ret; +}
[...]
Quoted 6 lines
checkpoint/checkpoint.c +2
-0@@ -156,4 +158,17 @@ struct cr_hdr_fd_data {__u64 f_version; } __attribute__((aligned(8))); +#define CR_NSP_UTS 1 +
checkpoint/checkpoint.c struct cr_hdr_fd_data { · line 172
Quoted 10 lines
checkpoint/checkpoint.c +10
-0+struct cr_hdr_nsproxy { +__u32 objref; +__u32 types; +}; + +struct cr_hdr_utsns { +/* Both of these fields are defined as 65-chars long */ +char nodename[__NEW_UTS_LEN+1 ]; +char domainname[__NEW_UTS_LEN+1 ]; +};
add ?
__u16 nodename_len; __u16 domainname_len;
checkpoint/checkpoint.c struct cr_hdr_fd_data { · line 174
Quoted 2 lines
checkpoint/checkpoint.c +1
-0+#endif /* _CHECKPOINT_CKPT_HDR_H_ */
Oren.
A message that is not in the archive (sent off-list or not yet received): [email protected]
OL> The length of ->nodename etc may change in the future. It's OL> probably safer to also add the length of the field as well (see OL> for instance how task->comm is saved).
Ah, good point. I'll fix it up.
Thanks!
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]