[CRIU] [PATCH 2/5] proc_parse: Rework fdinfo parser to use bfd

Andrew Vagin avagin at parallels.com
Wed Sep 24 01:38:14 PDT 2014


[root at avagin-fc19-cr criu]# bash test/zdtm.sh static/pipe00
================================= CRIU CHECK =================================
Error (proc_parse.c:1405): No records of type 6 found in fdinfo file
Error (proc_parse.c:1408): parse_fdinfo_pid_s: error parsing [(null)] for 6: Success
Error (cr-check.c:235): Error parsing proc fdinfo
Error (cr-check.c:339): TFD mismatch (or not met) 0 want 4
Error (proc_parse.c:1405): No records of type 9 found in fdinfo file
Error (proc_parse.c:1408): parse_fdinfo_pid_s: error parsing [(null)] for 9: Success
Error (cr-check.c:293): Error parsing proc fdinfo
Error (cr-check.c:388): WD mismatch (or not met) -1 want 1
Error (cr-check.c:269): fdinfo doesn't contain the mnt_id field
============================= WARNING =============================
Not all features needed for CRIU are merged to upstream kernel yet,
so for now we maintain our own branch which can be cloned from:
git://git.kernel.org/pub/scm/linux/kernel/git/gorcunov/linux-cr.git
===================================================================
Execute zdtm/live/static/pipe00
./pipe00 --pidfile=pipe00.pid --outfile=pipe00.out
Dump 17818
WARNING: pipe00 returned 1 and left running for debug needs
Test: zdtm/live/static/pipe00, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/pipe00, Namespace: 
Dump log   : /root/git/criu/test/dump/static/pipe00/17818/1/dump.log
--------------------------------- grep Error ---------------------------------
(00.020913) Error (pipes.c:445): Can't pick pipe data: Bad file descriptor
(00.020982) Error (cr-dump.c:1583): Dump files (pid: 17818) failed with -1
(00.021987) Error (cr-dump.c:1927): Dumping FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================


On Fri, Sep 19, 2014 at 05:31:11PM +0400, Pavel Emelyanov wrote:
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> ---
>  proc_parse.c | 49 +++++++++++++++++++++++++++++++------------------
>  1 file changed, 31 insertions(+), 18 deletions(-)
> 
> diff --git a/proc_parse.c b/proc_parse.c
> index 9aa17d4..a6f6f4c 100644
> --- a/proc_parse.c
> +++ b/proc_parse.c
> @@ -23,7 +23,7 @@
>  #include "kerndat.h"
>  #include "vdso.h"
>  #include "vma.h"
> -
> +#include "bfd.h"
>  #include "proc_parse.h"
>  #include "cr_options.h"
>  #include "sysfs_parse.h"
> @@ -1080,7 +1080,7 @@ static void parse_fhandle_encoded(char *tok, FhEntry *fh)
>  	}
>  }
>  
> -static int parse_timerfd(FILE *f, char *buf, size_t size, TimerfdEntry *tfy)
> +static int parse_timerfd(struct bfd *f, char *str, TimerfdEntry *tfy)
>  {
>  	/*
>  	 * Format is
> @@ -1093,26 +1093,30 @@ static int parse_timerfd(FILE *f, char *buf, size_t size, TimerfdEntry *tfy)
>  	if (sscanf(buf, "clockid: %d", &tfy->clockid) != 1)
>  		goto parse_err;
>  
> -	if (!fgets(buf, size, f))
> +	str = breadline(f);
> +	if (str == NULL || str == BREADERR)
>  		goto nodata;
> -	if (sscanf(buf, "ticks: %llu", (unsigned long long *)&tfy->ticks) != 1)
> +	if (sscanf(str, "ticks: %llu", (unsigned long long *)&tfy->ticks) != 1)
>  		goto parse_err;
>  
> -	if (!fgets(buf, size, f))
> +	str = breadline(f);
> +	if (str == NULL || str == BREADERR)
>  		goto nodata;
> -	if (sscanf(buf, "settime flags: 0%o", &tfy->settime_flags) != 1)
> +	if (sscanf(str, "settime flags: 0%o", &tfy->settime_flags) != 1)
>  		goto parse_err;
>  
> -	if (!fgets(buf, size, f))
> +	str = breadline(f);
> +	if (str == NULL || str == BREADERR)
>  		goto nodata;
> -	if (sscanf(buf, "it_value: (%llu, %llu)",
> +	if (sscanf(str, "it_value: (%llu, %llu)",
>  		   (unsigned long long *)&tfy->vsec,
>  		   (unsigned long long *)&tfy->vnsec) != 2)
>  		goto parse_err;
>  
> -	if (!fgets(buf, size, f))
> +	str = breadline(f);
> +	if (str == NULL || str == BREADERR)
>  		goto nodata;
> -	if (sscanf(buf, "it_interval: (%llu, %llu)",
> +	if (sscanf(str, "it_interval: (%llu, %llu)",
>  		   (unsigned long long *)&tfy->isec,
>  		   (unsigned long long *)&tfy->insec) != 2)
>  		goto parse_err;
> @@ -1130,20 +1134,29 @@ nodata:
>  static int parse_fdinfo_pid_s(int pid, int fd, int type,
>  		int (*cb)(union fdinfo_entries *e, void *arg), void *arg)
>  {
> -	FILE *f;
> -	char str[256];
> +	struct bfd f;
> +	char *str;
>  	bool entry_met = false;
>  	int ret = -1;
>  
> -	f = fopen_proc(pid, "fdinfo/%d", fd);
> -	if (!f) {
> -		pr_perror("Can't open %s to parse", str);
> +	f.fd = open_proc(pid, "fdinfo/%d", fd);
> +	if (f.fd < 0) {
> +		pr_perror("Can't open fdinfo/%d to parse", fd);
>  		return -1;
>  	}
>  
> -	while (fgets(str, sizeof(str), f)) {
> +	if (bfdopen(&f))
> +		return -1;
> +
> +	while (1) {
>  		union fdinfo_entries entry;
>  
> +		str = breadline(&f);
> +		if (!str)
> +			break;
> +		if (str == BREADERR)
> +			goto out;
> +
>  		if (fdinfo_field(str, "pos") ||
>  		    fdinfo_field(str, "flags") ||
>  		    fdinfo_field(str, "mnt_id")) {
> @@ -1191,7 +1204,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
>  
>  			if (type != FD_TYPES__TIMERFD)
>  				goto parse_err;
> -			ret = parse_timerfd(f, str, sizeof(str), &entry.tfy);
> +			ret = parse_timerfd(&f, str, &entry.tfy);
>  			if (ret)
>  				goto parse_err;
>  			ret = cb(&entry, arg);
> @@ -1394,7 +1407,7 @@ parse_err:
>  	ret = -1;
>  	pr_perror("%s: error parsing [%s] for %d", __func__, str, type);
>  out:
> -	fclose(f);
> +	bclose(&f);
>  	return ret;
>  }
>  
> -- 
> 1.8.4.2
> 
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list