mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 07:01:23 +00:00
[iov_iter] new primitives - copy_from_iter_full() and friends
copy_from_iter_full(), copy_from_iter_full_nocache() and csum_and_copy_from_iter_full() - counterparts of copy_from_iter() et.al., advancing iterator only in case of successful full copy and returning whether it had been successful or not. Convert some obvious users. *NOTE* - do not blindly assume that something is a good candidate for those unless you are sure that not advancing iov_iter in failure case is the right thing in this case. Anything that does short read/short write kind of stuff (or is in a loop, etc.) is unlikely to be a good one. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
e5517c2a5a
commit
cbbd26b8b1
17 changed files with 121 additions and 39 deletions
|
@ -568,6 +568,31 @@ size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)
|
|||
}
|
||||
EXPORT_SYMBOL(copy_from_iter);
|
||||
|
||||
bool copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i)
|
||||
{
|
||||
char *to = addr;
|
||||
if (unlikely(i->type & ITER_PIPE)) {
|
||||
WARN_ON(1);
|
||||
return false;
|
||||
}
|
||||
if (unlikely(i->count < bytes)) \
|
||||
return false;
|
||||
|
||||
iterate_all_kinds(i, bytes, v, ({
|
||||
if (__copy_from_user((to += v.iov_len) - v.iov_len,
|
||||
v.iov_base, v.iov_len))
|
||||
return false;
|
||||
0;}),
|
||||
memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page,
|
||||
v.bv_offset, v.bv_len),
|
||||
memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len)
|
||||
)
|
||||
|
||||
iov_iter_advance(i, bytes);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(copy_from_iter_full);
|
||||
|
||||
size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i)
|
||||
{
|
||||
char *to = addr;
|
||||
|
@ -587,6 +612,30 @@ size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i)
|
|||
}
|
||||
EXPORT_SYMBOL(copy_from_iter_nocache);
|
||||
|
||||
bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i)
|
||||
{
|
||||
char *to = addr;
|
||||
if (unlikely(i->type & ITER_PIPE)) {
|
||||
WARN_ON(1);
|
||||
return false;
|
||||
}
|
||||
if (unlikely(i->count < bytes)) \
|
||||
return false;
|
||||
iterate_all_kinds(i, bytes, v, ({
|
||||
if (__copy_from_user_nocache((to += v.iov_len) - v.iov_len,
|
||||
v.iov_base, v.iov_len))
|
||||
return false;
|
||||
0;}),
|
||||
memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page,
|
||||
v.bv_offset, v.bv_len),
|
||||
memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len)
|
||||
)
|
||||
|
||||
iov_iter_advance(i, bytes);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(copy_from_iter_full_nocache);
|
||||
|
||||
size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes,
|
||||
struct iov_iter *i)
|
||||
{
|
||||
|
@ -1008,7 +1057,7 @@ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum,
|
|||
}
|
||||
iterate_and_advance(i, bytes, v, ({
|
||||
int err = 0;
|
||||
next = csum_and_copy_from_user(v.iov_base,
|
||||
next = csum_and_copy_from_user(v.iov_base,
|
||||
(to += v.iov_len) - v.iov_len,
|
||||
v.iov_len, 0, &err);
|
||||
if (!err) {
|
||||
|
@ -1037,6 +1086,51 @@ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum,
|
|||
}
|
||||
EXPORT_SYMBOL(csum_and_copy_from_iter);
|
||||
|
||||
bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum,
|
||||
struct iov_iter *i)
|
||||
{
|
||||
char *to = addr;
|
||||
__wsum sum, next;
|
||||
size_t off = 0;
|
||||
sum = *csum;
|
||||
if (unlikely(i->type & ITER_PIPE)) {
|
||||
WARN_ON(1);
|
||||
return false;
|
||||
}
|
||||
if (unlikely(i->count < bytes))
|
||||
return false;
|
||||
iterate_all_kinds(i, bytes, v, ({
|
||||
int err = 0;
|
||||
next = csum_and_copy_from_user(v.iov_base,
|
||||
(to += v.iov_len) - v.iov_len,
|
||||
v.iov_len, 0, &err);
|
||||
if (err)
|
||||
return false;
|
||||
sum = csum_block_add(sum, next, off);
|
||||
off += v.iov_len;
|
||||
0;
|
||||
}), ({
|
||||
char *p = kmap_atomic(v.bv_page);
|
||||
next = csum_partial_copy_nocheck(p + v.bv_offset,
|
||||
(to += v.bv_len) - v.bv_len,
|
||||
v.bv_len, 0);
|
||||
kunmap_atomic(p);
|
||||
sum = csum_block_add(sum, next, off);
|
||||
off += v.bv_len;
|
||||
}),({
|
||||
next = csum_partial_copy_nocheck(v.iov_base,
|
||||
(to += v.iov_len) - v.iov_len,
|
||||
v.iov_len, 0);
|
||||
sum = csum_block_add(sum, next, off);
|
||||
off += v.iov_len;
|
||||
})
|
||||
)
|
||||
*csum = sum;
|
||||
iov_iter_advance(i, bytes);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(csum_and_copy_from_iter_full);
|
||||
|
||||
size_t csum_and_copy_to_iter(const void *addr, size_t bytes, __wsum *csum,
|
||||
struct iov_iter *i)
|
||||
{
|
||||
|
@ -1051,7 +1145,7 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, __wsum *csum,
|
|||
iterate_and_advance(i, bytes, v, ({
|
||||
int err = 0;
|
||||
next = csum_and_copy_to_user((from += v.iov_len) - v.iov_len,
|
||||
v.iov_base,
|
||||
v.iov_base,
|
||||
v.iov_len, 0, &err);
|
||||
if (!err) {
|
||||
sum = csum_block_add(sum, next, off);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue