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