All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongyang Yang <yanghy@cn.fujitsu.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>
Subject: Re: [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact()
Date: Tue, 8 Jul 2014 11:30:49 +0800	[thread overview]
Message-ID: <53BB65E9.4010805@cn.fujitsu.com> (raw)
In-Reply-To: <1404728318-13474-1-git-send-email-andrew.cooper3@citrix.com>



On 07/07/2014 06:18 PM, Andrew Cooper wrote:
> This implementation of writev_exact() will cope with an iovcnt greater than
> IOV_MAX because glibc will actually let this work anyway, and it is very
> useful not to have to work about this in the caller of writev_exact().  The
> caller is still required to ensure that the sum of iov_len's doesn't overflow
> a ssize_t.
>
> Promote the MAX() and MIN() macro definitions from xg_save_restore.h to
> xc_private.h
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> CC: Ian Campbell <Ian.Campbell@citrix.com>
> CC: Ian Jackson <Ian.Jackson@eu.citrix.com>

Reviewed-by: Yang Hongyang <yanghy@cn.fujitsu.com>

>
> ---
>
> v2: Remove adjustment for partial writes of a specific iov[] entry.
> ---
>   tools/libxc/xc_private.c      |   31 +++++++++++++++++++++++++++++++
>   tools/libxc/xc_private.h      |    9 +++++++++
>   tools/libxc/xg_save_restore.h |    6 ------
>   3 files changed, 40 insertions(+), 6 deletions(-)
>
> diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
> index a3da614..d610984 100644
> --- a/tools/libxc/xc_private.c
> +++ b/tools/libxc/xc_private.c
> @@ -854,6 +854,37 @@ int write_exact(int fd, const void *data, size_t size)
>       return 0;
>   }
>
> +int writev_exact(int fd, const struct iovec *iov, int iovcnt)
> +{
> +    int iov_idx = 0;
> +    ssize_t len;
> +
> +    while ( iov_idx < iovcnt )
> +    {
> +        /* Skip over iov[] enties with 0 length. */
> +        while ( iov[iov_idx].iov_len == 0 )
> +            if ( ++iov_idx == iovcnt )
> +                return 0;
> +
> +        len = writev(fd, &iov[iov_idx], MIN(iovcnt - iov_idx, IOV_MAX));
> +
> +        if ( (len == -1) && (errno == EINTR) )
> +            continue;
> +        if ( len <= 0 )
> +            return -1;
> +
> +        /* Check iov[] to see whether we had a partial or complete write. */
> +        while ( len > 0 && (iov_idx < iovcnt) )
> +            len -= iov[iov_idx++].iov_len;
> +
> +        /* writev() guarentees atomicity of individual iov[] elements.  Sanity
> +         * check that the returned len did lie on an iov[] element boundary. */
> +        assert(len == 0);
> +    }
> +
> +    return 0;
> +}
> +
>   int xc_ffs8(uint8_t x)
>   {
>       int i;
> diff --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
> index 6cc0f2b..198b8a0 100644
> --- a/tools/libxc/xc_private.h
> +++ b/tools/libxc/xc_private.h
> @@ -28,6 +28,7 @@
>   #include <sys/stat.h>
>   #include <stdlib.h>
>   #include <sys/ioctl.h>
> +#include <sys/uio.h>
>
>   #include "xenctrl.h"
>   #include "xenctrlosdep.h"
> @@ -343,6 +344,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_mmu *mmu);
>   /* Return 0 on success; -1 on error setting errno. */
>   int read_exact(int fd, void *data, size_t size); /* EOF => -1, errno=0 */
>   int write_exact(int fd, const void *data, size_t size);
> +int writev_exact(int fd, const struct iovec *iov, int iovcnt);
>
>   int xc_ffs8(uint8_t x);
>   int xc_ffs16(uint16_t x);
> @@ -367,4 +369,11 @@ int xc_mem_event_memop(xc_interface *xch, domid_t domain_id,
>   void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
>                             uint32_t *port);
>
> +#ifndef MAX
> +#define MAX(_a, _b) ((_a) >= (_b) ? (_a) : (_b))
> +#endif
> +#ifndef MIN
> +#define MIN(_a, _b) ((_a) <= (_b) ? (_a) : (_b))
> +#endif
> +
>   #endif /* __XC_PRIVATE_H__ */
> diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h
> index aa93c13..34019fa 100644
> --- a/tools/libxc/xg_save_restore.h
> +++ b/tools/libxc/xg_save_restore.h
> @@ -393,9 +393,3 @@ static inline int get_platform_info(xc_interface *xch, uint32_t dom,
>           memset(&(_p)->x32._f[0], (_v), sizeof((_p)->x32._f));      \
>   } while (0)
>
> -#ifndef MAX
> -#define MAX(_a, _b) ((_a) >= (_b) ? (_a) : (_b))
> -#endif
> -#ifndef MIN
> -#define MIN(_a, _b) ((_a) <= (_b) ? (_a) : (_b))
> -#endif
>

-- 
Thanks,
Yang.

  reply	other threads:[~2014-07-08  3:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-07 10:18 [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact() Andrew Cooper
2014-07-08  3:30 ` Hongyang Yang [this message]
2014-07-08  9:27 ` David Vrabel
2014-07-08  9:32   ` Andrew Cooper
2014-07-08 16:58     ` Ian Jackson
2014-07-02 18:04       ` [PATCH] " Andrew Cooper
2014-07-03 17:15         ` Ian Jackson
2014-07-03 17:41           ` Andrew Cooper
2014-07-08 17:00       ` [PATCH v2] " Andrew Cooper
2014-07-08 17:10         ` [PATCH] tools/libxc: Implement writev_exact() in the same style as write_exact() [and 1 more messages] Ian Jackson
2014-07-08 16:53 ` [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact() Ian Jackson

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=53BB65E9.4010805@cn.fujitsu.com \
    --to=yanghy@cn.fujitsu.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.