Skip to contentSkip to conversation

ui/input: strictly check console in finding input handler

PATCH In review Amos Kong 3 participants 6 messages Nov 4, 2014 – Nov 7, 2014

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 ui/input: strictly check console in finding input handler

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

'input-send-event' has a parameter to assign special console, so we should enable strict checking in finding handler.

---
 ui/input.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
ui/input.c +8 -4
index 002831e..61b26a0 100644
@@ -98,7 +98,7 @@ void qemu_input_handler_bind(QemuInputHandlerState *s,
 }
 
 static QemuInputHandlerState*
-qemu_input_find_handler(uint32_t mask, QemuConsole *con)
+qemu_input_find_handler(uint32_t mask, QemuConsole *con, bool strict_con)
 {
     QemuInputHandlerState *s;
 
@@ -111,6 +111,10 @@ qemu_input_find_handler(uint32_t mask, QemuConsole *con)
         }
     }
 
+    if (strict_con) {
+        return NULL;
+    }
+
     QTAILQ_FOREACH(s, &handlers, node) {
         if (s->con != NULL) {
             continue;
@@ -142,7 +146,7 @@ void qmp_input_send_event(int64_t console, InputEventList *events,
     for (e = events; e != NULL; e = e->next) {
         InputEvent *event = e->value;
 
-        if (!qemu_input_find_handler(1 << event->kind, con)) {
+        if (!qemu_input_find_handler(1 << event->kind, con, true)) {
             error_setg(errp, "Input handler not found for "
                              "event type %s",
                             InputEventKind_lookup[event->kind]);
@@ -311,7 +315,7 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
     }
 
     /* send event */
-    s = qemu_input_find_handler(1 << evt->kind, src);
+    s = qemu_input_find_handler(1 << evt->kind, src, NULL);
     if (!s) {
         return;
     }
@@ -428,7 +432,7 @@ bool qemu_input_is_absolute(void)
     QemuInputHandlerState *s;
 
     s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS,
-                                NULL);
+                                NULL, NULL);
     return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
 }
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 7 lines · Amos Kong

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

'input-send-event' has a parameter to assign special console, so we should enable strict checking in finding handler.

I don't think we want do that by default. It only matters in case of a multiseat setup where you actually have multiple input devices of the same kind. Which isn't a very typical use case.

Options I see are:

(a) Turn console into an optional parameter, do strict checking in case it is present.
(b) Add a optional 'strict' parameter.

cheers,
Gerd

author
#2 lore raw
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Amos Kong

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

If console is assigned, it will try to find right handler by first loop in qemu_input_find_handler(). The second loop is used to find mask matched handler if console isn't assigned.

If we assigned console and didn't find handler in first loop, it skip second loop body by 'continue', and return NULL.
It seems my concern is wrong, we don't need this repeated parameter.

NACK this patch.

Thanks.

Quoted 12 lines
Quoted 2 lines

'input-send-event' has a parameter to assign special console, so we should enable strict checking in finding handler.

I don't think we want do that by default. It only matters in case of a multiseat setup where you actually have multiple input devices of the same kind. Which isn't a very typical use case.

Options I see are:

(a) Turn console into an optional parameter, do strict checking in case it is present.
(b) Add a optional 'strict' parameter.

Signature · 1 line
			Amos.
author
#3 lore raw
Quoted 7 lines · Amos Kong
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Amos Kong

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

Quoted 7 lines

If console is assigned, it will try to find right handler by first loop in qemu_input_find_handler(). The second loop is used to find mask matched handler if console isn't assigned.

If we assigned console and didn't find handler in first loop, it skip second loop body by 'continue', and return NULL.
It seems my concern is wrong, we don't need this repeated parameter.

I was wrong, if we don't assign the console for qemu_input_find_handler(), it has chance to get an arbitrary console (mask matched). So the original issue this patch try to fix truely exists.

Quoted 11 lines

NACK this patch.

Thanks.

Quoted 7 lines
Quoted 2 lines

'input-send-event' has a parameter to assign special console, so we should enable strict checking in finding handler.

I don't think we want do that by default. It only matters in case of a multiseat setup where you actually have multiple input devices of the same kind. Which isn't a very typical use case.

Quoted 8 lines
Quoted 5 lines

Options I see are:

(a) Turn console into an optional parameter, do strict checking in case it is present.
(b) Add a optional 'strict' parameter.

Signature · 1 line
			Amos.

From Markus:

Quoted 22 lines

Current behavior (please correct misunderstandings):

The guest must be running.
input-send-event parameter 'console' is mandatory. The console identified by its value must exist.
If this console can accept the event, send it there. Else, a console that can accept the event must exist. Send it to
one of them. Which one exactly isn't specified.

Behavior with (a):

The guest must be running.
input-send-event parameter 'console' is optional.
If it's present, the console identified by its value must exist, and
must be able to accept the event. Send it there. Else, a console that can accept the event must exist. Send it to
one of them. Which one exactly isn't specified.

Quoted 5 lines

"Must" means "or else command fails".

I think that's a clear improvement. It's actually what I expected from
the command documentation, until I read the code.

Thanks for your clear description, I now agree with Gerd's option (a),
(a) is better than (b). So we need to change QMP to support optional console parameter and change qemu_input_find_handler() to support strict checking (as my patch).

Gerd, I'd like to work on both of them, if you already work on it, please let me know, thanks.

Signature · 1 line
			Amos.
author
#4 lore raw
Quoted 12 lines · Amos Kong
Quoted 11 lines · Amos Kong
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Amos Kong

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

If console is assigned, it will try to find right handler by first loop in qemu_input_find_handler(). The second loop is used to find mask matched handler if console isn't assigned.

Quoted 7 lines
Quoted 3 lines

If we assigned console and didn't find handler in first loop, it skip second loop body by 'continue', and return NULL.
It seems my concern is wrong, we don't need this repeated parameter.

I was wrong, if we don't assign the console for qemu_input_find_handler(), it has chance to get an arbitrary console (mask matched). So the original issue this patch try to fix truely exists.

The 'console' in my mind was the input destination, so I thgouth we need to distinguish the console with strictly checking.

The 'QemuConsole' is the input source for handler, we share some input handlers to process the input events from different QemuConsole.

Normally we only have one set of keyboard, mouse, usbtablet, etc. The devices have different mask, it's fine to just checking mask to insure that the handler has the ability to process the event.

I saw we try to bind console to handler in usb/dev-hid.c, but display always isn't available at that time.

If we have multiseat setup (as Gerd said), we only have 'problem' in this case. Actually event from different devices have the same effect for system, it's fine to always use the first available handler without caring about the console.

For send-key command, we just pass a NULL for console parameter in calling qemu_input_event_send_key(NULL, ..)

Conclusion:
* Generally assigning the special console is meanless, and we can't directly remove the QMP parameter for compatibility.

So we can make the parameter optional. The parameter might be useful for some special condition: we have multiple devices without binding console and they all have the ability(mask) to process events, and we don't want to use the first one.

Thanks. Amos

#5 lore raw
In reply to Gerd Hoffmann
Quoted 13 lines · Gerd Hoffmann
Quoted 7 lines · Amos Kong

qemu_input_find_handler() prefers a handler associated with con. But if none exists, it takes any. This patch added a parameter to strictly check console, in case we want to input event to special console.

'input-send-event' has a parameter to assign special console, so we should enable strict checking in finding handler.

I don't think we want do that by default. It only matters in case of a multiseat setup where you actually have multiple input devices of the same kind. Which isn't a very typical use case.

Quoted 5 lines

Options I see are:

(a) Turn console into an optional parameter, do strict checking in case it is present.
(b) Add a optional 'strict' parameter.

Current behavior (please correct misunderstandings):

The guest must be running.
input-send-event parameter 'console' is mandatory.
The console identified by its value must exist.
If this console can accept the event, send it there. Else, a console that can accept the event must exist. Send it to one of them. Which one exactly isn't specified.

Behavior with (a):

The guest must be running.
input-send-event parameter 'console' is optional.
If it's present, the console identified by its value must exist, and must be able to accept the event. Send it there.
Else, a console that can accept the event must exist. Send it to one of them. Which one exactly isn't specified.

"Must" means "or else command fails".

I think that's a clear improvement. It's actually what I expected from the command documentation, until I read the code.