Skip to contentSkip to conversation

Add chardev-send-break monitor command

PATCH Applied Stefan Fritsch 5 participants 8 messages Jun 11, 2017 – Jul 19, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add chardev-send-break monitor command

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

 chardev/char.c    | 12 ++++++++++++
 hmp-commands.hx   | 16 ++++++++++++++++
 hmp.c             |  8 ++++++++
 hmp.h             |  1 +
 qapi-schema.json  | 20 ++++++++++++++++++++
 tests/test-char.c | 12 ++++++++++--
 tests/test-hmp.c  |  1 +
 7 files changed, 68 insertions(+), 2 deletions(-)
chardev/char.c +12 -0
index 7aa0210765..cc56bca672 100644
@@ -951,6 +951,18 @@ void qmp_chardev_remove(const char *id, Error **errp)
     object_unparent(OBJECT(chr));
 }
 
+void qmp_chardev_send_break(const char *id, Error **errp)
+{
+    Chardev *chr;
+
+    chr = qemu_chr_find(id);
+    if (chr == NULL) {
+        error_setg(errp, "Chardev '%s' not found", id);
+        return;
+    }
+    qemu_chr_be_event(chr, CHR_EVENT_BREAK);
+}
+
 void qemu_chr_cleanup(void)
 {
     object_unparent(get_chardevs_root());
hmp-commands.hx +16 -0
index e763606fe5..fc8d54b52a 100644
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",
+        .cmd        = hmp_chardev_send_break,
+        .command_completion = chardev_remove_completion,
+    },
+
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.
+
+ETEXI
+
+    {
         .name       = "qemu-io",
         .args_type  = "device:B,command:s",
         .params     = "[device] \"[command]\"",
hmp.c +8 -0
index 8c72c58b20..94cafe970e 100644
@@ -2233,6 +2233,14 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
     hmp_handle_error(mon, &local_err);
 }
 
+void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
+{
+    Error *local_err = NULL;
+
+    qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
+    hmp_handle_error(mon, &local_err);
+}
+
 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
 {
     BlockBackend *blk;
hmp.h +1 -0
index d8b94ce9dc..214b2617e7 100644
@@ -103,6 +103,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
 void hmp_chardev_add(Monitor *mon, const QDict *qdict);
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict);
+void hmp_chardev_send_break(Monitor *mon, const QDict *qdict);
 void hmp_qemu_io(Monitor *mon, const QDict *qdict);
 void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
qapi-schema.json +20 -0
index 4b50b652d3..e01dd83dd9 100644
@@ -5114,6 +5114,26 @@
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
+# @chardev-send-break:
+#
+# Send a break to a character device
+#
+# @id: the chardev's ID, must exist
+#
+# Returns: Nothing on success
+#
+# Since: 2.10
+#
+# Example:
+#
+# -> { "execute": "chardev-send-break", "arguments": { "id" : "foo" } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'chardev-send-break', 'data': {'id': 'str'} }
+
+
+##
 # @TpmModel:
 #
 # An enumeration of TPM models
tests/test-char.c +10 -2
index dfe856cb85..c7f7ec1798 100644
@@ -53,7 +53,9 @@ static void fe_event(void *opaque, int event)
     FeHandler *h = opaque;
 
     h->last_event = event;
-    quit = true;
+    if (event != CHR_EVENT_BREAK) {
+        quit = true;
+    }
 }
 
 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
@@ -491,7 +493,7 @@ static void char_file_test(void)
 
         file.in = fifo;
         file.has_in = true;
-        chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend,
+        chr = qemu_chardev_new("label-file", TYPE_CHARDEV_FILE, &backend,
                                &error_abort);
 
         qemu_chr_fe_init(&be, chr, &error_abort);
@@ -501,6 +503,12 @@ static void char_file_test(void)
                                  fe_event,
                                  &fe, NULL, true);
 
+        g_assert_cmpint(fe.last_event, !=, CHR_EVENT_BREAK);
+        qmp_chardev_send_break("label-foo", NULL);
+        g_assert_cmpint(fe.last_event, !=, CHR_EVENT_BREAK);
+        qmp_chardev_send_break("label-file", NULL);
+        g_assert_cmpint(fe.last_event, ==, CHR_EVENT_BREAK);
+
         main_loop();
 
         close(fd);
