Skip to contentSkip to conversation

error: prepare for auto propagated local_err

PATCH Superseded Vladimir Sementsov-Ogievskiy 6 participants 41 messages Dec 5, 2019 – Dec 6, 2019

Subsystems (2)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 cover error: prepare for auto propagated local_err

Hi all!

This is the first part of the bit series, which contains mostly simple cleanups.

v6 was sent in separate (I'm sorry for inconvenience)

v7: by Markus review (and with his prepared fixups, thanks a lot!):
- don't rename Error** paramters
- switch to Error *const * where appropriate
last patch is new and replaces
"nbd: well form nbd_iter_channel_error errp handler"

Vladimir Sementsov-Ogievskiy (21):
hw/core/loader-fit: fix freeing errp in fit_load_fdt net/net: Clean up variable shadowing in net_client_init()
error: rename errp to errp_in where it is IN-argument
hmp: drop Error pointer indirection in hmp_handle_error
vnc: drop Error pointer indirection in vnc_client_io_error
qdev-monitor: well form error hint helpers
ppc: well form kvmppc_hint_smt_possible error hint helper 9pfs: well form error hint helpers
hw/core/qdev: cleanup Error ** variables
block/snapshot: rename Error ** parameter to more common errp hw/i386/amd_iommu: rename Error ** parameter to more common errp
qga: rename Error ** parameter to more common errp monitor/qmp-cmds: rename Error ** parameter to more common errp hw/s390x: rename Error ** parameter to more common errp hw/sd: drop extra whitespace in sdhci_sysbus_realize() header hw/tpm: rename Error ** parameter to more common errp hw/usb: rename Error ** parameter to more common errp include/qom/object.h: rename Error ** parameter to more common errp backends/cryptodev: drop local_err from cryptodev_backend_complete() hw/vfio/ap: drop local_err from vfio_ap_realize
nbd: assert that Error** is not NULL in nbd_iter_channel_error

Cc "Gonglei (Arei)" <[email protected]>
Cc Eric Blake <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc "Marc-André Lureau" <[email protected]>
Cc Greg Kurz <[email protected]>
Cc Paul Burton <[email protected]>
Cc Aleksandar Rikalo <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc "Daniel P. Berrangé" <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Richard Henderson <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Marcel Apfelbaum <[email protected]>
Cc David Gibson <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Halil Pasic <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Stefan Berger <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Tony Krowiak <[email protected]>
Cc Pierre Morel <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Michael Roth <[email protected]>
Cc "Dr. David Alan Gilbert" <[email protected]>
Cc Jason Wang <[email protected]>
 include/block/snapshot.h   |   2 +-
 include/monitor/hmp.h      |   2 +-
 include/qapi/error.h       |   6 +-
 include/qom/object.h       |   4 +-
 target/ppc/kvm_ppc.h       |   4 +-
 ui/vnc.h                   |   2 +-
 backends/cryptodev.c       |  11 +--
 block/nbd.c                |   1 +
 block/snapshot.c           |   4 +-
 dump/dump-hmp-cmds.c       |   4 +-
 hw/9pfs/9p-local.c         |   2 +-
 hw/9pfs/9p-proxy.c         |   2 +-
 hw/core/loader-fit.c       |   5 +-
 hw/core/machine-hmp-cmds.c |   6 +-
 hw/core/qdev.c             |  28 ++++---
 hw/i386/amd_iommu.c        |  14 ++--
 hw/ppc/spapr.c             |   2 +-
 hw/s390x/event-facility.c  |   2 +-
 hw/s390x/s390-stattrib.c   |   3 +-
 hw/sd/sdhci.c              |   2 +-
 hw/tpm/tpm_emulator.c      |   8 +-
 hw/usb/dev-network.c       |   2 +-
 hw/vfio/ap.c               |   9 +--
 monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
 monitor/qmp-cmds.c         |   2 +-
 net/net.c                  |  17 ++--
 qdev-monitor.c             |  16 ++--
 qga/commands-posix.c       |   2 +-
 qga/commands-win32.c       |   2 +-
 qga/commands.c             |  12 +--
 qom/qom-hmp-cmds.c         |   4 +-
 target/ppc/kvm.c           |   2 +-
 ui/vnc.c                   |  20 ++---
 util/error.c               |   6 +-
 34 files changed, 173 insertions(+), 190 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v7 1/21 hw/core/loader-fit: fix freeing errp in fit_load_fdt

fit_load_fdt forget to check that errp is not NULL and to zero it after freeing. Fix it.

---
 hw/core/loader-fit.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/core/loader-fit.c +4 -1
index 953b16bc82..3ee9fb2f2e 100644
@@ -200,7 +200,10 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
     err = fit_image_addr(itb, img_off, "load", &load_addr, errp);
     if (err == -ENOENT) {
         load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
-        error_free(*errp);
+        if (errp) {
+            error_free(*errp);
+            *errp = NULL;
+        }
     } else if (err) {
         error_prepend(errp, "unable to read FDT load address from FIT: ");
         ret = err;
Signature · 1 line
2.21.0
#2 lore raw

PATCH v7 2/21 net/net: Clean up variable shadowing in net_client_init()

In reply to Vladimir Sementsov-Ogievskiy

Variable int err in inner scope shadows Error *err in outer scope.

---
 net/net.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
net/net.c +7 -10
index 84aa6d8d00..9e93c3f8a1 100644
@@ -1126,16 +1126,13 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
 
             prefix_addr = substrings[0];
 
-            if (substrings[1]) {
-                /* User-specified prefix length.  */
-                int err;
-
-                err = qemu_strtoul(substrings[1], NULL, 10, &prefix_len);
-                if (err) {
-                    error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
-                               "ipv6-prefixlen", "a number");
-                    goto out;
-                }
+            /* Handle user-specified prefix length. */
+            if (substrings[1] &&
+                qemu_strtoul(substrings[1], NULL, 10, &prefix_len))
+            {
+                error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                           "ipv6-prefixlen", "a number");
+                goto out;
             }
 
             qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort);
Signature · 1 line
2.21.0
#3 lore raw

PATCH v7 3/21 error: rename errp to errp_in where it is IN-argument

In reply to Vladimir Sementsov-Ogievskiy

Error **errp is almost always OUT-argument: it's assumed to be NULL, or pointer to NULL-initialized pointer, or pointer to error_abort or error_fatal, for callee to report error.

But very few functions instead get Error **errp as IN-argument:
it's assumed to be set (or, maybe, NULL), and callee should clean it, or add some information.

In such cases, rename errp to errp_in.

This patch updates only error API functions. There still a few functions with errp-in semantics, they will be updated in further commits.

---
 include/qapi/error.h | 6 +++---
 util/error.c         | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
include/qapi/error.h +3 -3
index 3f95141a01..ad5b6e896d 100644
@@ -233,13 +233,13 @@ void error_propagate_prepend(Error **dst_errp, Error *local_err,
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, @ap like vprintf().
  */
-void error_vprepend(Error **errp, const char *fmt, va_list ap);
+void error_vprepend(Error *const *errp, const char *fmt, va_list ap);
 
 /*
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, ... like printf().
  */
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error *const *errp, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
@@ -256,7 +256,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
  * May be called multiple times.  The resulting hint should end with a
  * newline.
  */
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error *const *errp, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
util/error.c +3 -3
index d4532ce318..b6c89d1412 100644
@@ -121,7 +121,7 @@ void error_setg_file_open_internal(Error **errp,
                               "Could not open '%s'", filename);
 }
 
