[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact()
On 08/07/14 10:27, David Vrabel wrote: > 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. Final paragraph in the DESCRIPTION "The data transfers performed by readv() and writev() are atomic: the data written by writev() is written as a single block that is not intermingled with output from writes in other processes" By my reading, it cannot guarantee atomicity if it would split an iov[] element. > >> --- 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 Perhaphs, perhaps not, but there are no typesafe ones to hand. ~Andrew _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |