From nobody Mon Feb 9 19:08:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644422717; cv=none; d=zohomail.com; s=zohoarc; b=PHB2/bIMVxeP1X1+I7qjAm/MM7Zbpb7nyE08oe+Kq0lGFo9xRKMy6n8VHWFf9+yOF4++yupb0m7e4wLJPQI6iXNnmQX4QxvFcHLXQ1xj49U3q5n125SQvVEBEH8p+9cJAawAShAxYKW5E66UGHf3dpRrIXwS6tilahJ8ULJkAt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644422717; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pjUoRMnKAkEUNhRpn1QTOSsHfLHkl2oxPw1ASr9DGQg=; b=ciH0udRminP7WmYYuNwV39rw+RCKHCzF3VRw5yXZv3C8wlBJSx5XIfcZp9iWW/kf3lih4mbYwBrVukPpFlMlQdNRTG9O9SBhCes7Wehv2n0+mv/GCbCnwVrulWqquNK3Zp/llVhZcQH+4csedfFA1QA1YNCxlHN28HNLzAYDBWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644422717642386.0856972297993; Wed, 9 Feb 2022 08:05:17 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-329-lY3Xn6v0OrWqgPE-yySyRw-1; Wed, 09 Feb 2022 11:03:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBEA485EE6A; Wed, 9 Feb 2022 16:03:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B70D47DE59; Wed, 9 Feb 2022 16:03:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 794D94A708; Wed, 9 Feb 2022 16:03:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 219G2xYX012526 for ; Wed, 9 Feb 2022 11:02:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id B4E88838C3; Wed, 9 Feb 2022 16:02:59 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC988838D3 for ; Wed, 9 Feb 2022 16:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644422716; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=pjUoRMnKAkEUNhRpn1QTOSsHfLHkl2oxPw1ASr9DGQg=; b=YIiTk6OYAqfRSIwpbY8/dNKW3IeOVQzvhuKznSJjTMJZ1QUke+GnfhHNHvAsy8XhDf9ZXG 0PjtFVQjId0h9R60UZbpfomBeGmDBCPHo5TPvgSUSt4Mx3+YYneRZppyiE87KBFDfLDTpF cqA5flv/f7iVajbfAYGdjlNXiKYWlUc= X-MC-Unique: lY3Xn6v0OrWqgPE-yySyRw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 24/27] qemu: Honour 'virtlogd' use when hotplugging chardevs Date: Wed, 9 Feb 2022 17:02:16 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644422719658100001 Content-Type: text/plain; charset="utf-8" Setup the chardev similarly to how we do it on startup so that virtlogd is properly used with chardevs which are hotplugged to a VM. Signed-off-by: Peter Krempa --- src/qemu/qemu_driver.c | 3 +-- src/qemu/qemu_hotplug.c | 25 ++++++++++++++++++++++--- src/qemu/qemu_hotplug.h | 2 +- tests/qemuhotplugmock.c | 11 +++++++++++ tests/qemuhotplugtest.c | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9279eaf811..d6876baa34 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6730,8 +6730,7 @@ qemuDomainAttachDeviceLive(virDomainObj *vm, break; case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainAttachChrDevice(driver, vm, - dev->data.chr); + ret =3D qemuDomainAttachChrDevice(driver, vm, dev); if (!ret) { alias =3D dev->data.chr->info.alias; dev->data.chr =3D NULL; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e05edffae2..01523ce508 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2180,10 +2180,14 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainObj *v= m, return 0; } -int qemuDomainAttachChrDevice(virQEMUDriver *driver, - virDomainObj *vm, - virDomainChrDef *chr) + +int +qemuDomainAttachChrDevice(virQEMUDriver *driver, + virDomainObj *vm, + virDomainDeviceDef *dev) { + virDomainChrDef *chr =3D dev->data.chr; + qemuDomainChrSourcePrivate *charpriv =3D QEMU_DOMAIN_CHR_SOURCE_PRIVAT= E(chr->source); int ret =3D -1; qemuDomainObjPrivate *priv =3D vm->privateData; virErrorPtr orig_err; @@ -2224,6 +2228,19 @@ int qemuDomainAttachChrDevice(virQEMUDriver *driver, goto cleanup; teardowncgroup =3D true; + if (qemuProcessPrepareHostBackendChardevHotplug(vm, dev) < 0) + goto cleanup; + + if (charpriv->sourcefd || charpriv->logfd) { + qemuDomainObjEnterMonitor(driver, vm); + + if (qemuFDPassTransferMonitor(charpriv->sourcefd, priv->mon) < 0 || + qemuFDPassTransferMonitor(charpriv->logfd, priv->mon) < 0) + goto exit_monitor; + + qemuDomainObjExitMonitor(driver, vm); + } + if (guestfwd) { if (!(netdevprops =3D qemuBuildChannelGuestfwdNetdevProps(chr))) goto cleanup; @@ -2286,6 +2303,8 @@ int qemuDomainAttachChrDevice(virQEMUDriver *driver, /* detach associated chardev on error */ if (chardevAttached) qemuMonitorDetachCharDev(priv->mon, charAlias); + qemuFDPassTransferMonitorRollback(charpriv->sourcefd, priv->mon); + qemuFDPassTransferMonitorRollback(charpriv->logfd, priv->mon); qemuDomainObjExitMonitor(driver, vm); virErrorRestore(&orig_err); diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 244dd5278d..19c07497b5 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -117,7 +117,7 @@ int qemuDomainAttachLease(virQEMUDriver *driver, virDomainLeaseDef *lease); int qemuDomainAttachChrDevice(virQEMUDriver *driver, virDomainObj *vm, - virDomainChrDef *chr); + virDomainDeviceDef *dev); int qemuDomainAttachRNGDevice(virQEMUDriver *driver, virDomainObj *vm, virDomainRNGDef *rng); diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c index 051f2b20dc..e3f0715058 100644 --- a/tests/qemuhotplugmock.c +++ b/tests/qemuhotplugmock.c @@ -21,6 +21,7 @@ #include "qemu/qemu_hotplug.h" #include "qemu/qemu_interface.h" #include "qemu/qemu_process.h" +#include "testutilsqemu.h" #include "conf/domain_conf.h" #include "virdevmapper.h" #include "virutil.h" @@ -96,3 +97,13 @@ qemuInterfaceVDPAConnect(virDomainNetDef *net G_GNUC_UNU= SED) /* need a valid fd or sendmsg won't work. Just open /dev/null */ return open("/dev/null", O_RDONLY); } + + +int +qemuProcessPrepareHostBackendChardevHotplug(virDomainObj *vm, + virDomainDeviceDef *dev) +{ + return qemuDomainDeviceBackendChardevForeachOne(dev, + testQemuPrepareHostBac= kendChardevOne, + vm); +} diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index fe1b227b4e..ce215da099 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -135,7 +135,7 @@ testQemuHotplugAttach(virDomainObj *vm, ret =3D qemuDomainAttachDeviceDiskLive(&driver, vm, dev); break; case VIR_DOMAIN_DEVICE_CHR: - ret =3D qemuDomainAttachChrDevice(&driver, vm, dev->data.chr); + ret =3D qemuDomainAttachChrDevice(&driver, vm, dev); break; case VIR_DOMAIN_DEVICE_SHMEM: ret =3D qemuDomainAttachShmemDevice(&driver, vm, dev->data.shmem); --=20 2.34.1