From: Steve Sistare <[email protected]> Add a helper to walk all CPR fd's and run a callback for each.
Signed-off-by: Steve Sistare <[email protected]> Reviewed-by: Peter Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> --- include/migration/cpr.h | 3 +++ migration/cpr.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/migration/cpr.h b/include/migration/cpr.h index 3fc19a74ef..2b074d7a65 100644 --- a/include/migration/cpr.h +++ b/include/migration/cpr.h @@ -34,6 +34,9 @@ void cpr_resave_fd(const char *name, int id, int fd); int cpr_open_fd(const char *path, int flags, const char *name, int id, Error **errp); +typedef bool (*cpr_walk_fd_cb)(int fd); +bool cpr_walk_fd(cpr_walk_fd_cb cb); + MigMode cpr_get_incoming_mode(void); void cpr_set_incoming_mode(MigMode mode); bool cpr_is_incoming(void); diff --git a/migration/cpr.c b/migration/cpr.c index e0b47df222..6feda78f1b 100644 --- a/migration/cpr.c +++ b/migration/cpr.c @@ -122,6 +122,19 @@ int cpr_open_fd(const char *path, int flags, const char *name, int id, return fd; } +bool cpr_walk_fd(cpr_walk_fd_cb cb) +{ + CprFd *elem; + + QLIST_FOREACH(elem, &cpr_state.fds, next) { + g_assert(elem->fd >= 0); + if (!cb(elem->fd)) { + return false; + } + } + return true; +} + /*************************************************************************/ static const VMStateDescription vmstate_cpr_state = { .name = CPR_STATE, -- 2.50.1
