diff options
author | Laurent Vivier <lvivier@redhat.com> | 2024-12-19 12:13:59 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-01-20 19:51:24 +0100 |
commit | 31d70024beda1e49131d7b68dd7554bee16c79f3 (patch) | |
tree | d6648be39b0b3d78504ca8472caa6aae841b79a5 /vu_common.c | |
parent | 878e16345461eb2745c761f6929fd6e9da0df447 (diff) | |
download | passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar.gz passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar.bz2 passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar.lz passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar.xz passt-31d70024beda1e49131d7b68dd7554bee16c79f3.tar.zst passt-31d70024beda1e49131d7b68dd7554bee16c79f3.zip |
vhost-user: add VHOST_USER_SET_DEVICE_STATE_FD command
Set the file descriptor to use to transfer the
backend device state during migration.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
[sbrivio: Fixed nits and coding style here and there]
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'vu_common.c')
-rw-r--r-- | vu_common.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vu_common.c b/vu_common.c index 0ba2351..87a0d94 100644 --- a/vu_common.c +++ b/vu_common.c @@ -297,3 +297,52 @@ err: return -1; } + +/** + * vu_migrate() - Send/receive passt insternal state to/from QEMU + * @vdev: vhost-user device + * @events: epoll events + */ +void vu_migrate(struct vu_dev *vdev, uint32_t events) +{ + int ret; + + /* TODO: collect/set passt internal state + * and use vdev->device_state_fd to send/receive it + */ + debug("vu_migrate fd %d events %x", vdev->device_state_fd, events); + if (events & EPOLLOUT) { + debug("Saving backend state"); + + /* send some stuff */ + ret = write(vdev->device_state_fd, "PASST", 6); + /* value to be returned by VHOST_USER_CHECK_DEVICE_STATE */ + vdev->device_state_result = ret == -1 ? -1 : 0; + /* Closing the file descriptor signals the end of transfer */ + epoll_ctl(vdev->context->epollfd, EPOLL_CTL_DEL, + vdev->device_state_fd, NULL); + close(vdev->device_state_fd); + vdev->device_state_fd = -1; + } else if (events & EPOLLIN) { + char buf[6]; + + debug("Loading backend state"); + /* read some stuff */ + ret = read(vdev->device_state_fd, buf, sizeof(buf)); + /* value to be returned by VHOST_USER_CHECK_DEVICE_STATE */ + if (ret != sizeof(buf)) { + vdev->device_state_result = -1; + } else { + ret = strncmp(buf, "PASST", sizeof(buf)); + vdev->device_state_result = ret == 0 ? 0 : -1; + } + } else if (events & EPOLLHUP) { + debug("Closing migration channel"); + + /* The end of file signals the end of the transfer. */ + epoll_ctl(vdev->context->epollfd, EPOLL_CTL_DEL, + vdev->device_state_fd, NULL); + close(vdev->device_state_fd); + vdev->device_state_fd = -1; + } +} |