diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2024-04-12 17:30:55 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2024-04-12 17:31:35 +0000 |
commit | 4336161cc9c631d40d00adee97dfc8161b6bec9f (patch) | |
tree | e0c5b098db1738c2401305459417aeb3a7279919 /usr.bin | |
parent | 17dc7017d7375b3463d65adffe1eb980b0f86795 (diff) | |
download | src-4336161cc9c631d40d00adee97dfc8161b6bec9f.tar.gz src-4336161cc9c631d40d00adee97dfc8161b6bec9f.zip |
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
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 6ab0a88d5cd7..d696a8429c88 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -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); |