1 Star 0 Fork 98

misaka00251/systemd

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-virt-detect-OpenStack-Nova-instance.patch 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
From 01d9fbccddd694bc584aed24eaa0543f831dc929 Mon Sep 17 00:00:00 2001
From: wangyuhang <wangyuhang27@huawei.com>
Date: Tue, 19 Apr 2022 21:05:25 +0800
Subject: [PATCH] virt: detect OpenStack Nova instance
Conflict:add testcase for virt detect OpenStack Nova instance
Reference:https://github.com/systemd/systemd/commit/01d9fbccddd694bc584aed24eaa0543f831dc929
---
src/basic/virt.c | 1 +
src/test/meson.build | 14 ++
src/test/test-virt.c | 39 ++++++++++++++++++++++++++++++
3 file changed, 54 insertion(+)
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 7e88f09..d8740cf 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -154,6 +154,7 @@ static int detect_vm_dmi_vendor(void) {
int id;
} dmi_vendor_table[] = {
{ "KVM", VIRTUALIZATION_KVM },
+ { "OpenStack", VIRTUALIZATION_KVM }, /* Detect OpenStack instance as KVM in non x86 architecture */
{ "Amazon EC2", VIRTUALIZATION_AMAZON },
{ "QEMU", VIRTUALIZATION_QEMU },
{ "VMware", VIRTUALIZATION_VMWARE }, /* https://kb.vmware.com/s/article/1009458 */
diff --git a/src/test/meson.build b/src/test/meson.build
index e106059..ea64a12 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -602,6 +602,14 @@ tests += [
[['src/test/test-nscd-flush.c'],
[], [], [], 'ENABLE_NSCD', 'manual'],
+
+ [['src/test/test-virt.c',
+ 'src/basic/virt.c',
+ 'src/basic/virt.h'],
+ [libcore,
+ libshared],
+ [],
+ core_includes],
]
############################################################
diff --git a/src/test/test-virt.c b/src/test/test-virt.c
new file mode 100644
index 0000000..17cc22e
--- /dev/null
+++ b/src/test/test-virt.c
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sched.h>
+
+#include "string-util.h"
+#include "fileio.h"
+#include "virt.h"
+#include "log.h"
+#include "tests.h"
+
+static void detect_virt(const char *vendor) {
+ assert_se(write_string_file("/sys/class/dmi/id/product_name", vendor,
+ WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755) == 0);
+
+ assert_se(detect_virtualization() == VIRTUALIZATION_KVM);
+}
+
+int main(int argc, char *argv[]) {
+ char template[] = "/tmp/test-virt.XXXXXX";
+ assert_se(mkdtemp(template));
+
+ if (geteuid() > 0 && unshare(CLONE_NEWUSER) != 0) {
+ (void) log_tests_skipped("Don't have namespace support");
+ return EXIT_TEST_SKIP;
+ }
+
+ if (chroot(template) != 0) {
+ (void) log_tests_skipped("Don't have chroot support");
+ return EXIT_TEST_SKIP;
+ }
+
+#if defined(__arm__) || defined(__aarch64__)
+ detect_virt("OpenStack Nova");
+#endif
+
+ return 0;
+}
\ No newline at end of file
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/misaka00251/systemd.git
git@gitee.com:misaka00251/systemd.git
misaka00251
systemd
systemd
master

搜索帮助