-void error_vprepend(Error **errp, const char *fmt, va_list ap)
+void error_vprepend(Error *const *errp, const char *fmt, va_list ap)
 {
     GString *newmsg;
 
@@ -136,7 +136,7 @@ void error_vprepend(Error **errp, const char *fmt, va_list ap)
     (*errp)->msg = g_string_free(newmsg, 0);
 }
 
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error *const *errp, const char *fmt, ...)
 {
     va_list ap;
 
@@ -145,7 +145,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
     va_end(ap);
 }
 
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error *const *errp, const char *fmt, ...)
 {
     va_list ap;
     int saved_errno = errno;
Signature · 1 line
2.21.0
#4 lore raw

Re: [PATCH v7 03/21] error: rename errp to errp_in where it is IN-argument

Quoted 10 lines · On Thu, 5 Dec 2019 18:20:01 +0300 Vladimir Sementsov-Ogievskiy…

Error **errp is almost always OUT-argument: it's assumed to be NULL, or pointer to NULL-initialized pointer, or pointer to error_abort or error_fatal, for callee to report error.

But very few functions instead get Error **errp as IN-argument:
it's assumed to be set (or, maybe, NULL), and callee should clean it, or add some information.

In such cases, rename errp to errp_in.

This is no longer what the patch does. The subject needs to be amended too.

Quoted 70 lines

This patch updates only error API functions. There still a few functions with errp-in semantics, they will be updated in further commits.

---
 include/qapi/error.h | 6 +++---
 util/error.c         | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
include/qapi/error.h +3 -3
index 3f95141a01..ad5b6e896d 100644
@@ -233,13 +233,13 @@ void error_propagate_prepend(Error **dst_errp, Error *local_err,
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, @ap like vprintf().
  */
-void error_vprepend(Error **errp, const char *fmt, va_list ap);
+void error_vprepend(Error *const *errp, const char *fmt, va_list ap);
 
 /*
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, ... like printf().
  */
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error *const *errp, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
@@ -256,7 +256,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
  * May be called multiple times.  The resulting hint should end with a
  * newline.
  */
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error *const *errp, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
util/error.c +3 -3
index d4532ce318..b6c89d1412 100644
@@ -121,7 +121,7 @@ void error_setg_file_open_internal(Error **errp,
                               "Could not open '%s'", filename);
 }
 
-void error_vprepend(Error **errp, const char *fmt, va_list ap)
+void error_vprepend(Error *const *errp, const char *fmt, va_list ap)
 {
     GString *newmsg;
 
@@ -136,7 +136,7 @@ void error_vprepend(Error **errp, const char *fmt, va_list ap)
     (*errp)->msg = g_string_free(newmsg, 0);
 }
 
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error *const *errp, const char *fmt, ...)
 {
     va_list ap;
 
@@ -145,7 +145,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
     va_end(ap);
 }
 
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error *const *errp, const char *fmt, ...)
 {
     va_list ap;
     int saved_errno = errno;
#5 lore raw

PATCH v7 4/21 hmp: drop Error pointer indirection in hmp_handle_error

In reply to Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call. Use Error * instead.

---
 include/monitor/hmp.h      |   2 +-
 dump/dump-hmp-cmds.c       |   4 +-
 hw/core/machine-hmp-cmds.c |   6 +-
 monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
 qdev-monitor.c             |   4 +-
 qom/qom-hmp-cmds.c         |   4 +-
 6 files changed, 87 insertions(+), 88 deletions(-)
include/monitor/hmp.h +1 -1
index a0e9511440..3d329853b2 100644
@@ -16,7 +16,7 @@
 
 #include "qemu/readline.h"
 
-void hmp_handle_error(Monitor *mon, Error **errp);
+void hmp_handle_error(Monitor *mon, Error *err);
 
 void hmp_info_name(Monitor *mon, const QDict *qdict);
 void hmp_info_version(Monitor *mon, const QDict *qdict);
dump/dump-hmp-cmds.c +2 -2
index 3dbf44372c..e5053b04cd 100644
@@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     if (zlib + lzo + snappy + win_dmp > 1) {
         error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -66,7 +66,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
                           has_length, length, true, dump_format, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
     g_free(prot);
 }
 
hw/core/machine-hmp-cmds.c +3 -3
index cd970cc4c5..b76f7223af 100644
@@ -55,7 +55,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
 
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
@@ -66,7 +66,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
     CpuInstanceProperties *c;
 
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -135,7 +135,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 
     qapi_free_MemdevList(memdev_list);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_numa(Monitor *mon, const QDict *qdict)
monitor/hmp-cmds.c +77 -78

599 lines not on this page · raw message

qdev-monitor.c +2 -2
index e6b112eb0a..29ed73e56a 100644
@@ -890,7 +890,7 @@ void hmp_device_add(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_add((QDict *)qdict, NULL, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_device_del(Monitor *mon, const QDict *qdict)
@@ -899,7 +899,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_del(id, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
qom/qom-hmp-cmds.c +2 -2
index a268e01eb4..cd08233a4c 100644
@@ -37,7 +37,7 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
         }
         qapi_free_ObjectPropertyInfoList(start);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_qom_set(Monitor *mon, const QDict *qdict)
@@ -59,7 +59,7 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
         }
         object_property_parse(obj, value, property, &err);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 typedef struct QOMCompositionState {
Signature · 1 line
2.21.0
#6 lore raw

PATCH v7 5/21 vnc: drop Error pointer indirection in vnc_client_io_error

In reply to Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call, or NULL. Use Error * instead.

---
 ui/vnc.h |  2 +-
 ui/vnc.c | 20 +++++++-------------
 2 files changed, 8 insertions(+), 14 deletions(-)
ui/vnc.h +1 -1
index fea79c2fc9..4e2637ce6c 100644
@@ -547,7 +547,7 @@ uint32_t read_u32(uint8_t *data, size_t offset);
 
 /* Protocol stage functions */
 void vnc_client_error(VncState *vs);
-size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp);
+size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err);
 
 void start_client_init(VncState *vs);
 void start_auth_vnc(VncState *vs);
ui/vnc.c +7 -13
index 87b8045afe..4100d6e404 100644
@@ -1312,7 +1312,7 @@ void vnc_disconnect_finish(VncState *vs)
     g_free(vs);
 }
 
-size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
+size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err)
 {
     if (ret <= 0) {
         if (ret == 0) {
@@ -1320,15 +1320,11 @@ size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
             vnc_disconnect_start(vs);
         } else if (ret != QIO_CHANNEL_ERR_BLOCK) {
             trace_vnc_client_io_error(vs, vs->ioc,
-                                      errp ? error_get_pretty(*errp) :
-                                      "Unknown");
+                                      err ? error_get_pretty(err) : "Unknown");
             vnc_disconnect_start(vs);
         }
 
-        if (errp) {
-            error_free(*errp);
-            *errp = NULL;
-        }
+        error_free(err);
         return 0;
     }
     return ret;
@@ -1361,10 +1357,9 @@ size_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
 {
     Error *err = NULL;
     ssize_t ret;
-    ret = qio_channel_write(
-        vs->ioc, (const char *)data, datalen, &err);
+    ret = qio_channel_write(vs->ioc, (const char *)data, datalen, &err);
     VNC_DEBUG("Wrote wire %p %zd -> %ld\n", data, datalen, ret);
-    return vnc_client_io_error(vs, ret, &err);
+    return vnc_client_io_error(vs, ret, err);
 }
 
 
@@ -1488,10 +1483,9 @@ size_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
 {
     ssize_t ret;
     Error *err = NULL;
-    ret = qio_channel_read(
-        vs->ioc, (char *)data, datalen, &err);
+    ret = qio_channel_read(vs->ioc, (char *)data, datalen, &err);
     VNC_DEBUG("Read wire %p %zd -> %ld\n", data, datalen, ret);
-    return vnc_client_io_error(vs, ret, &err);
+    return vnc_client_io_error(vs, ret, err);
 }
 
 
Signature · 1 line
2.21.0
#7 lore raw

PATCH v7 6/21 qdev-monitor: well form error hint helpers

In reply to Vladimir Sementsov-Ogievskiy

Make qbus_list_bus and qbus_list_dev hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename functions to be error_append_*_hint.

---
 qdev-monitor.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
qdev-monitor.c +7 -5
index 29ed73e56a..3465a1e2d0 100644
@@ -328,7 +328,8 @@ static Object *qdev_get_peripheral_anon(void)
     return dev;
 }
 
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void qbus_error_append_bus_list_hint(DeviceState *dev,
+                                            Error *const *errp)
 {
     BusState *child;
     const char *sep = " ";
@@ -342,7 +343,8 @@ static void qbus_list_bus(DeviceState *dev, Error **errp)
     error_append_hint(errp, "\n");
 }
 
-static void qbus_list_dev(BusState *bus, Error **errp)
+static void qbus_error_append_dev_list_hint(BusState *bus,
+                                            Error *const *errp)
 {
     BusChild *kid;
     const char *sep = " ";
@@ -500,7 +502,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         if (!dev) {
             error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
                       "Device '%s' not found", elem);
-            qbus_list_dev(bus, errp);
+            qbus_error_append_dev_list_hint(bus, errp);
             return NULL;
         }
 
@@ -518,7 +520,7 @@ static BusState *qbus_find(const char *path, Error **errp)
             if (dev->num_child_bus) {
                 error_setg(errp, "Device '%s' has multiple child buses",
                            elem);
-                qbus_list_bus(dev, errp);
+                qbus_error_append_bus_list_hint(dev, errp);
             } else {
                 error_setg(errp, "Device '%s' has no child bus", elem);
             }
@@ -534,7 +536,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
             error_setg(errp, "Bus '%s' not found", elem);
-            qbus_list_bus(dev, errp);
+            qbus_error_append_bus_list_hint(dev, errp);
             return NULL;
         }
     }
Signature · 1 line
2.21.0
#8 lore raw

Re: [PATCH v7 06/21] qdev-monitor: well form error hint helpers

Quoted 3 lines · Vladimir Sementsov-Ogievskiy

Make qbus_list_bus and qbus_list_dev hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename functions to be error_append_*_hint.

Commit message mentions a rename...

Quoted 11 lines
---
  qdev-monitor.c | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
qdev-monitor.c +0 -0
index 29ed73e56a..3465a1e2d0 100644

qdev-monitor.c static Object *qdev_get_peripheral_anon(void) · line 332

Quoted 6 lines
qdev-monitor.c +2 -1
@@ -328,7 +328,8 @@ static Object *qdev_get_peripheral_anon(void)
      return dev;
  }
 
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void qbus_error_append_bus_list_hint(DeviceState *dev,
+                                            Error *const *errp)

...but instead you did a type change with the name left unchanged. Commit message needs a fix.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#9 lore raw

Re: [PATCH v7 06/21] qdev-monitor: well form error hint helpers

Quoted 13 lines · Eric Blake
Quoted 3 lines · Vladimir Sementsov-Ogievskiy

Make qbus_list_bus and qbus_list_dev hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename functions to be error_append_*_hint.

Commit message mentions a rename...

Quoted 6 lines

---
  qdev-monitor.c | 12 +++++++-----

  1 file changed, 7 insertions(+), 5 deletions(-)
Quoted 13 lines

qdev-monitor.c static Object *qdev_get_peripheral_anon(void) · line 331

Quoted 10 lines
qdev-monitor.c +2 -1
index 29ed73e56a..3465a1e2d0 100644
@@ -328,7 +328,8 @@ static Object *qdev_get_peripheral_anon(void)
       return dev;
   }
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void qbus_error_append_bus_list_hint(DeviceState *dev,
+                                            Error *const *errp)

...but instead you did a type change with the name left unchanged. Commit message needs a fix.

Oops. I blindly take Markus's fixum, and didn't fix commit messages. I'll resend.

Signature · 2 lines
Best regards,
Vladimir
#10 lore raw

PATCH v7 7/21 ppc: well form kvmppc_hint_smt_possible error hint helper

In reply to Vladimir Sementsov-Ogievskiy

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be kvmppc_error_append_*_hint.

---
 target/ppc/kvm_ppc.h | 4 ++--
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
target/ppc/kvm_ppc.h +2 -2
index 98bd7d5da6..f22daabf51 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void kvmppc_error_append_smt_possible_hint(Error *const *errp);
 int kvmppc_set_smt_threads(int smt);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
     return 1;
 }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     return;
 }
hw/ppc/spapr.c +1 -1
index e076f6023c..1b87eb0ffd 100644
@@ -2564,7 +2564,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                       " requires the use of VSMT mode %d.\n",
                                       smp_threads, kvm_smt, spapr->vsmt);
                 }
-                kvmppc_hint_smt_possible(&local_err);
+                kvmppc_error_append_smt_possible_hint(&local_err);
                 goto out;
             }
         }
target/ppc/kvm.c +1 -1
index c77f9848ec..27ea3ce535 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
     return ret;
 }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     int i;
     GString *g;
Signature · 1 line
2.21.0
Reviewed-by on v7 7/21
#11 lore raw

Re: [PATCH v7 07/21] ppc: well form kvmppc_hint_smt_possible error hint helper

Quoted 6 lines · On Thu, 5 Dec 2019 18:20:05 +0300 Vladimir Sementsov-Ogievskiy…

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be kvmppc_error_append_*_hint.

---

The changelog needs to be amended. Apart from that:

Quoted 53 lines
 target/ppc/kvm_ppc.h | 4 ++--
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
target/ppc/kvm_ppc.h +2 -2
index 98bd7d5da6..f22daabf51 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void kvmppc_error_append_smt_possible_hint(Error *const *errp);
 int kvmppc_set_smt_threads(int smt);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
     return 1;
 }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     return;
 }
hw/ppc/spapr.c +1 -1
index e076f6023c..1b87eb0ffd 100644
@@ -2564,7 +2564,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                       " requires the use of VSMT mode %d.\n",
                                       smp_threads, kvm_smt, spapr->vsmt);
                 }
-                kvmppc_hint_smt_possible(&local_err);
+                kvmppc_error_append_smt_possible_hint(&local_err);
                 goto out;
             }
         }
target/ppc/kvm.c +1 -1
index c77f9848ec..27ea3ce535 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
     return ret;
 }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     int i;
     GString *g;
Acked-by on v7 7/21
#12 lore raw

Re: [PATCH v7 07/21] ppc: well form kvmppc_hint_smt_possible error hint helper

In reply to Vladimir Sementsov-Ogievskiy
Quoted 6 lines · Vladimir Sementsov-Ogievskiy

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be kvmppc_error_append_*_hint.

Signed-off-by: Vladimir Sementsov-Ogievskiy
<[email protected]>

Apart from Greg's point about the changelog,

Quoted 54 lines
---
 target/ppc/kvm_ppc.h | 4 ++--
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
target/ppc/kvm_ppc.h +2 -2
index 98bd7d5da6..f22daabf51 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void kvmppc_error_append_smt_possible_hint(Error *const *errp);
 int kvmppc_set_smt_threads(int smt);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
     return 1;
 }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     return;
 }
hw/ppc/spapr.c +1 -1
index e076f6023c..1b87eb0ffd 100644
@@ -2564,7 +2564,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                       " requires the use of VSMT mode %d.\n",
                                       smp_threads, kvm_smt, spapr->vsmt);
                 }
-                kvmppc_hint_smt_possible(&local_err);
+                kvmppc_error_append_smt_possible_hint(&local_err);
                 goto out;
             }
         }
target/ppc/kvm.c +1 -1
index c77f9848ec..27ea3ce535 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
     return ret;
 }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void kvmppc_error_append_smt_possible_hint(Error *const *errp)
 {
     int i;
     GString *g;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#13 lore raw

Re: [PATCH v7 07/21] ppc: well form kvmppc_hint_smt_possible error hint helper

Quoted 11 lines · David Gibson
Quoted 6 lines · Vladimir Sementsov-Ogievskiy

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be kvmppc_error_append_*_hint.

Signed-off-by: Vladimir Sementsov-Ogievskiy
<[email protected]>

Apart from Greg's point about the changelog,

Thanks! actually, v8 is out with fixed commit message

Quoted 56 lines
Quoted 55 lines
---
  target/ppc/kvm_ppc.h | 4 ++--
  hw/ppc/spapr.c       | 2 +-
  target/ppc/kvm.c     | 2 +-
  3 files changed, 4 insertions(+), 4 deletions(-)
target/ppc/kvm_ppc.h +2 -2
index 98bd7d5da6..f22daabf51 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
  int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
  void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
  int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void kvmppc_error_append_smt_possible_hint(Error *const *errp);
  int kvmppc_set_smt_threads(int smt);
  int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
  int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
      return 1;
  }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp)
  {
      return;
  }
