From: Ian Jackson Subject: Re: [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact() Date: Tue, 8 Jul 2014 17:58:36 +0100 Message-ID: <21436.9020.757598.972931@mariner.uk.xensource.com> References: <1404728318-13474-1-git-send-email-andrew.cooper3@citrix.com> <53BBB966.4020609@citrix.com> <53BBBA9C.1030005@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <53BBBA9C.1030005@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 Cc: Ian Campbell , David Vrabel , Xen-devel List-Id: xen-devel@lists.xenproject.org Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2] tools/libxc: Implement writev_exact() in the same style as write_exact()"): > 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. Firstly, we should be using the spec, not manpages: http://pubs.opengroup.org/onlinepubs/9699919799/functions/writev.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html etc. There are various guarantees that write and writev provide, including the special rule for pipes (from write.html): Write requests to a pipe or FIFO shall be handled in the same way as a regular file with the following exceptions: [ complicated rules involving PIPE_BUF ] and the general rule about system call atomicity: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_07 All of the following functions shall be atomic with respect to each other in the effects specified in POSIX.1-2008 when they operate on regular files or symbolic links: [...] write() writev() [...] However neither of these are the guarantee that you are assuming. In particular, there is nothing saying that _if_ writev performs a partial write, it won't stop inside an iov. Ian.