From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konstantin Khlebnikov Subject: Re: [PATCH 1/2 V2] kvm tools: Add scatter-gather variants of IO functions Date: Sun, 17 Apr 2011 14:03:30 +0400 Message-ID: <4DAABAF2.1020700@parallels.com> References: <1302966356-13145-1-git-send-email-levinsasha928@gmail.com> <4DA9E285.5040308@openvz.org> <4DAAB0A3.3020206@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Cc: Sasha Levin , "penberg@kernel.org" , "mingo@elte.hu" , "asias.hejun@gmail.com" , "gorcunov@gmail.com" , "kvm@vger.kernel.org" To: Avi Kivity Return-path: Received: from relay.parallels.com ([195.214.232.42]:39777 "EHLO relay.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268Ab1DQKDd (ORCPT ); Sun, 17 Apr 2011 06:03:33 -0400 In-Reply-To: <4DAAB0A3.3020206@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Avi Kivity wrote: > On 04/16/2011 09:40 PM, 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++; >> } if (nr) { (*iov)->iov_base += nr; (*iov)->iov_len -= nr; } >> } >> > > What if nr is nonzero when the loop terminates? You need to update the > first iovec entry so you don't redo that segment. Oh yes, it is simple (hunk above), so "const" from prototype must be removed, while original syscalls declare iov argument as const. > >> 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; >> } >> -- >> To unsubscribe from this list: send the line "unsubscribe kvm" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html > >