diff mbox

[v2,3/3] char: emit the OPENED event only when a new char connection is opened

Message ID 1254920477-4645-4-git-send-email-amit.shah@redhat.com
State Changes Requested
Headers show

Commit Message

Amit Shah Oct. 7, 2009, 1:01 p.m. UTC
The OPENED event gets sent also when qemu resets its state initially.
The consumers of the event aren't interested in receiving this event
on reset.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 qemu-char.c |    7 ++++++-
 qemu-char.h |    2 ++
 2 files changed, 8 insertions(+), 1 deletions(-)

Comments

Jan Kiszka Oct. 24, 2009, 10:36 a.m. UTC | #1
Amit Shah wrote:
> The OPENED event gets sent also when qemu resets its state initially.
> The consumers of the event aren't interested in receiving this event
> on reset.

The monitor was. Now its initial prompt on activation is broken.

Does this patch fix/improve something for a different user? If not,
please let us revert it.

Jan

> 
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  qemu-char.c |    7 ++++++-
>  qemu-char.h |    2 ++
>  2 files changed, 8 insertions(+), 1 deletions(-)
> 
> diff --git a/qemu-char.c b/qemu-char.c
> index 4757689..0fd402c 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -119,7 +119,12 @@ static void qemu_chr_event(CharDriverState *s, int event)
>  static void qemu_chr_reset_bh(void *opaque)
>  {
>      CharDriverState *s = opaque;
> -    qemu_chr_event(s, CHR_EVENT_OPENED);
> +
> +    if (s->initial_reset_issued) {
> +        qemu_chr_event(s, CHR_EVENT_OPENED);
> +    } else {
> +        s->initial_reset_issued = true;
> +    }
>      qemu_bh_delete(s->bh);
>      s->bh = NULL;
>  }
> diff --git a/qemu-char.h b/qemu-char.h
> index 05fe15d..409961d 100644
> --- a/qemu-char.h
> +++ b/qemu-char.h
> @@ -1,6 +1,7 @@
>  #ifndef QEMU_CHAR_H
>  #define QEMU_CHAR_H
>  
> +#include <stdbool.h>
>  #include "qemu-common.h"
>  #include "qemu-queue.h"
>  #include "qemu-option.h"
> @@ -66,6 +67,7 @@ struct CharDriverState {
>      QEMUBH *bh;
>      char *label;
>      char *filename;
> +    bool initial_reset_issued;
>      QTAILQ_ENTRY(CharDriverState) next;
>  };
>
Amit Shah Oct. 26, 2009, 3:53 a.m. UTC | #2
On (Sat) Oct 24 2009 [12:36:54], Jan Kiszka wrote:
> Amit Shah wrote:
> > The OPENED event gets sent also when qemu resets its state initially.
> > The consumers of the event aren't interested in receiving this event
> > on reset.
> 
> The monitor was. Now its initial prompt on activation is broken.

The patch in Anthony's queue, titled

'console: call qemu_chr_reset() in text_console_init'

fixed that.

However, with the qcow2 synchronous patch, the monitor prompt doesn't
come up again -- which shows there is a problem with the way the bhs
work and also the initial resets.

I think the initial resets are a hack to work around something from my
reading of it; do you have a better idea of why it's there and how it's
all supposed to work?

> Does this patch fix/improve something for a different user? If not,
> please let us revert it.

There's another question too: is a separate 'reset' event needed in
addition to an 'opened' event?

I have a few apps (that are coming as part of the virtio-console work)
that need just an 'opened' event and are not interested in the 'reset'
event.

		Amit
Jan Kiszka Oct. 26, 2009, 7:40 a.m. UTC | #3
Amit Shah wrote:
> On (Sat) Oct 24 2009 [12:36:54], Jan Kiszka wrote:
>> Amit Shah wrote:
>>> The OPENED event gets sent also when qemu resets its state initially.
>>> The consumers of the event aren't interested in receiving this event
>>> on reset.
>> The monitor was. Now its initial prompt on activation is broken.
> 
> The patch in Anthony's queue, titled
> 
> 'console: call qemu_chr_reset() in text_console_init'

You may also want to rename qemu_chr_reset - unless there is still a
need for real "reset".

> 
> fixed that.
> 
> However, with the qcow2 synchronous patch, the monitor prompt doesn't
> come up again -- which shows there is a problem with the way the bhs
> work and also the initial resets.

Then the qcow2 patch is already in? At least applying your patch doesn't
change the picture.

> 
> I think the initial resets are a hack to work around something from my
> reading of it; do you have a better idea of why it's there and how it's
> all supposed to work?

From the monitor's POV, it's not a hack, it's simply the requirement to
receive an indication that the console was opened.

> 
>> Does this patch fix/improve something for a different user? If not,
>> please let us revert it.
> 
> There's another question too: is a separate 'reset' event needed in
> addition to an 'opened' event?

Not for the monitor, but I cannot speak for other users. I think it
would be good to check them in details before changing the reset/open
semantic.

> 
> I have a few apps (that are coming as part of the virtio-console work)
> that need just an 'opened' event and are not interested in the 'reset'
> event.
> 
> 		Amit

Jan
Amit Shah Oct. 26, 2009, 9:28 a.m. UTC | #4
On (Mon) Oct 26 2009 [08:40:12], Jan Kiszka wrote:
> Amit Shah wrote:
> > On (Sat) Oct 24 2009 [12:36:54], Jan Kiszka wrote:
> >> Amit Shah wrote:
> >>> The OPENED event gets sent also when qemu resets its state initially.
> >>> The consumers of the event aren't interested in receiving this event
> >>> on reset.
> >> The monitor was. Now its initial prompt on activation is broken.
> > 
> > The patch in Anthony's queue, titled
> > 
> > 'console: call qemu_chr_reset() in text_console_init'
> 
> You may also want to rename qemu_chr_reset - unless there is still a
> need for real "reset".

Yeah; there isn't a need after my patches -- I've been slowing working
towards renaming it all.

> > 
> > fixed that.
> > 
> > However, with the qcow2 synchronous patch, the monitor prompt doesn't
> > come up again -- which shows there is a problem with the way the bhs
> > work and also the initial resets.
> 
> Then the qcow2 patch is already in? At least applying your patch doesn't
> change the picture.

Yeah; that patch went in just before my patches. Can you try reverting

ef845c3bf421290153154635dc18eaa677cecb43

> > I think the initial resets are a hack to work around something from my
> > reading of it; do you have a better idea of why it's there and how it's
> > all supposed to work?
> 
> From the monitor's POV, it's not a hack, it's simply the requirement to
> receive an indication that the console was opened.

