1 /*
2  * Copyright (C) 2010-2012 Red Hat, Inc.
3  * Copyright IBM Corp. 2008
4  *
5  * lxc_domain.h: LXC domain helpers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library.  If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "vircgroup.h"
25 #include "lxc_conf.h"
26 #include "lxc_monitor.h"
27 #include "virenum.h"
28 
29 
30 typedef enum {
31     VIR_LXC_DOMAIN_NAMESPACE_SHARENET = 0,
32     VIR_LXC_DOMAIN_NAMESPACE_SHAREIPC,
33     VIR_LXC_DOMAIN_NAMESPACE_SHAREUTS,
34     VIR_LXC_DOMAIN_NAMESPACE_LAST,
35 } virLXCDomainNamespace;
36 
37 typedef enum {
38     VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NONE = 0,
39     VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NAME,
40     VIR_LXC_DOMAIN_NAMESPACE_SOURCE_PID,
41     VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NETNS,
42 
43     VIR_LXC_DOMAIN_NAMESPACE_SOURCE_LAST,
44 } virLXCDomainNamespaceSource;
45 
46 VIR_ENUM_DECL(virLXCDomainNamespace);
47 VIR_ENUM_DECL(virLXCDomainNamespaceSource);
48 
49 typedef struct _lxcDomainDef lxcDomainDef;
50 struct _lxcDomainDef {
51     int ns_source[VIR_LXC_DOMAIN_NAMESPACE_LAST]; /* virLXCDomainNamespaceSource */
52     char *ns_val[VIR_LXC_DOMAIN_NAMESPACE_LAST];
53 };
54 
55 
56 /* Only 1 job is allowed at any time
57  * A job includes *all* lxc.so api, even those just querying
58  * information, not merely actions */
59 
60 enum virLXCDomainJob {
61     LXC_JOB_NONE = 0,      /* Always set to 0 for easy if (jobActive) conditions */
62     LXC_JOB_QUERY,         /* Doesn't change any state */
63     LXC_JOB_DESTROY,       /* Destroys the domain (cannot be masked out) */
64     LXC_JOB_MODIFY,        /* May change state */
65     LXC_JOB_LAST
66 };
67 VIR_ENUM_DECL(virLXCDomainJob);
68 
69 
70 struct virLXCDomainJobObj {
71     virCond cond;                       /* Use to coordinate jobs */
72     enum virLXCDomainJob active;        /* Currently running job */
73     int owner;                          /* Thread which set current job */
74 };
75 
76 
77 typedef struct _virLXCDomainObjPrivate virLXCDomainObjPrivate;
78 struct _virLXCDomainObjPrivate {
79     virLXCMonitor *monitor;
80     bool doneStopEvent;
81     int stopReason;
82     bool wantReboot;
83 
84     pid_t initpid;
85 
86     virCgroup *cgroup;
87     char *machineName;
88 
89     struct virLXCDomainJobObj job;
90 };
91 
92 extern virXMLNamespace virLXCDriverDomainXMLNamespace;
93 extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
94 extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;
95 
96 int
97 virLXCDomainObjBeginJob(virLXCDriver *driver,
98                        virDomainObj *obj,
99                        enum virLXCDomainJob job)
100     G_GNUC_WARN_UNUSED_RESULT;
101 
102 void
103 virLXCDomainObjEndJob(virLXCDriver *driver,
104                      virDomainObj *obj);
105 
106 
107 char *
108 virLXCDomainGetMachineName(virDomainDef *def, pid_t pid);
109 
110 int
111 virLXCDomainSetRunlevel(virDomainObj *vm,
112                         int runlevel);
113