1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2024 SUSE Software Solutions Germany GmbH
4  *
5  * Interfaces of libxenmanage.
6  *
7  * libxenmanage provides management functions for the host using stable
8  * hypercall interfaces.
9  */
10 #ifndef XENMANAGE_H
11 #define XENMANAGE_H
12 
13 #include <stdint.h>
14 
15 /* Avoid the need to #include <xentoollog.h> */
16 struct xentoollog_logger;
17 
18 typedef struct xenmanage_handle xenmanage_handle;
19 
20 /*
21  * Open libxenmanage.
22  *
23  * Get a handle of the xenmanage library. The handle is required for all
24  * further operations of the library.
25  * Parameters:
26  *   logger:     Logging function to use. If NULL logging is done to stderr.
27  *   open_flags: Only 0 supported.
28  * Return value: Handle or NULL if error.
29  */
30 xenmanage_handle *xenmanage_open(struct xentoollog_logger *logger,
31                                  unsigned int open_flags);
32 
33 /*
34  * Close libxenmanage.
35  *
36  * Return a handle of the xenmanage library.
37  * Parameters:
38  *    hdl: Handle obtained by xenmanage_open().
39  * Return value: always 0.
40  */
41 int xenmanage_close(xenmanage_handle *hdl);
42 
43 #define XENMANAGE_GETDOMSTATE_STATE_EXIST     0x0001  /* Domain is existing. */
44 #define XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN  0x0002  /* Shutdown finished. */
45 #define XENMANAGE_GETDOMSTATE_STATE_DYING     0x0004  /* Domain dying. */
46 #define XENMANAGE_GETDOMSTATE_STATE_DEAD      0x0008  /* Domain dead. */
47 
48 /* Control Domain capability. */
49 #define XENMANAGE_GETDOMSTATE_CAP_CONTROL     0x0001
50 /* Hardware Domain capability. */
51 #define XENMANAGE_GETDOMSTATE_CAP_HARDWARE    0x0002
52 /* Xenstore Domain capability. */
53 #define XENMANAGE_GETDOMSTATE_CAP_XENSTORE    0x0004
54 /*
55  * Return state information of an existing domain.
56  *
57  * Returns the domain state and unique id of the given domain.
58  * Parameters:
59  *   hdl:       handle returned by xenmanage_open()
60  *   domid:     domain id of the domain to get the information for
61  *   state:     where to store the state (XENMANAGE_GETDOMSTATE_STATE_ flags,
62  *              nothing stored if NULL)
63  *   unique_id: where to store the unique id of the domain (nothing stored if
64  *              NULL)
65  * Return value: 0 if information was stored, -1 else (errno is set)
66  */
67 int xenmanage_get_domain_info(xenmanage_handle *hdl, unsigned int domid,
68                               unsigned int *state, unsigned int *caps,
69                               uint64_t *unique_id);
70 
71 /*
72  * Return information of a domain having changed state recently.
73  *
74  * Returns the domain id, state and unique id of a domain having changed
75  * state (any of the state bits was modified) since the last time information
76  * for that domain was returned by this function. Only usable by callers who
77  * have registered the VIRQ_DOM_EXC event (normally Xenstore).
78  * Parameters:
79  *   hdl:       handle returned by xenmanage_open()
80  *   domid:     where to store the domid of the domain (not NULL)
81  *   state:     where to store the state (XENMANAGE_GETDOMSTATE_STATE_ flags,
82  *              nothing stored if NULL)
83  *   caps:      where to store the capabilities (XENMANAGE_GETDOMSTATE_CAP_
84  *              flags, nothing stored if NULL)
85  *   unique_id: where to store the unique id of the domain (nothing stored if
86  *              NULL)
87  * Return value: 0 if information was stored, -1 else (errno is set)
88  */
89 int xenmanage_poll_changed_domain(xenmanage_handle *hdl, unsigned int *domid,
90                                   unsigned int *state, unsigned int *caps,
91                                   uint64_t *unique_id);
92 #endif /* XENMANAGE_H */
93 
94 /*
95  * Local variables:
96  * mode: C
97  * c-file-style: "BSD"
98  * c-basic-offset: 4
99  * tab-width: 4
100  * indent-tabs-mode: nil
101  * End:
102  */
103