From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Stefan Berger" <stefanb@linux.ibm.com>
Subject: [PATCH-for-5.1 v2 2/2] tpm: List the available TPM backends
Date: Thu, 23 Jul 2020 12:39:39 +0200 [thread overview]
Message-ID: <20200723103939.19624-3-philmd@redhat.com> (raw)
In-Reply-To: <20200723103939.19624-1-philmd@redhat.com>
When an incorrect backend is selected, tpm_display_backend_drivers()
is supposed to list the available backends. However the error is
directly propagated, and we never display the list. The user only
gets "Parameter 'type' expects a TPM backend type" error.
Convert the fprintf(stderr,) calls to error hints propagated with
the error.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Since v1:
- Use g_assert_not_reached after processing 'help' in tpm_config_parse
---
tpm.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/tpm.c b/tpm.c
index e36803a64d..f883340d1a 100644
--- a/tpm.c
+++ b/tpm.c
@@ -58,23 +58,21 @@ static int tpm_backend_drivers_count(void)
}
/*
- * Walk the list of available TPM backend drivers and display them on the
- * screen.
+ * Walk the list of available TPM backend drivers and list them as Error hint.
*/
-static void tpm_display_backend_drivers(void)
+static void tpm_list_backend_drivers_hint(Error **errp)
{
int i;
- fprintf(stderr, "Supported TPM types (choose only one):\n");
+ error_append_hint(errp, "Supported TPM types (choose only one):\n");
for (i = 0; i < TPM_TYPE__MAX; i++) {
const TPMBackendClass *bc = tpm_be_find_by_type(i);
if (!bc) {
continue;
}
- fprintf(stderr, "%12s %s\n", TpmType_str(i), bc->desc);
+ error_append_hint(errp, "%12s %s\n", TpmType_str(i), bc->desc);
}
- fprintf(stderr, "\n");
}
/*
@@ -97,6 +95,7 @@ TPMBackend *qemu_find_tpm_be(const char *id)
static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
{
+ ERRP_GUARD();
const char *value;
const char *id;
const TPMBackendClass *be;
@@ -122,7 +121,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
value = qemu_opt_get(opts, "type");
if (!value) {
error_setg(errp, QERR_MISSING_PARAMETER, "type");
- tpm_display_backend_drivers();
+ tpm_list_backend_drivers_hint(errp);
return 1;
}
@@ -131,7 +130,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
if (be == NULL) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
"a TPM backend type");
- tpm_display_backend_drivers();
+ tpm_list_backend_drivers_hint(errp);
return 1;
}
@@ -184,8 +183,8 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
QemuOpts *opts;
if (!strcmp(optarg, "help")) {
- tpm_display_backend_drivers();
- return -1;
+ tpm_list_backend_drivers_hint(&error_fatal);
+ g_assert_not_reached(); /* Using &error_fatal triggers exit(1). */
}
opts = qemu_opts_parse_noisily(opts_list, optarg, true);
if (!opts) {
--
2.21.3
next prev parent reply other threads:[~2020-07-23 10:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-23 10:39 [PATCH-for-5.1 v2 0/2] tpm: Improve error reporting Philippe Mathieu-Daudé
2020-07-23 10:39 ` [PATCH-for-5.1 v2 1/2] tpm: Display when no backend is available Philippe Mathieu-Daudé
2020-07-23 10:39 ` Philippe Mathieu-Daudé [this message]
2020-07-23 10:50 ` [PATCH-for-5.1 v2 2/2] tpm: List the available TPM backends Philippe Mathieu-Daudé
2020-07-23 12:13 ` [PATCH-for-5.1 v2 0/2] tpm: Improve error reporting Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200723103939.19624-3-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanb@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).