install: Don't skip syncing in the common case.

In `copy()`, if no digest was requested (which is the common case), we
use `copy_file_range()` to avoid needlessly copying the contents of the
file into user space and back.  When `copy_file_range()` returns
successfully (which, again, is the common case), we simply return, and
therefore never get to the point where we call `fsync()` if the `-S`
option was specified.  Fix this.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D44756
This commit is contained in:
Dag-Erling Smørgrav 2024-04-12 19:30:55 +02:00
parent 17dc7017d7
commit 4336161cc9

View file

@ -1232,15 +1232,12 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name,
#ifndef BOOTSTRAP_XINSTALL
/* Try copy_file_range() if no digest is requested */
if (digesttype == DIGEST_NONE) {
ret = 1;
while (ret > 0) {
do {
ret = copy_file_range(from_fd, NULL, to_fd, NULL,
SSIZE_MAX, 0);
}
if (ret == 0) {
/* DIGEST_NONE always returns NULL */
return (NULL);
}
} while (ret > 0);
if (ret == 0)
goto done;
if (errno != EINVAL) {
serrno = errno;
(void)unlink(to_name);
@ -1313,6 +1310,7 @@ copy(int from_fd, const char *from_name, int to_fd, const char *to_name,
err(EX_OSERR, "%s", from_name);
}
}
done:
if (safecopy && fsync(to_fd) == -1) {
serrno = errno;
(void)unlink(to_name);