]> git.proxmox.com Git - qemu-server.git/blame - qmeventd/qmeventd.h
schema: fix description of migrate_downtime parameter
[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 9#include <sys/syscall.h>
0a1641ae 10#include <time.h>
4c500f16
SR
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
e8e0fd93 19#define VERBOSE_PRINT(...) do { if (verbose) { printf(__VA_ARGS__); fflush(stdout); } } while (0)
4c17b2e3
DC
20
21static inline void log_neg(int errval, const char *msg)
22{
23 if (errval < 0) {
24 perror(msg);
25 }
26}
27
28static inline void bail_neg(int errval, const char *msg)
29{
30 if (errval < 0) {
31 perror(msg);
32 exit(EXIT_FAILURE);
33 }
34}
35
4c500f16
SR
36static inline int
37pidfd_open(pid_t pid, unsigned int flags)
38{
39 return syscall(__NR_pidfd_open, pid, flags);
40}
41
42static inline int
43pidfd_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
3ff85001
SR
48typedef enum {
49 CLIENT_NONE,
50 CLIENT_QEMU,
51 CLIENT_VZDUMP
52} ClientType;
53
54typedef enum {
55 STATE_HANDSHAKE,
56 STATE_IDLE,
57 STATE_EXPECT_STATUS_RESP,
58 STATE_TERMINATING
59} ClientState;
60
4c17b2e3
DC
61struct Client {
62 char buf[4096];
3ff85001
SR
63 unsigned int buflen;
64
4c17b2e3
DC
65 int fd;
66 pid_t pid;
0a1641ae
DC
67 int pidfd;
68 time_t timeout;
3ff85001
SR
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;
4c17b2e3
DC
87};
88
89void handle_qmp_handshake(struct Client *client);
90void handle_qmp_event(struct Client *client, struct json_object *obj);
3ff85001
SR
91void handle_qmp_return(struct Client *client, struct json_object *data, bool error);
92void handle_vzdump_handshake(struct Client *client, struct json_object *data);
4c17b2e3
DC
93void handle_client(struct Client *client);
94void add_new_client(int client_fd);
95void cleanup_client(struct Client *client);
3ff85001
SR
96void terminate_client(struct Client *client);
97void terminate_check(struct Client *client);