#include <linux/types.h>
#include <stdbool.h>
#include <sys/uio.h>
+#include <unistd.h>
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1UL << SECTOR_SHIFT)
int (*write_sector)(struct disk_image *disk, u64 sector, void *src, u32 src_len);
ssize_t (*read_sector_iov)(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
ssize_t (*write_sector_iov)(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
+ int (*flush)(struct disk_image *disk);
void (*close)(struct disk_image *disk);
};
return sector << SECTOR_SHIFT;
}
+static inline int disk_image__flush(struct disk_image *disk)
+{
+ if (disk->ops->flush)
+ return disk->ops->flush(disk);
+ return fsync(disk->fd);
+}
+
#endif /* KVM__DISK_IMAGE_H */
case VIRTIO_BLK_T_OUT:
block_cnt = disk_image__write_sector_iov(bdev->disk, req->sector, iov + 1, in + out - 2);
break;
+ case VIRTIO_BLK_T_FLUSH:
+ block_cnt = disk_image__flush(bdev->disk);
+ break;
default:
warning("request type %d", req->type);
block_cnt = -1;
* guest kernel will compute disk geometry by own, the
* same applies to VIRTIO_BLK_F_BLK_SIZE
*/
- .host_features = (1UL << VIRTIO_BLK_F_SEG_MAX),
+ .host_features = (1UL << VIRTIO_BLK_F_SEG_MAX | 1UL << VIRTIO_BLK_F_FLUSH),
};
if (irq__register_device(PCI_DEVICE_ID_VIRTIO_BLK, &dev, &pin, &line) < 0)