Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
4f3c2e39
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f3c2e39
编写于
9月 17, 2014
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
qemu: hook: Provide hook when restoring a domain save image
上级
a552a86e
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
78 addition
and
7 deletion
+78
-7
docs/hooks.html.in
docs/hooks.html.in
+11
-0
src/qemu/qemu_driver.c
src/qemu/qemu_driver.c
+64
-6
src/util/virhook.c
src/util/virhook.c
+2
-1
src/util/virhook.h
src/util/virhook.h
+1
-0
未找到文件。
docs/hooks.html.in
浏览文件 @
4f3c2e39
...
...
@@ -177,6 +177,17 @@
script returns failure or the output XML is not valid, incoming
migration will be canceled. This hook may be used, e.g., to change
location of disk images for incoming domains.
</li>
<li><span
class=
"since"
>
Since 1.2.9
</span>
, the qemu hook script is
also called when restoring a saved image either via the API or
automatically when restoring a managed save machine. It is called
as:
<pre>
/etc/libvirt/hooks/qemu guest_name restore begin -
</pre>
with domain XML sent to standard input of the script. In this case,
the script acts as a filter and is supposed to modify the domain
XML and print it out on its standard output. Empty output is
identical to copying the input XML without changing it. In case the
script returns failure or the output XML is not valid, restore of the
image will be aborted. This hook may be used, e.g., to change
location of disk images for restored domains.
</li>
<li><span
class=
"since"
>
Since 0.9.13
</span>
, the qemu hook script
is also called when the libvirtd daemon restarts and reconnects
to previously running QEMU processes. If the script fails, the
...
...
src/qemu/qemu_driver.c
浏览文件 @
4f3c2e39
...
...
@@ -5644,20 +5644,24 @@ qemuDomainRestoreFlags(virConnectPtr conn,
unsigned int flags)
{
virQEMUDriverPtr driver = conn->privateData;
qemuDomainObjPrivatePtr priv = NULL;
virDomainDefPtr def = NULL;
virDomainDefPtr newdef = NULL;
virDomainObjPtr vm = NULL;
char *xml = NULL;
char *xmlout = NULL;
const char *newxml = dxml;
int fd = -1;
int ret = -1;
virQEMUSaveHeader header;
virFileWrapperFdPtr wrapperFd = NULL;
bool hook_taint = false;
virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
VIR_DOMAIN_SAVE_RUNNING |
VIR_DOMAIN_SAVE_PAUSED, -1);
fd = qemuDomainSaveImageOpen(driver, path, &def, &header,
NULL
,
fd = qemuDomainSaveImageOpen(driver, path, &def, &header,
&xml
,
(flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0,
&wrapperFd, false, false);
if (fd < 0)
...
...
@@ -5666,12 +5670,31 @@ qemuDomainRestoreFlags(virConnectPtr conn,
if (virDomainRestoreFlagsEnsureACL(conn, def) < 0)
goto cleanup;
if (dxml) {
if (!(newdef = qemuDomainSaveImageUpdateDef(driver, def, dxml)))
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
int hookret;
if ((hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name,
VIR_HOOK_QEMU_OP_RESTORE,
VIR_HOOK_SUBOP_BEGIN,
NULL,
dxml ? dxml : xml,
&xmlout)) < 0)
goto cleanup;
if (hookret == 0 && xmlout) {
VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout);
hook_taint = true;
newxml = xmlout;
}
}
if (newxml) {
virDomainDefPtr tmp;
if (!(tmp = qemuDomainSaveImageUpdateDef(driver, def, newxml)))
goto cleanup;
virDomainDefFree(def);
def =
newdef
;
def =
tmp
;
}
if (!(vm = virDomainObjListAdd(driver->domains, def,
...
...
@@ -5687,6 +5710,11 @@ qemuDomainRestoreFlags(virConnectPtr conn,
else if (flags & VIR_DOMAIN_SAVE_PAUSED)
header.was_running = 0;
if (hook_taint) {
priv = vm->privateData;
priv->hookRun = true;
}
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
...
...
@@ -5705,6 +5733,8 @@ qemuDomainRestoreFlags(virConnectPtr conn,
cleanup:
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
VIR_FREE(xml);
VIR_FREE(xmlout);
virFileWrapperFdFree(wrapperFd);
if (vm)
virObjectUnlock(vm);
...
...
@@ -5842,12 +5872,15 @@ qemuDomainObjRestore(virConnectPtr conn,
bool bypass_cache)
{
virDomainDefPtr def = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
int fd = -1;
int ret = -1;
char *xml = NULL;
char *xmlout = NULL;
virQEMUSaveHeader header;
virFileWrapperFdPtr wrapperFd = NULL;
fd = qemuDomainSaveImageOpen(driver, path, &def, &header,
NULL
,
fd = qemuDomainSaveImageOpen(driver, path, &def, &header,
&xml
,
bypass_cache, &wrapperFd, false, true);
if (fd < 0) {
if (fd == -3)
...
...
@@ -5855,6 +5888,29 @@ qemuDomainObjRestore(virConnectPtr conn,
goto cleanup;
}
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
int hookret;
if ((hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name,
VIR_HOOK_QEMU_OP_RESTORE,
VIR_HOOK_SUBOP_BEGIN,
NULL, xml, &xmlout)) < 0)
goto cleanup;
if (hookret == 0 && xmlout) {
virDomainDefPtr tmp;
VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout);
if (!(tmp = qemuDomainSaveImageUpdateDef(driver, def, xmlout)))
goto cleanup;
virDomainDefFree(def);
def = tmp;
priv->hookRun = true;
}
}
if (STRNEQ(vm->def->name, def->name) ||
memcmp(vm->def->uuid, def->uuid, VIR_UUID_BUFLEN)) {
char vm_uuidstr[VIR_UUID_STRING_BUFLEN];
...
...
@@ -5878,6 +5934,8 @@ qemuDomainObjRestore(virConnectPtr conn,
VIR_WARN("Failed to close %s", path);
cleanup:
VIR_FREE(xml);
VIR_FREE(xmlout);
virDomainDefFree(def);
VIR_FORCE_CLOSE(fd);
virFileWrapperFdFree(wrapperFd);
...
...
src/util/virhook.c
浏览文件 @
4f3c2e39
...
...
@@ -77,7 +77,8 @@ VIR_ENUM_IMPL(virHookQemuOp, VIR_HOOK_QEMU_OP_LAST,
"migrate"
,
"started"
,
"reconnect"
,
"attach"
)
"attach"
,
"restore"
)
VIR_ENUM_IMPL
(
virHookLxcOp
,
VIR_HOOK_LXC_OP_LAST
,
"start"
,
...
...
src/util/virhook.h
浏览文件 @
4f3c2e39
...
...
@@ -60,6 +60,7 @@ typedef enum {
VIR_HOOK_QEMU_OP_STARTED
,
/* domain has started */
VIR_HOOK_QEMU_OP_RECONNECT
,
/* domain is being reconnected by libvirt */
VIR_HOOK_QEMU_OP_ATTACH
,
/* domain is being attached to be libvirt */
VIR_HOOK_QEMU_OP_RESTORE
,
/* domain is being restored */
VIR_HOOK_QEMU_OP_LAST
,
}
virHookQemuOpType
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录