1 /*
2  * libxl_domain.h: libxl domain object private state
3  *
4  * Copyright (C) 2011-2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include <libxl.h>
24 
25 #include "domain_conf.h"
26 #include "libxl_conf.h"
27 #include "virchrdev.h"
28 #include "virenum.h"
29 
30 /* Only 1 job is allowed at any time
31  * A job includes *all* libxl.so api, even those just querying
32  * information, not merely actions */
33 enum libxlDomainJob {
34     LIBXL_JOB_NONE = 0,      /* Always set to 0 for easy if (jobActive) conditions */
35     LIBXL_JOB_QUERY,         /* Doesn't change any state */
36     LIBXL_JOB_DESTROY,       /* Destroys the domain (cannot be masked out) */
37     LIBXL_JOB_MODIFY,        /* May change state */
38 
39     LIBXL_JOB_LAST
40 };
41 VIR_ENUM_DECL(libxlDomainJob);
42 
43 
44 struct libxlDomainJobObj {
45     virCond cond;                       /* Use to coordinate jobs */
46     enum libxlDomainJob active;         /* Currently running job */
47     int owner;                          /* Thread which set current job */
48     unsigned long long started;         /* When the job started */
49     virDomainJobInfoPtr current;        /* Statistics for the current job */
50 };
51 
52 typedef struct _libxlDomainObjPrivate libxlDomainObjPrivate;
53 struct _libxlDomainObjPrivate {
54     /* console */
55     virChrdevs *devs;
56     libxl_evgen_domain_death *deathW;
57     /* Flag to indicate the upcoming LIBXL_EVENT_TYPE_DOMAIN_DEATH is caused
58      * by libvirt and should not be handled separately */
59     bool ignoreDeathEvent;
60     virThread *migrationDstReceiveThr;
61     unsigned short migrationPort;
62     char *lockState;
63     bool lockProcessRunning;
64 
65     struct libxlDomainJobObj job;
66 
67     bool hookRun;  /* true if there was a hook run over this domain */
68 };
69 
70 
71 extern virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks;
72 extern virDomainDefParserConfig libxlDomainDefParserConfig;
73 extern virXMLNamespace libxlDriverDomainXMLNamespace;
74 extern const struct libxl_event_hooks ev_hooks;
75 
76 int
77 libxlDomainObjPrivateInitCtx(virDomainObj *vm);
78 
79 int
80 libxlDomainObjBeginJob(libxlDriverPrivate *driver,
81                        virDomainObj *obj,
82                        enum libxlDomainJob job)
83     G_GNUC_WARN_UNUSED_RESULT;
84 
85 void
86 libxlDomainObjEndJob(libxlDriverPrivate *driver,
87                      virDomainObj *obj);
88 
89 int
90 libxlDomainJobUpdateTime(struct libxlDomainJobObj *job)
91     G_GNUC_WARN_UNUSED_RESULT;
92 
93 char *
94 libxlDomainManagedSavePath(libxlDriverPrivate *driver,
95                            virDomainObj *vm);
96 
97 int
98 libxlDomainSaveImageOpen(libxlDriverPrivate *driver,
99                          const char *from,
100                          virDomainDef **ret_def,
101                          libxlSavefileHeader *ret_hdr)
102     ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
103 
104 int
105 libxlDomainHookRun(libxlDriverPrivate *driver,
106                    virDomainDef *def,
107                    unsigned int def_fmtflags,
108                    int hookop,
109                    int hooksubop,
110                    char **output);
111 
112 int
113 libxlDomainDestroyInternal(libxlDriverPrivate *driver,
114                            virDomainObj *vm);
115 
116 void
117 libxlDomainCleanup(libxlDriverPrivate *driver,
118                    virDomainObj *vm);
119 
120 void
121 libxlDomainEventHandler(void *data, libxl_event *event);
122 
123 int
124 libxlDomainAutoCoreDump(libxlDriverPrivate *driver,
125                         virDomainObj *vm);
126 
127 int
128 libxlDomainStartNew(libxlDriverPrivate *driver,
129                     virDomainObj *vm,
130                     bool start_paused);
131 
132 int
133 libxlDomainStartRestore(libxlDriverPrivate *driver,
134                         virDomainObj *vm,
135                         bool start_paused,
136                         int restore_fd,
137                         uint32_t restore_ver);
138 
139 bool
140 libxlDomainDefCheckABIStability(libxlDriverPrivate *driver,
141                                 virDomainDef *src,
142                                 virDomainDef *dst);
143