crit: Files now sit in another image

Submitted by Pavel Emelianov on Sept. 5, 2017, 11:39 a.m.

Details

Message ID b6162c4e-037f-8709-fba8-69454c496571@virtuozzo.com
State Accepted
Series "crit: Files now sit in another image"
Headers show

Commit Message

Pavel Emelianov Sept. 5, 2017, 11:39 a.m.
When merging files into one image we've forgotten about crit x
feature that scans image files by names.

https://github.com/xemul/criu/issues/381

The patch was made for master (as in criu-dev there was problem
with pstree_item.pid parsing), but should apply to dev smoothly.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 crit/crit | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/crit/crit b/crit/crit
index a6a6832..22e7ea7 100755
--- a/crit/crit
+++ b/crit/crit
@@ -89,8 +89,32 @@  def explore_ps(opts):
 	print "%7s%7s%7s   %s" % ('PID', 'PGID', 'SID', 'COMM')
 	show_ps(psr, opts)
 
+files_img = None
+
+def ftype_find_in_files(opts, ft, fid):
+	global files_img
+
+	if files_img is None:
+		try:
+			files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
+		except:
+			files_img = []
+
+	if len(files_img) == 0:
+		return None
+
+	for f in files_img:
+		if f['id'] == fid:
+			return f
+
+	return None
+
 
 def ftype_find_in_image(opts, ft, fid, img):
+	f = ftype_find_in_files(opts, ft, fid)
+	if f:
+		return f[ft['field']]
+
 	if ft['img'] == None:
 		ft['img'] = pycriu.images.load(dinf(opts, img))['entries']
 	for f in ft['img']:
@@ -111,13 +135,13 @@  def ftype_unix(opts, ft, fid):
 	if not ux:
 		return 'unix[?]'
 
-	n = ux['name'] and ' %s' % ux['name'].decode('base64') or ''
+	n = ux['name'] and ' %s' % ux['name'] or ''
 	return 'unix[%d (%d)%s]' % (ux['ino'], ux['peer'], n)
 
 file_types = {
-	'REG':		{'get': ftype_reg,	'img': None},
-	'PIPE':		{'get': ftype_pipe,	'img': None},
-	'UNIXSK':	{'get': ftype_unix,	'img': None},
+	'REG':		{'get': ftype_reg,	'img': None,	'field': 'reg'},
+	'PIPE':		{'get': ftype_pipe,	'img': None,	'field': 'pipe'},
+	'UNIXSK':	{'get': ftype_unix,	'img': None,	'field': 'usk'},
 }
 
 def ftype_gen(opts, ft, fid):

Comments

Andrey Vagin Sept. 9, 2017, 1:13 a.m.
Applied, thanks!
On Tue, Sep 05, 2017 at 02:39:35PM +0300, Pavel Emelyanov wrote:
> When merging files into one image we've forgotten about crit x
> feature that scans image files by names.
> 
> https://github.com/xemul/criu/issues/381
> 
> The patch was made for master (as in criu-dev there was problem
> with pstree_item.pid parsing), but should apply to dev smoothly.
> 
> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
> ---
>  crit/crit | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/crit/crit b/crit/crit
> index a6a6832..22e7ea7 100755
> --- a/crit/crit
> +++ b/crit/crit
> @@ -89,8 +89,32 @@ def explore_ps(opts):
>  	print "%7s%7s%7s   %s" % ('PID', 'PGID', 'SID', 'COMM')
>  	show_ps(psr, opts)
>  
> +files_img = None
> +
> +def ftype_find_in_files(opts, ft, fid):
> +	global files_img
> +
> +	if files_img is None:
> +		try:
> +			files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
> +		except:
> +			files_img = []
> +
> +	if len(files_img) == 0:
> +		return None
> +
> +	for f in files_img:
> +		if f['id'] == fid:
> +			return f
> +
> +	return None
> +
>  
>  def ftype_find_in_image(opts, ft, fid, img):
> +	f = ftype_find_in_files(opts, ft, fid)
> +	if f:
> +		return f[ft['field']]
> +
>  	if ft['img'] == None:
>  		ft['img'] = pycriu.images.load(dinf(opts, img))['entries']
>  	for f in ft['img']:
> @@ -111,13 +135,13 @@ def ftype_unix(opts, ft, fid):
>  	if not ux:
>  		return 'unix[?]'
>  
> -	n = ux['name'] and ' %s' % ux['name'].decode('base64') or ''
> +	n = ux['name'] and ' %s' % ux['name'] or ''
>  	return 'unix[%d (%d)%s]' % (ux['ino'], ux['peer'], n)
>  
>  file_types = {
> -	'REG':		{'get': ftype_reg,	'img': None},
> -	'PIPE':		{'get': ftype_pipe,	'img': None},
> -	'UNIXSK':	{'get': ftype_unix,	'img': None},
> +	'REG':		{'get': ftype_reg,	'img': None,	'field': 'reg'},
> +	'PIPE':		{'get': ftype_pipe,	'img': None,	'field': 'pipe'},
> +	'UNIXSK':	{'get': ftype_unix,	'img': None,	'field': 'usk'},
>  }
>  
>  def ftype_gen(opts, ft, fid):
> -- 
> 2.5.5
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu