[tip:tools/kvm] kvm tools: Add VIRTIO_BLK_T_FLUSH feature to handle flush operation from VM

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

 



Commit-ID:  f6ab29c73f8221250d74c9038511e93001df0412
Gitweb:     http://git.kernel.org/tip/f6ab29c73f8221250d74c9038511e93001df0412
Author:     Prasad Joshi <prasadjoshi124@xxxxxxxxx>
AuthorDate: Fri, 13 May 2011 15:02:46 +0100
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Sat, 14 May 2011 14:53:36 +0300

kvm tools: Add VIRTIO_BLK_T_FLUSH feature to handle flush operation from VM

The virtual machine calls 'sync' when the machine
is halted. Adding the virtio flush feature will
ensure that the data is synced on to disk before
the virtual machine is halted. This is needed to
ensure the intigrity of the data.

Signed-off-by: Prasad Joshi <prasadjoshi124@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/include/kvm/disk-image.h |    9 +++++++++
 tools/kvm/virtio/blk.c             |    5 ++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h
index 9d7b572..6cc9441 100644
--- a/tools/kvm/include/kvm/disk-image.h
+++ b/tools/kvm/include/kvm/disk-image.h
@@ -4,6 +4,7 @@
 #include <linux/types.h>
 #include <stdbool.h>
 #include <sys/uio.h>
+#include <unistd.h>
 
 #define SECTOR_SHIFT		9
 #define SECTOR_SIZE		(1UL << SECTOR_SHIFT)
@@ -15,6 +16,7 @@ struct disk_image_operations {
 	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);
 };
 
@@ -72,4 +74,11 @@ static inline ssize_t disk_image__write_sector_iov(struct disk_image *disk, u64
 	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 */
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 1c6b608..6c9eb19 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -145,6 +145,9 @@ static bool virtio_blk_do_io_request(struct kvm *kvm,
 	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;
@@ -304,7 +307,7 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)
 		 * 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)
--
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


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux