Commit 2112ff5c authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Al Viro
Browse files

iov_iter: track truncated size



Remember how many bytes were truncated and reverted back. Because
not reexpanded iterators don't always work well with reverting, we may
need to know that to reexpand ourselves when needed.

Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent e73f0f0e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct iov_iter {
		};
		loff_t xarray_start;
	};
	size_t truncated;
};

static inline enum iter_type iov_iter_type(const struct iov_iter *i)
@@ -254,9 +255,11 @@ static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
	 * conversion in assignement is by definition greater than all
	 * values of size_t, including old i->count.
	 */
	if (i->count > count)
	if (i->count > count) {
		i->truncated += i->count - count;
		i->count = count;
	}
}

/*
 * reexpand a previously truncated iterator; count must be no more than how much
@@ -264,6 +267,7 @@ static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
 */
static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
{
	i->truncated -= count - i->count;
	i->count = count;
}