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