From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Vrabel Subject: Re: [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact() Date: Tue, 8 Jul 2014 10:27:02 +0100 Message-ID: <53BBB966.4020609@citrix.com> References: <1404728318-13474-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1404728318-13474-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper , Xen-devel Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org On 07/07/14 11:18, 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 [...] > --- 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) > +{ [...] > + /* writev() guarentees atomicity of individual iov[] elements. Sanity > + * check that the returned len did lie on an iov[] element boundary. */ > + assert(len == 0); There's nothing in the writev(2) man page that says this. I think you need to handle partial writes of an entry. > --- a/tools/libxc/xc_private.h > +++ b/tools/libxc/xc_private.h [...] > +#ifndef MAX > +#define MAX(_a, _b) ((_a) >= (_b) ? (_a) : (_b)) > +#endif > +#ifndef MIN > +#define MIN(_a, _b) ((_a) <= (_b) ? (_a) : (_b)) > +#endif Do we really want to use these unsafe macros in more places? David