hw/ppc/spapr.c +1 -1
index e076f6023c..1b87eb0ffd 100644
@@ -2564,7 +2564,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                        " requires the use of VSMT mode %d.\n",
                                        smp_threads, kvm_smt, spapr->vsmt);
                  }
-                kvmppc_hint_smt_possible(&local_err);
+                kvmppc_error_append_smt_possible_hint(&local_err);
                  goto out;
              }
          }
target/ppc/kvm.c +1 -1
index c77f9848ec..27ea3ce535 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
      return ret;
  }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void kvmppc_error_append_smt_possible_hint(Error *const *errp)
  {
      int i;
      GString *g;
Signature · 2 lines
Best regards,
Vladimir
#14 lore raw

PATCH v7 8/21 9pfs: well form error hint helpers

In reply to Vladimir Sementsov-Ogievskiy

Make error_append_security_model_hint and error_append_socket_sockfd_hint hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

---
 hw/9pfs/9p-local.c | 2 +-
 hw/9pfs/9p-proxy.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +1 -1
index 4708c0bd89..ca641390fb 100644
@@ -1473,7 +1473,7 @@ static void local_cleanup(FsContext *ctx)
     g_free(data);
 }
 
-static void error_append_security_model_hint(Error **errp)
+static void error_append_security_model_hint(Error *const *errp)
 {
     error_append_hint(errp, "Valid options are: security_model="
                       "[passthrough|mapped-xattr|mapped-file|none]\n");
hw/9pfs/9p-proxy.c +1 -1
index 97ab9c58a5..8136e1342d 100644
@@ -1114,7 +1114,7 @@ static int connect_namedsocket(const char *path, Error **errp)
     return sockfd;
 }
 
-static void error_append_socket_sockfd_hint(Error **errp)
+static void error_append_socket_sockfd_hint(Error *const *errp)
 {
     error_append_hint(errp, "Either specify socket=/some/path where /some/path"
                       " points to a listening AF_UNIX socket or sock_fd=fd"
Signature · 1 line
2.21.0
Acked-by on v7 8/21
#15 lore raw

Re: [PATCH v7 08/21] 9pfs: well form error hint helpers

Quoted 7 lines · On Thu, 5 Dec 2019 18:20:06 +0300 Vladimir Sementsov-Ogievskiy…

Make error_append_security_model_hint and error_append_socket_sockfd_hint hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

---

Quoted 30 lines
 hw/9pfs/9p-local.c | 2 +-
 hw/9pfs/9p-proxy.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +1 -1
index 4708c0bd89..ca641390fb 100644
@@ -1473,7 +1473,7 @@ static void local_cleanup(FsContext *ctx)
     g_free(data);
 }
 
-static void error_append_security_model_hint(Error **errp)
+static void error_append_security_model_hint(Error *const *errp)
 {
     error_append_hint(errp, "Valid options are: security_model="
                       "[passthrough|mapped-xattr|mapped-file|none]\n");
hw/9pfs/9p-proxy.c +1 -1
index 97ab9c58a5..8136e1342d 100644
@@ -1114,7 +1114,7 @@ static int connect_namedsocket(const char *path, Error **errp)
     return sockfd;
 }
 
-static void error_append_socket_sockfd_hint(Error **errp)
+static void error_append_socket_sockfd_hint(Error *const *errp)
 {
     error_append_hint(errp, "Either specify socket=/some/path where /some/path"
                       " points to a listening AF_UNIX socket or sock_fd=fd"
#16 lore raw

Re: [PATCH v7 08/21] 9pfs: well form error hint helpers

Quoted 8 lines · On Thu, 5 Dec 2019 18:08:56 +0100 Greg Kurz <[email protected]> wrote:
Quoted 5 lines · On Thu, 5 Dec 2019 18:20:06 +0300 Vladimir Sementsov-Ogievskiy…

Make error_append_security_model_hint and error_append_socket_sockfd_hint hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

Quoted 5 lines
Quoted 2 lines

---

With an updated changelog that no longer mentions errp_in :)

Quoted 31 lines
Quoted 30 lines
 hw/9pfs/9p-local.c | 2 +-
 hw/9pfs/9p-proxy.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +1 -1
index 4708c0bd89..ca641390fb 100644
@@ -1473,7 +1473,7 @@ static void local_cleanup(FsContext *ctx)
     g_free(data);
 }
 
-static void error_append_security_model_hint(Error **errp)
+static void error_append_security_model_hint(Error *const *errp)
 {
     error_append_hint(errp, "Valid options are: security_model="
                       "[passthrough|mapped-xattr|mapped-file|none]\n");
hw/9pfs/9p-proxy.c +1 -1
index 97ab9c58a5..8136e1342d 100644
@@ -1114,7 +1114,7 @@ static int connect_namedsocket(const char *path, Error **errp)
     return sockfd;
 }
 
-static void error_append_socket_sockfd_hint(Error **errp)
+static void error_append_socket_sockfd_hint(Error *const *errp)
 {
     error_append_hint(errp, "Either specify socket=/some/path where /some/path"
                       " points to a listening AF_UNIX socket or sock_fd=fd"
#17 lore raw

PATCH v7 9/21 hw/core/qdev: cleanup Error ** variables

In reply to Vladimir Sementsov-Ogievskiy

Rename Error ** parameter in check_only_migratable to common errp.

In device_set_realized:

- Move "if (local_err != NULL)" closer to error setters.

- Drop 'Error **local_errp': it doesn't save any LoCs, but it's very unusual.

---
 hw/core/qdev.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
hw/core/qdev.c +13 -15
index cf1ba28fe3..82d3ee590a 100644
@@ -820,12 +820,12 @@ static bool device_get_realized(Object *obj, Error **errp)
     return dev->realized;
 }
 
-static bool check_only_migratable(Object *obj, Error **err)
+static bool check_only_migratable(Object *obj, Error **errp)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
 
     if (!vmstate_check_only_migratable(dc->vmsd)) {
-        error_setg(err, "Device %s is not migratable, but "
+        error_setg(errp, "Device %s is not migratable, but "
                    "--only-migratable was specified",
                    object_get_typename(obj));
         return false;
@@ -874,10 +874,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
 
         if (dc->realize) {
             dc->realize(dev, &local_err);
-        }
-
-        if (local_err != NULL) {
-            goto fail;
+            if (local_err != NULL) {
+                goto fail;
+            }
         }
 
         DEVICE_LISTENER_CALL(realize, Forward, dev);
@@ -918,27 +917,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
        }
 
     } else if (!value && dev->realized) {
-        Error **local_errp = NULL;
+        /* We want local_err to track only the first error */
         QLIST_FOREACH(bus, &dev->child_bus, sibling) {
-            local_errp = local_err ? NULL : &local_err;
             object_property_set_bool(OBJECT(bus), false, "realized",
-                                     local_errp);
+                                     local_err ? NULL : &local_err);
         }
         if (qdev_get_vmsd(dev)) {
             vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
         }
         if (dc->unrealize) {
-            local_errp = local_err ? NULL : &local_err;
-            dc->unrealize(dev, local_errp);
+            dc->unrealize(dev, local_err ? NULL : &local_err);
         }
         dev->pending_deleted_event = true;
         DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
-    }
 
-    if (local_err != NULL) {
-        goto fail;
+        if (local_err != NULL) {
+            goto fail;
+        }
     }
 
+    assert(local_err == NULL);
     dev->realized = value;
     return;
 
@@ -976,7 +974,7 @@ static bool device_get_hotpluggable(Object *obj, Error **errp)
                                 qbus_is_hotpluggable(dev->parent_bus));
 }
 
