char: Allow devices to use a single multiplexed chardev.
PATCH 1/1 char: Allow devices to use a single multiplexed chardev.
This fixes regression caused by commit 2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6 ("char: Prevent multiple devices opening same chardev").
--- hw/qdev-properties.c | 4 ++-- qemu-char.c | 5 ++++- qemu-char.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)
hw/qdev-properties.c +2 -2
@@ -354,10 +354,10 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)if (*ptr ==NULL ) {return -ENOENT ; } -if ((*ptr)->assigned) { +if ((*ptr)->avail <1 ) {return -EEXIST ; } - (*ptr)->assigned =1 ; + --(*ptr)->avail;return 0 ; }
qemu-char.c +4 -1
@@ -199,7 +199,7 @@ void qemu_chr_add_handlers(CharDriverState *s, {if (!opaque) {/* chr driver being released. */ - s->assigned =0 ; + ++s->avail; } s->chr_can_read = fd_can_read; s->chr_read = fd_read;
@@ -2544,7 +2544,10 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,snprintf (base->label, len,"%s-base" ,qemu_opts_id (opts)); chr =qemu_chr_open_mux (base); chr->filename = base->filename; + chr->avail =MAX_MUX ;QTAILQ_INSERT_TAIL (&chardevs, chr, next); + }else { + chr->avail =1 ; } chr->label =qemu_strdup (qemu_opts_id (opts));return chr;
qemu-char.h +1 -1
@@ -70,7 +70,7 @@ struct CharDriverState {char *label;char *filename;int opened; -int assigned;/* chardev assigned to a device */ +int avail;QTAILQ_ENTRY (CharDriverState) next; };
Signature · 1 line
1.7.4.4
Quoted 3 lines · Kusanagi Kouichi
This fixes regression caused by commit
2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6("char: Prevent multiple devices opening same chardev").
What's the regression? How do I test it?
Quoted 29 lines
Signed-off-by Kusanagi Kouichi <[email protected]>--- hw/qdev-properties.c | 4 ++-- qemu-char.c | 5 ++++- qemu-char.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)hw/qdev-properties.c +2
-2@@ -354,10 +354,10 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)if (*ptr ==NULL ) {return -ENOENT ; } -if ((*ptr)->assigned) { +if ((*ptr)->avail <1 ) {return -EEXIST ; } - (*ptr)->assigned =1 ; + --(*ptr)->avail;return 0 ; }qemu-char.c +0
-0
qemu-char.c void qemu_chr_add_handlers(CharDriverState *s, · line 203
Quoted 6 lines
qemu-char.c +1
-1@@ -199,7 +199,7 @@ void qemu_chr_add_handlers(CharDriverState *s, {if (!opaque) {/* chr driver being released. */ - s->assigned =0 ; + ++s->avail; }
Will just checking for handlers (fd_can_read, fd_read, fd_write not NULL) here help instead of this patch?
Quoted 30 lines
qemu-char.c +3
-0s->chr_can_read = fd_can_read; s->chr_read = fd_read;@@ -2544,7 +2544,10 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,snprintf (base->label, len,"%s-base" ,qemu_opts_id (opts)); chr =qemu_chr_open_mux (base); chr->filename = base->filename; + chr->avail =MAX_MUX ;QTAILQ_INSERT_TAIL (&chardevs, chr, next); + }else { + chr->avail =1 ; } chr->label =qemu_strdup (qemu_opts_id (opts));return chr;qemu-char.h +1
-1@@ -70,7 +70,7 @@ struct CharDriverState {char *label;char *filename;int opened; -int assigned;/* chardev assigned to a device */ +int avail;QTAILQ_ENTRY (CharDriverState) next; };Signature · 1 line
1.7.4.4
Amit
Quoted 7 lines · Amit Shah
Quoted 3 lines · Kusanagi Kouichi
This fixes regression caused by commit
2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6("char: Prevent multiple devices opening same chardev").What's the regression? How do I test it?
-nodefaults -nographic -chardev stdio,id=stdio,mux=on,signal=off -mon stdio -device virtio-serial-pci -device virtconsole,chardev=stdio -device isa-serial,chardev=stdio fails with
qemu-system-x86_64: -device isa-serial,chardev=stdio: Property 'isa-serial.chardev' can't take value 'stdio', it's in use
Is this intended?
Quoted 24 lines
Quoted 24 lines
Signed-off-by Kusanagi Kouichi <[email protected]>--- hw/qdev-properties.c | 4 ++-- qemu-char.c | 5 ++++- qemu-char.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-)hw/qdev-properties.c +2
-2@@ -354,10 +354,10 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)if (*ptr ==NULL ) {return -ENOENT ; } -if ((*ptr)->assigned) { +if ((*ptr)->avail <1 ) {return -EEXIST ; } - (*ptr)->assigned =1 ; + --(*ptr)->avail;return 0 ; }
Quoted 15 lines
qemu-char.c void qemu_chr_add_handlers(CharDriverState *s, · line 203
Quoted 11 lines
qemu-char.c +1
-1@@ -199,7 +199,7 @@ void qemu_chr_add_handlers(CharDriverState *s, {if (!opaque) {/* chr driver being released. */ - s->assigned =0 ; + ++s->avail; }Will just checking for handlers (
fd_can_read,fd_read,fd_writenot NULL) here help instead of this patch?
That doesn't help.
Quoted 32 lines
Quoted 30 lines
qemu-char.c +3
-0s->chr_can_read = fd_can_read; s->chr_read = fd_read;@@ -2544,7 +2544,10 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,snprintf (base->label, len,"%s-base" ,qemu_opts_id (opts)); chr =qemu_chr_open_mux (base); chr->filename = base->filename; + chr->avail =MAX_MUX ;QTAILQ_INSERT_TAIL (&chardevs, chr, next); + }else { + chr->avail =1 ; } chr->label =qemu_strdup (qemu_opts_id (opts));return chr;qemu-char.h +1
-1@@ -70,7 +70,7 @@ struct CharDriverState {char *label;char *filename;int opened; -int assigned;/* chardev assigned to a device */ +int avail;QTAILQ_ENTRY (CharDriverState) next; };Signature · 1 line
1.7.4.4Amit
Quoted 6 lines · Kusanagi Kouichi
Quoted 5 lines · Amit Shah
Quoted 3 lines · Kusanagi Kouichi
This fixes regression caused by commit
2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6("char: Prevent multiple devices opening same chardev").
Quoted 6 lines
Quoted 2 lines
What's the regression? How do I test it?
-nodefaults -nographic -chardev stdio,id=stdio,mux=on,signal=off -mon stdio -device virtio-serial-pci -device virtconsole,chardev=stdio -device isa-serial,chardev=stdio fails with
qemu-system-x86_64: -device isa-serial,chardev=stdio: Property 'isa-serial.chardev' can't take value 'stdio', it's in use
OK, so please mention it in the commit message :-)
Quoted 1 line
Is this intended?
No, it's not.
Just one more thing:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
hw/qdev-properties.c +0
-0@@ -354,10 +354,10 @@ static int parse_chr(DeviceState *dev, Property *prop, const char *str)if (*ptr ==NULL ) {return -ENOENT ; }
Quoted 8 lines
Quoted 8 lines
hw/qdev-properties.c static int parse_chr(DeviceState *dev, Property *prop, const char *str) · line 362
Quoted 8 lines
hw/qdev-properties.c +2
-2-if ((*ptr)->assigned) { +if ((*ptr)->avail <1 ) {return -EEXIST ; } - (*ptr)->assigned =1 ; + --(*ptr)->avail;return 0 ; }
'avail' isn't readily intuitive. Can you use a better name, like 'avail_connections' or something like that?
Please CC me on the updated patch.
Amit