From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH 1/2 V2] kvm tools: Add scatter-gather variants of IO functions Date: Sat, 16 Apr 2011 23:33:27 +0300 Message-ID: <1302986007.4090.0.camel@stimpy> References: <1302966356-13145-1-git-send-email-levinsasha928@gmail.com> <4DA9E285.5040308@openvz.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: "penberg@kernel.org" , "mingo@elte.hu" , "asias.hejun@gmail.com" , "gorcunov@gmail.com" , "kvm@vger.kernel.org" To: Konstantin Khlebnikov Return-path: Received: from mail-wy0-f174.google.com ([74.125.82.174]:60908 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706Ab1DPUdl (ORCPT ); Sat, 16 Apr 2011 16:33:41 -0400 Received: by wya21 with SMTP id 21so3028279wya.19 for ; Sat, 16 Apr 2011 13:33:39 -0700 (PDT) In-Reply-To: <4DA9E285.5040308@openvz.org> Sender: kvm-owner@vger.kernel.org List-ID: On Sat, 2011-04-16 at 22:40 +0400, Konstantin Khlebnikov wrote: > It might be better to add an helper function, something like this: > > static inline void shift_iovec(const struct iovec **iov, int *iovcnt, > size_t nr, ssize_t *total, off_t *offset) > { > while (nr >= (*iov)->iov_len) { > nr -= (*iov)->iov_len; > *total += (*iov)->iov_len; > *offset += (*iov)->iov_len; > *iovcnt--; > *iov++; > } > } > > ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offset) > { > ssize_t nr, total = 0; > > while (iovcnt) { > nr = xpwritev(fd, iov, iovcnt, offset); > if (nr < 0) > return -1; > if (nr == 0) { > errno = ENOSPC; > return -1; > } > shift_iovec(&iov, &iovcnt, nr, &total, &offset); > } > > return total; > } Yup, Good idea - Let's do that. Thanks! -- Sasha.