-static bool device_get_hotplugged(Object *obj, Error **err)
+static bool device_get_hotplugged(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
 
Signature · 1 line
2.21.0
#18 lore raw

PATCH v7 10/21 block/snapshot: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 include/block/snapshot.h | 2 +-
 block/snapshot.c         | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/block/snapshot.h +1 -1
index b5d5084a12..2bfcd57578 100644
@@ -78,7 +78,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
 
 bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs);
 int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bsd_bs,
-                             Error **err);
+                             Error **errp);
 int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs,
                            Error **errp);
 int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs);
block/snapshot.c +2 -2
index 8081616ae9..bd9fb01817 100644
@@ -426,7 +426,7 @@ fail:
 }
 
 int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
-                             Error **err)
+                             Error **errp)
 {
     int ret = 0;
     BlockDriverState *bs;
@@ -441,7 +441,7 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
             bdrv_snapshot_find(bs, snapshot, name) >= 0)
         {
             ret = bdrv_snapshot_delete(bs, snapshot->id_str,
-                                       snapshot->name, err);
+                                       snapshot->name, errp);
         }
         aio_context_release(ctx);
         if (ret < 0) {
Signature · 1 line
2.21.0
#19 lore raw

PATCH v7 11/21 hw/i386/amd_iommu: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/i386/amd_iommu.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/i386/amd_iommu.c +7 -7
index d55dbf07fc..b1175e52c7 100644
@@ -1533,7 +1533,7 @@ static void amdvi_reset(DeviceState *dev)
     amdvi_init(s);
 }
 
-static void amdvi_realize(DeviceState *dev, Error **err)
+static void amdvi_realize(DeviceState *dev, Error **errp)
 {
     int ret = 0;
     AMDVIState *s = AMD_IOMMU_DEVICE(dev);
@@ -1549,21 +1549,21 @@ static void amdvi_realize(DeviceState *dev, Error **err)
     /* This device should take care of IOMMU PCI properties */
     x86_iommu->type = TYPE_AMD;
     qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);
-    object_property_set_bool(OBJECT(&s->pci), true, "realized", err);
+    object_property_set_bool(OBJECT(&s->pci), true, "realized", errp);
     ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,
-                                         AMDVI_CAPAB_SIZE, err);
+                                         AMDVI_CAPAB_SIZE, errp);
     if (ret < 0) {
         return;
     }
     s->capab_offset = ret;
 
     ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0,
-                             AMDVI_CAPAB_REG_SIZE, err);
+                             AMDVI_CAPAB_REG_SIZE, errp);
     if (ret < 0) {
         return;
     }
     ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0,
-                             AMDVI_CAPAB_REG_SIZE, err);
+                             AMDVI_CAPAB_REG_SIZE, errp);
     if (ret < 0) {
         return;
     }
@@ -1578,8 +1578,8 @@ static void amdvi_realize(DeviceState *dev, Error **err)
     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);
     sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);
     pci_setup_iommu(bus, amdvi_host_dma_iommu, s);
-    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", err);
-    msi_init(&s->pci.dev, 0, 1, true, false, err);
+    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", errp);
+    msi_init(&s->pci.dev, 0, 1, true, false, errp);
     amdvi_init(s);
 }
 
Signature · 1 line
2.21.0
#20 lore raw

PATCH v7 12/21 qga: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 qga/commands-posix.c |  2 +-
 qga/commands-win32.c |  2 +-
 qga/commands.c       | 12 ++++++------
 3 files changed, 8 insertions(+), 8 deletions(-)
qga/commands-posix.c +1 -1
index 1c1a165dae..3bd7b54c08 100644
@@ -2781,7 +2781,7 @@ static double ga_get_login_time(struct utmpx *user_info)
     return seconds + useconds;
 }
 
-GuestUserList *qmp_guest_get_users(Error **err)
+GuestUserList *qmp_guest_get_users(Error **errp)
 {
     GHashTable *cache = NULL;
     GuestUserList *head = NULL, *cur_item = NULL;
qga/commands-win32.c +1 -1
index 55ba5b263a..2461fd19bf 100644
@@ -1946,7 +1946,7 @@ typedef struct _GA_WTSINFOA {
 
 } GA_WTSINFOA;
 
-GuestUserList *qmp_guest_get_users(Error **err)
+GuestUserList *qmp_guest_get_users(Error **errp)
 {
 #define QGA_NANOSECONDS 10000000
 
qga/commands.c +6 -6
index 0c7d1385c2..43c323cead 100644
@@ -143,7 +143,7 @@ static GuestExecInfo *guest_exec_info_find(int64_t pid_numeric)
     return NULL;
 }
 
-GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err)
+GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)
 {
     GuestExecInfo *gei;
     GuestExecStatus *ges;
@@ -152,7 +152,7 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err)
 
     gei = guest_exec_info_find(pid);
     if (gei == NULL) {
-        error_setg(err, QERR_INVALID_PARAMETER, "pid");
+        error_setg(errp, QERR_INVALID_PARAMETER, "pid");
         return NULL;
     }
 
@@ -385,7 +385,7 @@ GuestExec *qmp_guest_exec(const char *path,
                        bool has_env, strList *env,
                        bool has_input_data, const char *input_data,
                        bool has_capture_output, bool capture_output,
-                       Error **err)
+                       Error **errp)
 {
     GPid pid;
     GuestExec *ge = NULL;
@@ -405,7 +405,7 @@ GuestExec *qmp_guest_exec(const char *path,
     arglist.next = has_arg ? arg : NULL;
 
     if (has_input_data) {
-        input = qbase64_decode(input_data, -1, &ninput, err);
+        input = qbase64_decode(input_data, -1, &ninput, errp);
         if (!input) {
             return NULL;
         }
@@ -424,7 +424,7 @@ GuestExec *qmp_guest_exec(const char *path,
             guest_exec_task_setup, NULL, &pid, has_input_data ? &in_fd : NULL,
             has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr);
     if (!ret) {
-        error_setg(err, QERR_QGA_COMMAND_FAILED, gerr->message);
+        error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message);
         g_error_free(gerr);
         goto done;
     }
@@ -499,7 +499,7 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
     return -1;
 }
 
-GuestHostName *qmp_guest_get_host_name(Error **err)
+GuestHostName *qmp_guest_get_host_name(Error **errp)
 {
     GuestHostName *result = NULL;
     gchar const *hostname = g_get_host_name();
Signature · 1 line
2.21.0
#21 lore raw

PATCH v7 13/21 monitor/qmp-cmds: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 monitor/qmp-cmds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/qmp-cmds.c +1 -1
index 0880341a2d..c6faa3eaf0 100644
@@ -109,7 +109,7 @@ void qmp_system_reset(Error **errp)
     qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET);
 }
 
-void qmp_system_powerdown(Error **erp)
+void qmp_system_powerdown(Error **errp)
 {
     qemu_system_powerdown_request();
 }
Signature · 1 line
2.21.0
#22 lore raw

PATCH v7 14/21 hw/s390x: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/s390x/event-facility.c | 2 +-
 hw/s390x/s390-stattrib.c  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/s390x/event-facility.c +1 -1
index 66205697ae..dc733ee2af 100644
@@ -439,7 +439,7 @@ static void sclp_event_set_allow_all_mask_sizes(Object *obj, bool value,
     ef->allow_all_mask_sizes = value;
 }
 
-static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **e)
+static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **errp)
 {
     SCLPEventFacility *ef = (SCLPEventFacility *)obj;
 
hw/s390x/s390-stattrib.c +2 -1
index bf5ac014c4..58121b9f68 100644
@@ -352,7 +352,8 @@ static void s390_stattrib_class_init(ObjectClass *oc, void *data)
     dc->realize = s390_stattrib_realize;
 }
 
