Re: git: 35b7759c05cb - main - cp: Fix build without VM_AND_BUFFER_CACHE_SYNCHRONIZED.

From: Mateusz Guzik <mjguzik_at_gmail.com>
Date: Tue, 30 Aug 2022 14:58:35 UTC
On 8/30/22, Alexander Motin <mav@freebsd.org> wrote:
> The branch main has been updated by mav:
>
> URL:
> https://cgit.FreeBSD.org/src/commit/?id=35b7759c05cbc65c06d87141da79f0f80af0f458
>
> commit 35b7759c05cbc65c06d87141da79f0f80af0f458
> Author:     Alexander Motin <mav@FreeBSD.org>
> AuthorDate: 2022-08-30 14:51:21 +0000
> Commit:     Alexander Motin <mav@FreeBSD.org>
> CommitDate: 2022-08-30 14:51:21 +0000
>
>     cp: Fix build without VM_AND_BUFFER_CACHE_SYNCHRONIZED.
>
>     It allows to not use mmap() for small files, which is not helpful
>     in case of ZFS.  Should be no functional change.
>

This should be of no use thanks to copy_file_range

>     MFC after:      1 week
> ---
>  bin/cp/utils.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/bin/cp/utils.c b/bin/cp/utils.c
> index e7ae0c9dd733..07de0495ba9e 100644
> --- a/bin/cp/utils.c
> +++ b/bin/cp/utils.c
> @@ -99,13 +99,12 @@ copy_file(const FTSENT *entp, int dne)
>  	static char *buf = NULL;
>  	static size_t bufsize;
>  	struct stat *fs;
> -	ssize_t rcount, wcount;
> -	size_t wresid;
> +	ssize_t wcount;
>  	off_t wtotal;
>  	int ch, checkch, from_fd, rval, to_fd;
> -	char *bufp;
>  #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
> -	char *p;
> +	size_t wresid;
> +	char *bufp, *p;
>  #endif
>  	int use_copy_file_range = 1;
>
> @@ -234,18 +233,18 @@ copy_file(const FTSENT *entp, int dne)
>  			wtotal = 0;
>  			do {
>  				if (use_copy_file_range) {
> -					rcount = copy_file_range(from_fd, NULL,
> +					wcount = copy_file_range(from_fd, NULL,
>  					    to_fd, NULL, SSIZE_MAX, 0);
> -					if (rcount < 0 && errno == EINVAL) {
> +					if (wcount < 0 && errno == EINVAL) {
>  						/* Prob a non-seekable FD */
>  						use_copy_file_range = 0;
>  					}
>  				}
>  				if (!use_copy_file_range) {
> -					rcount = copy_fallback(from_fd, to_fd,
> +					wcount = copy_fallback(from_fd, to_fd,
>  					    buf, bufsize);
>  				}
> -				wtotal += rcount;
> +				wtotal += wcount;
>  				if (info) {
>  					info = 0;
>  					(void)fprintf(stderr,
> @@ -253,8 +252,8 @@ copy_file(const FTSENT *entp, int dne)
>  					    entp->fts_path, to.p_path,
>  					    cp_pct(wtotal, fs->st_size));
>  				}
> -			} while (rcount > 0);
> -			if (rcount < 0) {
> +			} while (wcount > 0);
> +			if (wcount < 0) {
>  				warn("%s", entp->fts_path);
>  				rval = 1;
>  			}
>
>


-- 
Mateusz Guzik <mjguzik gmail.com>