[RFC,09/10] vhost: add support to postcopy's end request
Checks
Commit Message
The master sends this message before stopping handling
userfaults, so that the backend closes the userfaultfd.
The master waits for the slave to acknowledge the request
with an empty 64bits payload for synchronization purpose.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/librte_vhost/vhost_user.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
@@ -75,6 +75,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {
[VHOST_USER_CRYPTO_CLOSE_SESS] = "VHOST_USER_CRYPTO_CLOSE_SESS",
[VHOST_USER_POSTCOPY_ADVISE] = "VHOST_USER_POSTCOPY_ADVISE",
[VHOST_USER_POSTCOPY_LISTEN] = "VHOST_USER_POSTCOPY_LISTEN",
+ [VHOST_USER_POSTCOPY_END] = "VHOST_USER_POSTCOPY_END",
};
static int
@@ -1512,6 +1513,18 @@ vhost_user_set_postcopy_listen(struct virtio_net *dev)
return 0;
}
+static int
+vhost_user_postcopy_end(struct virtio_net *dev)
+{
+ dev->postcopy_listening = 0;
+ if (dev->postcopy_ufd > 0) {
+ close(dev->postcopy_ufd);
+ dev->postcopy_ufd = -1;
+ }
+
+ return 0;
+}
+
/* return bytes# of read on success or negative val on failure. */
static int
read_vhost_message(int sockfd, struct VhostUserMsg *msg)
@@ -1864,6 +1877,14 @@ vhost_user_msg_handler(int vid, int fd)
ret = vhost_user_set_postcopy_listen(dev);
break;
+ case VHOST_USER_POSTCOPY_END:
+ vhost_user_postcopy_end(dev);
+ msg.payload.u64 = 0;
+ msg.size = sizeof(msg.payload.u64);
+ msg.fd_num = 0;
+ send_vhost_reply(fd, &msg);
+ break;
+
default:
ret = -1;
break;