-static inline bool s390_stattrib_get_migration_enabled(Object *obj, Error **e)
+static inline bool s390_stattrib_get_migration_enabled(Object *obj,
+                                                       Error **errp)
 {
     S390StAttribState *s = S390_STATTRIB(obj);
 
Signature · 1 line
2.21.0
#23 lore raw

PATCH v7 15/21 hw/sd: drop extra whitespace in sdhci_sysbus_realize() header

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +1 -1
index 88404d0e9d..18c0c052ce 100644
@@ -1459,7 +1459,7 @@ static void sdhci_sysbus_finalize(Object *obj)
     sdhci_uninitfn(s);
 }
 
-static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp)
+static void sdhci_sysbus_realize(DeviceState *dev, Error **errp)
 {
     SDHCIState *s = SYSBUS_SDHCI(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
Signature · 1 line
2.21.0
#24 lore raw

PATCH v7 16/21 hw/tpm: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/tpm/tpm_emulator.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/tpm/tpm_emulator.c +4 -4
index 22f9113432..10d587ed40 100644
@@ -155,7 +155,7 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
                                      const uint8_t *in, uint32_t in_len,
                                      uint8_t *out, uint32_t out_len,
                                      bool *selftest_done,
-                                     Error **err)
+                                     Error **errp)
 {
     ssize_t ret;
     bool is_selftest = false;
@@ -165,20 +165,20 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
         is_selftest = tpm_util_is_selftest(in, in_len);
     }
 
-    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, err);
+    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, errp);
     if (ret != 0) {
         return -1;
     }
 
     ret = qio_channel_read_all(tpm_emu->data_ioc, (char *)out,
-              sizeof(struct tpm_resp_hdr), err);
+              sizeof(struct tpm_resp_hdr), errp);
     if (ret != 0) {
         return -1;
     }
 
     ret = qio_channel_read_all(tpm_emu->data_ioc,
               (char *)out + sizeof(struct tpm_resp_hdr),
-              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), err);
+              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), errp);
     if (ret != 0) {
         return -1;
     }
Signature · 1 line
2.21.0
#25 lore raw

PATCH v7 17/21 hw/usb: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/usb/dev-network.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/dev-network.c +1 -1
index 5de6213cc4..b81a8abe83 100644
@@ -1342,7 +1342,7 @@ static NetClientInfo net_usbnet_info = {
     .cleanup = usbnet_cleanup,
 };
 
-static void usb_net_realize(USBDevice *dev, Error **errrp)
+static void usb_net_realize(USBDevice *dev, Error **errp)
 {
     USBNetState *s = USB_NET(dev);
 
Signature · 1 line
2.21.0
#26 lore raw

PATCH v7 18/21 include/qom/object.h: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 include/qom/object.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/qom/object.h +2 -2
index 128d00c77f..716f6f655d 100644
@@ -1635,9 +1635,9 @@ void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
  * property of type 'uint64'.
  */
 void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **Errp);
+                                    const uint64_t *v, Error **errp);
 void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
-                                          const uint64_t *v, Error **Errp);
+                                          const uint64_t *v, Error **errp);
 
 /**
  * object_property_add_alias:
Signature · 1 line
2.21.0
#27 lore raw

PATCH v7 19/21 backends/cryptodev: drop local_err from cryptodev_backend_complete()

In reply to Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 backends/cryptodev.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
backends/cryptodev.c +1 -10
index 3c071eab95..5a9735684e 100644
@@ -176,19 +176,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
 {
     CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
     CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
-    Error *local_err = NULL;
 
     if (bc->init) {
-        bc->init(backend, &local_err);
-        if (local_err) {
-            goto out;
-        }
+        bc->init(backend, errp);
     }
-
-    return;
-
-out:
-    error_propagate(errp, local_err);
 }
 
 void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
Signature · 1 line
2.21.0
#28 lore raw

PATCH v7 20/21 hw/vfio/ap: drop local_err from vfio_ap_realize

In reply to Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 hw/vfio/ap.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/vfio/ap.c +3 -6
index da6a20669d..8fbaa724c2 100644
@@ -89,14 +89,13 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
 {
     int ret;
     char *mdevid;
-    Error *local_err = NULL;
     VFIOGroup *vfio_group;
     APDevice *apdev = AP_DEVICE(dev);
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
 
-    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    vfio_group = vfio_ap_get_group(vapdev, errp);
     if (!vfio_group) {
-        goto out_err;
+        return;
     }
 
     vapdev->vdev.ops = &vfio_ap_ops;
@@ -113,7 +112,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
      */
     vapdev->vdev.balloon_allowed = true;
 
-    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
+    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);
     if (ret) {
         goto out_get_dev_err;
     }
@@ -123,8 +122,6 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
 out_get_dev_err:
     vfio_ap_put_device(vapdev);
     vfio_put_group(vfio_group);
-out_err:
-    error_propagate(errp, local_err);
 }
 
 static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
Signature · 1 line
2.21.0
Reviewed-by on v7 20/21
#29 lore raw

Re: [PATCH v7 20/21] hw/vfio/ap: drop local_err from vfio_ap_realize

Quoted 7 lines · On Thu, 5 Dec 2019 18:20:18 +0300 Vladimir Sementsov-Ogievskiy…

No reason for local_err here, use errp directly instead.

---
 hw/vfio/ap.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
#30 lore raw

PATCH v7 21/21 nbd: assert that Error** is not NULL in nbd_iter_channel_error

In reply to Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

---
 block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
