qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* How can I find problematic uses of error_report() with vrc?
@ 2023-05-08  8:32 Markus Armbruster
  2023-05-08 10:41 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Armbruster @ 2023-05-08  8:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

Calling error_report() from within a function using Error to return
error information is almost always wrong.  Example:

    QMP command qmp_migrate()
    calls rdma_start_outgoing_migration()
    calls qemu_rdma_source_init()
    calls qemu_rdma_reg_control()

The first four have an Error **errp parameter, and use it to return
error information.  Good.

The last one does not.  Instead, qemu_rdma_reg_control() calls
error_report() on failure:

    error_report("qemu_rdma_reg_control failed");
    return -1;

Its caller qemu_rdma_source_init() detects the failure and sets an
error:

        ret = qemu_rdma_reg_control(rdma, idx);
        if (ret) {
            error_setg(temp, "RDMA ERROR: rdma migration: error registering %d control!",
                                                            idx);
            goto err_rdma_source_init;
        }

Because of this, QMP command migrate spams stderr on this particular
failure.  Inappropriate.

Easy enough to fix, but I'm after the error pattern, not a single
instance that happened to catch my eye.

Problem: find call chains from functions using Error to error_report().

Two sub-problems:

1. Find functions using Error

   Doesn't have to be perfect.  I have a simple Coccinelle script
   (appended) that spits out some 4400 functions.  I run it like

    $ spatch --sp-file find-error-fns.cocci --macro-file scripts/cocci-macro-file.h `git-grep -Fl 'Error **' \*.[ch]`

2. Find call chains from these functions to error_report()

   I'm hoping vrc can do that for me.  How?



Here's my find-error-fns.cocci:

@r@
identifier fn, errp;
position p;
@@
 fn@p(..., Error **errp, ...)
 {
     ...
 }
@script:python@
fn << r.fn;
p << r.p;
@@
print(f'{p[0].file}:{p[0].line}:{p[0].column}:{fn}')



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-08 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-08  8:32 How can I find problematic uses of error_report() with vrc? Markus Armbruster
2023-05-08 10:41 ` Paolo Bonzini
2023-05-08 15:11   ` Paolo Bonzini

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).