aboutsummaryrefslogtreecommitdiff
path: root/lib/migration.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2021-02-18 11:16:37 +0000
committerGitHub <noreply@github.com>2021-02-18 11:16:37 +0000
commit22a80ef616beaf7ac495698a4219f37efe5635c8 (patch)
tree5ea58cbaa0123adf48add07aee5b09b26ede0d56 /lib/migration.c
parent0243c6dd892f5ac0ed9c195034a67d2f1f08cec6 (diff)
downloadlibvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.zip
libvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.tar.gz
libvfio-user-22a80ef616beaf7ac495698a4219f37efe5635c8.tar.bz2
unit test exec_command and friends w.r.t. migration device state (#346)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'lib/migration.c')
-rw-r--r--lib/migration.c79
1 files changed, 1 insertions, 78 deletions
diff --git a/lib/migration.c b/lib/migration.c
index ec07961..234366c 100644
--- a/lib/migration.c
+++ b/lib/migration.c
@@ -37,87 +37,10 @@
#include "common.h"
#include "migration.h"
#include "private.h"
+#include "migration_priv.h"
/* FIXME no need to use __u32 etc., use uint32_t etc */
-/*
- * FSM to simplify saving device state.
- */
-enum migr_iter_state {
- VFIO_USER_MIGR_ITER_STATE_INITIAL,
- VFIO_USER_MIGR_ITER_STATE_STARTED,
- VFIO_USER_MIGR_ITER_STATE_DATA_PREPARED,
- VFIO_USER_MIGR_ITER_STATE_FINISHED
-};
-
-struct migration {
- /*
- * TODO if the user provides an FD then should mmap it and use the migration
- * registers in the file
- */
- struct vfio_device_migration_info info;
- size_t pgsize;
- vfu_migration_callbacks_t callbacks;
- uint64_t data_offset;
-
- /*
- * This is only for the saving state. The resuming state is simpler so we
- * don't need it.
- */
- struct {
- enum migr_iter_state state;
- __u64 pending_bytes;
- __u64 offset;
- __u64 size;
- } iter;
-};
-
-struct migr_state_data {
- __u32 state;
- const char *name;
-};
-
-#define VFIO_DEVICE_STATE_ERROR (VFIO_DEVICE_STATE_SAVING | VFIO_DEVICE_STATE_RESUMING)
-
-/* valid migration state transitions */
-static const struct migr_state_data migr_states[(VFIO_DEVICE_STATE_MASK + 1)] = {
- [VFIO_DEVICE_STATE_STOP] = {
- .state = 1 << VFIO_DEVICE_STATE_STOP,
- .name = "stopped"
- },
- [VFIO_DEVICE_STATE_RUNNING] = {
- .state =
- (1 << VFIO_DEVICE_STATE_STOP) |
- (1 << VFIO_DEVICE_STATE_RUNNING) |
- (1 << VFIO_DEVICE_STATE_SAVING) |
- (1 << (VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING)) |
- (1 << VFIO_DEVICE_STATE_RESUMING) |
- (1 << VFIO_DEVICE_STATE_ERROR),
- .name = "running"
- },
- [VFIO_DEVICE_STATE_SAVING] = {
- .state =
- (1 << VFIO_DEVICE_STATE_STOP) |
- (1 << VFIO_DEVICE_STATE_SAVING) |
- (1 << VFIO_DEVICE_STATE_ERROR),
- .name = "stop-and-copy"
- },
- [VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING] = {
- .state =
- (1 << VFIO_DEVICE_STATE_STOP) |
- (1 << VFIO_DEVICE_STATE_SAVING) |
- (1 << VFIO_DEVICE_STATE_RUNNING | VFIO_DEVICE_STATE_SAVING) |
- (1 << VFIO_DEVICE_STATE_ERROR),
- .name = "pre-copy"
- },
- [VFIO_DEVICE_STATE_RESUMING] = {
- .state =
- (1 << VFIO_DEVICE_STATE_RUNNING) |
- (1 << VFIO_DEVICE_STATE_RESUMING) |
- (1 << VFIO_DEVICE_STATE_ERROR),
- .name = "resuming"
- }
-};
bool
vfio_migr_state_transition_is_valid(__u32 from, __u32 to)