[PATCH V2] kvm tools: Return correct values from disk IOV functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <levinsasha928@xxxxxxxxx>
---
 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 */
-- 
1.7.5.rc3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux