[CRIU] [PATCH v3 5/6] p.haul: handle older criu RPC interfaces

Nikita Spiridonov nspiridonov at odin.com
Thu Oct 8 10:46:32 PDT 2015


On Thu, 2015-10-08 at 20:18 +0200, Adrian Reber wrote:
> On Thu, Oct 08, 2015 at 08:29:48PM +0400, Nikita Spiridonov wrote:
> > On Thu, 2015-10-08 at 14:06 +0000, Adrian Reber wrote:
> > > From: Adrian Reber <areber at redhat.com>
> > > 
> > > Wrap the calls to the new feature-check RPC interface into try: except:
> > > to continue gracefully without stack traces. If the installed criu
> > > supports feature-check it will be used to detect if memory tracking
> > > should be enabled. If the installed criu is too old to support
> > > feature-check no pre-dumping will be performed. Pre-dumps can still be
> > > manually enabled via p.haul's command-line.
> > > 
> > > v2: rebased
> > > 
> > > v3: rebased
> > > 
> > > Signed-off-by: Adrian Reber <areber at redhat.com>
> > > ---
> > >  phaul/criu_req.py     | 30 +++++++++++++++++++++---------
> > >  phaul/p_haul_iters.py | 40 ++++++++++++++++++++++++++++------------
> > >  2 files changed, 49 insertions(+), 21 deletions(-)
> > > 
> > > diff --git a/phaul/criu_req.py b/phaul/criu_req.py
> > > index d97d4cf..9409c0d 100644
> > > --- a/phaul/criu_req.py
> > > +++ b/phaul/criu_req.py
> > > @@ -4,15 +4,27 @@
> > >  
> > >  import pycriu.rpc
> > >  
> > > -_names = {
> > > -	pycriu.rpc.DUMP: "dump",
> > > -	pycriu.rpc.PRE_DUMP: "pre_dump",
> > > -	pycriu.rpc.PAGE_SERVER: "page_server",
> > > -	pycriu.rpc.RESTORe: "restore",
> > > -	pycriu.rpc.CPUINFO_DUMP: "cpuinfo-dump",
> > > -	pycriu.rpc.CPUINFO_CHECK: "cpuinfo-check",
> > > -	pycriu.rpc.FEATURE_CHECK: "feature-check",
> > > -}
> > > +try:
> > > +	_names = {
> > > +		pycriu.rpc.DUMP: "dump",
> > > +		pycriu.rpc.PRE_DUMP: "pre_dump",
> > > +		pycriu.rpc.PAGE_SERVER: "page_server",
> > > +		pycriu.rpc.RESTORe: "restore",
> > > +		pycriu.rpc.CPUINFO_DUMP: "cpuinfo-dump",
> > > +		pycriu.rpc.CPUINFO_CHECK: "cpuinfo-check",
> > > +		pycriu.rpc.FEATURE_CHECK: "feature-check",
> > > +	}
> > > +except:
> > > +	# Do not fail if installed criu does not support
> > > +	# RPC call DIRTY_TRACKING
> > > +	_names = {
> > > +		pycriu.rpc.DUMP: "dump",
> > > +		pycriu.rpc.PRE_DUMP: "pre_dump",
> > > +		pycriu.rpc.PAGE_SERVER: "page_server",
> > > +		pycriu.rpc.RESTORe: "restore",
> > > +		pycriu.rpc.CPUINFO_DUMP: "cpuinfo-dump",
> > > +		pycriu.rpc.CPUINFO_CHECK: "cpuinfo-check",
> > > +	}
> > 
> > Can you replace code above with something like
> > 
> > def _build_names(name_strings):
> >         names = {}
> >         for key, value in name_strings.items():
> >                 if hasattr(pycriu.rpc, key):
> >                         names[getattr(pycriu.rpc, key)] = value
> >         return names
> > 
> > _name_strings = {
> >         "DUMP": "dump",
> >         "PRE_DUMP": "pre_dump",
> >         "PAGE_SERVER": "page_server",
> >         "RESTORE": "restore",
> >         "CPUINFO_DUMP": "cpuinfo-dump",
> >         "CPUINFO_CHECK": "cpuinfo-check",
> >         "FEATURE_CHECK": "feature-check",
> > }
> > 
> > _names = _build_names(_name_strings)
> > 
> > to avoid code duplication?
> 
> Good idea!
> 
> > Don't know is it better to do in current patchset or in further commit
> > cause I need your patches applied asap to rebase on it
> 
> I will do it in follow up patch. I also had to rebase my patches two
> times as the are right now lots of changes in p.haul, so I know how it
> is to wait on rebases.
> 
> 		Adrian

It seems it was my commits, sorry for that. Currently implement
virtuozzo containers live imgration and have a lot of issues to fix.

> 
> > >  
> > >  def get_name(req_type):
> > >  	"""Return printable request name"""
> > > diff --git a/phaul/p_haul_iters.py b/phaul/p_haul_iters.py
> > > index 96458b8..85efc8b 100644
> > > --- a/phaul/p_haul_iters.py
> > > +++ b/phaul/p_haul_iters.py
> > > @@ -91,25 +91,41 @@ class phaul_iter_worker:
> > >  		self.fs.set_work_dir(self.img.work_dir())
> > >  		self.fs.start_migration()
> > >  
> > > +		logging.info("Checking for Dirty Tracking")
> > >  		if self.pre_dump == 0:
> > >  			# pre-dump auto-detection
> > > -			logging.info("Checking for Dirty Tracking")
> > > -			req = criu_req.make_dirty_tracking_req(self.htype, self.img)
> > > -			resp = self.criu_connection.send_req(req)
> > > -			pre_dump = resp.success
> > > +			try:
> > > +				req = criu_req.make_dirty_tracking_req(
> > > +						self.htype, self.img)
> > > +				resp = self.criu_connection.send_req(req)
> > > +				pre_dump = False
> > > +				if not resp.success:
> > > +					# Not able to do auto-detection, disable memory tracking
> > > +					raise Exception()
> > > +				if resp.HasField('features'):
> > > +					if resp.features.HasField('mem_track'):
> > > +						if resp.features.mem_track:
> > > +							logging.info("\t`- Auto Enabled")
> > > +							pre_dump = True
> > > +				else:
> > > +					logging.info("\t`- Auto Disabled")
> > > +
> > > +			except:
> > > +				# The available criu seems to not
> > > +				# support memory tracking auto detection.
> > > +				pre_dump = False
> > > +				logging.info("\t`- Auto detection not possible "
> > > +						"- Disabled")
> > > +
> > >  		elif self.pre_dump == 1:
> > >  			pre_dump = False
> > > +			logging.info("\t`- Command-line disabled")
> > >  		else:
> > >  			pre_dump = True
> > > +			logging.info("\t`- Command-line enabled")
> > >  
> > > -		if resp.success:
> > > -			if resp.HasField('features'):
> > > -				if resp.features.HasField('mem_track'):
> > > -					if resp.features.mem_track:
> > > -						logging.info("Starting iterations")
> > > -						pre_dump = True
> > > -			else:
> > > -				self.criu_connection.memory_tracking(False)
> > > +		if pre_dump:
> > > +			logging.info("Starting iterations")
> > >  		else:
> > >  			self.criu_connection.memory_tracking(False)
> > >  




More information about the CRIU mailing list