@@ -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
@@ -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 */
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@gmail.com> --- tools/kvm/disk-image.c | 38 ++++++++++++++++++++++++++++++++++++ tools/kvm/include/kvm/disk-image.h | 33 +----------------------------- 2 files changed, 40 insertions(+), 31 deletions(-)