From patchwork Wed Mar 27 16:36:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 231749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D46C02C007E for ; Thu, 28 Mar 2013 03:39:12 +1100 (EST) Received: from localhost ([::1]:55118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKtNU-0001HE-Et for incoming@patchwork.ozlabs.org; Wed, 27 Mar 2013 12:39:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKtLD-0006Io-81 for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKtL8-0002qg-AL for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:47 -0400 Received: from mail-ee0-f43.google.com ([74.125.83.43]:57926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKtL8-0002qK-4O for qemu-devel@nongnu.org; Wed, 27 Mar 2013 12:36:42 -0400 Received: by mail-ee0-f43.google.com with SMTP id e50so474466eek.30 for ; Wed, 27 Mar 2013 09:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=O5yiSbLq2tA/HR7acdU6W1iOhU3zGiNaCuq5o5I/Zns=; b=GzGx1IYgz/0BMs/WoqvBwr1t1BheG/a1IS5rHeKjaLMKCr3SahI3wkE4V+ubNHjmft zinlDWdzgZkR3wdi2KByqsHEDdfJQ97O9UOo+Ka5NWxHg8ZTbYe7afBUGUR1ohmPbxGQ Z9EgGNU+4JlZSQxm8gfHHrn4XWY19L8s46Rp//aITs/LXuGeuEisXsrs1H65h/U1DWqR dHT0JdMDH5nVzjLF2tDyxAVfunV66wIuoHiEs1y8ToDCK09vnDeS2glHLGwo3ltv17Af vPf8Hfw0TG2eEcvT9HZyCbhrPsQD3bhufN9ytwQjr5Q+JeGSSdbdkYFQgs9MRk9EBlbA xaJA== X-Received: by 10.14.207.200 with SMTP id n48mr29537764eeo.4.1364402201415; Wed, 27 Mar 2013 09:36:41 -0700 (PDT) Received: from playground.lan (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPS id d47sm32366397eem.9.2013.03.27.09.36.39 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 27 Mar 2013 09:36:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 27 Mar 2013 17:36:28 +0100 Message-Id: <1364402192-18169-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> References: <1364402192-18169-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 74.125.83.43 Cc: owasserm@redhat.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 2/6] iov: reorganize iov_send_recv, part 1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Once the initial part of the iov is dropped, it is not used anymore. Modify iov/iovcnt directly instead of adjusting them with the "si" variable. Signed-off-by: Paolo Bonzini Reviewed-by: Juan Quintela --- util/iov.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/iov.c b/util/iov.c index 9dae318..adb9a70 100644 --- a/util/iov.c +++ b/util/iov.c @@ -159,16 +159,22 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, for (si = 0; si < iov_cnt && offset >= iov[si].iov_len; ++si) { offset -= iov[si].iov_len; } + + /* si == iov_cnt would only be valid if bytes == 0, which + * we already ruled out above. */ + assert(si < iov_cnt); + iov += si; + iov_cnt -= si; + if (offset) { - assert(si < iov_cnt); /* second, skip `offset' bytes from the (now) first element, * undo it on exit */ - iov[si].iov_base += offset; - iov[si].iov_len -= offset; + iov[0].iov_base += offset; + iov[0].iov_len -= offset; } /* Find the end position skipping `bytes' bytes: */ /* first, skip all full-sized elements */ - for (ei = si; ei < iov_cnt && iov[ei].iov_len <= bytes; ++ei) { + for (ei = 0; ei < iov_cnt && iov[ei].iov_len <= bytes; ++ei) { bytes -= iov[ei].iov_len; } if (bytes) { @@ -183,12 +189,12 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, ++ei; } - ret = do_send_recv(sockfd, iov + si, ei - si, do_send); + ret = do_send_recv(sockfd, iov, ei, do_send); /* Undo the changes above */ if (offset) { - iov[si].iov_base -= offset; - iov[si].iov_len += offset; + iov[0].iov_base -= offset; + iov[0].iov_len += offset; } if (bytes) { iov[ei-1].iov_len += bytes;