[dpdk-dev,v3,16/22] vhost: add features changed callback

Message ID 1490705142-893-17-git-send-email-yuanhan.liu@linux.intel.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/Intel-compilation fail apply patch file failure
ci/checkpatch success coding style OK

Commit Message

Yuanhan Liu March 28, 2017, 12:45 p.m. UTC
  Features could be changed after the feature negotiation. For example,
VHOST_F_LOG_ALL will be set/cleared at the start/end of live migration,
respecitively. Thus, we need a new callback to inform the application
on such change.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 doc/guides/prog_guide/vhost_lib.rst |  6 ++++++
 lib/librte_vhost/rte_virtio_net.h   | 10 +++++++++-
 lib/librte_vhost/vhost_user.c       |  5 +++++
 3 files changed, 20 insertions(+), 1 deletion(-)
  

Comments

Maxime Coquelin March 31, 2017, 7:50 a.m. UTC | #1
On 03/28/2017 02:45 PM, Yuanhan Liu wrote:
> Features could be changed after the feature negotiation. For example,
> VHOST_F_LOG_ALL will be set/cleared at the start/end of live migration,
> respecitively. Thus, we need a new callback to inform the application
> on such change.
>
> Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> ---
>  doc/guides/prog_guide/vhost_lib.rst |  6 ++++++
>  lib/librte_vhost/rte_virtio_net.h   | 10 +++++++++-
>  lib/librte_vhost/vhost_user.c       |  5 +++++
>  3 files changed, 20 insertions(+), 1 deletion(-)

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst
index 88f0591..a4fb1f1 100644
--- a/doc/guides/prog_guide/vhost_lib.rst
+++ b/doc/guides/prog_guide/vhost_lib.rst
@@ -143,6 +143,12 @@  The following is an overview of some key Vhost API functions:
     This callback is invoked when a specific queue's state is changed, for
     example to enabled or disabled.
 
+  * ``features_changed(int vid, uint64_t features)``
+
+    This callback is invoked when the features is changed. For example,
+    ``VHOST_F_LOG_ALL`` will be set/cleared at the start/end of live
+    migration, respectively.
+
 * ``rte_vhost_enqueue_burst(vid, queue_id, pkts, count)``
 
   Transmits (enqueues) ``count`` packets from host to guest.
diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 845d0fd..4256927 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -93,7 +93,15 @@  struct vhost_device_ops {
 
 	int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);	/**< triggered when a vring is enabled or disabled */
 
-	void *reserved[5]; /**< Reserved for future extension */
+	/**
+	 * Features could be changed after the feature negotiation.
+	 * For example, VHOST_F_LOG_ALL will be set/cleared at the
+	 * start/end of live migration, respectively. This callback
+	 * is used to inform the application on such change.
+	 */
+	int (*features_changed)(int vid, uint64_t features);
+
+	void *reserved[4]; /**< Reserved for future extension */
 };
 
 /**
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 7f93f27..40cc973 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -161,6 +161,11 @@ 
 	if (features & ~rte_vhost_driver_get_features(dev->ifname))
 		return -1;
 
+	if ((dev->flags & VIRTIO_DEV_RUNNING) && dev->features != features) {
+		if (dev->notify_ops->features_changed)
+			dev->notify_ops->features_changed(dev->vid, features);
+	}
+
 	dev->features = features;
 	if (dev->features &
 		((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {