[PATCH 3/3] xfs_fsr: test for more potential failures in packfile()

Brian Foster bfoster at redhat.com
Mon Jun 9 08:02:49 CDT 2014


On Fri, Jun 06, 2014 at 04:06:47PM -0500, Eric Sandeen wrote:
> Test for lseek, ftruncate, and fsync failures in packfile()
> 
> Signed-off-by: Eric Sandeen <sandeen at redhat.com>
> ---

Reviewed-by: Brian Foster <bfoster at redhat.com>

> 
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index 8b191e6..48629fd 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -1325,7 +1325,11 @@ packfile(char *fname, char *tname, int fd,
>  				fsrprintf(_("could not trunc tmp %s\n"),
>  					   tname);
>  			}
> -			lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
> +			if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
> +				fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
> +				   tname, strerror(errno));
> +				goto out;
> +			}
>  			continue;
>  		} else if (outmap[extent].bmv_length == 0) {
>  			/* to catch holes at the beginning of the file */
> @@ -1341,7 +1345,11 @@ packfile(char *fname, char *tname, int fd,
>  					" %s\n"), tname);
>  				goto out;
>  			}
> -			lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
> +			if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
> +				fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
> +				   tname, strerror(errno));
> +				goto out;
> +			}
>  		}
>  	} /* end of space allocation loop */
>  
> @@ -1365,8 +1373,16 @@ packfile(char *fname, char *tname, int fd,
>  	for (extent = 0; extent < nextents; extent++) {
>  		pos = outmap[extent].bmv_offset;
>  		if (outmap[extent].bmv_block == -1) {
> -			lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR);
> -			lseek64(fd, outmap[extent].bmv_length, SEEK_CUR);
> +			if (lseek64(tfd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
> +				fsrprintf(_("could not lseek in tmpfile: %s : %s\n"),
> +				   tname, strerror(errno));
> +				goto out;
> +			}
> +			if (lseek64(fd, outmap[extent].bmv_length, SEEK_CUR) < 0) {
> +				fsrprintf(_("could not lseek in file: %s : %s\n"),
> +				   fname, strerror(errno));
> +				goto out;
> +			}
>  			continue;
>  		} else if (outmap[extent].bmv_length == 0) {
>  			/* to catch holes at the beginning of the file */
> @@ -1442,8 +1458,16 @@ packfile(char *fname, char *tname, int fd,
>  			}
>  		}
>  	}
> -	ftruncate64(tfd, statp->bs_size);
> -	fsync(tfd);
> +	if (ftruncate64(tfd, statp->bs_size) < 0) {
> +		fsrprintf(_("could not truncate tmpfile: %s : %s\n"),
> +				fname, strerror(errno));
> +		goto out;
> +	}
> +	if (fsync(tfd) < 0) {
> +		fsrprintf(_("could not fsync tmpfile: %s : %s\n"),
> +				fname, strerror(errno));
> +		goto out;
> +	}
>  
>  	sx.sx_stat     = *statp; /* struct copy */
>  	sx.sx_version  = XFS_SX_VERSION;
> 
> _______________________________________________
> xfs mailing list
> xfs at oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs



More information about the xfs mailing list