From patchwork Sun May 15 10:22:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 785682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4FAN4Qd003815 for ; Sun, 15 May 2011 10:23:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755136Ab1EOKXB (ORCPT ); Sun, 15 May 2011 06:23:01 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:60598 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754491Ab1EOKXA (ORCPT ); Sun, 15 May 2011 06:23:00 -0400 Received: by fxm17 with SMTP id 17so2510896fxm.19 for ; Sun, 15 May 2011 03:22:59 -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; bh=08CSWHFtu1DdIdpsfaBxLujbH+W22bLSPcMAFFlEEIs=; b=SVB6LhobRQKoo/Q0c1Mz9sHhKgAXnbhR5vc7LAOVxXI7U9ZRL4GvFEJnRgxpEQtUGz oe0KGwef4eFvSLPdqRfvba2H8GFqzku6vjH+4DpXEbHtsPHTnP9cuKmLFjRM/DSXEbOo VsxIZg5Jq4NMEpelBgDOV/vxZek3A84+bwjzM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=c0E+qXxTdHE0fAYWXiSZBFfthYnJlblTw5hgHrD4cgqGqfKykRVHLL1pZ27a6q0LJI WdLxRxZuyZfvHaIH+Tn85HF9coD64ow3iRE80I2xrssgZBbnmDlhlVkO9WtxZxogOx2/ rWONdZicFFRNKxmsBoYeVsMCPkMnkSWctm0OI= Received: by 10.223.3.132 with SMTP id 4mr2687850fan.132.1305454979157; Sun, 15 May 2011 03:22:59 -0700 (PDT) Received: from localhost.localdomain ([188.120.132.169]) by mx.google.com with ESMTPS id j12sm1429253fax.9.2011.05.15.03.22.57 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 15 May 2011 03:22:58 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH V2] kvm tools: Return correct values from disk IOV functions Date: Sun, 15 May 2011 13:22:39 +0300 Message-Id: <1305454959-22091-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc3 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 (demeter2.kernel.org [140.211.167.43]); Sun, 15 May 2011 10:23:05 +0000 (UTC) Currently read/write IOV functions return an incorrect value instead of the amount of bytes read/written. This incorrect value may cause errors within the virtio layer. Return correct amount of bytes read/written from _iov functions. Changes in V2: - Un-inline the functions. - Add some comments regarding the expected return value. Signed-off-by: Sasha Levin --- tools/kvm/disk-image.c | 38 ++++++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/disk-image.h | 33 +----------------------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 1a704b3..9a7a914 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -172,3 +172,41 @@ void disk_image__close(struct disk_image *disk) free(disk); } + +/* Fill iov with disk data, starting from sector 'sector'. Return amount of bytes read. */ +inline ssize_t disk_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount) +{ + u64 first_sector = sector; + + if (disk->ops->read_sector_iov) + return disk->ops->read_sector_iov(disk, sector, iov, iovcount); + + while (iovcount--) { + if (disk->ops->read_sector(disk, sector, iov->iov_base, iov->iov_len) < 0) + return -1; + + sector += iov->iov_len >> SECTOR_SHIFT; + iov++; + } + + return (sector - first_sector) << SECTOR_SHIFT; +} + +/* Write iov to disk, starting from sector 'sector'. Return amount of bytes written. */ +inline ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount) +{ + u64 first_sector = sector; + + if (disk->ops->write_sector_iov) + return disk->ops->write_sector_iov(disk, sector, iov, iovcount); + + while (iovcount--) { + if (disk->ops->write_sector(disk, sector, iov->iov_base, iov->iov_len) < 0) + return -1; + + sector += iov->iov_len >> SECTOR_SHIFT; + iov++; + } + + return (sector - first_sector) << SECTOR_SHIFT; +} \ No newline at end of file diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h index 9d7b572..aa5b12b 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -40,36 +40,7 @@ static inline int disk_image__write_sector(struct disk_image *disk, u64 sector, return disk->ops->write_sector(disk, sector, src, src_len); } -static inline ssize_t disk_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount) -{ - if (disk->ops->read_sector_iov) - return disk->ops->read_sector_iov(disk, sector, iov, iovcount); - - while (iovcount--) { - if (disk->ops->read_sector(disk, sector, iov->iov_base, iov->iov_len) < 0) - return -1; - - sector += iov->iov_len >> SECTOR_SHIFT; - iov++; - } - - return sector << SECTOR_SHIFT; -} - -static inline ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount) -{ - if (disk->ops->write_sector_iov) - return disk->ops->write_sector_iov(disk, sector, iov, iovcount); - - while (iovcount--) { - if (disk->ops->write_sector(disk, sector, iov->iov_base, iov->iov_len) < 0) - return -1; - - sector += iov->iov_len >> SECTOR_SHIFT; - iov++; - } - - return sector << SECTOR_SHIFT; -} +inline ssize_t disk_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); +inline ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); #endif /* KVM__DISK_IMAGE_H */