linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: linux-fsdevel@vger.kernel.org
Cc: brauner@kernel.org, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 1/4] iov_iter: add copy_to_iter_full()
Date: Tue,  9 Apr 2024 09:22:15 -0600	[thread overview]
Message-ID: <20240409152438.77960-2-axboe@kernel.dk> (raw)
In-Reply-To: <20240409152438.77960-1-axboe@kernel.dk>

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(+)

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)
 {
-- 
2.43.0


  reply	other threads:[~2024-04-09 15:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 15:22 [PATCHSET v3 0/3] Convert fs drivers to ->read_iter() Jens Axboe
2024-04-09 15:22 ` Jens Axboe [this message]
2024-04-09 17:06   ` [PATCH 1/4] iov_iter: add copy_to_iter_full() Al Viro
2024-04-09 17:10     ` Jens Axboe
2024-04-09 15:22 ` [PATCH 2/4] timerfd: convert to ->read_iter() Jens Axboe
2024-04-10 22:27   ` Jens Axboe
     [not found]     ` <CGME20240411114048eucas1p21707a2d0bfb9c5a21f3e8aa76c0d82c1@eucas1p2.samsung.com>
2024-04-11 11:40       ` Marek Szyprowski
2024-04-11 16:32         ` Jens Axboe
2024-04-09 15:22 ` [PATCH 3/4] userfaultfd: " Jens Axboe
2024-04-09 15:22 ` [PATCH 4/4] signalfd: " Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240409152438.77960-2-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).