Add the cpr_needed_for_reuse and cpr_resave_fd helpers, for use when adding cpr support for vfio and iommufd.
Signed-off-by: Steve Sistare <steven.sist...@oracle.com> --- include/migration/cpr.h | 3 +++ migration/cpr.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 3a6deb7..faeb0cc 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -18,6 +18,7 @@ void cpr_save_fd(const char *name, int id, int fd); void cpr_delete_fd(const char *name, int id); int cpr_find_fd(const char *name, int id); +void cpr_resave_fd(const char *name, int id, int fd); MigMode cpr_get_incoming_mode(void); void cpr_set_incoming_mode(MigMode mode); @@ -27,6 +28,8 @@ int cpr_state_load(MigrationChannel *channel, Error **errp); void cpr_state_close(void); struct QIOChannel *cpr_state_ioc(void); +bool cpr_needed_for_reuse(void *opaque); + QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp); QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp); diff --git a/migration/cpr.c b/migration/cpr.c index 584b0b9..e3f27e9 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -95,6 +95,21 @@ int cpr_find_fd(const char *name, int id) trace_cpr_find_fd(name, id, fd); return fd; } + +void cpr_resave_fd(const char *name, int id, int fd) +{ + CprFd *elem = find_fd(&cpr_state.fds, name, id); + int old_fd = elem ? elem->fd : -1; + + if (old_fd < 0) { + cpr_save_fd(name, id, fd); + } else if (old_fd != fd) { + error_setg(&error_fatal, + "internal error: cpr fd '%s' id %d value %d " + "already saved with a different value %d", + name, id, fd, old_fd); + } +} /*************************************************************************/ #define CPR_STATE "CprState" @@ -222,3 +237,9 @@ void cpr_state_close(void) cpr_state_file = NULL; } } + +bool cpr_needed_for_reuse(void *opaque) +{ + MigMode mode = migrate_mode(); + return mode == MIG_MODE_CPR_TRANSFER; +} -- 1.8.3.1