@@ -38,7 +38,7 @@ checkpointed.`,
3838		cli.StringFlag {Name : "page-server" , Value : "" , Usage : "ADDRESS:PORT of the page server" },
3939		cli.BoolFlag {Name : "file-locks" , Usage : "handle file locks, for safety" },
4040		cli.BoolFlag {Name : "pre-dump" , Usage : "dump container's memory information only, leave the container running after this" },
41- 		cli.StringFlag {Name : "manage-cgroups-mode" , Value : "" , Usage : "cgroups mode: ' soft'  (default), 'full' and 'strict' " },
41+ 		cli.StringFlag {Name : "manage-cgroups-mode" , Value : "" , Usage : "cgroups mode: soft|full|strict|ignore  (default: soft) " },
4242		cli.StringSliceFlag {Name : "empty-ns" , Usage : "create a namespace, but don't restore its properties" },
4343		cli.BoolFlag {Name : "auto-dedup" , Usage : "enable auto deduplication of memory images" },
4444	},
@@ -67,17 +67,6 @@ checkpointed.`,
6767			return  err 
6868		}
6969
70- 		// these are the mandatory criu options for a container 
71- 		if  err  :=  setPageServer (context , options ); err  !=  nil  {
72- 			return  err 
73- 		}
74- 		if  err  :=  setManageCgroupsMode (context , options ); err  !=  nil  {
75- 			return  err 
76- 		}
77- 		if  err  :=  setEmptyNsMask (context , options ); err  !=  nil  {
78- 			return  err 
79- 		}
80- 
8170		err  =  container .Checkpoint (options )
8271		if  err  ==  nil  &&  ! (options .LeaveRunning  ||  options .PreDump ) {
8372			// Destroy the container unless we tell CRIU to keep it. 
@@ -119,59 +108,80 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
119108	return  imagePath , parentPath , nil 
120109}
121110
122- func  setPageServer (context  * cli.Context , options  * libcontainer.CriuOpts ) error  {
123- 	// xxx following criu opts are optional 
124- 	// The dump image can be sent to a criu page server 
111+ func  criuOptions (context  * cli.Context ) (* libcontainer.CriuOpts , error ) {
112+ 	imagePath , parentPath , err  :=  prepareImagePaths (context )
113+ 	if  err  !=  nil  {
114+ 		return  nil , err 
115+ 	}
116+ 
117+ 	opts  :=  & libcontainer.CriuOpts {
118+ 		ImagesDirectory :         imagePath ,
119+ 		WorkDirectory :           context .String ("work-path" ),
120+ 		ParentImage :             parentPath ,
121+ 		LeaveRunning :            context .Bool ("leave-running" ),
122+ 		TcpEstablished :          context .Bool ("tcp-established" ),
123+ 		ExternalUnixConnections : context .Bool ("ext-unix-sk" ),
124+ 		ShellJob :                context .Bool ("shell-job" ),
125+ 		FileLocks :               context .Bool ("file-locks" ),
126+ 		PreDump :                 context .Bool ("pre-dump" ),
127+ 		AutoDedup :               context .Bool ("auto-dedup" ),
128+ 		LazyPages :               context .Bool ("lazy-pages" ),
129+ 		StatusFd :                context .Int ("status-fd" ),
130+ 		LsmProfile :              context .String ("lsm-profile" ),
131+ 		LsmMountContext :         context .String ("lsm-mount-context" ),
132+ 	}
133+ 
134+ 	// CRIU options below may or may not be set. 
135+ 
125136	if  psOpt  :=  context .String ("page-server" ); psOpt  !=  ""  {
126137		address , port , err  :=  net .SplitHostPort (psOpt )
127138
128139		if  err  !=  nil  ||  address  ==  ""  ||  port  ==  ""  {
129- 			return  errors .New ("Use --page-server ADDRESS:PORT to specify page server" )
140+ 			return  nil ,  errors .New ("Use --page-server ADDRESS:PORT to specify page server" )
130141		}
131142		portInt , err  :=  strconv .Atoi (port )
132143		if  err  !=  nil  {
133- 			return  errors .New ("Invalid port number" )
144+ 			return  nil ,  errors .New ("Invalid port number" )
134145		}
135- 		options .PageServer  =  libcontainer.CriuPageServerInfo {
146+ 		opts .PageServer  =  libcontainer.CriuPageServerInfo {
136147			Address : address ,
137148			Port :    int32 (portInt ),
138149		}
139150	}
140- 	return  nil 
141- }
142151
143- func  setManageCgroupsMode (context  * cli.Context , options  * libcontainer.CriuOpts ) error  {
144- 	if  cgOpt  :=  context .String ("manage-cgroups-mode" ); cgOpt  !=  ""  {
145- 		switch  cgOpt  {
146- 		case  "soft" :
147- 			options .ManageCgroupsMode  =  criu .CriuCgMode_SOFT 
148- 		case  "full" :
149- 			options .ManageCgroupsMode  =  criu .CriuCgMode_FULL 
150- 		case  "strict" :
151- 			options .ManageCgroupsMode  =  criu .CriuCgMode_STRICT 
152- 		default :
153- 			return  errors .New ("Invalid manage cgroups mode" )
154- 		}
152+ 	switch  context .String ("manage-cgroups-mode" ) {
153+ 	case  "" :
154+ 		// do nothing 
155+ 	case  "soft" :
156+ 		opts .ManageCgroupsMode  =  criu .CriuCgMode_SOFT 
157+ 	case  "full" :
158+ 		opts .ManageCgroupsMode  =  criu .CriuCgMode_FULL 
159+ 	case  "strict" :
160+ 		opts .ManageCgroupsMode  =  criu .CriuCgMode_STRICT 
161+ 	case  "ignore" :
162+ 		opts .ManageCgroupsMode  =  criu .CriuCgMode_IGNORE 
163+ 	default :
164+ 		return  nil , errors .New ("Invalid manage-cgroups-mode value" )
155165	}
156- 	return  nil 
157- }
158166
159- var  namespaceMapping  =  map [specs.LinuxNamespaceType ]int {
160- 	specs .NetworkNamespace : unix .CLONE_NEWNET ,
161- }
162- 
163- func  setEmptyNsMask (context  * cli.Context , options  * libcontainer.CriuOpts ) error  {
164- 	/* Runc doesn't manage network devices and their configuration */ 
167+ 	// runc doesn't manage network devices and their configuration. 
165168	nsmask  :=  unix .CLONE_NEWNET 
166169
167- 	for  _ , ns  :=  range  context .StringSlice ("empty-ns" ) {
168- 		f , exists  :=  namespaceMapping [specs .LinuxNamespaceType (ns )]
169- 		if  ! exists  {
170- 			return  fmt .Errorf ("namespace %q is not supported" , ns )
170+ 	if  context .IsSet ("empty-ns" ) {
171+ 		namespaceMapping  :=  map [specs.LinuxNamespaceType ]int {
172+ 			specs .NetworkNamespace : unix .CLONE_NEWNET ,
173+ 		}
174+ 
175+ 		for  _ , ns  :=  range  context .StringSlice ("empty-ns" ) {
176+ 			f , exists  :=  namespaceMapping [specs .LinuxNamespaceType (ns )]
177+ 			if  ! exists  {
178+ 				return  nil , fmt .Errorf ("namespace %q is not supported" , ns )
179+ 			}
180+ 			nsmask  |=  f 
171181		}
172- 		nsmask  |=  f 
173182	}
174183
175- 	options .EmptyNs  =  uint32 (nsmask )
176- 	return  nil 
184+ 	opts .EmptyNs  =  uint32 (nsmask )
185+ 
186+ 	return  opts , nil 
177187}
0 commit comments