Commit-ID: f072ebe8c41555d76a25bbe56a0541623222355f Gitweb: http://git.kernel.org/tip/f072ebe8c41555d76a25bbe56a0541623222355f Author: Sasha Levin <levinsasha928@xxxxxxxxx> AuthorDate: Sun, 15 May 2011 13:22:39 +0300 Committer: Pekka Enberg <penberg@xxxxxxxxxx> CommitDate: Sun, 15 May 2011 13:52:18 +0300 kvm tools: Return correct values from disk IOV functions 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. [ penberg@xxxxxxxxxx: don't use 'inline' for out-of-line functions ] Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx> --- 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..4172b05 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. */ +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. */ +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 6cc9441..cc83f38 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -42,37 +42,8 @@ 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; -} +ssize_t disk_image__read_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); +ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount); static inline int disk_image__flush(struct disk_image *disk) { -- To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html