1 /*
2  * Copyright Intel Corp. 2020-2021
3  *
4  * ch_conf.h: header file for Cloud-Hypervisor configuration
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 "virdomainobjlist.h"
24 #include "virthread.h"
25 
26 #define CH_DRIVER_NAME "CH"
27 #define CH_CMD "cloud-hypervisor"
28 
29 typedef struct _virCHDriver virCHDriver;
30 
31 typedef struct _virCHDriverConfig virCHDriverConfig;
32 
33 struct _virCHDriverConfig {
34     GObject parent;
35 
36     char *stateDir;
37     char *logDir;
38 
39     uid_t user;
40     gid_t group;
41 };
42 
43 struct _virCHDriver
44 {
45     virMutex lock;
46 
47     /* Require lock to get a reference on the object,
48      * lockless access thereafter */
49     virCaps *caps;
50 
51     /* Immutable pointer, Immutable object */
52     virDomainXMLOption *xmlopt;
53 
54     /* Immutable pointer, self-locking APIs */
55     virDomainObjList *domains;
56 
57     /* Cloud-Hypervisor version */
58     int version;
59 
60     /* Require lock to get reference on 'config',
61      * then lockless thereafter */
62     virCHDriverConfig *config;
63 
64     /* pid file FD, ensures two copies of the driver can't use the same root */
65     int lockFD;
66 };
67 
68 virCaps *virCHDriverCapsInit(void);
69 virCaps *virCHDriverGetCapabilities(virCHDriver *driver,
70                                       bool refresh);
71 virDomainXMLOption *chDomainXMLConfInit(virCHDriver *driver);
72 virCHDriverConfig *virCHDriverConfigNew(bool privileged);
73 virCHDriverConfig *virCHDriverGetConfig(virCHDriver *driver);
74 int chExtractVersion(virCHDriver *driver);
75 
chDriverLock(virCHDriver * driver)76 static inline void chDriverLock(virCHDriver *driver)
77 {
78     virMutexLock(&driver->lock);
79 }
80 
chDriverUnlock(virCHDriver * driver)81 static inline void chDriverUnlock(virCHDriver *driver)
82 {
83     virMutexUnlock(&driver->lock);
84 }
85