]> git.proxmox.com Git - qemu-server.git/blob - qmeventd/qmeventd.h
schema: fix description of migrate_downtime parameter
[qemu-server.git] / qmeventd / qmeventd.h
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2 /*
3 Copyright (C) 2018 - 2021 Proxmox Server Solutions GmbH
4
5 Author: Dominik Csapak <d.csapak@proxmox.com>
6 Author: Stefan Reiter <s.reiter@proxmox.com>
7 */
8
9 #include <sys/syscall.h>
10 #include <time.h>
11
12 #ifndef __NR_pidfd_open
13 #define __NR_pidfd_open 434
14 #endif
15 #ifndef __NR_pidfd_send_signal
16 #define __NR_pidfd_send_signal 424
17 #endif
18
19 #define VERBOSE_PRINT(...) do { if (verbose) { printf(__VA_ARGS__); fflush(stdout); } } while (0)
20
21 static inline void log_neg(int errval, const char *msg)
22 {
23 if (errval < 0) {
24 perror(msg);
25 }
26 }
27
28 static inline void bail_neg(int errval, const char *msg)
29 {
30 if (errval < 0) {
31 perror(msg);
32 exit(EXIT_FAILURE);
33 }
34 }
35
36 static inline int
37 pidfd_open(pid_t pid, unsigned int flags)
38 {
39 return syscall(__NR_pidfd_open, pid, flags);
40 }
41
42 static inline int
43 pidfd_send_signal(int pidfd, int sig, siginfo_t *info, unsigned int flags)
44 {
45 return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
46 }
47
48 typedef enum {
49 CLIENT_NONE,
50 CLIENT_QEMU,
51 CLIENT_VZDUMP
52 } ClientType;
53
54 typedef enum {
55 STATE_HANDSHAKE,
56 STATE_IDLE,
57 STATE_EXPECT_STATUS_RESP,
58 STATE_TERMINATING
59 } ClientState;
60
61 struct Client {
62 char buf[4096];
63 unsigned int buflen;
64
65 int fd;
66 pid_t pid;
67 int pidfd;
68 time_t timeout;
69
70 ClientType type;
71 ClientState state;
72
73 // only relevant for type=CLIENT_QEMU
74 struct {
75 char vmid[16];
76 unsigned short graceful;
77 unsigned short guest;
78 bool term_check_queued;
79 bool backup;
80 } qemu;
81
82 // only relevant for type=CLIENT_VZDUMP
83 struct {
84 // vmid of referenced backup
85 char vmid[16];
86 } vzdump;
87 };
88
89 void handle_qmp_handshake(struct Client *client);
90 void handle_qmp_event(struct Client *client, struct json_object *obj);
91 void handle_qmp_return(struct Client *client, struct json_object *data, bool error);
92 void handle_vzdump_handshake(struct Client *client, struct json_object *data);
93 void handle_client(struct Client *client);
94 void add_new_client(int client_fd);
95 void cleanup_client(struct Client *client);
96 void terminate_client(struct Client *client);
97 void terminate_check(struct Client *client);