Message ID | 20240409152438.77960-2-axboe@kernel.dk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Convert fs drivers to ->read_iter() | expand |
On Tue, Apr 09, 2024 at 09:22:15AM -0600, Jens Axboe wrote: > Add variant of copy_to_iter() that either copies the full amount asked > for and return success, or ensures that the iov_iter is back to where > it started on failure and returns false. FWIW, see git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.iov_iter There was an open-coded instance (skb_copy_linear()) that I'd converted to that helper in the same commit; I can split it, of course, but I don't see much point in that.
On 4/9/24 11:06 AM, Al Viro wrote: > On Tue, Apr 09, 2024 at 09:22:15AM -0600, Jens Axboe wrote: >> Add variant of copy_to_iter() that either copies the full amount asked >> for and return success, or ensures that the iov_iter is back to where >> it started on failure and returns false. > > FWIW, see git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.iov_iter > > There was an open-coded instance (skb_copy_linear()) that I'd converted to > that helper in the same commit; I can split it, of course, but I don't > see much point in that. No reason to split it, I'll have a dependency regardless. I'll just pull your branch in, so ignore patch 1 here, 2-4 will remain the same.
diff --git a/include/linux/uio.h b/include/linux/uio.h index 00cebe2b70de..9e9510672b28 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -197,6 +197,16 @@ size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) return 0; } +static __always_inline __must_check +bool copy_to_iter_full(const void *addr, size_t bytes, struct iov_iter *i) +{ + size_t copied = copy_to_iter(addr, bytes, i); + if (likely(copied == bytes)) + return true; + iov_iter_revert(i, copied); + return false; +} + static __always_inline __must_check size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) {
Add variant of copy_to_iter() that either copies the full amount asked for and return success, or ensures that the iov_iter is back to where it started on failure and returns false. Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Jens Axboe <axboe@kernel.dk> --- include/linux/uio.h | 10 ++++++++++ 1 file changed, 10 insertions(+)