]> git.proxmox.com Git - qemu-server.git/blame - qmeventd/qmeventd.h
qmeventd: flush after verbose printing
[qemu-server.git] / qmeventd / qmeventd.h
CommitLineData
4c17b2e3
DC
1/*
2
3 Copyright (C) 2018 Proxmox Server Solutions GmbH
4
5 Copyright: qemumonitor is under GNU GPL, the GNU General Public License.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 dated June, 1991.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20
21 Author: Dominik Csapak <d.csapak@proxmox.com>
22*/
23
4c500f16
SR
24#include <sys/syscall.h>
25
26#ifndef __NR_pidfd_open
27#define __NR_pidfd_open 434
28#endif
29#ifndef __NR_pidfd_send_signal
30#define __NR_pidfd_send_signal 424
31#endif
32
e8e0fd93 33#define VERBOSE_PRINT(...) do { if (verbose) { printf(__VA_ARGS__); fflush(stdout); } } while (0)
4c17b2e3
DC
34
35static inline void log_neg(int errval, const char *msg)
36{
37 if (errval < 0) {
38 perror(msg);
39 }
40}
41
42static inline void bail_neg(int errval, const char *msg)
43{
44 if (errval < 0) {
45 perror(msg);
46 exit(EXIT_FAILURE);
47 }
48}
49
4c500f16
SR
50static inline int
51pidfd_open(pid_t pid, unsigned int flags)
52{
53 return syscall(__NR_pidfd_open, pid, flags);
54}
55
56static inline int
57pidfd_send_signal(int pidfd, int sig, siginfo_t *info, unsigned int flags)
58{
59 return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
60}
61
3ff85001
SR
62typedef enum {
63 CLIENT_NONE,
64 CLIENT_QEMU,
65 CLIENT_VZDUMP
66} ClientType;
67
68typedef enum {
69 STATE_HANDSHAKE,
70 STATE_IDLE,
71 STATE_EXPECT_STATUS_RESP,
72 STATE_TERMINATING
73} ClientState;
74
4c17b2e3
DC
75struct Client {
76 char buf[4096];
3ff85001
SR
77 unsigned int buflen;
78
4c17b2e3
DC
79 int fd;
80 pid_t pid;
3ff85001
SR
81
82 ClientType type;
83 ClientState state;
84
85 // only relevant for type=CLIENT_QEMU
86 struct {
87 char vmid[16];
88 unsigned short graceful;
89 unsigned short guest;
90 bool term_check_queued;
91 bool backup;
92 } qemu;
93
94 // only relevant for type=CLIENT_VZDUMP
95 struct {
96 // vmid of referenced backup
97 char vmid[16];
98 } vzdump;
4c17b2e3
DC
99};
100
4c500f16
SR
101struct CleanupData {
102 pid_t pid;
103 int pidfd;
104};
105
4c17b2e3
DC
106void handle_qmp_handshake(struct Client *client);
107void handle_qmp_event(struct Client *client, struct json_object *obj);
3ff85001
SR
108void handle_qmp_return(struct Client *client, struct json_object *data, bool error);
109void handle_vzdump_handshake(struct Client *client, struct json_object *data);
4c17b2e3
DC
110void handle_client(struct Client *client);
111void add_new_client(int client_fd);
112void cleanup_client(struct Client *client);
3ff85001
SR
113void terminate_client(struct Client *client);
114void terminate_check(struct Client *client);