Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
5320ce02
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5320ce02
编写于
7月 06, 2009
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add domain autostart for LXC driver
* src/lxc_driver.c: Implement support for domain autostart
上级
9b5655a8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
182 addition
and
2 deletion
+182
-2
src/lxc_driver.c
src/lxc_driver.c
+182
-2
未找到文件。
src/lxc_driver.c
浏览文件 @
5320ce02
...
...
@@ -48,6 +48,7 @@
#include "event.h"
#include "cgroup.h"
#include "nodeinfo.h"
#include "uuid.h"
#define VIR_FROM_THIS VIR_FROM_LXC
...
...
@@ -1301,6 +1302,48 @@ static int lxcCheckNetNsSupport(void)
return
1
;
}
static
void
lxcAutostartConfigs
(
lxc_driver_t
*
driver
)
{
unsigned
int
i
;
/* XXX: Figure out a better way todo this. The domain
* startup code needs a connection handle in order
* to lookup the bridge associated with a virtual
* network
*/
virConnectPtr
conn
=
virConnectOpen
(
"lxc:///"
);
/* Ignoring NULL conn which is mostly harmless here */
lxcDriverLock
(
driver
);
for
(
i
=
0
;
i
<
driver
->
domains
.
count
;
i
++
)
{
virDomainObjPtr
vm
=
driver
->
domains
.
objs
[
i
];
virDomainObjLock
(
vm
);
if
(
vm
->
autostart
&&
!
virDomainIsActive
(
vm
))
{
int
ret
=
lxcVmStart
(
conn
,
driver
,
vm
);
if
(
ret
<
0
)
{
virErrorPtr
err
=
virGetLastError
();
VIR_ERROR
(
_
(
"Failed to autostart VM '%s': %s
\n
"
),
vm
->
def
->
name
,
err
?
err
->
message
:
""
);
}
else
{
virDomainEventPtr
event
=
virDomainEventNewFromObj
(
vm
,
VIR_DOMAIN_EVENT_STARTED
,
VIR_DOMAIN_EVENT_STARTED_BOOTED
);
if
(
event
)
lxcDomainEventQueue
(
driver
,
event
);
}
}
virDomainObjUnlock
(
vm
);
}
lxcDriverUnlock
(
driver
);
if
(
conn
)
virConnectClose
(
conn
);
}
static
int
lxcStartup
(
int
privileged
)
{
unsigned
int
i
;
...
...
@@ -1413,6 +1456,45 @@ cleanup:
return
-
1
;
}
static
void
lxcNotifyLoadDomain
(
virDomainObjPtr
vm
,
int
newVM
,
void
*
opaque
)
{
lxc_driver_t
*
driver
=
opaque
;
if
(
newVM
)
{
virDomainEventPtr
event
=
virDomainEventNewFromObj
(
vm
,
VIR_DOMAIN_EVENT_DEFINED
,
VIR_DOMAIN_EVENT_DEFINED_ADDED
);
if
(
event
)
lxcDomainEventQueue
(
driver
,
event
);
}
}
/**
* lxcReload:
*
* Function to restart the LXC driver, it will recheck the configuration
* files and perform autostart
*/
static
int
lxcReload
(
void
)
{
if
(
!
lxc_driver
)
return
0
;
lxcDriverLock
(
lxc_driver
);
virDomainLoadAllConfigs
(
NULL
,
lxc_driver
->
caps
,
&
lxc_driver
->
domains
,
lxc_driver
->
configDir
,
lxc_driver
->
autostartDir
,
0
,
lxcNotifyLoadDomain
,
lxc_driver
);
lxcDriverUnlock
(
lxc_driver
);
lxcAutostartConfigs
(
lxc_driver
);
return
0
;
}
static
int
lxcShutdown
(
void
)
{
if
(
lxc_driver
==
NULL
)
...
...
@@ -1589,6 +1671,103 @@ cleanup:
return
ret
;
}
static
int
lxcDomainGetAutostart
(
virDomainPtr
dom
,
int
*
autostart
)
{
lxc_driver_t
*
driver
=
dom
->
conn
->
privateData
;
virDomainObjPtr
vm
;
int
ret
=
-
1
;
lxcDriverLock
(
driver
);
vm
=
virDomainFindByUUID
(
&
driver
->
domains
,
dom
->
uuid
);
lxcDriverUnlock
(
driver
);
if
(
!
vm
)
{
char
uuidstr
[
VIR_UUID_STRING_BUFLEN
];
virUUIDFormat
(
dom
->
uuid
,
uuidstr
);
lxcError
(
dom
->
conn
,
dom
,
VIR_ERR_NO_DOMAIN
,
_
(
"no domain with matching uuid '%s'"
),
uuidstr
);
goto
cleanup
;
}
*
autostart
=
vm
->
autostart
;
ret
=
0
;
cleanup:
if
(
vm
)
virDomainObjUnlock
(
vm
);
return
ret
;
}
static
int
lxcDomainSetAutostart
(
virDomainPtr
dom
,
int
autostart
)
{
lxc_driver_t
*
driver
=
dom
->
conn
->
privateData
;
virDomainObjPtr
vm
;
char
*
configFile
=
NULL
,
*
autostartLink
=
NULL
;
int
ret
=
-
1
;
lxcDriverLock
(
driver
);
vm
=
virDomainFindByUUID
(
&
driver
->
domains
,
dom
->
uuid
);
if
(
!
vm
)
{
char
uuidstr
[
VIR_UUID_STRING_BUFLEN
];
virUUIDFormat
(
dom
->
uuid
,
uuidstr
);
lxcError
(
dom
->
conn
,
dom
,
VIR_ERR_NO_DOMAIN
,
_
(
"no domain with matching uuid '%s'"
),
uuidstr
);
goto
cleanup
;
}
if
(
!
vm
->
persistent
)
{
lxcError
(
dom
->
conn
,
dom
,
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"cannot set autostart for transient domain"
));
goto
cleanup
;
}
autostart
=
(
autostart
!=
0
);
if
(
vm
->
autostart
!=
autostart
)
{
if
((
configFile
=
virDomainConfigFile
(
dom
->
conn
,
driver
->
configDir
,
vm
->
def
->
name
))
==
NULL
)
goto
cleanup
;
if
((
autostartLink
=
virDomainConfigFile
(
dom
->
conn
,
driver
->
autostartDir
,
vm
->
def
->
name
))
==
NULL
)
goto
cleanup
;
if
(
autostart
)
{
int
err
;
if
((
err
=
virFileMakePath
(
driver
->
autostartDir
)))
{
virReportSystemError
(
dom
->
conn
,
err
,
_
(
"cannot create autostart directory %s"
),
driver
->
autostartDir
);
goto
cleanup
;
}
if
(
symlink
(
configFile
,
autostartLink
)
<
0
)
{
virReportSystemError
(
dom
->
conn
,
errno
,
_
(
"Failed to create symlink '%s to '%s'"
),
autostartLink
,
configFile
);
goto
cleanup
;
}
}
else
{
if
(
unlink
(
autostartLink
)
<
0
&&
errno
!=
ENOENT
&&
errno
!=
ENOTDIR
)
{
virReportSystemError
(
dom
->
conn
,
errno
,
_
(
"Failed to delete symlink '%s'"
),
autostartLink
);
goto
cleanup
;
}
}
vm
->
autostart
=
autostart
;
}
ret
=
0
;
cleanup:
VIR_FREE
(
configFile
);
VIR_FREE
(
autostartLink
);
if
(
vm
)
virDomainObjUnlock
(
vm
);
lxcDriverUnlock
(
driver
);
return
ret
;
}
static
char
*
lxcGetHostname
(
virConnectPtr
conn
)
{
char
*
result
;
...
...
@@ -1651,8 +1830,8 @@ static virDriver lxcDriver = {
lxcDomainUndefine
,
/* domainUndefine */
NULL
,
/* domainAttachDevice */
NULL
,
/* domainDetachDevice */
NULL
,
/* domainGetAutostart */
NULL
,
/* domainSetAutostart */
lxcDomainGetAutostart
,
/* domainGetAutostart */
lxcDomainSetAutostart
,
/* domainSetAutostart */
lxcGetSchedulerType
,
/* domainGetSchedulerType */
lxcGetSchedulerParameters
,
/* domainGetSchedulerParameters */
lxcSetSchedulerParameters
,
/* domainSetSchedulerParameters */
...
...
@@ -1678,6 +1857,7 @@ static virStateDriver lxcStateDriver = {
.
initialize
=
lxcStartup
,
.
cleanup
=
lxcShutdown
,
.
active
=
lxcActive
,
.
reload
=
lxcReload
,
};
int
lxcRegister
(
void
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录