[SLOF] [PATCH v1 19/27] virtio 1.0: helper for guest features negotiation
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Wed Jan 13 22:17:06 AEDT 2016
Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
lib/libvirtio/virtio.c | 20 ++++++++++++++++++++
lib/libvirtio/virtio.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index 3bd8c67..e81d78e 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -474,6 +474,26 @@ void virtio_get_host_features_long(struct virtio_device *dev, uint64_t *features
}
}
+int virtio_negotiate_guest_features(struct virtio_device *dev, uint64_t features)
+{
+ uint64_t host_features = 0;
+
+ /* Negotiate features */
+ virtio_get_host_features_long(dev, &host_features);
+ if (!(host_features & VIRTIO_F_VERSION_1)) {
+ fprintf(stderr, "Device does not support virtio 1.0 %llx\n", host_features);
+ return false;
+ }
+
+ virtio_set_guest_features_long(dev, features);
+ virtio_get_host_features_long(dev, &host_features);
+ if ((host_features & features) != features) {
+ fprintf(stderr, "Features error %llx\n", features);
+ return false;
+ }
+ return true;
+}
+
/**
* Get additional config values
*/
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index 7ef2f94..07bd28c 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -127,6 +127,7 @@ extern void virtio_set_guest_features(struct virtio_device *dev, int features);
extern void virtio_get_host_features(struct virtio_device *dev, int *features);
extern void virtio_set_guest_features_long(struct virtio_device *dev, uint64_t features);
extern void virtio_get_host_features_long(struct virtio_device *dev, uint64_t *features);
+extern int virtio_negotiate_guest_features(struct virtio_device *dev, uint64_t features);
extern uint64_t virtio_get_config(struct virtio_device *dev, int offset, int size);
extern int __virtio_read_config(struct virtio_device *dev, void *dst,
int offset, int len);
--
2.5.0
More information about the SLOF
mailing list