aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio/vhost.c
diff options
context:
space:
mode:
authorNikolay Nikolaev <n.nikolaev@virtualopensystems.com>2014-05-27 15:04:42 +0300
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 16:41:55 +0300
commit2e6d46d77ed328d34a94688da8371bcbe243479b (patch)
treeb81d5f34c7f98e7c0372bb0db7fb34804b963603 /hw/virtio/vhost.c
parentcdaa86a54b232572bba594bf87a7416e527e460c (diff)
downloadqemu-2e6d46d77ed328d34a94688da8371bcbe243479b.zip
qemu-2e6d46d77ed328d34a94688da8371bcbe243479b.tar.gz
qemu-2e6d46d77ed328d34a94688da8371bcbe243479b.tar.bz2
vhost: add vhost_get_features and vhost_ack_features
Generalize the features get/ack to be used for both vhost-net and vhost-scsi. In vhost-net add vhost_net_get_feature_bits to select the feature bit set depending on the NetClient kind. Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/virtio/vhost.c')
-rw-r--r--hw/virtio/vhost.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 9e6023a..a3e872d 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -990,6 +990,33 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n,
assert(r >= 0);
}
+unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
+ unsigned features)
+{
+ const int *bit = feature_bits;
+ while (*bit != VHOST_INVALID_FEATURE_BIT) {
+ unsigned bit_mask = (1 << *bit);
+ if (!(hdev->features & bit_mask)) {
+ features &= ~bit_mask;
+ }
+ bit++;
+ }
+ return features;
+}
+
+void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
+ unsigned features)
+{
+ const int *bit = feature_bits;
+ while (*bit != VHOST_INVALID_FEATURE_BIT) {
+ unsigned bit_mask = (1 << *bit);
+ if (features & bit_mask) {
+ hdev->acked_features |= bit_mask;
+ }
+ bit++;
+ }
+}
+
/* Host notifiers must be enabled at this point. */
int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)
{