1 Star 0 Fork 70

mds.lanruo/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qemu-command-Generate-commandline-of-sev0-sev-guest-.patch 4.05 KB
一键复制 编辑 原始数据 按行查看 历史
yezengruan 提交于 2022-03-24 14:54 . update patch with openeuler !58
From 2626cba5134d81501f0fcc138c0f6d3427f7656e Mon Sep 17 00:00:00 2001
From: Yan Wang <[email protected]>
Date: Thu, 24 Mar 2022 12:37:24 +0800
Subject: [PATCH 08/16] qemu: command: Generate commandline of 'sev0' sev-guest
object via JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
While the 'sev0' sev-guest object will never be hotplugged, but we want
to generate it through JSON so that we'll be able to validate all
parameters of '-object' against the QAPI schema once 'object-add' is
qapified in qemu.
Signed-off-by: Peter Krempa <[email protected]>
Reviewed-by: Ján Tomko <[email protected]>
Signed-off-by: Yan Wang <[email protected]>
---
src/qemu/qemu_command.c | 32 +++++++++++--------
.../launch-security-sev.x86_64-2.12.0.args | 2 +-
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6a861f3c8f..4ec661e4b5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9392,9 +9392,11 @@ static int
qemuBuildSEVCommandLine(virDomainObjPtr vm, virCommandPtr cmd,
virDomainSEVDefPtr sev)
{
+ g_autoptr(virJSONValue) props = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
qemuDomainObjPrivatePtr priv = vm->privateData;
- char *path = NULL;
+ g_autofree char *dhpath = NULL;
+ g_autofree char *sessionpath = NULL;
if (!sev)
return 0;
@@ -9402,21 +9404,23 @@ qemuBuildSEVCommandLine(virDomainObjPtr vm, virCommandPtr cmd,
VIR_DEBUG("policy=0x%x cbitpos=%d reduced_phys_bits=%d",
sev->policy, sev->cbitpos, sev->reduced_phys_bits);
- virBufferAsprintf(&buf, "sev-guest,id=sev0,cbitpos=%d", sev->cbitpos);
- virBufferAsprintf(&buf, ",reduced-phys-bits=%d", sev->reduced_phys_bits);
- virBufferAsprintf(&buf, ",policy=0x%x", sev->policy);
+ if (sev->dh_cert)
+ dhpath = g_strdup_printf("%s/dh_cert.base64", priv->libDir);
- if (sev->dh_cert) {
- path = g_strdup_printf("%s/dh_cert.base64", priv->libDir);
- virBufferAsprintf(&buf, ",dh-cert-file=%s", path);
- VIR_FREE(path);
- }
+ if (sev->session)
+ sessionpath = g_strdup_printf("%s/session.base64", priv->libDir);
- if (sev->session) {
- path = g_strdup_printf("%s/session.base64", priv->libDir);
- virBufferAsprintf(&buf, ",session-file=%s", path);
- VIR_FREE(path);
- }
+ if (qemuMonitorCreateObjectProps(&props, "sev-guest", "sev0",
+ "u:cbitpos", sev->cbitpos,
+ "u:reduced-phys-bits", sev->reduced_phys_bits,
+ "u:policy", sev->policy,
+ "S:dh-cert-file", dhpath,
+ "S:session-file", sessionpath,
+ NULL) < 0)
+ return -1;
+
+ if (virQEMUBuildObjectCommandlineFromJSON(&buf, props) < 0)
+ return -1;
virCommandAddArg(cmd, "-object");
virCommandAddArgBuffer(cmd, &buf);
diff --git a/tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args b/tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args
index 378c3b681c..9fad85737a 100644
--- a/tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args
+++ b/tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args
@@ -29,7 +29,7 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
--object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=1,policy=0x1,\
+-object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=1,policy=1,\
dh-cert-file=/tmp/lib/domain--1-QEMUGuest1/dh_cert.base64,\
session-file=/tmp/lib/domain--1-QEMUGuest1/session.base64 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mdslanruo/libvirt.git
[email protected]:mdslanruo/libvirt.git
mdslanruo
libvirt
libvirt
master

搜索帮助