git: 89698430bf83 - stable/13 - bhyve/snapshot: split up mutex/cond initialization from socket creation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Jan 2023 18:54:23 UTC
The branch stable/13 has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=89698430bf833857599ce101cef8147bb1dada18
commit 89698430bf833857599ce101cef8147bb1dada18
Author: Robert Wing <rew@FreeBSD.org>
AuthorDate: 2021-05-15 19:58:21 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 18:46:15 +0000
bhyve/snapshot: split up mutex/cond initialization from socket creation
Move initialization of the mutex/condition variables required by the
save/restore feature to their own function.
The unix domain socket that facilitates communication between bhyvectl
and bhyve doesn't rely on these variables in order to be functional.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D30281
(cherry picked from commit fdbc86cf79784f56fab8115f2d565962e1111b2e)
---
usr.sbin/bhyve/bhyverun.c | 3 +++
usr.sbin/bhyve/snapshot.c | 25 ++++++++++++++++---------
usr.sbin/bhyve/snapshot.h | 1 +
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index c14c0c60837f..48d9a66ea624 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -1588,6 +1588,9 @@ main(int argc, char *argv[])
if (restore_file != NULL)
destroy_restore_state(&rstate);
+ /* initialize mutex/cond variables */
+ init_snapshot();
+
/*
* checkpointing thread for communication with bhyvectl
*/
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index b70e43adfe2d..b99c8beed2be 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -1493,6 +1493,22 @@ checkpoint_thread(void *param)
return (NULL);
}
+void
+init_snapshot(void)
+{
+ int err;
+
+ err = pthread_mutex_init(&vcpu_lock, NULL);
+ if (err != 0)
+ errc(1, err, "checkpoint mutex init");
+ err = pthread_cond_init(&vcpus_idle, NULL);
+ if (err != 0)
+ errc(1, err, "checkpoint cv init (vcpus_idle)");
+ err = pthread_cond_init(&vcpus_can_run, NULL);
+ if (err != 0)
+ errc(1, err, "checkpoint cv init (vcpus_can_run)");
+}
+
/*
* Create the listening socket for IPC with bhyvectl
*/
@@ -1508,15 +1524,6 @@ init_checkpoint_thread(struct vmctx *ctx)
memset(&addr, 0, sizeof(addr));
- err = pthread_mutex_init(&vcpu_lock, NULL);
- if (err != 0)
- errc(1, err, "checkpoint mutex init");
- err = pthread_cond_init(&vcpus_idle, NULL);
- if (err == 0)
- err = pthread_cond_init(&vcpus_can_run, NULL);
- if (err != 0)
- errc(1, err, "checkpoint cv init");
-
socket_fd = socket(PF_UNIX, SOCK_DGRAM, 0);
if (socket_fd < 0) {
EPRINTLN("Socket creation failed: %s", strerror(errno));
diff --git a/usr.sbin/bhyve/snapshot.h b/usr.sbin/bhyve/snapshot.h
index f28b56cf0a7f..3ffd42fbeabc 100644
--- a/usr.sbin/bhyve/snapshot.h
+++ b/usr.sbin/bhyve/snapshot.h
@@ -127,6 +127,7 @@ int vm_resume_user_devs(struct vmctx *ctx);
int get_checkpoint_msg(int conn_fd, struct vmctx *ctx);
void *checkpoint_thread(void *param);
int init_checkpoint_thread(struct vmctx *ctx);
+void init_snapshot(void);
int load_restore_file(const char *filename, struct restore_state *rstate);