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

Nikita Spiridonov nspiridonov at odin.com
Thu Oct 8 09:29:48 PDT 2015


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?

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

>  
>  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