From nobody Sun Nov 24 02:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1715768984634222.8280620904743; Wed, 15 May 2024 03:29:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8D9451B26; Wed, 15 May 2024 06:29:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id F40561A8F; Wed, 15 May 2024 06:28:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ACD5E1A13; Wed, 15 May 2024 06:28:15 -0400 (EDT) Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 72E7D1A10 for ; Wed, 15 May 2024 06:28:14 -0400 (EDT) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a5a88339780so156002166b.0 for ; Wed, 15 May 2024 03:28:14 -0700 (PDT) Received: from localhost.localdomain ([212.70.118.255]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b17754sm832975266b.192.2024.05.15.03.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 03:28:12 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715768893; x=1716373693; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SyXACupSKuaMzat/Ioj2Ab6AgTJVCfoEGS669iSJ2Dg=; b=jT7/XZAMByLRNEYH6lLd1eWHjORSroZSty1sZ9lP5PUpGoXlW3jMz8mlbQSXqN1nrd Vf59KWZ7fx5nOqdnq0fxkcZXmetxGr9sJ4GDbvDtFGOX02xB4AQLvSeqez8T9EtyqKHM itSBxx/0OwQK+6C+jv1gRL1rJE4J+tlOACYYknRPde9opFy701wVKHabCJqXF4uL8b/Q yBe7KXb6AJrtyfCu2FoHySPt+Ii+vY6qjOah6JHEcbuvIoIzERtId4PDlF0GT9eVRevV W/CszRLLagwr73wHI9fjOE30rU2w933tEI9J7AibMYpJDX7can7mnWoJYBVTExvHKeU1 t1TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715768893; x=1716373693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SyXACupSKuaMzat/Ioj2Ab6AgTJVCfoEGS669iSJ2Dg=; b=gZDN5G5Pz+YjicKdD27utTOSZUFwz77jJANGPZUjKUxSzd18l6YTvre/BykZmq0XIL k9FDd0heTTiyIwmUqL2Cxw/4wjSq6U8r1YpNdUuCaXdCu0jEi9DAImAGgTq9+LtnXcKn ipOqjTUiiM0bQqBytTkxdFfl9N7BkgUZRm5x/NJpg4T8dujIC6xM2zPf+bSKkETzbeUm WE3ix4wGGgw0XRYytHje+VJ9A7amUNelPAEVnGScv7iWSJMs4a1BDTUA3dKPV3O/0hTh N1QK3zD5BcPyH2m/a0ebQnMUtpC2aHI54xD5P3526FbcfTPCLjkmLc2T+wJGcGKZty6X u9Fg== X-Gm-Message-State: AOJu0Yy1otAUaexSgYqYr/k4CbclEFZrE+GnqLXDjfrHlSqR6+kKLg9O fXKc90OSSON5UVS687K7BUytYnoYgBQpOqja8OdvzxuuYMUilmRrmKrcrw== X-Google-Smtp-Source: AGHT+IE/PjLxaY88K0bwHjeHj8cSheA4aY7QI/skc+JbsdwvyvNtR3U8oBW6h9XIxi0bMmGnE9pl8Q== X-Received: by 2002:a17:906:3546:b0:a59:9ef3:f6df with SMTP id a640c23a62f3a-a5a2d581e6emr1074984666b.22.1715768892707; Wed, 15 May 2024 03:28:12 -0700 (PDT) From: Rayhan Faizel To: devel@lists.libvirt.org Subject: [PATCH 1/2] qemu: Implement support for hotplugging evdev input devices Date: Wed, 15 May 2024 15:57:53 +0530 Message-Id: <20240515102754.31493-2-rayhan.faizel@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240515102754.31493-1-rayhan.faizel@gmail.com> References: <20240515102754.31493-1-rayhan.faizel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JCDH5G64A5MEZ4DCZHBI77IEYCTJ3QCW X-Message-ID-Hash: JCDH5G64A5MEZ4DCZHBI77IEYCTJ3QCW X-MailFrom: rayhan.faizel@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Rayhan Faizel X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1715768986204100001 Content-Type: text/plain; charset="utf-8" Unlike other input types, evdev is not a true device since it's backed by '-object'. We must use object-add/object-del monitor commands instead of device-add/device-del in this particular case. This patch adds support for handling live attachment and detachment of evdev type devices. Signed-off-by: Rayhan Faizel --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_command.h | 3 ++ src/qemu/qemu_hotplug.c | 95 +++++++++++++++++++++++++++++------------ 3 files changed, 71 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9859ea67a4..63bfeb790e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4367,7 +4367,7 @@ qemuBuildInputUSBDevProps(const virDomainDef *def, } =20 =20 -static virJSONValue * +virJSONValue * qemuBuildInputEvdevProps(virDomainInputDef *dev) { g_autoptr(virJSONValue) props =3D NULL; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 341ec43f9a..dca8877703 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -233,6 +233,9 @@ virJSONValue * qemuBuildInputUSBDevProps(const virDomainDef *def, virDomainInputDef *dev); =20 +virJSONValue * +qemuBuildInputEvdevProps(virDomainInputDef *dev); + virJSONValue * qemuBuildVsockDevProps(virDomainDef *def, virDomainVsockDef *vsock, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3b39941780..4739beead8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3016,36 +3016,40 @@ qemuDomainAttachInputDevice(virDomainObj *vm, bool teardowncgroup =3D false; =20 qemuAssignDeviceInputAlias(vm->def, input, -1); + if (input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) { + if (!(devprops =3D qemuBuildInputEvdevProps(input))) + goto cleanup; + } else { + switch ((virDomainInputBus) input->bus) { + case VIR_DOMAIN_INPUT_BUS_USB: + if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < = 0) + return -1; =20 - switch ((virDomainInputBus) input->bus) { - case VIR_DOMAIN_INPUT_BUS_USB: - if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0) - return -1; - - releaseaddr =3D true; + releaseaddr =3D true; =20 - if (!(devprops =3D qemuBuildInputUSBDevProps(vm->def, input))) - goto cleanup; - break; + if (!(devprops =3D qemuBuildInputUSBDevProps(vm->def, input))) + goto cleanup; + break; =20 - case VIR_DOMAIN_INPUT_BUS_VIRTIO: - if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) - goto cleanup; + case VIR_DOMAIN_INPUT_BUS_VIRTIO: + if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) + goto cleanup; =20 - if (!(devprops =3D qemuBuildInputVirtioDevProps(vm->def, input, pr= iv->qemuCaps))) - goto cleanup; - break; + if (!(devprops =3D qemuBuildInputVirtioDevProps(vm->def, input= , priv->qemuCaps))) + goto cleanup; + break; =20 - case VIR_DOMAIN_INPUT_BUS_DEFAULT: - case VIR_DOMAIN_INPUT_BUS_PS2: - case VIR_DOMAIN_INPUT_BUS_XEN: - case VIR_DOMAIN_INPUT_BUS_PARALLELS: - case VIR_DOMAIN_INPUT_BUS_NONE: - case VIR_DOMAIN_INPUT_BUS_LAST: - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("input device on bus '%1$s' cannot be hot plugged= ."), - virDomainInputBusTypeToString(input->bus)); - return -1; + case VIR_DOMAIN_INPUT_BUS_DEFAULT: + case VIR_DOMAIN_INPUT_BUS_PS2: + case VIR_DOMAIN_INPUT_BUS_XEN: + case VIR_DOMAIN_INPUT_BUS_PARALLELS: + case VIR_DOMAIN_INPUT_BUS_NONE: + case VIR_DOMAIN_INPUT_BUS_LAST: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("input device on bus '%1$s' cannot be hot plugge= d."), + virDomainInputBusTypeToString(input->bus)); + return -1; + } } =20 if (qemuDomainNamespaceSetupInput(vm, input, &teardowndevice) < 0) @@ -3066,9 +3070,14 @@ qemuDomainAttachInputDevice(virDomainObj *vm, if (qemuDomainAttachExtensionDevice(priv->mon, &input->info) < 0) goto exit_monitor; =20 - if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) { - ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &input->in= fo)); - goto exit_monitor; + if (input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) { + if (qemuMonitorAddObject(priv->mon, &devprops, NULL) < 0) + goto exit_monitor; + } else { + if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) { + ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &input= ->info)); + goto exit_monitor; + } } =20 qemuDomainObjExitMonitor(vm); @@ -6093,6 +6102,29 @@ qemuDomainDetachDeviceLease(virQEMUDriver *driver, } =20 =20 +static int +qemuDomainDetachDeviceInputEvdev(virQEMUDriver *driver, + virDomainObj *vm, + virDomainDeviceDef *detach) +{ + int rc; + virDomainInputDef *input =3D detach->data.input; + qemuDomainObjPrivate *priv =3D vm->privateData; + + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorDelObject(priv->mon, input->info.alias, true); + qemuDomainObjExitMonitor(vm); + + if (rc < 0) + return -1; + + if (qemuDomainRemoveDevice(driver, vm, detach) < 0) + return -1; + + return 0; +} + + int qemuDomainDetachDeviceLive(virDomainObj *vm, virDomainDeviceDef *match, @@ -6176,6 +6208,13 @@ qemuDomainDetachDeviceLive(virDomainObj *vm, &detach.data.input) < 0) { return -1; } + + /* + * Input devices of type 'evdev' are regular QOM objects + * (-object instead of -device), so it must be handled differently. + */ + if (detach.data.input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) + return qemuDomainDetachDeviceInputEvdev(driver, vm, &detach); break; case VIR_DOMAIN_DEVICE_REDIRDEV: if (qemuDomainDetachPrepRedirdev(vm, match->data.redirdev, --=20 2.34.1