From: Hans de Goede <hdegoede@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] chardev-frontends: Explicitly check, inc and dec avail_connections
Date: Wed, 27 Mar 2013 16:36:30 +0100 [thread overview]
Message-ID: <515311FE.1050009@redhat.com> (raw)
In-Reply-To: <51530C15.2090901@redhat.com>
Hi,
On 03/27/2013 04:11 PM, Paolo Bonzini wrote:
<snip>
>> diff --git a/backends/rng-egd.c b/backends/rng-egd.c
>> index 5e012e9..d8e9d63 100644
>> --- a/backends/rng-egd.c
>> +++ b/backends/rng-egd.c
>> @@ -149,6 +149,12 @@ static void rng_egd_opened(RngBackend *b, Error **errp)
>> return;
>> }
>>
>> + if (s->chr->avail_connections < 1) {
>> + error_set(errp, QERR_DEVICE_IN_USE, s->chr_name);
>> + return;
>> + }
>> + s->chr->avail_connections--;
>> +
>> /* FIXME we should resubmit pending requests when the CDS reconnects. */
>> qemu_chr_add_handlers(s->chr, rng_egd_chr_can_read, rng_egd_chr_read,
>> NULL, s);
>> @@ -191,6 +197,7 @@ static void rng_egd_finalize(Object *obj)
>>
>> if (s->chr) {
>> qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL);
>> + s->chr->avail_connections++;
>> }
>>
>> g_free(s->chr_name);
>
> Ok, but please create wrappers for these (e.g. qemu_chr_be_start/stop
> and qemu_chr_be_start_nofail) and use them throughout.
That would be fe_start fe_stop, ack otherwise.
>> diff --git a/gdbstub.c b/gdbstub.c
>> index a666cb5..83267e0 100644
>> --- a/gdbstub.c
>> +++ b/gdbstub.c
>> @@ -3025,6 +3025,7 @@ int gdbserver_start(const char *device)
>> if (!chr)
>> return -1;
>>
>> + chr->avail_connections--;
>> qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
>> gdb_chr_event, NULL);
>> }
>
> Ok.
>
>> diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
>> index 7467cca..df4b458 100644
>> --- a/hw/arm/pxa2xx.c
>> +++ b/hw/arm/pxa2xx.c
>> @@ -1981,9 +1981,16 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,
>> memory_region_init_io(&s->iomem, &pxa2xx_fir_ops, s, "pxa2xx-fir", 0x1000);
>> memory_region_add_subregion(sysmem, base, &s->iomem);
>>
>> - if (chr)
>> + if (chr) {
>> + if (chr->avail_connections < 1) {
>> + fprintf(stderr, "pxa2xx_fir_init error chardev %s already used\n",
>> + chr->label);
>> + exit(1);
>> + }
>> + chr->avail_connections--;
>> qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty,
>> pxa2xx_fir_rx, pxa2xx_fir_event, s);
>> + }
>>
>> register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save,
>> pxa2xx_fir_load, s);
>
> Errors won't be reported, because serial_hds[] will always create its
> own CharDriverState and avail_connections will always be 1. Use a
> wrapper and the code can ignore this.
Unless some smartass adds, ie: -mon chardev=serial0 to the cmdline, then an
error will be reported.
I'll respin the patch taking your comments into account.
Regards,
Hans
next prev parent reply other threads:[~2013-03-27 15:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-27 14:10 [Qemu-devel] [PATCH] chardev-frontends: Explicitly check, inc and dec avail_connections Hans de Goede
2013-03-27 15:11 ` Paolo Bonzini
2013-03-27 15:36 ` Hans de Goede [this message]
2013-03-27 15:37 ` Paolo Bonzini
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=515311FE.1050009@redhat.com \
--to=hdegoede@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 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).