Just an indication that the monitor was opened -- agreed. But git
history shows you added that as 'reset', so I'm wondering if maybe you
wanted it to do something else as well (or you did it that way just
because of the way qemu's bhs are handled?).

> >> Does this patch fix/improve something for a different user? If not,
> >> please let us revert it.
> > 
> > There's another question too: is a separate 'reset' event needed in
> > addition to an 'opened' event?
> 
> Not for the monitor, but I cannot speak for other users. I think it
> would be good to check them in details before changing the reset/open
> semantic.

As far as I could see in the git history, the 'reset' was added for the
monitor. And the others could live with the double 'reset' events they
were getting -- one for the reset and one when the device was opened.

		Amit
Jan Kiszka Oct. 26, 2009, 8:15 p.m. UTC | #5
Amit Shah wrote:
> On (Mon) Oct 26 2009 [08:40:12], Jan Kiszka wrote:
>> Amit Shah wrote:
>>> On (Sat) Oct 24 2009 [12:36:54], Jan Kiszka wrote:
>>>> Amit Shah wrote:
>>>>> The OPENED event gets sent also when qemu resets its state initially.
>>>>> The consumers of the event aren't interested in receiving this event
>>>>> on reset.
>>>> The monitor was. Now its initial prompt on activation is broken.
>>> The patch in Anthony's queue, titled
>>>
>>> 'console: call qemu_chr_reset() in text_console_init'
>> You may also want to rename qemu_chr_reset - unless there is still a
>> need for real "reset".
> 
> Yeah; there isn't a need after my patches -- I've been slowing working
> towards renaming it all.
> 
>>> fixed that.
>>>
>>> However, with the qcow2 synchronous patch, the monitor prompt doesn't
>>> come up again -- which shows there is a problem with the way the bhs
>>> work and also the initial resets.
>> Then the qcow2 patch is already in? At least applying your patch doesn't
>> change the picture.
> 
> Yeah; that patch went in just before my patches. Can you try reverting
> 
> ef845c3bf421290153154635dc18eaa677cecb43

Makes no difference either - but it also does not touch any code that
code impact the open/reset signaling.

> 
>>> I think the initial resets are a hack to work around something from my
>>> reading of it; do you have a better idea of why it's there and how it's
>>> all supposed to work?
>> From the monitor's POV, it's not a hack, it's simply the requirement to
>> receive an indication that the console was opened.
> 
> Just an indication that the monitor was opened -- agreed. But git
> history shows you added that as 'reset', so I'm wondering if maybe you
> wanted it to do something else as well (or you did it that way just
> because of the way qemu's bhs are handled?).

I didn't add the reset hook for the monitor (it was Anthony), I just
made some improvements.

> 
>>>> Does this patch fix/improve something for a different user? If not,
>>>> please let us revert it.
>>> There's another question too: is a separate 'reset' event needed in
>>> addition to an 'opened' event?
>> Not for the monitor, but I cannot speak for other users. I think it
>> would be good to check them in details before changing the reset/open
>> semantic.
> 
> As far as I could see in the git history, the 'reset' was added for the
> monitor. And the others could live with the double 'reset' events they
> were getting -- one for the reset and one when the device was opened.	

OK.

However, the problems of your approach to avoid potential double resets
on startup is that the supposed two events for the monitor (first one
from qemu_chr_open_fs, second one via qemu_chr_initial_reset) actually
coalesce into one, thus are never delivered. So whatever may happen
later on, during startup the skipping of the first reset/open event is
bogus.

Jan
Amit Shah Oct. 27, 2009, 7:46 a.m. UTC | #6
On (Mon) Oct 26 2009 [21:15:57], Jan Kiszka wrote:
> >>> However, with the qcow2 synchronous patch, the monitor prompt doesn't
> >>> come up again -- which shows there is a problem with the way the bhs
> >>> work and also the initial resets.
> >> Then the qcow2 patch is already in? At least applying your patch doesn't
> >> change the picture.
> > 
> > Yeah; that patch went in just before my patches. Can you try reverting
> > 
> > ef845c3bf421290153154635dc18eaa677cecb43
> 
> Makes no difference either - but it also does not touch any code that
> code impact the open/reset signaling.

What happens is the BHs that are run get run in a different order.

Let me explain the two scenarios:

1. Current qemu tree, plus my patch to fix this issue that's in
Anthony's queue plus reverting the qcow2 patch -- the monitor prompt
appears fine.

2. Current qemu tree plus my patch from Anthony's queue - the monitor
prompt doesn't appear.

The difference is in the order the BHs are scheduled. In the case
without the qcow2 patch, the bhs get scheduled early on and results in
initial_reset_issued getting set. Later, when the char devs are
initialsed, the OPENED event is sent out.

In the case with the qcow2 patch, the bhs are run in a different order
-- the bhs are scheduled but not run, and when the char init happens,
the condition

if (s->bh == NULL)

is false and the bhs in effect get scheduled only once, not emitting the
opened event.

Of course, the qcow2 patch just causes some conditions for the bh
handling to happen differently which I've not examined yet. I just
tracked why this was happening.

All that said, I'm ok with reverting that patch now till I find some
kind of a solution to this.

		Amit
Kevin Wolf Oct. 27, 2009, 8:40 a.m. UTC | #7
Am 27.10.2009 08:46, schrieb Amit Shah:
> On (Mon) Oct 26 2009 [21:15:57], Jan Kiszka wrote:
>>>>> However, with the qcow2 synchronous patch, the monitor prompt doesn't
>>>>> come up again -- which shows there is a problem with the way the bhs
>>>>> work and also the initial resets.
>>>> Then the qcow2 patch is already in? At least applying your patch doesn't
>>>> change the picture.
>>>
>>> Yeah; that patch went in just before my patches. Can you try reverting
>>>
>>> ef845c3bf421290153154635dc18eaa677cecb43
>>
>> Makes no difference either - but it also does not touch any code that
>> code impact the open/reset signaling.
> 
> What happens is the BHs that are run get run in a different order.
> 
> Let me explain the two scenarios:
> 
> 1. Current qemu tree, plus my patch to fix this issue that's in
> Anthony's queue plus reverting the qcow2 patch -- the monitor prompt
> appears fine.

Try it with no disk or with a disk in a format other than qcow2. It's
still broken. With a qcow2 image (and the qcow2 patch reverted), two
bugs just cancel each other out.

If you really need to run BHs during initialization (which doesn't
really sound like the clean solution), call qemu_bh_poll() manually.

> 2. Current qemu tree plus my patch from Anthony's queue - the monitor
> prompt doesn't appear.
> 
> The difference is in the order the BHs are scheduled. In the case
> without the qcow2 patch, the bhs get scheduled early on and results in
> initial_reset_issued getting set. Later, when the char devs are
> initialsed, the OPENED event is sent out.
> 
> In the case with the qcow2 patch, the bhs are run in a different order
> -- the bhs are scheduled but not run, and when the char init happens,
> the condition
> 
> if (s->bh == NULL)
> 
> is false and the bhs in effect get scheduled only once, not emitting the
> opened event.
> 
> Of course, the qcow2 patch just causes some conditions for the bh
> handling to happen differently which I've not examined yet. I just
> tracked why this was happening.
> 
> All that said, I'm ok with reverting that patch now till I find some
> kind of a solution to this.

Which patch do you want to revert? You're aware that the qcow2 patch is
a data corruption fix?

Kevin
Amit Shah Oct. 27, 2009, 9:20 a.m. UTC | #8
On (Tue) Oct 27 2009 [09:40:27], Kevin Wolf wrote:
> > 
> > All that said, I'm ok with reverting that patch now till I find some
> > kind of a solution to this.
> 
> Which patch do you want to revert? You're aware that the qcow2 patch is
> a data corruption fix?

Ah, no. Reverting my patch that causes this problem. I know the qcow2
patch only exposes the bh handling issue. I intend to fix that
appropriately elsewhere :-)

		Amit
Anthony Liguori Oct. 27, 2009, 2:04 p.m. UTC | #9
Amit Shah wrote:
> On (Tue) Oct 27 2009 [09:40:27], Kevin Wolf wrote:
>   
>>> All that said, I'm ok with reverting that patch now till I find some
>>> kind of a solution to this.
>>>       
>> Which patch do you want to revert? You're aware that the qcow2 patch is
>> a data corruption fix?
>>     
>
> Ah, no. Reverting my patch that causes this problem. I know the qcow2
> patch only exposes the bh handling issue. I intend to fix that
> appropriately elsewhere :-)
>   

