Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/snapshot.c
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
#define KB (1024UL) | #define KB (1024UL) | ||||
#define MB (1024UL * KB) | #define MB (1024UL * KB) | ||||
#define GB (1024UL * MB) | #define GB (1024UL * MB) | ||||
#define SNAPSHOT_CHUNK (4 * MB) | #define SNAPSHOT_CHUNK (4 * MB) | ||||
#define PROG_BUF_SZ (8192) | #define PROG_BUF_SZ (8192) | ||||
#define BHYVE_RUN_DIR "/var/run/bhyve" | |||||
#define CHECKPOINT_RUN_DIR BHYVE_RUN_DIR "/checkpoint" | |||||
#define MAX_VMNAME 100 | #define MAX_VMNAME 100 | ||||
#define MAX_MSG_SIZE 1024 | #define MAX_MSG_SIZE 1024 | ||||
#define SNAPSHOT_BUFFER_SIZE (20 * MB) | #define SNAPSHOT_BUFFER_SIZE (20 * MB) | ||||
#define JSON_STRUCT_ARR_KEY "structs" | #define JSON_STRUCT_ARR_KEY "structs" | ||||
#define JSON_DEV_ARR_KEY "devices" | #define JSON_DEV_ARR_KEY "devices" | ||||
▲ Show 20 Lines • Show All 1,373 Lines • ▼ Show 20 Lines | checkpoint_thread(void *param) | ||||
if (conn_fd < -1) { | if (conn_fd < -1) { | ||||
perror("Failed to accept connection"); | perror("Failed to accept connection"); | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* Create directory tree to store runtime specific information: | |||||
* i.e. UNIX sockets for IPC with bhyvectl. | |||||
*/ | |||||
static int | |||||
make_checkpoint_dir(void) | |||||
{ | |||||
int err; | |||||
err = mkdir(BHYVE_RUN_DIR, 0755); | |||||
if (err < 0 && errno != EEXIST) | |||||
return (err); | |||||
err = mkdir(CHECKPOINT_RUN_DIR, 0755); | |||||
if (err < 0 && errno != EEXIST) | |||||
return (err); | |||||
return 0; | |||||
} | |||||
/* | |||||
* Create the listening socket for IPC with bhyvectl | * Create the listening socket for IPC with bhyvectl | ||||
*/ | */ | ||||
int | int | ||||
init_checkpoint_thread(struct vmctx *ctx) | init_checkpoint_thread(struct vmctx *ctx) | ||||
{ | { | ||||
struct checkpoint_thread_info *checkpoint_info = NULL; | struct checkpoint_thread_info *checkpoint_info = NULL; | ||||
struct sockaddr_un addr; | struct sockaddr_un addr; | ||||
int socket_fd; | int socket_fd; | ||||
Show All 14 Lines | init_checkpoint_thread(struct vmctx *ctx) | ||||
socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); | socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); | ||||
if (socket_fd < 0) { | if (socket_fd < 0) { | ||||
perror("Socket creation failed (IPC with bhyvectl"); | perror("Socket creation failed (IPC with bhyvectl"); | ||||
err = -1; | err = -1; | ||||
goto fail; | goto fail; | ||||
} | } | ||||
err = make_checkpoint_dir(); | |||||
if (err < 0) { | |||||
perror("Failed to create checkpoint runtime directory"); | |||||
goto fail; | |||||
} | |||||
addr.sun_family = AF_UNIX; | addr.sun_family = AF_UNIX; | ||||
err = vm_get_name(ctx, vmname_buf, MAX_VMNAME - 1); | err = vm_get_name(ctx, vmname_buf, MAX_VMNAME - 1); | ||||
if (err != 0) { | if (err != 0) { | ||||
perror("Failed to get VM name"); | perror("Failed to get VM name"); | ||||
goto fail; | goto fail; | ||||
} | } | ||||
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", | snprintf(addr.sun_path, sizeof(addr.sun_path), "%s%s", | ||||
CHECKPOINT_RUN_DIR, vmname_buf); | BHYVE_RUN_DIR, vmname_buf); | ||||
addr.sun_len = SUN_LEN(&addr); | addr.sun_len = SUN_LEN(&addr); | ||||
unlink(addr.sun_path); | unlink(addr.sun_path); | ||||
if (bind(socket_fd, (struct sockaddr *)&addr, addr.sun_len) != 0) { | if (bind(socket_fd, (struct sockaddr *)&addr, addr.sun_len) != 0) { | ||||
perror("Failed to bind socket (IPC with bhyvectl)"); | perror("Failed to bind socket (IPC with bhyvectl)"); | ||||
err = -1; | err = -1; | ||||
goto fail; | goto fail; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |