Skip to contentSkip to conversation

: Second set of cleanups

PATCH NAK Sukadev Bhattiprolu 3 participants 19 messages Mar 5, 2010 – Mar 15, 2010 6 messages not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

cover : Second set of cleanups

Second set of cleanup patches. With these patches, LXC will be able to compile/link directly using restart.o and app-checkpoint.h from the user-cr directory. Something like:

USER_CR=/home/suka/user-cr make lxc_restart

After having more detailed discussions on the API, we could install restart.o in /lib/libcheckpoint.a and app-checkpoint.h in /usr/include.

	[PATCH 01/12][user-cr] restart: Mark globals as static
	[PATCH 02/12][user-cr] restart: Add args->send_sigint
	[PATCH 03/12][user-cr] Add app_restart_args->debug
	[PATCH 04/12][user-cr] Add app_restart_args->verbose
	[PATCH 05/12][user-cr] Add app_restart_args->ulogfd
	[PATCH 06/12][user-cr] Add app_restart_args->uerrfd
	[PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
	[PATCH 08/12][user-cr] Create common.h 
	[PATCH 09/12][user-cr] Create app-checkpoint.h
	[PATCH 10/12][user-cr] restart: Move main() to restart-main.c
	[PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
	[PATCH 12/12][user-cr] Have app_restart() return pid

A message that is not in the archive (sent off-list or not yet received): 20100305223439.GA15300-r/[email protected]

#2 lore raw

PATCH 1/12 restart: Mark globals as static

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:41:04 -0800
Subject: [PATCH 01/12][user-cr] restart: Mark globals as static

app_restart() will in the future be exported to other programs. To avoid potential variable-name collisions, make the globals in restart.c static.

---
 restart.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
restart.c +9 -9
index 6994298..0c74bb6 100644
@@ -301,15 +301,15 @@ struct ckpt_ctx {
  * TODO: Do we need to direct user-space restart messages to two different
  * 	 fds (like stdout and stderr) or can we just use one ?
  */
-int global_ulogfd;
-int global_uerrfd;
-int global_debug;
-int global_verbose;
-pid_t global_child_pid;
-int global_child_status;
-int global_child_collected;
-int global_send_sigint = -1;
-int global_sent_sigint;
+static int global_ulogfd;
+static int global_uerrfd;
+static int global_debug;
+static int global_verbose;
+static pid_t global_child_pid;
+static int global_child_status;
+static int global_child_collected;
+static int global_send_sigint = -1;
+static int global_sent_sigint;
 
 static int ckpt_remount_proc(struct ckpt_ctx *ctx);
 static int ckpt_remount_devpts(struct ckpt_ctx *ctx);
Signature · 1 line
1.6.0.4
#3 lore raw

PATCH 2/12 restart: Add args->send_sigint

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:37:39 -0800
Subject: [PATCH 02/12][user-cr] restart: Add args->send_sigint

restart command supports a command line option, --send-sigint to let user specify whether SIGINT signal should be processed/ignored during restart. Make this a field in 'struct app_restart_args' so that other callers of app_restart() in the future can also control the SIGINT behavior.

---
 restart.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
restart.c +5 -1
index 0c74bb6..314390c 100644
@@ -376,6 +376,7 @@ struct app_restart_args {
 	int pids;
 	int pidns;
 	int inspect;
+	int send_sigint;
 	char *root;
 	int wait;
 	int mntns;
@@ -497,6 +498,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 	args->klogfd = -1;
 	args->warn = CKPT_COND_WARN;
 	args->fail = CKPT_COND_FAIL;
+	args->send_sigint = -1;
 	no_pidns = 0;
 
 	klogfile = NULL;
@@ -554,7 +556,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 				ckpt_err("restart: invalid signal\n");
 				exit(1);
 			}
-			global_send_sigint = sig;
+			args->send_sigint = sig;
 			break;
 		case 3:  /* --pids */
 			args->pids = 1;
@@ -815,6 +817,8 @@ int app_restart(struct app_restart_args *args)
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.args = args;
 
+	global_send_sigint = args->send_sigint;
+
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
 		if (dup2(args->infd, STDIN_FILENO) < 0) {
Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 20100305223658.GB15939-r/[email protected]

#5 lore raw

Re: [PATCH 02/12][user-cr] restart: Add args->send_sigint

Nack - the library should not handle signals for callers.

Instead, there should be an interface through which the caller can ask the library to destroy the tree that it just created. Thus it will be the caller who catches the signal and acts on it.

Oren.

Quoted 53 lines · Sukadev Bhattiprolu

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:37:39 -0800
Subject: [PATCH 02/12][user-cr] restart: Add args->send_sigint

restart command supports a command line option, --send-sigint to let user specify whether SIGINT signal should be processed/ignored during restart. Make this a field in 'struct app_restart_args' so that other callers of app_restart() in the future can also control the SIGINT behavior.

---
 restart.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
restart.c +5 -1
index 0c74bb6..314390c 100644
@@ -376,6 +376,7 @@ struct app_restart_args {
 	int pids;
 	int pidns;
 	int inspect;
+	int send_sigint;
 	char *root;
 	int wait;
 	int mntns;
@@ -497,6 +498,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 	args->klogfd = -1;
 	args->warn = CKPT_COND_WARN;
 	args->fail = CKPT_COND_FAIL;
+	args->send_sigint = -1;
 	no_pidns = 0;
 
 	klogfile = NULL;
@@ -554,7 +556,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 				ckpt_err("restart: invalid signal\n");
 				exit(1);
 			}
-			global_send_sigint = sig;
+			args->send_sigint = sig;
 			break;
 		case 3:  /* --pids */
 			args->pids = 1;
@@ -815,6 +817,8 @@ int app_restart(struct app_restart_args *args)
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.args = args;
 
+	global_send_sigint = args->send_sigint;
+
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
 		if (dup2(args->infd, STDIN_FILENO) < 0) {
#6 lore raw

PATCH 3/12 Add app_restart_args->debug

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:46:31 -0800
Subject: [PATCH 03/12][user-cr] Add app_restart_args->debug

Make 'debug' a field in struct app_restart_args so other callers of app_restart() can also control the debug output of app_restart().

---
 restart.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
restart.c +3 -1
index 314390c..87fff1e 100644
@@ -387,6 +387,7 @@ struct app_restart_args {
 	int infd;
 	int klogfd;
 	long warn;
+	int debug;
 	long fail;
 	int keep_lsm;
 };
@@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 			args->copy_status = 1;
 			break;
 		case 'd':
-			global_debug = 1;
+			global_debug = args->debug = 1;
 			break;
 		case 'F':
 			args->freezer = optarg;
@@ -818,6 +819,7 @@ int app_restart(struct app_restart_args *args)
 	ctx.args = args;
 
 	global_send_sigint = args->send_sigint;
+	global_debug = args->debug;
 
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 20100305223723.GC15939-r/[email protected]

#8 lore raw

Re: [PATCH 03/12][user-cr] Add app_restart_args->debug

Quoted 26 lines · Sukadev Bhattiprolu

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:46:31 -0800
Subject: [PATCH 03/12][user-cr] Add app_restart_args->debug

Make 'debug' a field in struct app_restart_args so other callers of app_restart() can also control the debug output of app_restart().

---
 restart.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
restart.c +1 -0
index 314390c..87fff1e 100644
@@ -387,6 +387,7 @@ struct app_restart_args {
 	int infd;
 	int klogfd;
 	long warn;
+	int debug;
 	long fail;
 	int keep_lsm;
 };

restart.c static void parse_args(struct app_restart_args *args, int argc, char *argv[]) · line 587

Quoted 5 lines
restart.c +1 -1
@@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 			args->copy_status = 1;
 			break;
 		case 'd':
-			global_debug = 1;
+			global_debug = args->debug = 1;

You don't actually need to also set global_debug here, right?

Quoted 18 lines
restart.c +1 -0
 			break;
 		case 'F':
 			args->freezer = optarg;
@@ -818,6 +819,7 @@ int app_restart(struct app_restart_args *args)
 	ctx.args = args;
 
 	global_send_sigint = args->send_sigint;
+	global_debug = args->debug;
 
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
Signature · 6 lines
1.6.0.4

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20100308193929.GA20030-r/[email protected]

#10 lore raw

Re: [PATCH 03/12][user-cr] Add app_restart_args->debug

Serge E. Hallyn [serue-r/[email protected]] wrote:

| > @@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
| >  			args->copy_status = 1;
| >  			break;
| >  		case 'd':
| > -			global_debug = 1;
| > +			global_debug = args->debug = 1;
| 
| You don't actually need to also set global_debug here, right?

Well, there is a subtlelty in a follow-on patch. Maybe I should move this set of global_debug there.

global_debug is (eventually) static in both restart.c and restart-main.c The ckpt_debug() macro defined in common.h uses the global_debug. While there are no callers of ckpt_debug() in restart-main.c now, setting it here may enable us just call ckpt_debug() if necessary.

Sukadev

#11 lore raw

PATCH 4/12 Add app_restart_args->verbose

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 17:53:27 -0800
Subject: [PATCH 04/12][user-cr] Add app_restart_args->verbose

Make 'verbose' a field in struct app_restart_args so other callers of app_restart() can also control the verbose output of app_restart().

---
 restart.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
restart.c +3 -1
index 87fff1e..8513042 100644
@@ -388,6 +388,7 @@ struct app_restart_args {
 	int klogfd;
 	long warn;
 	int debug;
+	int verbose;
 	long fail;
 	int keep_lsm;
 };
@@ -515,7 +516,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 		case 'h':
 			usage(usage_str);
 		case 'v':
-			global_verbose = 1;
+			global_verbose = args->verbose = 1;
 			break;
 		case 5:  /* --inspect */
 			args->inspect = 1;
@@ -820,6 +821,7 @@ int app_restart(struct app_restart_args *args)
 
 	global_send_sigint = args->send_sigint;
 	global_debug = args->debug;
+	global_verbose = args->verbose;
 
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
Signature · 1 line
1.6.0.4
#12 lore raw

PATCH 5/12 Add app_restart_args->ulogfd

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 22:33:34 -0800
Subject: [PATCH 05/12][user-cr] Add app_restart_args->ulogfd

Add a 'ulogfd' field in struct app_restart_args so other callers of app_restart() can also choose a file descriptor for the log messages from app_restart().

---
 restart.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
restart.c +3 -0
index 8513042..ac0acf3 100644
@@ -386,6 +386,7 @@ struct app_restart_args {
 	char *freezer;
 	int infd;
 	int klogfd;
+	int ulogfd;
 	long warn;
 	int debug;
 	int verbose;
@@ -498,6 +499,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 	args->wait = 1;
 	args->infd = -1;
 	args->klogfd = -1;
+	args->ulogfd = fileno(stdout);
 	args->warn = CKPT_COND_WARN;
 	args->fail = CKPT_COND_FAIL;
 	args->send_sigint = -1;
@@ -822,6 +824,7 @@ int app_restart(struct app_restart_args *args)
 	global_send_sigint = args->send_sigint;
 	global_debug = args->debug;
 	global_verbose = args->verbose;
+	global_ulogfd = args->ulogfd;
 
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
Signature · 1 line
1.6.0.4
#13 lore raw

PATCH 6/12 Add app_restart_args->uerrfd

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 22:36:31 -0800
Subject: [PATCH 06/12][user-cr] Add app_restart_args->uerrfd

Add a 'uerrfd' field in struct app_restart_args so other callers of app_restart() can also choose a file descriptor for the error messages from app_restart().

---
 restart.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
restart.c +3 -0
index ac0acf3..d4a4000 100644
@@ -387,6 +387,7 @@ struct app_restart_args {
 	int infd;
 	int klogfd;
 	int ulogfd;
+	int uerrfd;
 	long warn;
 	int debug;
 	int verbose;
@@ -500,6 +501,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 	args->infd = -1;
 	args->klogfd = -1;
 	args->ulogfd = fileno(stdout);
+	args->uerrfd = fileno(stderr);
 	args->warn = CKPT_COND_WARN;
 	args->fail = CKPT_COND_FAIL;
 	args->send_sigint = -1;
@@ -825,6 +827,7 @@ int app_restart(struct app_restart_args *args)
 	global_debug = args->debug;
 	global_verbose = args->verbose;
 	global_ulogfd = args->ulogfd;
+	global_uerrfd = args->uerrfd;
 
 	/* input file descriptor (default: stdin) */
 	if (args->infd >= 0) {
Signature · 1 line
1.6.0.4
#14 lore raw

PATCH 7/12 Define INIT_SIGNAL_ARRAY

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 21:15:25 -0800
Subject: [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY

Code to initialize the signal_array[] table will need to be shared by more than one file. To enable this sharing with, define INIT_SIGNAL_ARRAY which can later be used in many places.

---
 restart.c |   76 ++++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 40 insertions(+), 36 deletions(-)
restart.c +40 -36
index d4a4000..b37bf81 100644
@@ -157,46 +157,50 @@ static inline void ckpt_msg(int fd, char *format, ...)
 			ckpt_msg(global_ulogfd, __VA_ARGS__);	\
 	} while(0)
 
-#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
-
-struct {
+struct signal_array {
 	int signum;
 	char *sigstr;
-} signal_array[] = {
-	{ 0, "NONE" },
-	SIGNAL_ENTRY(ALRM),
-	SIGNAL_ENTRY(HUP),
-	SIGNAL_ENTRY(INT),
-	SIGNAL_ENTRY(KILL),
-	SIGNAL_ENTRY(PIPE),
-	SIGNAL_ENTRY(POLL),
-	SIGNAL_ENTRY(PROF),
-	SIGNAL_ENTRY(TERM),
-	SIGNAL_ENTRY(USR1),
-	SIGNAL_ENTRY(USR2),
-	SIGNAL_ENTRY(VTALRM),
-	SIGNAL_ENTRY(STKFLT),
-	SIGNAL_ENTRY(PWR),
-	SIGNAL_ENTRY(WINCH),
-	SIGNAL_ENTRY(CHLD),
-	SIGNAL_ENTRY(URG),
-	SIGNAL_ENTRY(TTIN),
-	SIGNAL_ENTRY(TTOU),
-	SIGNAL_ENTRY(STOP),
-	SIGNAL_ENTRY(CONT),
-	SIGNAL_ENTRY(ABRT),
-	SIGNAL_ENTRY(FPE),
-	SIGNAL_ENTRY(ILL),
-	SIGNAL_ENTRY(QUIT),
-	SIGNAL_ENTRY(SEGV),
-	SIGNAL_ENTRY(TRAP),
-	SIGNAL_ENTRY(SYS),
-	SIGNAL_ENTRY(BUS),
-	SIGNAL_ENTRY(XCPU),
-	SIGNAL_ENTRY(XFSZ),
-	{ -1, "LAST" },
 };
 
+#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
+
+#define INIT_SIGNAL_ARRAY { 	\
+	{ 0, "NONE" },		\
+	SIGNAL_ENTRY(ALRM),	\
+	SIGNAL_ENTRY(HUP),	\
+	SIGNAL_ENTRY(INT),	\
+	SIGNAL_ENTRY(KILL),	\
+	SIGNAL_ENTRY(PIPE),	\
+	SIGNAL_ENTRY(POLL),	\
+	SIGNAL_ENTRY(PROF),	\
+	SIGNAL_ENTRY(TERM),	\
+	SIGNAL_ENTRY(USR1),	\
+	SIGNAL_ENTRY(USR2),	\
+	SIGNAL_ENTRY(VTALRM),	\
+	SIGNAL_ENTRY(STKFLT),	\
+	SIGNAL_ENTRY(PWR),	\
+	SIGNAL_ENTRY(WINCH),	\
+	SIGNAL_ENTRY(CHLD),	\
+	SIGNAL_ENTRY(URG),	\
+	SIGNAL_ENTRY(TTIN),	\
+	SIGNAL_ENTRY(TTOU),	\
+	SIGNAL_ENTRY(STOP),	\
+	SIGNAL_ENTRY(CONT),	\
+	SIGNAL_ENTRY(ABRT),	\
+	SIGNAL_ENTRY(FPE),	\
+	SIGNAL_ENTRY(ILL),	\
+	SIGNAL_ENTRY(QUIT),	\
+	SIGNAL_ENTRY(SEGV),	\
+	SIGNAL_ENTRY(TRAP),	\
+	SIGNAL_ENTRY(SYS),	\
+	SIGNAL_ENTRY(BUS),	\
+	SIGNAL_ENTRY(XCPU),	\
+	SIGNAL_ENTRY(XFSZ),	\
+	{ -1, "LAST" },		\
+}
+
+static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
+
 static char *sig2str(int sig)
 {
 	int i = 0;
Signature · 1 line
1.6.0.4
#15 lore raw

PATCH 8/12 Create common.h

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 21:30:50 -0800
Subject: [PATCH 08/12][user-cr] Create common.h

Code in common.h can be shared by checkpoint.c and restart.c for now.

---
 Makefile     |    4 ++
 checkpoint.c |   31 +---------------
 common.h     |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 restart.c    |  110 +--------------------------------------------------------
 4 files changed, 119 insertions(+), 138 deletions(-)
 create mode 100644 common.h
Makefile +4 -0
index b312358..acebdd5 100644
@@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
 		include/linux/checkpoint_hdr.h \
 		include/asm/checkpoint_hdr.h
 
+CR_OBJS = checkpoint.o restart.o
+
 # detect architecture (for eclone)
 SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
 
@@ -41,6 +43,8 @@ $(LIB_ECLONE):
 # restart needs to be thread-safe
 restart: CFLAGS += -D__REENTRANT -pthread
 
+$(CR_OBJS): common.h
+
 # eclone() is architecture specific
 ifneq ($(SUBARCH),)
 $(ECLONE_PROGS): $(LIB_ECLONE) 
checkpoint.c +2 -29
index ace17e2..6e91149 100644
@@ -21,6 +21,8 @@
 
 #include <linux/checkpoint.h>
 
+#include "common.h"
+
 static char usage_str[] =
 "usage: ckpt [opts] PID\n"
 "  'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
@@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
 	return syscall(__NR_checkpoint, pid, fd, flags, logfd);
 }
 
-#define BUFSIZE  (4 * 4096)
-static inline void ckpt_msg(int fd, char *format, ...)
-{
-        va_list ap;
-        char *bufp;
-        if (fd < 0)
-                return;
-
-        va_start(ap, format);
-
-        bufp = malloc(BUFSIZE);
-        if(bufp) {
-                vsnprintf(bufp, BUFSIZE, format, ap);
-                write(fd, bufp, strlen(bufp));
-        }
-        free(bufp);
-
-        va_end(ap);
-}
-
-#define ckpt_err(...)  \
-	ckpt_msg(global_uerrfd, __VA_ARGS__)
-
-#define ckpt_perror(s)                                                  \
-        do {                                                            \
-                ckpt_msg(global_uerrfd, s);                             \
-                ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));     \
-        } while (0)
-
 static void usage(char *str)
 {
 	ckpt_err("%s", str);
common.h new file +112 -0

112 lines not on this page · raw message

restart.c +1 -109

128 lines not on this page · raw message

Signature · 1 line
1.6.0.4

A message that is not in the archive (sent off-list or not yet received): 20100305223907.GH15939-r/[email protected]

#17 lore raw

Re: [PATCH 08/12][user-cr] Create common.h

Quoted 6 lines · Sukadev Bhattiprolu

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 21:30:50 -0800
Subject: [PATCH 08/12][user-cr] Create common.h

Code in common.h can be shared by checkpoint.c and restart.c for now.

There is already user-cr.h and restart.h... a 'common.h' filename isn't particularly helpful. Should they all get combined?

Not NACking the patch, btw, just something to consider for a future patch.

Quoted 340 lines
---
 Makefile     |    4 ++
 checkpoint.c |   31 +---------------
 common.h     |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 restart.c    |  110 +--------------------------------------------------------
 4 files changed, 119 insertions(+), 138 deletions(-)
 create mode 100644 common.h
Makefile +4 -0
index b312358..acebdd5 100644
@@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
 		include/linux/checkpoint_hdr.h \
 		include/asm/checkpoint_hdr.h
 
+CR_OBJS = checkpoint.o restart.o
+
 # detect architecture (for eclone)
 SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
 
@@ -41,6 +43,8 @@ $(LIB_ECLONE):
 # restart needs to be thread-safe
 restart: CFLAGS += -D__REENTRANT -pthread
 
+$(CR_OBJS): common.h
+
 # eclone() is architecture specific
 ifneq ($(SUBARCH),)
 $(ECLONE_PROGS): $(LIB_ECLONE) 
checkpoint.c +2 -29
index ace17e2..6e91149 100644
@@ -21,6 +21,8 @@
 
 #include <linux/checkpoint.h>
 
+#include "common.h"
+
 static char usage_str[] =
 "usage: ckpt [opts] PID\n"
 "  'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
@@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
 	return syscall(__NR_checkpoint, pid, fd, flags, logfd);
 }
 
-#define BUFSIZE  (4 * 4096)
-static inline void ckpt_msg(int fd, char *format, ...)
-{
-        va_list ap;
-        char *bufp;
-        if (fd < 0)
-                return;
-
-        va_start(ap, format);
-
-        bufp = malloc(BUFSIZE);
-        if(bufp) {
-                vsnprintf(bufp, BUFSIZE, format, ap);
-                write(fd, bufp, strlen(bufp));
-        }
-        free(bufp);
-
-        va_end(ap);
-}
-
-#define ckpt_err(...)  \
-	ckpt_msg(global_uerrfd, __VA_ARGS__)
-
-#define ckpt_perror(s)                                                  \
-        do {                                                            \
-                ckpt_msg(global_uerrfd, s);                             \
-                ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));     \
-        } while (0)
-
 static void usage(char *str)
 {
 	ckpt_err("%s", str);
common.h new file +112 -0
new file mode 100644
index 0000000..99b224d
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <signal.h>
+
+#define BUFSIZE  (4 * 4096)
+
+static inline void ckpt_msg(int fd, char *format, ...)
+{
+	va_list ap;
+	char *bufp;
+	if (fd < 0)
+		return;
+
+	va_start(ap, format);
+
+	bufp = malloc(BUFSIZE);
+	if(bufp) {
+		vsnprintf(bufp, BUFSIZE, format, ap);
+		write(fd, bufp, strlen(bufp));
+	}
+	free(bufp);
+
+	va_end(ap);
+}
+
+#define ckpt_perror(s) 							\
+	do {								\
+		ckpt_msg(global_uerrfd, s);				\
+		ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));	\
+	} while (0)
+
+#ifdef CHECKPOINT_DEBUG
+#define ckpt_dbg(_format, _args...)					\
+	do {								\
+		if (global_debug)					\
+			ckpt_msg(global_uerrfd, "<%d>" _format, 	\
+					_gettid(), ##_args); 		\
+	} while (0)
+#define ckpt_dbg_cont(_format, _args...)				\
+	do {								\
+		if (global_debug)					\
+			ckpt_msg(global_uerrfd, _format, ##_args);	\
+	} while (0)
+#else
+#define ckpt_dbg(_format, _args...)  \
+	do { } while (0)
+#define ckpt_dbg_cont(_format, _args...)  \
+	do { } while (0)
+#endif
+
+#define ckpt_err(...)  \
+	ckpt_msg(global_uerrfd, __VA_ARGS__)
+
+#define ckpt_verbose(...)					\
+	do {							\
+		if (global_verbose)				\
+			ckpt_msg(global_ulogfd, __VA_ARGS__);	\
+	} while(0)
+
+struct signal_array {
+	int signum;
+	char *sigstr;
+};
+
+#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
+
+#define INIT_SIGNAL_ARRAY { 	\
+	{ 0, "NONE" },		\
+	SIGNAL_ENTRY(ALRM),	\
+	SIGNAL_ENTRY(HUP),	\
+	SIGNAL_ENTRY(INT),	\
+	SIGNAL_ENTRY(KILL),	\
+	SIGNAL_ENTRY(PIPE),	\
+	SIGNAL_ENTRY(POLL),	\
+	SIGNAL_ENTRY(PROF),	\
+	SIGNAL_ENTRY(TERM),	\
+	SIGNAL_ENTRY(USR1),	\
+	SIGNAL_ENTRY(USR2),	\
+	SIGNAL_ENTRY(VTALRM),	\
+	SIGNAL_ENTRY(STKFLT),	\
+	SIGNAL_ENTRY(PWR),	\
+	SIGNAL_ENTRY(WINCH),	\
+	SIGNAL_ENTRY(CHLD),	\
+	SIGNAL_ENTRY(URG),	\
+	SIGNAL_ENTRY(TTIN),	\
+	SIGNAL_ENTRY(TTOU),	\
+	SIGNAL_ENTRY(STOP),	\
+	SIGNAL_ENTRY(CONT),	\
+	SIGNAL_ENTRY(ABRT),	\
+	SIGNAL_ENTRY(FPE),	\
+	SIGNAL_ENTRY(ILL),	\
+	SIGNAL_ENTRY(QUIT),	\
+	SIGNAL_ENTRY(SEGV),	\
+	SIGNAL_ENTRY(TRAP),	\
+	SIGNAL_ENTRY(SYS),	\
+	SIGNAL_ENTRY(BUS),	\
+	SIGNAL_ENTRY(XCPU),	\
+	SIGNAL_ENTRY(XFSZ),	\
+	{ -1, "LAST" },		\
+}
+
+#define CKPT_COND_PIDZERO  0x1
+#define CKPT_COND_MNTPROC  0x2
+#define CKPT_COND_MNTPTY   0x4
+
+#define CKPT_COND_NONE     0
+#define CKPT_COND_ANY      ULONG_MAX
+
+/* default for skip/warn/fail */
+#define CKPT_COND_WARN     (CKPT_COND_MNTPROC | \
+			    CKPT_COND_MNTPTY)
+#define CKPT_COND_FAIL     (CKPT_COND_NONE)
+
restart.c +1 -109
index b37bf81..f65eafb 100644
@@ -40,6 +40,7 @@
 #include "eclone.h"
 #include "genstack.h"
 #include "compat.h"
+#include "common.h"
 
 static char usage_str[] =
 "usage: restart [opts]\n"
@@ -102,103 +103,6 @@ static char usage_str[] =
  * of the checkpoint image stream.
  */
 
-#define BUFSIZE  (4 * 4096)
-
-static inline void ckpt_msg(int fd, char *format, ...)
-{
-	va_list ap;
-	char *bufp;
-	if (fd < 0)
-		return;
-
-	va_start(ap, format);
-
-	bufp = malloc(BUFSIZE);
-	if(bufp) {
-		vsnprintf(bufp, BUFSIZE, format, ap);
-		write(fd, bufp, strlen(bufp));
-	}
-	free(bufp);
-
-	va_end(ap);
-}
-
-#define ckpt_perror(s) 							\
-	do {								\
-		ckpt_msg(global_uerrfd, s);				\
-		ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));	\
-	} while (0)
-
-#ifdef CHECKPOINT_DEBUG
-#define ckpt_dbg(_format, _args...)					\
-	do {								\
-		if (global_debug)					\
-			ckpt_msg(global_uerrfd, "<%d>" _format, 	\
-					_gettid(), ##_args); 		\
-	} while (0)
-#define ckpt_dbg_cont(_format, _args...)				\
-	do {								\
-		if (global_debug)					\
-			ckpt_msg(global_uerrfd, _format, ##_args);	\
-	} while (0)
-#else
-#define ckpt_dbg(_format, _args...)  \
-	do { } while (0)
-#define ckpt_dbg_cont(_format, _args...)  \
-	do { } while (0)
-#endif
-
-#define ckpt_err(...)  \
-	ckpt_msg(global_uerrfd, __VA_ARGS__)
-
-#define ckpt_verbose(...)					\
-	do {							\
-		if (global_verbose)				\
-			ckpt_msg(global_ulogfd, __VA_ARGS__);	\
-	} while(0)
-
-struct signal_array {
-	int signum;
-	char *sigstr;
-};
-
-#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
-
-#define INIT_SIGNAL_ARRAY { 	\
-	{ 0, "NONE" },		\
-	SIGNAL_ENTRY(ALRM),	\
-	SIGNAL_ENTRY(HUP),	\
-	SIGNAL_ENTRY(INT),	\
-	SIGNAL_ENTRY(KILL),	\
-	SIGNAL_ENTRY(PIPE),	\
-	SIGNAL_ENTRY(POLL),	\
-	SIGNAL_ENTRY(PROF),	\
-	SIGNAL_ENTRY(TERM),	\
-	SIGNAL_ENTRY(USR1),	\
-	SIGNAL_ENTRY(USR2),	\
-	SIGNAL_ENTRY(VTALRM),	\
-	SIGNAL_ENTRY(STKFLT),	\
-	SIGNAL_ENTRY(PWR),	\
-	SIGNAL_ENTRY(WINCH),	\
-	SIGNAL_ENTRY(CHLD),	\
-	SIGNAL_ENTRY(URG),	\
-	SIGNAL_ENTRY(TTIN),	\
-	SIGNAL_ENTRY(TTOU),	\
-	SIGNAL_ENTRY(STOP),	\
-	SIGNAL_ENTRY(CONT),	\
-	SIGNAL_ENTRY(ABRT),	\
-	SIGNAL_ENTRY(FPE),	\
-	SIGNAL_ENTRY(ILL),	\
-	SIGNAL_ENTRY(QUIT),	\
-	SIGNAL_ENTRY(SEGV),	\
-	SIGNAL_ENTRY(TRAP),	\
-	SIGNAL_ENTRY(SYS),	\
-	SIGNAL_ENTRY(BUS),	\
-	SIGNAL_ENTRY(XCPU),	\
-	SIGNAL_ENTRY(XFSZ),	\
-	{ -1, "LAST" },		\
-}
-
 static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
 
 static char *sig2str(int sig)
@@ -399,18 +303,6 @@ struct app_restart_args {
 	int keep_lsm;
 };
 
-#define CKPT_COND_PIDZERO  0x1
-#define CKPT_COND_MNTPROC  0x2
-#define CKPT_COND_MNTPTY   0x4
-
-#define CKPT_COND_NONE     0
-#define CKPT_COND_ANY      ULONG_MAX
-
-/* default for skip/warn/fail */
-#define CKPT_COND_WARN     (CKPT_COND_MNTPROC | \
-			    CKPT_COND_MNTPTY)
-#define CKPT_COND_FAIL     (CKPT_COND_NONE)
-
 static void usage(char *str)
 {
 	ckpt_err("%s", str);
Signature · 6 lines
1.6.0.4

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20100308194427.GB20030-r/[email protected]

#19 lore raw

Re: [PATCH 08/12][user-cr] Create common.h

Serge E. Hallyn [serue-r/[email protected]] wrote:

| Quoting Sukadev Bhattiprolu ([email protected]):
| > 
| > From: Sukadev Bhattiprolu <[email protected]>
| > Date: Thu, 4 Mar 2010 21:30:50 -0800
| > Subject: [PATCH 08/12][user-cr] Create common.h
| > 
| > Code in common.h can be shared by checkpoint.c and restart.c for now.
| 
| There is already user-cr.h and restart.h...  a 'common.h' filename
| isn't particularly helpful.  Should they all get combined?

Hmm, there should be no 'restart.h' in this version of the patchset. restart.h from previous version is now common.h (since some definitions apply to checkpoint.c) and is internal to user-cr.

I renamed usercr.h to "app-checkpoint.h" for now, but don't particularly like either name :-). This file presents the external API to user-cr.

| 
| Not NACking the patch, btw, just something to consider for a future
| patch.
| 

Thanks for the review. If you test with /bin/restart, you should see no problems. If you plan to test with LXC, let me know - I will need to send you couple of patches to USER-CR and couple of patches (under development) for LXC.

| > Signed-off-by: Sukadev Bhattiprolu <[email protected]>
| > ---
| >  Makefile     |    4 ++
| >  checkpoint.c |   31 +---------------
| >  common.h     |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| >  restart.c    |  110 +--------------------------------------------------------
| >  4 files changed, 119 insertions(+), 138 deletions(-)
| >  create mode 100644 common.h
| > 
| > diff --git a/Makefile b/Makefile
| > index b312358..acebdd5 100644
| > --- a/Makefile
| > +++ b/Makefile
| > @@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
| >  		include/linux/checkpoint_hdr.h \
| >  		include/asm/checkpoint_hdr.h
| > 
| > +CR_OBJS = checkpoint.o restart.o
| > +
| >  # detect architecture (for eclone)
| >  SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
| > 
| > @@ -41,6 +43,8 @@ $(LIB_ECLONE):
| >  # restart needs to be thread-safe
| >  restart: CFLAGS += -D__REENTRANT -pthread
| > 
| > +$(CR_OBJS): common.h
| > +
| >  # eclone() is architecture specific
| >  ifneq ($(SUBARCH),)
| >  $(ECLONE_PROGS): $(LIB_ECLONE) 
| > diff --git a/checkpoint.c b/checkpoint.c
| > index ace17e2..6e91149 100644
| > --- a/checkpoint.c
| > +++ b/checkpoint.c
| > @@ -21,6 +21,8 @@
| > 
| >  #include <linux/checkpoint.h>
| > 
| > +#include "common.h"
| > +
| >  static char usage_str[] =
| >  "usage: ckpt [opts] PID\n"
| >  "  'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
| > @@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
| >  	return syscall(__NR_checkpoint, pid, fd, flags, logfd);
| >  }
| > 
| > -#define BUFSIZE  (4 * 4096)
| > -static inline void ckpt_msg(int fd, char *format, ...)
| > -{
| > -        va_list ap;
| > -        char *bufp;
| > -        if (fd < 0)
| > -                return;
| > -
| > -        va_start(ap, format);
| > -
| > -        bufp = malloc(BUFSIZE);
| > -        if(bufp) {
| > -                vsnprintf(bufp, BUFSIZE, format, ap);
| > -                write(fd, bufp, strlen(bufp));
| > -        }
| > -        free(bufp);
| > -
| > -        va_end(ap);
| > -}
| > -
| > -#define ckpt_err(...)  \
| > -	ckpt_msg(global_uerrfd, __VA_ARGS__)
| > -
| > -#define ckpt_perror(s)                                                  \
| > -        do {                                                            \
| > -                ckpt_msg(global_uerrfd, s);                             \
| > -                ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));     \
| > -        } while (0)
| > -
| >  static void usage(char *str)
| >  {
| >  	ckpt_err("%s", str);
| > diff --git a/common.h b/common.h
| > new file mode 100644
| > index 0000000..99b224d
| > --- /dev/null
| > +++ b/common.h
| > @@ -0,0 +1,112 @@
| > +#include <stdio.h>
| > +#include <signal.h>
| > +
| > +#define BUFSIZE  (4 * 4096)
| > +
| > +static inline void ckpt_msg(int fd, char *format, ...)
| > +{
| > +	va_list ap;
| > +	char *bufp;
| > +	if (fd < 0)
| > +		return;
| > +
| > +	va_start(ap, format);
| > +
| > +	bufp = malloc(BUFSIZE);
| > +	if(bufp) {
| > +		vsnprintf(bufp, BUFSIZE, format, ap);
| > +		write(fd, bufp, strlen(bufp));
| > +	}
| > +	free(bufp);
| > +
| > +	va_end(ap);
| > +}
| > +
| > +#define ckpt_perror(s) 							\
| > +	do {								\
| > +		ckpt_msg(global_uerrfd, s);				\
| > +		ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));	\
| > +	} while (0)
| > +
| > +#ifdef CHECKPOINT_DEBUG
| > +#define ckpt_dbg(_format, _args...)					\
| > +	do {								\
| > +		if (global_debug)					\
| > +			ckpt_msg(global_uerrfd, "<%d>" _format, 	\
| > +					_gettid(), ##_args); 		\
| > +	} while (0)
| > +#define ckpt_dbg_cont(_format, _args...)				\
| > +	do {								\
| > +		if (global_debug)					\
| > +			ckpt_msg(global_uerrfd, _format, ##_args);	\
| > +	} while (0)
| > +#else
| > +#define ckpt_dbg(_format, _args...)  \
| > +	do { } while (0)
| > +#define ckpt_dbg_cont(_format, _args...)  \
| > +	do { } while (0)
| > +#endif
| > +
| > +#define ckpt_err(...)  \
| > +	ckpt_msg(global_uerrfd, __VA_ARGS__)
| > +
| > +#define ckpt_verbose(...)					\
| > +	do {							\
| > +		if (global_verbose)				\
| > +			ckpt_msg(global_ulogfd, __VA_ARGS__);	\
| > +	} while(0)
| > +
| > +struct signal_array {
| > +	int signum;
| > +	char *sigstr;
| > +};
| > +
| > +#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
| > +
| > +#define INIT_SIGNAL_ARRAY { 	\
| > +	{ 0, "NONE" },		\
| > +	SIGNAL_ENTRY(ALRM),	\
| > +	SIGNAL_ENTRY(HUP),	\
| > +	SIGNAL_ENTRY(INT),	\
| > +	SIGNAL_ENTRY(KILL),	\
| > +	SIGNAL_ENTRY(PIPE),	\
| > +	SIGNAL_ENTRY(POLL),	\
| > +	SIGNAL_ENTRY(PROF),	\
| > +	SIGNAL_ENTRY(TERM),	\
| > +	SIGNAL_ENTRY(USR1),	\
| > +	SIGNAL_ENTRY(USR2),	\
| > +	SIGNAL_ENTRY(VTALRM),	\
| > +	SIGNAL_ENTRY(STKFLT),	\
| > +	SIGNAL_ENTRY(PWR),	\
| > +	SIGNAL_ENTRY(WINCH),	\
| > +	SIGNAL_ENTRY(CHLD),	\
| > +	SIGNAL_ENTRY(URG),	\
| > +	SIGNAL_ENTRY(TTIN),	\
| > +	SIGNAL_ENTRY(TTOU),	\
| > +	SIGNAL_ENTRY(STOP),	\
| > +	SIGNAL_ENTRY(CONT),	\
| > +	SIGNAL_ENTRY(ABRT),	\
| > +	SIGNAL_ENTRY(FPE),	\
| > +	SIGNAL_ENTRY(ILL),	\
| > +	SIGNAL_ENTRY(QUIT),	\
| > +	SIGNAL_ENTRY(SEGV),	\
| > +	SIGNAL_ENTRY(TRAP),	\
| > +	SIGNAL_ENTRY(SYS),	\
| > +	SIGNAL_ENTRY(BUS),	\
| > +	SIGNAL_ENTRY(XCPU),	\
| > +	SIGNAL_ENTRY(XFSZ),	\
| > +	{ -1, "LAST" },		\
| > +}
| > +
| > +#define CKPT_COND_PIDZERO  0x1
| > +#define CKPT_COND_MNTPROC  0x2
| > +#define CKPT_COND_MNTPTY   0x4
| > +
| > +#define CKPT_COND_NONE     0
| > +#define CKPT_COND_ANY      ULONG_MAX
| > +
| > +/* default for skip/warn/fail */
| > +#define CKPT_COND_WARN     (CKPT_COND_MNTPROC | \
| > +			    CKPT_COND_MNTPTY)
| > +#define CKPT_COND_FAIL     (CKPT_COND_NONE)
| > +
| > diff --git a/restart.c b/restart.c
| > index b37bf81..f65eafb 100644
| > --- a/restart.c
| > +++ b/restart.c
| > @@ -40,6 +40,7 @@
| >  #include "eclone.h"
| >  #include "genstack.h"
| >  #include "compat.h"
| > +#include "common.h"
| > 
| >  static char usage_str[] =
| >  "usage: restart [opts]\n"
| > @@ -102,103 +103,6 @@ static char usage_str[] =
| >   * of the checkpoint image stream.
| >   */
| > 
| > -#define BUFSIZE  (4 * 4096)
| > -
| > -static inline void ckpt_msg(int fd, char *format, ...)
| > -{
| > -	va_list ap;
| > -	char *bufp;
| > -	if (fd < 0)
| > -		return;
| > -
| > -	va_start(ap, format);
| > -
| > -	bufp = malloc(BUFSIZE);
| > -	if(bufp) {
| > -		vsnprintf(bufp, BUFSIZE, format, ap);
| > -		write(fd, bufp, strlen(bufp));
| > -	}
| > -	free(bufp);
| > -
| > -	va_end(ap);
| > -}
| > -
| > -#define ckpt_perror(s) 							\
| > -	do {								\
| > -		ckpt_msg(global_uerrfd, s);				\
| > -		ckpt_msg(global_uerrfd, ": %s\n", strerror(errno));	\
| > -	} while (0)
| > -
| > -#ifdef CHECKPOINT_DEBUG
| > -#define ckpt_dbg(_format, _args...)					\
| > -	do {								\
| > -		if (global_debug)					\
| > -			ckpt_msg(global_uerrfd, "<%d>" _format, 	\
| > -					_gettid(), ##_args); 		\
| > -	} while (0)
| > -#define ckpt_dbg_cont(_format, _args...)				\
| > -	do {								\
| > -		if (global_debug)					\
| > -			ckpt_msg(global_uerrfd, _format, ##_args);	\
| > -	} while (0)
| > -#else
| > -#define ckpt_dbg(_format, _args...)  \
| > -	do { } while (0)
| > -#define ckpt_dbg_cont(_format, _args...)  \
| > -	do { } while (0)
| > -#endif
| > -
| > -#define ckpt_err(...)  \
| > -	ckpt_msg(global_uerrfd, __VA_ARGS__)
| > -
| > -#define ckpt_verbose(...)					\
| > -	do {							\
| > -		if (global_verbose)				\
| > -			ckpt_msg(global_ulogfd, __VA_ARGS__);	\
| > -	} while(0)
| > -
| > -struct signal_array {
| > -	int signum;
| > -	char *sigstr;
| > -};
| > -
| > -#define SIGNAL_ENTRY(signal)  { SIG ## signal, #signal }
| > -
| > -#define INIT_SIGNAL_ARRAY { 	\
| > -	{ 0, "NONE" },		\
| > -	SIGNAL_ENTRY(ALRM),	\
| > -	SIGNAL_ENTRY(HUP),	\
| > -	SIGNAL_ENTRY(INT),	\
| > -	SIGNAL_ENTRY(KILL),	\
| > -	SIGNAL_ENTRY(PIPE),	\
| > -	SIGNAL_ENTRY(POLL),	\
| > -	SIGNAL_ENTRY(PROF),	\
| > -	SIGNAL_ENTRY(TERM),	\
| > -	SIGNAL_ENTRY(USR1),	\
| > -	SIGNAL_ENTRY(USR2),	\
| > -	SIGNAL_ENTRY(VTALRM),	\
| > -	SIGNAL_ENTRY(STKFLT),	\
| > -	SIGNAL_ENTRY(PWR),	\
| > -	SIGNAL_ENTRY(WINCH),	\
| > -	SIGNAL_ENTRY(CHLD),	\
| > -	SIGNAL_ENTRY(URG),	\
| > -	SIGNAL_ENTRY(TTIN),	\
| > -	SIGNAL_ENTRY(TTOU),	\
| > -	SIGNAL_ENTRY(STOP),	\
| > -	SIGNAL_ENTRY(CONT),	\
| > -	SIGNAL_ENTRY(ABRT),	\
| > -	SIGNAL_ENTRY(FPE),	\
| > -	SIGNAL_ENTRY(ILL),	\
| > -	SIGNAL_ENTRY(QUIT),	\
| > -	SIGNAL_ENTRY(SEGV),	\
| > -	SIGNAL_ENTRY(TRAP),	\
| > -	SIGNAL_ENTRY(SYS),	\
| > -	SIGNAL_ENTRY(BUS),	\
| > -	SIGNAL_ENTRY(XCPU),	\
| > -	SIGNAL_ENTRY(XFSZ),	\
| > -	{ -1, "LAST" },		\
| > -}
| > -
| >  static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
| > 
| >  static char *sig2str(int sig)
| > @@ -399,18 +303,6 @@ struct app_restart_args {
| >  	int keep_lsm;
| >  };
| > 
| > -#define CKPT_COND_PIDZERO  0x1
| > -#define CKPT_COND_MNTPROC  0x2
| > -#define CKPT_COND_MNTPTY   0x4
| > -
| > -#define CKPT_COND_NONE     0
| > -#define CKPT_COND_ANY      ULONG_MAX
| > -
| > -/* default for skip/warn/fail */
| > -#define CKPT_COND_WARN     (CKPT_COND_MNTPROC | \
| > -			    CKPT_COND_MNTPTY)
| > -#define CKPT_COND_FAIL     (CKPT_COND_NONE)
| > -
| >  static void usage(char *str)
| >  {
| >  	ckpt_err("%s", str);
| > -- 
| > 1.6.0.4
| > 
| > _______________________________________________
| > Containers mailing list
| > Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
| > https://lists.linux-foundation.org/mailman/listinfo/containers
#20 lore raw

PATCH 9/12 Create app-checkpoint.h

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 21:51:27 -0800
Subject: [PATCH 09/12][user-cr] Create app-checkpoint.h

Create a new header file, app-checkpoint.h that can be used to export the app_checkpoint() and app_restart() functionality to other users (such as LXC).

---
 Makefile         |    2 +-
 app-checkpoint.h |   37 +++++++++++++++++++++++++++++++++++++
 checkpoint.c     |    9 +--------
 restart.c        |   25 +------------------------
 4 files changed, 40 insertions(+), 33 deletions(-)
 create mode 100644 app-checkpoint.h
Makefile +1 -1
index acebdd5..b037f93 100644
@@ -43,7 +43,7 @@ $(LIB_ECLONE):
 # restart needs to be thread-safe
 restart: CFLAGS += -D__REENTRANT -pthread
 
-$(CR_OBJS): common.h
+$(CR_OBJS): common.h app-checkpoint.h
 
 # eclone() is architecture specific
 ifneq ($(SUBARCH),)
app-checkpoint.h new file +37 -0
new file mode 100644
index 0000000..75204b5
@@ -0,0 +1,37 @@
+
+struct app_checkpoint_args {
+	int outfd;
+	int logfd;
+	int uerrfd;
+	int container;
+	int verbose;
+};
+
+struct app_restart_args {
+	int self;
+	int pids;
+	int pidns;
+	int inspect;
+	int send_sigint;
+	char *root;
+	int wait;
+	int mntns;
+	int mnt_pty;
+	int show_status;
+	int copy_status;
+	char *freezer;
+	int infd;
+	int klogfd;
+	int ulogfd;
+	int uerrfd;
+	long warn;
+	int debug;
+	int verbose;
+	long fail;
+	int keep_lsm;
+};
+
+extern int app_checkpoint(int pid, unsigned long flags,
+				struct app_checkpoint_args *args);
+
+extern int app_restart(struct app_restart_args *args);
checkpoint.c +1 -8
index 6e91149..291cb36 100644
@@ -21,6 +21,7 @@
 
 #include <linux/checkpoint.h>
 
+#include "app-checkpoint.h"
 #include "common.h"
 
 static char usage_str[] =
@@ -44,14 +45,6 @@ static char usage_str[] =
 
 static int global_uerrfd = -1;
 
-struct app_checkpoint_args {
-	int outfd;
-	int logfd;
-	int uerrfd;
-	int container;
-	int verbose;
-};
-
 inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
 {
 	return syscall(__NR_checkpoint, pid, fd, flags, logfd);
restart.c +1 -24
index f65eafb..a9b287d 100644
@@ -40,6 +40,7 @@
 #include "eclone.h"
 #include "genstack.h"
 #include "compat.h"
+#include "app-checkpoint.h"
 #include "common.h"
 
 static char usage_str[] =
@@ -279,30 +280,6 @@ struct pid_swap {
 	pid_t new;
 };
 
-struct app_restart_args {
-	int self;
-	int pids;
-	int pidns;
-	int inspect;
-	int send_sigint;
-	char *root;
-	int wait;
-	int mntns;
-	int mnt_pty;
-	int show_status;
-	int copy_status;
-	char *freezer;
-	int infd;
-	int klogfd;
-	int ulogfd;
-	int uerrfd;
-	long warn;
-	int debug;
-	int verbose;
-	long fail;
-	int keep_lsm;
-};
-
 static void usage(char *str)
 {
 	ckpt_err("%s", str);
Signature · 1 line
1.6.0.4
#21 lore raw

PATCH 10/12 restart: Move main() to restart-main.c

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 21:46:14 -0800
Subject: [PATCH 10/12][user-cr] restart: Move main() to restart-main.c

---
 Makefile       |    4 +-
 restart-main.c |  351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 restart.c      |  332 -----------------------------------------------------
 3 files changed, 354 insertions(+), 333 deletions(-)
 create mode 100644 restart-main.c
Makefile +3 -1
index b037f93..8a91d10 100644
@@ -5,7 +5,7 @@ CKPT_HEADERS = include/linux/checkpoint.h \
 		include/linux/checkpoint_hdr.h \
 		include/asm/checkpoint_hdr.h
 
-CR_OBJS = checkpoint.o restart.o
+CR_OBJS = checkpoint.o restart.o restart-main.o
 
 # detect architecture (for eclone)
 SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
@@ -45,6 +45,8 @@ restart: CFLAGS += -D__REENTRANT -pthread
 
 $(CR_OBJS): common.h app-checkpoint.h
 
+restart: restart.o restart-main.o
+
 # eclone() is architecture specific
 ifneq ($(SUBARCH),)
 $(ECLONE_PROGS): $(LIB_ECLONE) 
restart-main.c new file +351 -0

351 lines not on this page · raw message

restart.c +0 -332

362 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#22 lore raw

PATCH 11/12 checkpoint: Move main() to checkpoint-main.c

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Thu, 4 Mar 2010 22:28:34 -0800
Subject: [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c

---
 Makefile          |    4 +-
 checkpoint-main.c |  171 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 checkpoint.c      |  157 ------------------------------------------------
 3 files changed, 174 insertions(+), 158 deletions(-)
 create mode 100644 checkpoint-main.c
Makefile +3 -1
index 8a91d10..e520425 100644
@@ -5,7 +5,7 @@ CKPT_HEADERS = include/linux/checkpoint.h \
 		include/linux/checkpoint_hdr.h \
 		include/asm/checkpoint_hdr.h
 
-CR_OBJS = checkpoint.o restart.o restart-main.o
+CR_OBJS = checkpoint.o checkpoint-main.o restart.o restart-main.o
 
 # detect architecture (for eclone)
 SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
@@ -47,6 +47,8 @@ $(CR_OBJS): common.h app-checkpoint.h
 
 restart: restart.o restart-main.o
 
+checkpoint: checkpoint.o checkpoint-main.o
+
 # eclone() is architecture specific
 ifneq ($(SUBARCH),)
 $(ECLONE_PROGS): $(LIB_ECLONE) 
checkpoint-main.c new file +171 -0

171 lines not on this page · raw message

checkpoint.c +0 -157

172 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#23 lore raw

PATCH 12/12 Have app_restart() return pid

In reply to a message not in the archive

From: Sukadev Bhattiprolu <[email protected]>
Date: Fri, 5 Mar 2010 10:24:53 -0800
Subject: [PATCH 12/12][user-cr] Have app_restart() return pid

On success, return the pid of a the root of the restarted process tree. This would enable callers to manage the restarted process-tree as a cgroup.

---
 restart-main.c |    7 ++++++-
 restart.c      |    6 ++++++
 2 files changed, 12 insertions(+), 1 deletions(-)
restart-main.c +6 -1
index 96bca42..39ab05a 100644
@@ -333,6 +333,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
 
 int main(int argc, char *argv[])
 {
+	int ret;
 	struct app_restart_args args;
 
 	/*
@@ -346,6 +347,10 @@ int main(int argc, char *argv[])
 
 	parse_args(&args, argc, argv);
 
-	return app_restart(&args);
+	ret = app_restart(&args);
+	if (ret > 0)
+		ret = 0;
+
+	return ret;
 }
 
restart.c +6 -0
index 6ac4647..7ea3732 100644
@@ -486,6 +486,12 @@ int app_restart(struct app_restart_args *args)
 		ret = ckpt_coordinator(&ctx);
 	}
 
+	/*
+	 * On success, return pid of root of the restart process tree.
+	 */
+	if (ret >= 0)
+		ret = global_child_pid;
+
 	return ret;
 }
 
Signature · 1 line
1.6.0.4
#24 lore raw
In reply to a message not in the archive
Quoted 23 lines · Sukadev Bhattiprolu

Second set of cleanup patches. With these patches, LXC will be able to compile/link directly using restart.o and app-checkpoint.h from the user-cr directory. Something like:

USER_CR=/home/suka/user-cr make lxc_restart

After having more detailed discussions on the API, we could install restart.o in /lib/libcheckpoint.a and app-checkpoint.h in /usr/include.

	[PATCH 01/12][user-cr] restart: Mark globals as static
	[PATCH 02/12][user-cr] restart: Add args->send_sigint
	[PATCH 03/12][user-cr] Add app_restart_args->debug
	[PATCH 04/12][user-cr] Add app_restart_args->verbose
	[PATCH 05/12][user-cr] Add app_restart_args->ulogfd
	[PATCH 06/12][user-cr] Add app_restart_args->uerrfd
	[PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
	[PATCH 08/12][user-cr] Create common.h 
	[PATCH 09/12][user-cr] Create app-checkpoint.h
	[PATCH 10/12][user-cr] restart: Move main() to restart-main.c
	[PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
	[PATCH 12/12][user-cr] Have app_restart() return pid
Quoted 1 line

Again, not yet tested (though will do that soon as I will base my mounts c/r patchset on ckpt-v19-suka), but looks good, thanks.

-serge