From nobody Mon Feb 9 00:06:01 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=1612365977; cv=none; d=zohomail.com; s=zohoarc; b=jUOOQzlzaZlf52KZTAkR7cie+cqr+SND2LyirHmeCVkhF0ZFvVCyNWk4Z7Wx2gS2j0cNDwHEqorA48dFt/HBXAjU7nMCgq8uEfs9heAKr3Vh/WfoiyekoUw0R8JpOaUWtVb0MUXYo05PkMgzg7LMN+8ZR84TY3x8Mv7zQSjpIF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612365977; 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=/kP08TobvIKpgULV86jV898CSdqqzHVCJEaK/sSSsAo=; b=A0Ovb2SqNDmQkazMj23lTKl4Sqi7sUoQFQ5rE4p9uImMeFtqxUkZXLGz0AhJh7Rt4Cndg3EgnbmVAT416739kksTOw0W0OjM/yU5tdxsp2mIqU31KjIQ/TpKpsyJjd/j3iL1cgPrzy1k0r1y+J+fKILb0hZho3fhNEdaobBgtlU= 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) header.from= 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 1612365977938811.5245970838114; Wed, 3 Feb 2021 07:26:17 -0800 (PST) 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-34-JKr_pHg9NdWhMh-RH1aSew-1; Wed, 03 Feb 2021 10:26:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 818BA1936B60; Wed, 3 Feb 2021 15:26:09 +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 F38A360C13; Wed, 3 Feb 2021 15:26:08 +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 0A2EA49; Wed, 3 Feb 2021 15:26:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 113FQ5bk002776 for ; Wed, 3 Feb 2021 10:26:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3B2035B692; Wed, 3 Feb 2021 15:26:05 +0000 (UTC) Received: from antique-work.lan (unknown [10.40.192.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB4425D6A8 for ; Wed, 3 Feb 2021 15:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612365976; 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=/kP08TobvIKpgULV86jV898CSdqqzHVCJEaK/sSSsAo=; b=gqoB9sHIeOAkUJrd/FhG4Fo/GYNj3FnapTsLJq+oNp5zLCkMF9qFtLvLi1rMq52Mjqc+d1 tc4AyrG3i6l0pJDD1WuwPcOkKUJC4kzrE6PMJHV+cv+9VVBYGD34160zj3BLTKfKcrKoqn Iji4AgskMWEVOHVuvoRHOY2790yRfak= X-MC-Unique: JKr_pHg9NdWhMh-RH1aSew-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/6] qemu_validate: move and refactor qemuValidateDomainDefVirtioFSSharedMemory Date: Wed, 3 Feb 2021 16:25:55 +0100 Message-Id: <2fb9bf2959494a52e0adb34a3953f62d8423997a.1612364698.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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) Make the function reusable by other vhost-user based devices. Signed-off-by: Pavel Hrdina Reviewed-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- Changes in v2: - added documentation for qemuValidateDomainDefVhostUserRequireSharedMe= mory src/qemu/qemu_validate.c | 111 ++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index faadfbf7c8..f5016e4d0c 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1381,6 +1381,66 @@ qemuValidateDomainVirtioOptions(const virDomainVirti= oOptions *virtio, } =20 =20 +/** + * qemuValidateDomainDefVhostUserRequireSharedMemory: + * @def: VM definition + * @name: name of the attribute/element + * @qemuCaps: capabilities of QEMU binary + * + * Check if the VM definition contains any form of shared memory + * which is required by vhost-user devices to operate properly. + * + * On success returns 0, on error returns -1 and reports proper error + * message. + */ +static int +qemuValidateDomainDefVhostUserRequireSharedMemory(const virDomainDef *def, + const char *name, + virQEMUCapsPtr qemuCaps) +{ + const char *defaultRAMId =3D virQEMUCapsGetMachineDefaultRAMid(qemuCap= s, + def->virt= Type, + def->os.m= achine); + size_t numa_nodes =3D virDomainNumaGetNodeCount(def->numa); + size_t i; + + if (numa_nodes =3D=3D 0 && + !(defaultRAMId && def->mem.access =3D=3D VIR_DOMAIN_MEMORY_ACCESS_= SHARED)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("'%s' requires shared memory"), name); + return -1; + } + + for (i =3D 0; i < numa_nodes; i++) { + virDomainMemoryAccess node_access =3D + virDomainNumaGetNodeMemoryAccessMode(def->numa, i); + + switch (node_access) { + case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT: + if (def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_SHARED) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("'%s' requires shared memory"), name); + return -1; + } + break; + case VIR_DOMAIN_MEMORY_ACCESS_SHARED: + break; + case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("'%s' requires shared memory"), name); + return -1; + + case VIR_DOMAIN_MEMORY_ACCESS_LAST: + default: + virReportEnumRangeError(virDomainMemoryAccess, node_access); + return -1; + + } + } + return 0; +} + + static int qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net, virQEMUCapsPtr qemuCaps) @@ -3948,53 +4008,6 @@ qemuValidateDomainDeviceDefGraphics(const virDomainG= raphicsDef *graphics, } =20 =20 -static int -qemuValidateDomainDefVirtioFSSharedMemory(const virDomainDef *def, - virQEMUCapsPtr qemuCaps) -{ - const char *defaultRAMId =3D virQEMUCapsGetMachineDefaultRAMid(qemuCap= s, - def->virt= Type, - def->os.m= achine); - size_t numa_nodes =3D virDomainNumaGetNodeCount(def->numa); - size_t i; - - if (numa_nodes =3D=3D 0 && - !(defaultRAMId && def->mem.access =3D=3D VIR_DOMAIN_MEMORY_ACCESS_= SHARED)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtiofs requires shared memory")); - return -1; - } - - for (i =3D 0; i < numa_nodes; i++) { - virDomainMemoryAccess node_access =3D - virDomainNumaGetNodeMemoryAccessMode(def->numa, i); - - switch (node_access) { - case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT: - if (def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_SHARED) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtiofs requires shared memory")); - return -1; - } - break; - case VIR_DOMAIN_MEMORY_ACCESS_SHARED: - break; - case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("virtiofs requires shared memory")); - return -1; - - case VIR_DOMAIN_MEMORY_ACCESS_LAST: - default: - virReportEnumRangeError(virDomainMemoryAccess, node_access); - return -1; - - } - } - return 0; -} - - static int qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs, const virDomainDef *def, @@ -4092,8 +4105,10 @@ qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs, _("virtiofs does not support fmode and dmode")); return -1; } - if (qemuValidateDomainDefVirtioFSSharedMemory(def, qemuCaps) < 0) + if (qemuValidateDomainDefVhostUserRequireSharedMemory(def, "virtio= fs", + qemuCaps) < = 0) { return -1; + } if (fs->info.bootIndex && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOST_USER_FS_BOOTINDEX)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", --=20 2.29.2