From nobody Sun Feb 8 11:06:54 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=1633504630; cv=none; d=zohomail.com; s=zohoarc; b=AFCDwdCScf3kpec1+r18vOXPyqKivEc1Q68jHMhLMtGy7/RQ2fIPyoW7V2Wdy8JyUdjocOMGRSLSyZlP8eIL1qLd9i6iOQI5BX1VmRpBqEy+voqZiaU+MXytPOJHhm0rBEGDdHFtN36CSqzwFoLnfdHEfSfRWmQrteHcAEPsHD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633504630; 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=KxVWa100loTQAothnzqfGO4yRLXd1iEUqx8L4bjyDV8=; b=WNJOcplxxhDr2aASOhhGe9XT6eJmDQhgxVM8CnzOkmiPb9ziPRQlXZTU2+Pe3GCtrXycdEfbaASkmAZGm+6Q3YWVh65x7HSMFT2I6lcu6IpOmEZWQSjRzlfkO8T3p5ogppDqpwcPk22kQ8l+1eBvKI3kCjVoFecZ0YFppISY/ao= 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 163350463080730.861723245640064; Wed, 6 Oct 2021 00:17:10 -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-559-RC_ChmmDPFiqfXV4EYatMQ-1; Wed, 06 Oct 2021 03:16:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFC0A10151E4; Wed, 6 Oct 2021 07:16:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCA8D5D9D5; Wed, 6 Oct 2021 07:16:53 +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 9731C181A1D0; Wed, 6 Oct 2021 07:16:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1967G5oJ007640 for ; Wed, 6 Oct 2021 03:16:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5CE1260936; Wed, 6 Oct 2021 07:16:05 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id D758A60853 for ; Wed, 6 Oct 2021 07:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633504629; 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=KxVWa100loTQAothnzqfGO4yRLXd1iEUqx8L4bjyDV8=; b=b2IGbJqlOiLfyuI+nuXfw8voozsiaozlPkbTE1jiU2sBFTvJDThqfo4kJirIYxzvyQnWEL /io5tWhFxiGfW0HwWShAJh17wjT44aybVENZQv/Loi04szaZqDTv+agvOIaEx7jNSCCTln KXTdF2M6p05nhrydTdlmwQSC6bFgStQ= X-MC-Unique: RC_ChmmDPFiqfXV4EYatMQ-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 15/16] qemu: implement virtiofs hotplug Date: Wed, 6 Oct 2021 09:15:21 +0200 Message-Id: <6c045257ea788ec84127bc493c79ccfc075cd2cf.1633504466.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.14 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: 1633504631106100001 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 | 96 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 760d30a867..65b2ef8e86 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 22239b2689..f5dad0b829 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" @@ -3396,6 +3397,101 @@ 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; + virErrorPtr origErr =3D NULL; + bool releaseaddr =3D false; + bool chardevAdded =3D false; + bool started =3D false; + g_autofree char *devstr =3D NULL; + 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 qemuDomainGetVHostUserChrSourceDef(priv, fs); + charAlias =3D qemuDomainGetVhostUserChrAlias(fs->info.alias); + + if (!(devstr =3D qemuBuildVHostUserFsDevStr(fs, vm->def, charAlias, pr= iv))) + goto cleanup; + + if (!fs->sock) { + if (qemuVirtioFSPrepareDomain(driver, fs) < 0) + goto cleanup; + + if (qemuVirtioFSStart(qemuDomainLogContextGetManager(priv->logCtxt= ), 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 (qemuMonitorAddDevice(priv->mon, devstr) < 0) { + ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &fs->info)= ); + goto exit_monitor; + } + + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + releaseaddr =3D false; + goto cleanup; + } + + VIR_APPEND_ELEMENT(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