mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-10-03 15:29:05 +00:00
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@kernel.org: don't use 'inline' for out-of-line functions ] Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user