tests/test-hmp.c +1 -0
index 99e35ec15a..6dfa0c36e2 100644
@@ -22,6 +22,7 @@ static int verbose;
 static const char *hmp_cmds[] = {
     "boot_set ndc",
     "chardev-add null,id=testchardev1",
+    "chardev-send-break testchardev2",
     "chardev-remove testchardev1",
     "commit all",
     "cpu-add 1",
Signature · 1 line
2.11.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

+++ b/hmp-commands.hx

hmp-commands.hx Removes the chardev @var{id}. · line 1751

Quoted 7 lines
hmp-commands.hx +4 -0
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",

Compare this wording,...

hmp-commands.hx Removes the chardev @var{id}. · line 1759

Quoted 4 lines
hmp-commands.hx +4 -0
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.

repeated here,

qapi-schema.json line 5119

Quoted 8 lines
qapi-schema.json +4 -0
+++ b/qapi-schema.json
@@ -5114,6 +5114,26 @@
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
+# @chardev-send-break:
+#
+# Send a break to a character device

...with this wording. I like 'send a break' better than 'send break', but even better might be 'send a break sequence' or even 'emulate a break sequence' (by definition, a break is NOT a character, but on bare metal character devices it IS a defined electrical sequence distinct from characters to make the recipient aware that the sender is trying to get attention).

Otherwise, the patch looks fine to me. If all that changes is some word-smithing (and the maintainer may be willing to do that), you can add:

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Reviewed-by
#2 lore raw
Quoted 9 lines · Eric Blake
Quoted 7 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

Looks good to me,

Quoted 39 lines

---

hmp-commands.hx Removes the chardev @var{id}. · line 1751

Quoted 12 lines

v2: added tests and Acked-by line

+++ b/hmp-commands.hx

hmp-commands.hx +4 -0
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",

Compare this wording,...

hmp-commands.hx Removes the chardev @var{id}. · line 1759

Quoted 4 lines
hmp-commands.hx +4 -0
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.

repeated here,

qapi-schema.json line 5119

Quoted 8 lines
qapi-schema.json +4 -0
+++ b/qapi-schema.json
@@ -5114,6 +5114,26 @@
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
+# @chardev-send-break:
+#
+# Send a break to a character device

...with this wording. I like 'send a break' better than 'send break', but even better might be 'send a break sequence' or even 'emulate a break sequence' (by definition, a break is NOT a character, but on bare metal character devices it IS a defined electrical sequence distinct from characters to make the recipient aware that the sender is trying to get attention).

Quoted 4 lines

Otherwise, the patch looks fine to me. If all that changes is some word-smithing (and the maintainer may be willing to do that), you can add:

Paolo would you take it (perhaps on the next iteration)?

thanks

Signature · 1 line
Marc-André Lureau
#3 lore raw
Quoted 55 lines · * Marc-André Lureau ([email protected]) wrote:
Quoted 9 lines · Eric Blake
Quoted 7 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

Looks good to me,

Quoted 39 lines

---

hmp-commands.hx Removes the chardev @var{id}. · line 1751

Quoted 12 lines

v2: added tests and Acked-by line

+++ b/hmp-commands.hx

hmp-commands.hx +4 -0
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",

Compare this wording,...

hmp-commands.hx Removes the chardev @var{id}. · line 1759

Quoted 4 lines
hmp-commands.hx +4 -0
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.

repeated here,

qapi-schema.json line 5119

Quoted 8 lines
qapi-schema.json +4 -0
+++ b/qapi-schema.json
@@ -5114,6 +5114,26 @@
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
+# @chardev-send-break:
+#
+# Send a break to a character device

...with this wording. I like 'send a break' better than 'send break', but even better might be 'send a break sequence' or even 'emulate a break sequence' (by definition, a break is NOT a character, but on bare metal character devices it IS a defined electrical sequence distinct from characters to make the recipient aware that the sender is trying to get attention).

Quoted 6 lines
Quoted 4 lines

Otherwise, the patch looks fine to me. If all that changes is some word-smithing (and the maintainer may be willing to do that), you can add:

Paolo would you take it (perhaps on the next iteration)?

I can take it through HMP; I'm just doing a pull now.

Dave

Quoted 3 lines

thanks

Signature · 1 line
Marc-André Lureau

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#4 lore raw
In reply to Eric Blake
Quoted 47 lines · * Eric Blake ([email protected]) wrote:
Quoted 13 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

+++ b/hmp-commands.hx

Review Removes the chardev @var{id}. · line 1751

Quoted 7 lines
(quoted diff) +4 -0
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 ETEXI
 
     {
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",

Compare this wording,...

Review Removes the chardev @var{id}. · line 1755

Quoted 4 lines
(quoted diff) +4 -0
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.

repeated here,

Review line 5119

Quoted 8 lines
(quoted diff) +4 -0
+++ b/qapi-schema.json
@@ -5114,6 +5114,26 @@
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
+# @chardev-send-break:
+#
+# Send a break to a character device

...with this wording. I like 'send a break' better than 'send break', but even better might be 'send a break sequence' or even 'emulate a break sequence' (by definition, a break is NOT a character, but on bare metal character devices it IS a defined electrical sequence distinct from characters to make the recipient aware that the sender is trying to get attention).

Quoted 3 lines

Otherwise, the patch looks fine to me. If all that changes is some word-smithing (and the maintainer may be willing to do that), you can add:

I'll go with the 'send a break' - the official terminology seems to be a 'break condition', but I've never heard anyone say that, it's always been 'send a break'.

hmp-commands.hx +2 -2
index fc8d54b52a..275ccdfbc7 100644
@@ -1748,7 +1748,7 @@ ETEXI
         .name       = "chardev-send-break",
         .args_type  = "id:s",
         .params     = "id",
-        .help       = "send break on chardev",
+        .help       = "send a break on chardev",
         .cmd        = hmp_chardev_send_break,
         .command_completion = chardev_remove_completion,
     },
@@ -1756,7 +1756,7 @@ ETEXI
 STEXI
 @item chardev-send-break id
 @findex chardev-send-break
-Sends break on the chardev @var{id}.
+Send a break on the chardev @var{id}.
 
 ETEXI
 

Queued to HMP

Dave

Quoted 6 lines
Signature · 4 lines
-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#5 lore raw
Quoted 52 lines · On Thursday, 29 June 2017 16:00:54 CEST Dr. David Alan Gilbert wrote:
Quoted 51 lines · * Eric Blake ([email protected]) wrote:
Quoted 13 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

+++ b/hmp-commands.hx

Review Removes the chardev @var{id}. · line 1753

Quoted 9 lines
(quoted diff) +4 -0
@@ -1745,6 +1745,22 @@ Removes the chardev @var{id}.
 
 ETEXI
 
     {
 
+        .name       = "chardev-send-break",
+        .args_type  = "id:s",
+        .params     = "id",
+        .help       = "send break on chardev",

Compare this wording,...

Review Removes the chardev @var{id}. · line 1757

Quoted 4 lines
(quoted diff) +4 -0
+STEXI
+@item chardev-send-break id
+@findex chardev-send-break
+Sends break on the chardev @var{id}.

repeated here,

Review line 5121

Quoted 10 lines
(quoted diff) +4 -0
+++ b/qapi-schema.json
@@ -5114,6 +5114,26 @@
 
 { 'command': 'chardev-remove', 'data': {'id': 'str'} }
 
 ##
 
+# @chardev-send-break:
+#
+# Send a break to a character device

...with this wording. I like 'send a break' better than 'send break', but even better might be 'send a break sequence' or even 'emulate a break sequence' (by definition, a break is NOT a character, but on bare metal character devices it IS a defined electrical sequence distinct from characters to make the recipient aware that the sender is trying to get attention).

Quoted 7 lines
Quoted 3 lines

Otherwise, the patch looks fine to me. If all that changes is some word-smithing (and the maintainer may be willing to do that), you can add:

I'll go with the 'send a break' - the official terminology seems to be a 'break condition', but I've never heard anyone say that, it's always been 'send a break'.

I also think that "send a break" is best for people who google for it.

Thanks.

Cheers,
Stefan

#6 lore raw
In reply to Stefan Fritsch

Hi,

Quoted 9 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

[...]

tests/test-hmp.c static int verbose; · line 28

Quoted 12 lines
tests/test-hmp.c +1 -0
index 99e35ec15a..6dfa0c36e2 100644
@@ -22,6 +22,7 @@ static int verbose;
 static const char *hmp_cmds[] = {
     "boot_set ndc",
     "chardev-add null,id=testchardev1",
+    "chardev-send-break testchardev2",
     "chardev-remove testchardev1",
     "commit all",
     "cpu-add 1",

Did you use "testchardev2" here on purpose, or should that have been a "testchardev1" instead? "testchardev2" is not a valid identifier in the HMP test, so this might not exercise the code path that you might have intended?

Thomas

#7 lore raw
Quoted 20 lines · Thomas Huth
Quoted 9 lines · Stefan Fritsch

Sending a break on a serial console can be useful for debugging the guest. But not all chardev backends support sending breaks (only telnet and mux do). The chardev-send-break command allows to send a break even if using other backends.

---
v2: added tests and Acked-by line

[...]

Quoted 9 lines
tests/test-hmp.c +1 -0
index 99e35ec15a..6dfa0c36e2 100644
@@ -22,6 +22,7 @@ static int verbose;
 static const char *hmp_cmds[] = {
     "boot_set ndc",
     "chardev-add null,id=testchardev1",
+    "chardev-send-break testchardev2",
Quoted 8 lines

tests/test-hmp.c static int verbose; · line 28

Quoted 3 lines
tests/test-hmp.c +0 -0
     "chardev-remove testchardev1",
     "commit all",
     "cpu-add 1",

Did you use "testchardev2" here on purpose, or should that have been a "testchardev1" instead? "testchardev2" is not a valid identifier in the HMP test, so this might not exercise the code path that you might have intended?

You are right, this should have been "testchardev1". Actually, one could do both, which would then exercise two different code paths.

Cheers,
Stefan