block/nbd.c +1 -0
index 5f18f78a94..d085554f21 100644
@@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter {
 static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
                                    int ret, Error **local_err)
 {
+    assert(local_err && *local_err);
     assert(ret < 0);
 
     if (!iter->ret) {
Signature · 1 line
2.21.0
#31 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 16 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

---
  block/nbd.c | 1 +
  1 file changed, 1 insertion(+)
block/nbd.c +0 -0
index 5f18f78a94..d085554f21 100644

block/nbd.c typedef struct NBDReplyChunkIter { · line 869

Quoted 4 lines
block/nbd.c +1 -0
@@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter {
  static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
                                     int ret, Error **local_err)
  {
+    assert(local_err && *local_err);

Why are we forbidding grandparent callers from passing NULL when they want to ignore an error? We are called by several parent functions that get an errp from the grandparent, and use this function to do some common grunt work. Let's look at the possibilities:

1. grandparent passes address of a local error: we want to append to the error message, parent will then deal with the error how it wants (report it, ignore it, propagate it, whatever)

2. grandparent passes &error_fatal: we want to append a hint, but before ERRP_AUTO_PROPAGATE, the parent has already exited. After ERRP_AUTO_PROPAGATE, this looks like case 1.

3. grandparent passes &error_abort: we should never be reached (failure earlier in the parent should have already aborted) - true whether or not ERRP_AUTO_PROPAGATE is applied

4. grandparent passes NULL to ignore the error. Does not currently happen in any of the grandparent callers, because if it did, your assertion in this patch would now fire. After ERRP_AUTO_PROPAGATE, this would look like case 1.

Would it be better to assert(!local_err || *local_err)? The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

Quoted 4 lines
block/nbd.c +0 -0
      assert(ret < 0);
 
      if (!iter->ret) {
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#32 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 26 lines · Eric Blake
Quoted 16 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

---
  block/nbd.c | 1 +

  1 file changed, 1 insertion(+)
block/nbd.c +0 -0
index 5f18f78a94..d085554f21 100644

block/nbd.c typedef struct NBDReplyChunkIter { · line 869

Quoted 4 lines
block/nbd.c +1 -0
@@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter {
   static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
                                      int ret, Error **local_err)
   {
+    assert(local_err && *local_err);

Why are we forbidding grandparent callers from passing NULL when they want to ignore an error?  We are called by several parent functions that get an errp from the grandparent, and use this function to do some common grunt work.  Let's look at the possibilities:

1. grandparent passes address of a local error: we want to append to the error message, parent will then deal with the error how it wants (report it, ignore it, propagate it, whatever)

Quoted 7 lines

2. grandparent passes &error_fatal: we want to append a hint, but before ERRP_AUTO_PROPAGATE, the parent has already exited.  After ERRP_AUTO_PROPAGATE, this looks like case 1.

3. grandparent passes &error_abort: we should never be reached (failure earlier in the parent should have already aborted) - true whether or not ERRP_AUTO_PROPAGATE is applied

4. grandparent passes NULL to ignore the error. Does not currently happen in any of the grandparent callers, because if it did, your assertion in this patch would now fire.  After ERRP_AUTO_PROPAGATE, this would look like case 1.

Would it be better to assert(!local_err || *local_err)?  The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

We don't have any grandparents, this function is always called on local_err. And it's argument named local_err to stress it. The function is an API to report error, and it wants filled local_err object.

It will crash anyway if local_err is NULL, as it dereferences it.

I just want to place an assertion at start of functions like this, which will be easily recognizable by coccinelle.

---

We can improve the API, to support local_err==NULL, for the case when original request was called with errp==NULL, but for this we'll need more changes, like, pass errp to NBD_FOREACH_REPLY_CHUNK and save it into iter object...

But how to detect it in code? Something like

block/nbd.c +4 -2
@@ -1059,8 +1059,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s,
          case NBD_REPLY_TYPE_BLOCK_STATUS:
              if (received) {
                  nbd_channel_error(s, -EINVAL);
-                error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
-                nbd_iter_channel_error(&iter, -EINVAL, &local_err);
+                if (errp) {
+                    error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
+                }
+                nbd_iter_channel_error(&iter, -EINVAL, errp ? &local_err : NULL);
              }
              received = true;
 

is ugly..

So, to support original errp=NULL the whole thing should be refactored.. Not worth it, I think.

Quoted 5 lines
Quoted 4 lines
block/nbd.c +0 -0
       assert(ret < 0);
       if (!iter->ret) {
 
Signature · 2 lines
Best regards,
Vladimir
Reviewed-by
#33 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Quoted 9 lines · Eric Blake
Quoted 6 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

Quoted 3 lines
Quoted 1 line

Would it be better to assert(!local_err || *local_err)?  The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

We don't have any grandparents, this function is always called on local_err. And it's argument named local_err to stress it.

Then the commit message should state that. How about:

All callers of nbd_iter_channel_error() pass the address of a local_err variable, and only call this function if an error has already occurred, using this function to append details to that error. This is already implied by its name (local_err instead of the classic errp), but it is worth additionally stressing this by adding an assertion to make it part of the function contract.

Quoted 6 lines

The function is an API to report error, and it wants filled local_err object.

It will crash anyway if local_err is NULL, as it dereferences it.

I just want to place an assertion at start of functions like this, which will be easily recognizable by coccinelle.

With an improved commit message, the assertion makes sense, so

Quoted 13 lines

---

We can improve the API, to support local_err==NULL, for the case when original request was called with errp==NULL, but for this we'll need more changes, like, pass errp to NBD_FOREACH_REPLY_CHUNK and save it into iter object...

But how to detect it in code? Something like

block/nbd.c static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s, · line 1065

Quoted 9 lines
block/nbd.c +4 -2
@@ -1059,8 +1059,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s,
           case NBD_REPLY_TYPE_BLOCK_STATUS:
               if (received) {
                   nbd_channel_error(s, -EINVAL);
-                error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
-                nbd_iter_channel_error(&iter, -EINVAL, &local_err);
+                if (errp) {
+                    error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
+                }
+                nbd_iter_channel_error(&iter, -EINVAL, errp ? &local_err : NULL);

No, that's not worth it.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#34 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 13 lines · Eric Blake
Quoted 12 lines · Vladimir Sementsov-Ogievskiy
Quoted 10 lines · Eric Blake
Quoted 6 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

Would it be better to assert(!local_err || *local_err)?  The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

Quoted 7 lines
Quoted 1 line

We don't have any grandparents, this function is always called on local_err. And it's argument named local_err to stress it.

Then the commit message should state that. How about:

All callers of nbd_iter_channel_error() pass the address of a local_err variable, and only call this function if an error has already occurred, using this function

to append details to that error.

Hmm, not to append details but to report the error to the magical receiving loop, which doesn't yet know about the error

Quoted 1 line

This is already implied by its name (local_err instead of the classic errp), but it is worth additionally stressing this by adding an assertion to make it part of the function contract.

So, how about simply s/to append details to that error/to report that error/ ?

Quoted 37 lines
Quoted 7 lines

The function is an API to report error, and it wants filled local_err object.

It will crash anyway if local_err is NULL, as it dereferences it.

I just want to place an assertion at start of functions like this, which will be easily recognizable by coccinelle.

With an improved commit message, the assertion makes sense, so

Quoted 14 lines

---

We can improve the API, to support local_err==NULL, for the case when original request was called with errp==NULL, but for this we'll need more changes, like, pass errp to NBD_FOREACH_REPLY_CHUNK and save it into iter object...

But how to detect it in code? Something like

block/nbd.c +0 -0
@@ -1059,8 +1059,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s,

           case NBD_REPLY_TYPE_BLOCK_STATUS:

Quoted 8 lines

               if (received) {
                   nbd_channel_error(s, -EINVAL);
-                error_setg(&local_err, "Several BLOCK_STATUS chunks in reply"); -                nbd_iter_channel_error(&iter, -EINVAL, &local_err);
+                if (errp) {
+                    error_setg(&local_err, "Several BLOCK_STATUS chunks in reply"); +                }
+                nbd_iter_channel_error(&iter, -EINVAL, errp ? &local_err : NULL);

No, that's not worth it.

Signature · 2 lines
Best regards,
Vladimir
#35 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 11 lines · Vladimir Sementsov-Ogievskiy
Quoted 4 lines

All callers of nbd_iter_channel_error() pass the address of a local_err variable, and only call this function if an error has already occurred, using this function

to append details to that error.

Hmm, not to append details but to report the error to the magical receiving loop, which doesn't yet know about the error

Quoted 1 line

This is already implied by its name (local_err instead of the classic errp), but it is worth additionally stressing this by adding an assertion to make it part of the function contract.

So, how about simply s/to append details to that error/to report that error/ ?

That should be fine.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#36 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

In reply to Vladimir Sementsov-Ogievskiy
Quoted 31 lines · Vladimir Sementsov-Ogievskiy
Quoted 30 lines · Eric Blake
Quoted 16 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

---
  block/nbd.c | 1 +

  1 file changed, 1 insertion(+)
block/nbd.c +0 -0
index 5f18f78a94..d085554f21 100644

block/nbd.c typedef struct NBDReplyChunkIter { · line 869

Quoted 4 lines
block/nbd.c +1 -0
@@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter {
   static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
                                      int ret, Error **local_err)
   {
+    assert(local_err && *local_err);

Why are we forbidding grandparent callers from passing NULL when they want to ignore an error?  We are called by several parent functions that get an errp from the grandparent, and use this function to do some common grunt work.  Let's look at the possibilities:

1. grandparent passes address of a local error: we want to append to the error message, parent will then deal with the error how it wants (report it, ignore it, propagate it, whatever)

2. grandparent passes &error_fatal: we want to append a hint, but before ERRP_AUTO_PROPAGATE, the parent has already exited.  After ERRP_AUTO_PROPAGATE, this looks like case 1.

3. grandparent passes &error_abort: we should never be reached (failure earlier in the parent should have already aborted) - true whether or not ERRP_AUTO_PROPAGATE is applied

Quoted 8 lines
Quoted 3 lines

4. grandparent passes NULL to ignore the error. Does not currently happen in any of the grandparent callers, because if it did, your assertion in this patch would now fire.  After ERRP_AUTO_PROPAGATE, this would look like case 1.

Would it be better to assert(!local_err || *local_err)?  The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

We don't have any grandparents, this function is always called on local_err. And it's argument named local_err to stress it. The function is an API to report error, and it wants filled local_err object.

It will crash anyway if local_err is NULL, as it dereferences it.

Yes.

We already assert ret < 0 explicitly, and we rely on !local_err implicitly. Making that explicit is obviously safe.

The code doesn't actually rely on !*local_err. But when ret < 0, and !local_err, surely local_err should point to an Error object. Asserting that makes sense to me.

Quoted 2 lines

I just want to place an assertion at start of functions like this, which will be easily recognizable by coccinelle.

That's not a convincing argument. Doesn't matter as long as we have convincing ones :)

Quoted 26 lines

---

We can improve the API, to support local_err==NULL, for the case when original request was called with errp==NULL, but for this we'll need more changes, like, pass errp to NBD_FOREACH_REPLY_CHUNK and save it into iter object...

But how to detect it in code? Something like

block/nbd.c +4 -2
@@ -1059,8 +1059,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s,
          case NBD_REPLY_TYPE_BLOCK_STATUS:
              if (received) {
                  nbd_channel_error(s, -EINVAL);
-                error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
-                nbd_iter_channel_error(&iter, -EINVAL, &local_err);
+                if (errp) {
+                    error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
+                }
+                nbd_iter_channel_error(&iter, -EINVAL, errp ? &local_err : NULL);
              }
              received = true;
 
Quoted 4 lines

is ugly..

So, to support original errp=NULL the whole thing should be refactored.. Not worth it, I think.

The only change I'd consider in addition to the assertion is this simplification:

block/nbd.c +1 -3
index 5f18f78a94..7bbac1e5b8 100644
@@ -870,11 +870,9 @@ static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
 
     if (!iter->ret) {
         iter->ret = ret;
-        error_propagate(&iter->err, *local_err);
-    } else {
-        error_free(*local_err);
     }
 
+    error_propagate(&iter->err, *local_err);
     *local_err = NULL;
 }
 
#37 lore raw

Re: [PATCH v7 21/21] nbd: assert that Error** is not NULL in nbd_iter_channel_error

Quoted 47 lines · Markus Armbruster
Quoted 31 lines · Vladimir Sementsov-Ogievskiy
Quoted 30 lines · Eric Blake
Quoted 16 lines · Vladimir Sementsov-Ogievskiy

The local_err parameter is not here to return information about nbd_iter_channel_error failure. Instead it's assumed to be filled when passed to the function. This is already stressed by its name (local_err, instead of classic errp). Stress it additionally by assertion.

---
   block/nbd.c | 1 +
   1 file changed, 1 insertion(+)
block/nbd.c +0 -0
index 5f18f78a94..d085554f21 100644

block/nbd.c typedef struct NBDReplyChunkIter { · line 869

Quoted 4 lines
block/nbd.c +1 -0
@@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter {
   static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
                                      int ret, Error **local_err)
   {
+    assert(local_err && *local_err);

Why are we forbidding grandparent callers from passing NULL when they want to ignore an error?  We are called by several parent functions that get an errp from the grandparent, and use this function to do some common grunt work.  Let's look at the possibilities:

1. grandparent passes address of a local error: we want to append to the error message, parent will then deal with the error how it wants (report it, ignore it, propagate it, whatever)

2. grandparent passes &error_fatal: we want to append a hint, but before ERRP_AUTO_PROPAGATE, the parent has already exited.  After ERRP_AUTO_PROPAGATE, this looks like case 1.

3. grandparent passes &error_abort: we should never be reached (failure earlier in the parent should have already aborted) - true whether or not ERRP_AUTO_PROPAGATE is applied

Quoted 8 lines
Quoted 3 lines

4. grandparent passes NULL to ignore the error. Does not currently happen in any of the grandparent callers, because if it did, your assertion in this patch would now fire.  After ERRP_AUTO_PROPAGATE, this would look like case 1.

Would it be better to assert(!local_err || *local_err)?  The assertion as written is too strict without ERRP_AUTO_PROPAGATE, but you get away with it because none of the grandparents pass NULL; but is appropriate as written for after after the macro conversion so then we wonder if churn on the macro is worth it.

We don't have any grandparents, this function is always called on local_err. And it's argument named local_err to stress it. The function is an API to report error, and it wants filled local_err object.

It will crash anyway if local_err is NULL, as it dereferences it.

Yes.

We already assert ret < 0 explicitly, and we rely on !local_err implicitly. Making that explicit is obviously safe.

Quoted 8 lines

The code doesn't actually rely on !*local_err. But when ret < 0, and !local_err, surely local_err should point to an Error object. Asserting that makes sense to me.

Quoted 2 lines

I just want to place an assertion at start of functions like this, which will be easily recognizable by coccinelle.

That's not a convincing argument.

That's why it is absent in commit message)

Quoted 42 lines

Doesn't matter as long as we have
convincing ones :)

Quoted 26 lines

---

We can improve the API, to support local_err==NULL, for the case when original request was called with errp==NULL, but for this we'll need more changes, like, pass errp to NBD_FOREACH_REPLY_CHUNK and save it into iter object...

But how to detect it in code? Something like

block/nbd.c +4 -2
@@ -1059,8 +1059,10 @@ static int nbd_co_receive_blockstatus_reply(BDRVNBDState *s,
           case NBD_REPLY_TYPE_BLOCK_STATUS:
               if (received) {
                   nbd_channel_error(s, -EINVAL);
-                error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
-                nbd_iter_channel_error(&iter, -EINVAL, &local_err);
+                if (errp) {
+                    error_setg(&local_err, "Several BLOCK_STATUS chunks in reply");
+                }
+                nbd_iter_channel_error(&iter, -EINVAL, errp ? &local_err : NULL);
               }
               received = true;
 
Quoted 4 lines

is ugly..

So, to support original errp=NULL the whole thing should be refactored.. Not worth it, I think.

The only change I'd consider in addition to the assertion is this simplification:

block/nbd.c +0 -0
index 5f18f78a94..7bbac1e5b8 100644

block/nbd.c static void nbd_iter_channel_error(NBDReplyChunkIter *iter, · line 875

Quoted 9 lines
block/nbd.c +1 -3
@@ -870,11 +870,9 @@ static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
 
      if (!iter->ret) {
          iter->ret = ret;
-        error_propagate(&iter->err, *local_err);
-    } else {
-        error_free(*local_err);
      }
 
+    error_propagate(&iter->err, *local_err);

because it will just free the second argument if the first one already set.. OK, will add this.

Quoted 4 lines
block/nbd.c +0 -0
      *local_err = NULL;
  }
 
Signature · 2 lines
Best regards,
Vladimir
#38 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 4 lines · On Thu, 5 Dec 2019 18:19:58 +0300 Vladimir Sementsov-Ogievskiy…

Hi all!

This is the first part of the bit series, which contains mostly simple cleanups.

What's the plan? Should subsystem maintainers pick up individual patches, or will they be merged in one go?

#39 lore raw
Quoted 11 lines · Cornelia Huck
Quoted 4 lines · On Thu, 5 Dec 2019 18:19:58 +0300 Vladimir Sementsov-Ogievskiy…

Hi all!

This is the first part of the bit series, which contains mostly simple cleanups.

What's the plan? Should subsystem maintainers pick up individual patches, or will they be merged in one go?

The latter. Markus will take them all together.

Signature · 2 lines
Best regards,
Vladimir
#40 lore raw
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
Quoted 5 lines · Cornelia Huck
Quoted 2 lines · On Thu, 5 Dec 2019 18:19:58 +0300 Vladimir Sementsov-Ogievskiy…

Hi all!

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

This is the first part of the bit series, which contains mostly simple cleanups.

What's the plan? Should subsystem maintainers pick up individual patches, or will they be merged in one go?

The latter. Markus will take them all together.

Subsystem maintainers are welcome to take truly independent patches through their trees if that's more convenient for them, say because it avoids or reduces the likelihood of conflicts.

Whatever is left I will take through my tree. Me taking everything is slightly easier for me, and results in a more coherent git-log. Neither is serious enough to justify inconveniencing subsystem maintainers.