How does Kevin's latest patches that introduces new BHs semantics affect 
all of this?
Amit Shah Oct. 27, 2009, 2:14 p.m. UTC | #10
On (Tue) Oct 27 2009 [09:04:50], Anthony Liguori wrote:
> Amit Shah wrote:
>> On (Tue) Oct 27 2009 [09:40:27], Kevin Wolf wrote:
>>   
>>>> All that said, I'm ok with reverting that patch now till I find some
>>>> kind of a solution to this.
>>>>       
>>> Which patch do you want to revert? You're aware that the qcow2 patch is
>>> a data corruption fix?
>>>     
>>
>> Ah, no. Reverting my patch that causes this problem. I know the qcow2
>> patch only exposes the bh handling issue. I intend to fix that
>> appropriately elsewhere :-)
>>   
>
> How does Kevin's latest patches that introduces new BHs semantics affect  
> all of this?

I explained that a couple of mails ago in this thread in a reply to Jan.
Basically, the order in which the BHs run causes the problem, so it's a
race, and Kevin's patch make the BHs run later.

		Amit
Kevin Wolf Oct. 27, 2009, 2:22 p.m. UTC | #11
Am 27.10.2009 15:04, schrieb Anthony Liguori:
> Amit Shah wrote:
>> On (Tue) Oct 27 2009 [09:40:27], Kevin Wolf wrote:
>>   
>>>> All that said, I'm ok with reverting that patch now till I find some
>>>> kind of a solution to this.
>>>>       
>>> Which patch do you want to revert? You're aware that the qcow2 patch is
>>> a data corruption fix?
>>>     
>>
>> Ah, no. Reverting my patch that causes this problem. I know the qcow2
>> patch only exposes the bh handling issue. I intend to fix that
>> appropriately elsewhere :-)
>>   
> 
> How does Kevin's latest patches that introduces new BHs semantics affect 
> all of this?

I'd expect that it will make the bug visible it in the very same way as
the qcow2 workaround currently does. In both cases we don't run BHs that
the monitor/char code relies on to be run early.

Kevin
diff mbox

Patch

diff --git a/qemu-char.c b/qemu-char.c
index 4757689..0fd402c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -119,7 +119,12 @@  static void qemu_chr_event(CharDriverState *s, int event)
 static void qemu_chr_reset_bh(void *opaque)
 {
     CharDriverState *s = opaque;
-    qemu_chr_event(s, CHR_EVENT_OPENED);
+
+    if (s->initial_reset_issued) {
+        qemu_chr_event(s, CHR_EVENT_OPENED);
+    } else {
+        s->initial_reset_issued = true;
+    }
     qemu_bh_delete(s->bh);
     s->bh = NULL;
 }
diff --git a/qemu-char.h b/qemu-char.h
index 05fe15d..409961d 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -1,6 +1,7 @@ 
 #ifndef QEMU_CHAR_H
 #define QEMU_CHAR_H
 
+#include <stdbool.h>
 #include "qemu-common.h"
 #include "qemu-queue.h"
 #include "qemu-option.h"
@@ -66,6 +67,7 @@  struct CharDriverState {
     QEMUBH *bh;
     char *label;
     char *filename;
+    bool initial_reset_issued;
     QTAILQ_ENTRY(CharDriverState) next;
 };