From: Markus Armbruster <armbru@redhat.com>
To: Steven Sistare <steven.sistare@oracle.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
qemu-devel@nongnu.org, "Michael Roth" <michael.roth@amd.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>
Subject: Re: [PATCH] monitor: flush messages on abort
Date: Wed, 15 Nov 2023 17:05:10 +0100 [thread overview]
Message-ID: <87sf57knnt.fsf@pond.sub.org> (raw)
In-Reply-To: <587d8444-17a4-4d19-a856-ac55e46069c5@oracle.com> (Steven Sistare's message of "Wed, 15 Nov 2023 10:30:29 -0500")
Steven Sistare <steven.sistare@oracle.com> writes:
> On 11/6/2023 5:10 AM, Daniel P. Berrangé wrote:
>> On Fri, Nov 03, 2023 at 03:51:00PM -0400, Steven Sistare wrote:
>>> On 11/3/2023 1:33 PM, Daniel P. Berrangé wrote:
>>>> On Fri, Nov 03, 2023 at 09:01:29AM -0700, Steve Sistare wrote:
>>>>> Buffered monitor output is lost when abort() is called. The pattern
>>>>> error_report() followed by abort() occurs about 60 times, so valuable
>>>>> information is being lost when the abort is called in the context of a
>>>>> monitor command.
>>>>
>>>> I'm curious, was there a particular abort() scenario that you hit ?
>>>
>>> Yes, while tweaking the suspended state, and forgetting to add transitions:
>>>
>>> error_report("invalid runstate transition: '%s' -> '%s'",
>>> abort();
>>>
>>> But I have previously hit this for other errors.
>>>
>>>> For some crude statistics:
>>>>
>>>> $ for i in abort return exit goto ; do echo -n "$i: " ; git grep --after 1 error_report | grep $i | wc -l ; done
>>>> abort: 47
>>>> return: 512
>>>> exit: 458
>>>> goto: 177
>>>>
>>>> to me those numbers say that calling "abort()" after error_report
>>>> should be considered a bug, and we can blanket replace all the
>>>> abort() calls with exit(EXIT_FAILURE), and thus avoid the need to
>>>> special case flushing the monitor.
>>>
>>> And presumably add an atexit handler to flush the monitor ala monitor_abort.
>>> AFAICT currently no destructor is called for the monitor at exit time.
>>
>> The HMP monitor flushes at each newline, and exit() will take care of
>> flushing stdout, so I don't think there's anything else needed.
>>
>>>> Also I think there's a decent case to be made for error_report()
>>>> to call monitor_flush().
>>>
>>> A good start, but that would not help for monitors with skip_flush=true, which
>>> need to format the buffered string in a json response, which is the case I
>>> tripped over.
>>
>> 'skip_flush' is only set to 'true' when using a QMP monitor and invoking
>> "hmp-monitor-command".
>
> OK, that is narrower than I thought. Now I see that other QMP monitors send
> error_report() to stderr, hence it is visible after abort and exit:
>
> int error_vprintf(const char *fmt, va_list ap) {
> if (cur_mon && !monitor_cur_is_qmp())
> return monitor_vprintf(cur_mon, fmt, ap);
> return vfprintf(stderr, fmt, ap); <-- HERE
>
> That surprises me, I thought that would be returned to the monitor caller in the
> json response. I guess the rationale is that the "main" error, if any, will be
> set and returned by the err object that is passed down the stack during command
> evaluation.
Three cases:
1. !cur_mon
Not executing a monitor command. We want to report errors etc to
stderr.
2. cur_mon && !monitor_cur_is_qmp()
Executing an HMP command. We want to report errors to the current
monitor.
2. cur_mon && monitor_cur_is_qmp()
Executing a QMP command. What we want is less obvious.
Somewhere up the call stack is the QMP command's handler function.
It takes an Error **errp argument.
Within such a function, any errors need to be passed up the call
chain into that argument. Reporting them with error_report() is
*wrong*. Reporting must be left to the function's caller.
A QMP command handler returns it output, it doesn't print it. So
calling monitor_printf() is wrong, too.
But what about warn_report()? Is that wrong, too? We decided it's
not, mostly because we have nothing else to offer.
The stupidest way to keep it useful in QMP command context is to have
error_vprintf() print to stderr. So that's what it does.
We could instead accumulate error_vprintf() output in a buffer, and
include it with the QMP reply. However, it's not clear what a
management application could do with it. So we stick to stupid.
[...]
next prev parent reply other threads:[~2023-11-15 16:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 16:01 [PATCH] monitor: flush messages on abort Steve Sistare
2023-11-03 17:33 ` Daniel P. Berrangé
2023-11-03 19:51 ` Steven Sistare
2023-11-03 20:28 ` Steven Sistare
2023-11-06 10:10 ` Daniel P. Berrangé
2023-11-15 8:41 ` Markus Armbruster
2023-11-15 15:52 ` Steven Sistare
2023-11-15 16:15 ` Markus Armbruster
2023-11-15 17:41 ` Steven Sistare
2023-11-16 15:14 ` Markus Armbruster
2023-11-16 17:03 ` Steven Sistare
2023-11-15 15:30 ` Steven Sistare
2023-11-15 16:05 ` Markus Armbruster [this message]
2023-11-16 11:21 ` Daniel P. Berrangé
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=87sf57knnt.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave@treblig.org \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
--cc=steven.sistare@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.