Skip to contentSkip to conversation

9p: Print error hints if option parsing fails

PATCH In review Greg Kurz 2 participants 3 messages Sep 13, 2019 – Sep 15, 2019

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 9p: Print error hints if option parsing fails

Option parsing fonctions are called with &error_fatal, which causes error_setg() to call exit() and the hints are never printed.

Use an intermediate error object so that exit() happens in error_propagate() after error_append_hint() could be called.

---
 hw/9pfs/9p-local.c |   11 +++++++----
 hw/9pfs/9p-proxy.c |   11 +++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)
hw/9pfs/9p-local.c +7 -4
index 6f7309f4e691..2c80d2ac30f5 100644
@@ -1486,8 +1486,9 @@ static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
     Error *local_err = NULL;
 
     if (!sec_model) {
-        error_setg(errp, "security_model property not set");
-        error_append_security_model_hint(errp);
+        error_setg(&local_err, "security_model property not set");
+        error_append_security_model_hint(&local_err);
+        error_propagate(errp, local_err);
         return -1;
     }
 
@@ -1501,8 +1502,10 @@ static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)
     } else if (!strcmp(sec_model, "mapped-file")) {
         fse->export_flags |= V9FS_SM_MAPPED_FILE;
     } else {
-        error_setg(errp, "invalid security_model property '%s'", sec_model);
-        error_append_security_model_hint(errp);
+        error_setg(&local_err, "invalid security_model property '%s'",
+                   sec_model);
+        error_append_security_model_hint(&local_err);
+        error_propagate(errp, local_err);
         return -1;
     }
 
hw/9pfs/9p-proxy.c +7 -4
index 97ab9c58a573..5de5e53702f7 100644
@@ -1126,15 +1126,18 @@ static int proxy_parse_opts(QemuOpts *opts, FsDriverEntry *fs, Error **errp)
 {
     const char *socket = qemu_opt_get(opts, "socket");
     const char *sock_fd = qemu_opt_get(opts, "sock_fd");
+    Error *local_err = NULL;
 
     if (!socket && !sock_fd) {
-        error_setg(errp, "both socket and sock_fd properties are missing");
-        error_append_socket_sockfd_hint(errp);
+        error_setg(&local_err, "both socket and sock_fd properties are missing");
+        error_append_socket_sockfd_hint(&local_err);
+        error_propagate(errp, local_err);
         return -1;
     }
     if (socket && sock_fd) {
-        error_setg(errp, "both socket and sock_fd properties are set");
-        error_append_socket_sockfd_hint(errp);
+        error_setg(&local_err, "both socket and sock_fd properties are set");
+        error_append_socket_sockfd_hint(&local_err);
+        error_propagate(errp, local_err);
         return -1;
     }
     if (socket) {
#1 lore raw
Quoted 1 line · Greg Kurz

Option parsing fonctions are called with &error_fatal, which

functions

Quoted 5 lines

causes error_setg() to call exit() and the hints are never printed.

Use an intermediate error object so that exit() happens in error_propagate() after error_append_hint() could be called.

Hmm.

Code that creates error objects should not need to know how they are handled.

Your patch shows that error_append_hint() requires error_propagate() to work regardless of how the error is handled. We should amend error_append_hint()'s contract in error.h to spell this out, and search the tree for more misuse of error_append_hint().

author
#2 lore raw
Quoted 9 lines · On Sat, 14 Sep 2019 20:59:46 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 1 line · Greg Kurz

Option parsing fonctions are called with &error_fatal, which

functions

Quoted 3 lines

causes error_setg() to call exit() and the hints are never printed.

Quoted 8 lines
Quoted 2 lines

Use an intermediate error object so that exit() happens in error_propagate() after error_append_hint() could be called.

Hmm.

Code that creates error objects should not need to know how they are handled.

Agreed.

Quoted 4 lines

Your patch shows that error_append_hint() requires error_propagate() to work regardless of how the error is handled. We should amend error_append_hint()'s contract in error.h to spell this out, and search the tree for more misuse of error_append_hint().

Sure. I'll take care of that.

Cheers,

--
Greg