lkml.org 
[lkml]   [2020]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH RFC 11/12] vringh: allow vringh_iov_xfer() to skip bytes when ptr is NULL
From
Date

On 2020/11/13 下午9:47, Stefano Garzarella wrote:
> In some cases, it may be useful to provide a way to skip a number
> of bytes in a vringh_iov.
>
> In order to keep vringh_iov consistent, let's reuse vringh_iov_xfer()
> logic and skip bytes when the ptr is NULL.
>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> ---
>
> I'm not sure if this is the best option, maybe we can add a new
> function vringh_iov_skip().
>
> Suggestions?


I might be worth to check whether we can convert vringh_iov to use iov
iterator then we can use iov_iterator_advance() here.

Thanks


> ---
> drivers/vhost/vringh.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 8bd8b403f087..ed3290946ad7 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -75,7 +75,9 @@ static inline int __vringh_get_head(const struct vringh *vrh,
> return head;
> }
>
> -/* Copy some bytes to/from the iovec. Returns num copied. */
> +/* Copy some bytes to/from the iovec. Returns num copied.
> + * If ptr is NULL, skips at most len bytes.
> + */
> static inline ssize_t vringh_iov_xfer(struct vringh *vrh,
> struct vringh_kiov *iov,
> void *ptr, size_t len,
> @@ -89,12 +91,16 @@ static inline ssize_t vringh_iov_xfer(struct vringh *vrh,
> size_t partlen;
>
> partlen = min(iov->iov[iov->i].iov_len, len);
> - err = xfer(vrh, iov->iov[iov->i].iov_base, ptr, partlen);
> - if (err)
> - return err;
> +
> + if (ptr) {
> + err = xfer(vrh, iov->iov[iov->i].iov_base, ptr, partlen);
> + if (err)
> + return err;
> + ptr += partlen;
> + }
> +
> done += partlen;
> len -= partlen;
> - ptr += partlen;
> iov->consumed += partlen;
> iov->iov[iov->i].iov_len -= partlen;
> iov->iov[iov->i].iov_base += partlen;

\
 
 \ /
  Last update: 2020-11-16 05:34    [W:0.451 / U:2.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site