[CRIU] [PATCH] reg-files: skip size for O_APPEND|O_WRONLY files.

Pavel Emelyanov xemul at parallels.com
Thu Mar 19 06:41:12 PDT 2015


On 03/19/2015 02:39 PM, Ruslan Kuprieiev wrote:
> This is common for log files, when a number of processes
> are writing something into one file. Currently, if someone
> wrote something to log since dump happened, on restore criu
> will complain about "File has bad size" and refuse to restore.
> 
> If file is opened with O_APPEND|O_WRONLY flags it is going to
> jump to the EOF anyway.
> 
> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
> ---
>  files-reg.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/files-reg.c b/files-reg.c
> index a716a69..8115984 100644
> --- a/files-reg.c
> +++ b/files-reg.c
> @@ -837,7 +837,9 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
>  	rfe.fown	= (FownEntry *)&p->fown;
>  	rfe.name	= &link->name[1];
>  
> -	if (S_ISREG(p->stat.st_mode)) {
> +	/* Skip size if file has O_APPEND and O_WRONLY flags(i.e. log file). */
> +	if (S_ISREG(p->stat.st_mode) &&
> +	    !((rfe.flags & O_APPEND) && (rfe.flags & O_WRONLY))) {

It's not correct to check access mode like this. The proper way is
(flags & O_ACCMODE == O_WRONLY).

Can you also move this condition into a helper named like should_check_size()?
For better readability.

>  		rfe.has_size = true;
>  		rfe.size = p->stat.st_size;
>  	}
> 



More information about the CRIU mailing list