systemd/1028-detect-virt-add-list-cvm-option.patch

93 lines
3.9 KiB
Diff
Raw Normal View History

From a7d640fa28095c246b4c648bc6052fd4d091f268 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Fri, 30 Jun 2023 19:07:29 +0100
Subject: [PATCH] detect-virt: add --list-cvm option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The --list-cvm option reports the known types of confidential virtualization
technology that can be detected.
Related: https://github.com/systemd/systemd/issues/27604
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit f460fec91524b6171183e70f03e10ab025bd1f03)
Related: RHEL-50651
---
man/systemd-detect-virt.xml | 6 ++++++
shell-completion/bash/systemd-detect-virt | 2 +-
src/detect-virt/detect-virt.c | 8 ++++++++
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/man/systemd-detect-virt.xml b/man/systemd-detect-virt.xml
index 9b24f061bb..5aaff839a4 100644
--- a/man/systemd-detect-virt.xml
+++ b/man/systemd-detect-virt.xml
@@ -276,6 +276,12 @@
<listitem><para>Output all currently known and detectable container and VM environments.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--list-cvm</option></term>
+
+ <listitem><para>Output all currently known and detectable confidential virtualization technologies.</para></listitem>
+ </varlistentry>
+
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
diff --git a/shell-completion/bash/systemd-detect-virt b/shell-completion/bash/systemd-detect-virt
index e67570e674..9ade2af220 100644
--- a/shell-completion/bash/systemd-detect-virt
+++ b/shell-completion/bash/systemd-detect-virt
@@ -29,7 +29,7 @@ _systemd_detect_virt() {
local -A OPTS=(
[STANDALONE]='-h --help --version -c --container -v --vm -q --quiet --cvm
- --private-users'
+ --private-users --list --list-cvm'
)
_init_completion || return
diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c
index 6b470642dd..9732e3731f 100644
--- a/src/detect-virt/detect-virt.c
+++ b/src/detect-virt/detect-virt.c
@@ -42,6 +42,8 @@ static int help(void) {
" --cvm Only detect whether we are run in a confidential VM\n"
" -q --quiet Don't output anything, just set return value\n"
" --list List all known and detectable types of virtualization\n"
+ " --list-cvm List all known and detectable types of confidential \n"
+ " virtualization\n"
"\nSee the %s for details.\n",
program_invocation_short_name,
link);
@@ -56,6 +58,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_PRIVATE_USERS,
ARG_LIST,
ARG_CVM,
+ ARG_LIST_CVM,
};
static const struct option options[] = {
@@ -68,6 +71,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "quiet", no_argument, NULL, 'q' },
{ "cvm", no_argument, NULL, ARG_CVM },
{ "list", no_argument, NULL, ARG_LIST },
+ { "list-cvm", no_argument, NULL, ARG_LIST_CVM },
{}
};
@@ -114,6 +118,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_mode = ONLY_CVM;
return 1;
+ case ARG_LIST_CVM:
+ DUMP_STRING_TABLE(confidential_virtualization, ConfidentialVirtualization, _CONFIDENTIAL_VIRTUALIZATION_MAX);
+ return 0;
+
case '?':
return -EINVAL;