From nobody Sun Feb 8 19:43:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1634040912; cv=none; d=zohomail.com; s=zohoarc; b=hWRCHNlzO/YG4XQDkj37I5cfDOpAei8CV/XcVGlO5Y1Kaeu2nzhxmriArRi2Zea9i3anUp4OgOKnNPuJFMEPwLEyqn6h2Mo2e7zAVGk6TlKQwAes57gE3Y5IcjpwNP6rNqrxCM1u+GaMI5m4gsEuaxdSiQq8bEhT+muLFde+6rQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634040912; 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=QGwELFyqorhSRwqOW6empR6WAWcVghNbHz+J9C/97dg=; b=me8XKgOs3COUWTgENvRHI/INeN9IkyzyWGOOnYR3X+pN3byu98jusNUO9fiDZtbWqsYB0GQ2mhoJ5/Ka5gRDuFn/Fs/QhPE4HAUoV3ynH4Wj2BSwvXaKkMqP3d7/iOWPlu0Y9wJXIAVntDYPC6q8jWVHhzOYZwnErI/H0kD7RW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1634040912570226.92564191447593; Tue, 12 Oct 2021 05:15:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-pKfbI5EAOkmzMIdN1mu95Q-1; Tue, 12 Oct 2021 08:15:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6535210066F3; Tue, 12 Oct 2021 12:14:56 +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 9B78C7092B; Tue, 12 Oct 2021 12:14:55 +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 E1F6C4E58E; Tue, 12 Oct 2021 12:14:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19CCEpCx015181 for ; Tue, 12 Oct 2021 08:14:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id A71F119736; Tue, 12 Oct 2021 12:14:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ECF019730 for ; Tue, 12 Oct 2021 12:14:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634040911; 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=QGwELFyqorhSRwqOW6empR6WAWcVghNbHz+J9C/97dg=; b=cc3mi2wHHKg1tXmbQRsHtnwGYzJjMK1yPbDnLzHJcMaiTXCqRuiNeuJgvgXACwrmm1/eB6 MZUbyiWLpQJFMvGQj/s3P40a5PTrm+6VM9mfW9jPntAE/c0ccFXEIXyojwQEPvoB+8SCae K+pA6c53FKT2u/b8a94jBcG4WQ/GCDU= X-MC-Unique: pKfbI5EAOkmzMIdN1mu95Q-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv3 1/2] qemu: implement virtiofs hotplug Date: Tue, 12 Oct 2021 14:14:43 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.13 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1634040913177100003 https://bugzilla.redhat.com/show_bug.cgi?id=3D1897708 Signed-off-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 9 +++- src/qemu/qemu_hotplug.c | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e0a3b4d978..2b759f5719 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6945,8 +6945,15 @@ qemuDomainAttachDeviceLive(virDomainObj *vm, } break; =20 - case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: + ret =3D qemuDomainAttachFSDevice(driver, vm, dev->data.fs); + if (ret =3D=3D 0) { + alias =3D dev->data.fs->info.alias; + dev->data.fs =3D NULL; + } + break; + + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_SOUND: case VIR_DOMAIN_DEVICE_VIDEO: case VIR_DOMAIN_DEVICE_GRAPHICS: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index b9937220db..5289b57f04 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -35,6 +35,7 @@ #include "qemu_security.h" #include "qemu_block.h" #include "qemu_snapshot.h" +#include "qemu_virtiofs.h" #include "domain_audit.h" #include "netdev_bandwidth_conf.h" #include "domain_nwfilter.h" @@ -3419,6 +3420,104 @@ qemuDomainAttachVsockDevice(virQEMUDriver *driver, } =20 =20 +int +qemuDomainAttachFSDevice(virQEMUDriver *driver, + virDomainObj *vm, + virDomainFSDef *fs) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + virDomainDeviceDef dev =3D { VIR_DOMAIN_DEVICE_FS, + { .fs =3D fs } }; + g_autoptr(virDomainChrSourceDef) chardev =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; + virErrorPtr origErr =3D NULL; + bool releaseaddr =3D false; + bool chardevAdded =3D false; + bool started =3D false; + g_autofree char *charAlias =3D NULL; + int ret =3D -1; + + if (fs->fsdriver !=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("only virtiofs filesystems can be hotplugged")); + return -1; + } + + if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) + return -1; + + if (qemuAssignDeviceFSAlias(vm->def, fs) < 0) + goto cleanup; + + chardev =3D virDomainChrSourceDefNew(priv->driver->xmlopt); + chardev->type =3D VIR_DOMAIN_CHR_TYPE_UNIX; + chardev->data.nix.path =3D qemuDomainGetVHostUserFSSocketPath(priv, fs= ); + + charAlias =3D qemuDomainGetVhostUserChrAlias(fs->info.alias); + + if (qemuBuildVHostUserFsDevProps(fs, vm->def, charAlias, priv) < 0) + goto cleanup; + + if (!fs->sock) { + if (qemuVirtioFSPrepareDomain(driver, fs) < 0) + goto cleanup; + + if (qemuVirtioFSStart(driver, vm, fs) < 0) + goto cleanup; + started =3D true; + + if (qemuVirtioFSSetupCgroup(vm, fs, priv->cgroup) < 0) + goto cleanup; + } + + qemuDomainObjEnterMonitor(driver, vm); + + if (qemuMonitorAttachCharDev(priv->mon, charAlias, chardev) < 0) + goto exit_monitor; + chardevAdded =3D true; + + if (qemuDomainAttachExtensionDevice(priv->mon, &fs->info) < 0) + goto exit_monitor; + + if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) { + ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &fs->info)= ); + goto exit_monitor; + } + + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + releaseaddr =3D false; + goto cleanup; + } + + VIR_APPEND_ELEMENT_COPY(vm->def->fss, vm->def->nfss, fs); + + ret =3D 0; + + audit: + virDomainAuditFS(vm, NULL, fs, "attach", ret =3D=3D 0); + cleanup: + if (ret < 0) { + virErrorPreserveLast(&origErr); + if (releaseaddr) + qemuDomainReleaseDeviceAddress(vm, &fs->info); + if (started) + qemuVirtioFSStop(driver, vm, fs); + virErrorRestore(&origErr); + } + + return ret; + + exit_monitor: + virErrorPreserveLast(&origErr); + if (chardevAdded) + ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias)); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + releaseaddr =3D false; + virErrorRestore(&origErr); + goto audit; +} + + int qemuDomainAttachLease(virQEMUDriver *driver, virDomainObj *vm, --=20 2.31.1