From patchwork Mon Apr 18 13:02:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 715061 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3ID38Z8016421 for ; Mon, 18 Apr 2011 13:03:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804Ab1DRNDF (ORCPT ); Mon, 18 Apr 2011 09:03:05 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:49382 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751356Ab1DRNDC (ORCPT ); Mon, 18 Apr 2011 09:03:02 -0400 Received: by mail-wy0-f174.google.com with SMTP id 21so3882683wya.19 for ; Mon, 18 Apr 2011 06:03:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=wvgPIt5EdAPXMyeaT/SCokQF1N0Q9omyxqPTlvdwWVE=; b=TIlS3sedgchO/a3xt63Yr9g4Etsz5m5tioqmg/VmXW/JqPjX8+Ft973Sa+AMKCGpJK ylxsXwgfTlieSeeRZYHzAn1ZG0HfR8RALfkvogDt5z6bQ8AVHcVXlPp0uVxDWegrzDT+ s+H5O1dxtVsH1+Lahq2H5K7NmKd0UMCo+hQIo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=NUOn4vRxxnhX0tcqUqUDPKZOFlegpARYEvo7VDNFDwywcrp3OjXLWTUFTv8xkQmqJE t2eRva/wK6GKW8bYnp4D5xkysp0l/MWZJC6wqFM27LSO9E6NAywx67VuFTNfipEMS493 PsxwDf8Hg1DejIWxcirgbJNxVWFvpFzk0mrLw= Received: by 10.216.64.139 with SMTP id c11mr10698161wed.46.1303131781592; Mon, 18 Apr 2011 06:03:01 -0700 (PDT) Received: from localhost.localdomain (bzq-79-181-210-229.red.bezeqint.net [79.181.210.229]) by mx.google.com with ESMTPS id f30sm2576031wef.31.2011.04.18.06.02.59 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Apr 2011 06:03:01 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 4/4] kvm tools: Complete missing segments in a iov op using regular op Date: Mon, 18 Apr 2011 16:02:34 +0300 Message-Id: <1303131754-25072-4-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc1 In-Reply-To: <1303131754-25072-1-git-send-email-levinsasha928@gmail.com> References: <1303131754-25072-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 18 Apr 2011 13:03:09 +0000 (UTC) If any of the iov operations return mid-block, use regular ops to complete the current block and continue using iov ops. Signed-off-by: Sasha Levin --- tools/kvm/read-write.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 51 insertions(+), 7 deletions(-) diff --git a/tools/kvm/read-write.c b/tools/kvm/read-write.c index 0c995c8..bf2e4a0 100644 --- a/tools/kvm/read-write.c +++ b/tools/kvm/read-write.c @@ -189,10 +189,10 @@ static inline ssize_t get_iov_size(const struct iovec *iov, int iovcnt) } static inline void shift_iovec(const struct iovec **iov, int *iovcnt, - size_t nr, ssize_t *total, size_t *count, off_t *offset) + ssize_t *nr, ssize_t *total, size_t *count, off_t *offset) { - while (nr >= (*iov)->iov_len) { - nr -= (*iov)->iov_len; + while ((size_t)*nr >= (*iov)->iov_len) { + *nr -= (*iov)->iov_len; *total += (*iov)->iov_len; *count -= (*iov)->iov_len; if (offset) @@ -218,7 +218,18 @@ ssize_t readv_in_full(int fd, const struct iovec *iov, int iovcnt) return -1; } - shift_iovec(&iov, &iovcnt, nr, &total, &count, NULL); + shift_iovec(&iov, &iovcnt, &nr, &total, &count, NULL); + + while (nr > 0) { + ssize_t nr_readagain; + nr_readagain = xread(fd, iov->iov_base + nr, + iov->iov_len - nr); + if (nr_readagain <= 0) + return total; + + nr += nr_readagain; + shift_iovec(&iov, &iovcnt, &nr, &total, &count, NULL); + } } return total; @@ -240,7 +251,18 @@ ssize_t writev_in_full(int fd, const struct iovec *iov, int iovcnt) return -1; } - shift_iovec(&iov, &iovcnt, nr, &total, &count, NULL); + shift_iovec(&iov, &iovcnt, &nr, &total, &count, NULL); + + while (nr > 0) { + ssize_t nr_writeagain; + nr_writeagain = xwrite(fd, iov->iov_base + nr, + iov->iov_len - nr); + if (nr_writeagain <= 0) + return total; + + nr += nr_writeagain; + shift_iovec(&iov, &iovcnt, &nr, &total, &count, NULL); + } } return total; @@ -288,7 +310,18 @@ ssize_t preadv_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offset return -1; } - shift_iovec(&iov, &iovcnt, nr, &total, &count, &offset); + shift_iovec(&iov, &iovcnt, &nr, &total, &count, &offset); + + while (nr > 0) { + ssize_t nr_readagain; + nr_readagain = xpread(fd, iov->iov_base + nr, + iov->iov_len - nr, offset + nr); + if (nr_readagain <= 0) + return total; + + nr += nr_readagain; + shift_iovec(&iov, &iovcnt, &nr, &total, &count, &offset); + } } return total; @@ -310,7 +343,18 @@ ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt, off_t offse return -1; } - shift_iovec(&iov, &iovcnt, nr, &total, &count, &offset); + shift_iovec(&iov, &iovcnt, &nr, &total, &count, &offset); + + while (nr > 0) { + ssize_t nr_writeagain; + nr_writeagain = xpread(fd, iov->iov_base + nr, + iov->iov_len - nr, offset + nr); + if (nr_writeagain <= 0) + return total; + + nr += nr_writeagain; + shift_iovec(&iov, &iovcnt, &nr, &total, &count, &offset); + } } return total;