From nobody Mon Feb 9 01:50:46 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=1613655094; cv=none; d=zohomail.com; s=zohoarc; b=Kc2EsOy1eQXvIBYpAIR/sUa0TGUFaABy2d6lS7g3FnAWjlx4wH9LSAqgHS9evHuibHRz7hKLyLvT4GYD6IDaZ/Z4SecWu52E0Z4zNxUDb4Wjod34m/g4ak4zz17G9QGeAT+bC5nTBx/jpTXXUdhqXjd1h5ZtJMXChDdW/gOiqQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613655094; h=Content-Type:Content-Transfer-Encoding:Cc: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=KrUVfmYx5eQuNF1IEkw21ZSbKG9ZGXBSyRbV0RFTLgA=; b=ZCdR2YHIeXnQ4KqNePw43yLnJRDgEJt4RYuO5l2twDBjGrKeiGlcflvrYXpKVM2EFWLxDsiFaCcjzqKKlXn0fE4s1pTcUf3Ko8mXdJZS25sNRnTT2jGmS/8OlFpgc+rsR4W7CTlbVMQ276OVghu3cNkXBxRVrSYcs1Xw7MtlUm8= 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) header.from= 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 1613655094298935.1614922215265; Thu, 18 Feb 2021 05:31:34 -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-459-mdKxSMFQM0-11uB1km-0jA-1; Thu, 18 Feb 2021 08:31:30 -0500 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 1B30A80197B; Thu, 18 Feb 2021 13:31:25 +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 EA1066A03D; Thu, 18 Feb 2021 13:31:24 +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 2D91118095CC; Thu, 18 Feb 2021 13:31:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11IDVLUq022091 for ; Thu, 18 Feb 2021 08:31:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5DE532BFE9; Thu, 18 Feb 2021 13:31:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8AF660BD8; Thu, 18 Feb 2021 13:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613655093; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=KrUVfmYx5eQuNF1IEkw21ZSbKG9ZGXBSyRbV0RFTLgA=; b=eTuYM/4zCvaG5Uj0SkAOpTugJZ01hHQ2poBhVl2XuNIjxjp86zyum2NtwxCeGpzmV1kSfq MytB9/gqQdXWXveLJRFl3keAx6kh0xN2nma+woMvhBPBvmBykReFwQVPDug/XfgAt5/Wo2 tFB4oVZ41GB82JfAXLXp9Z/9tg1QDJ0= X-MC-Unique: mdKxSMFQM0-11uB1km-0jA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 02/13] qemu_process: Deduplicate code in qemuProcessNeedHugepagesPath() Date: Thu, 18 Feb 2021 14:30:57 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: david@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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The aim of qemuProcessNeedHugepagesPath() is to return whether guest needs private path inside HugeTLBFS mounts (deducted from domain definition @def) or whether the memory device that user is hotplugging in needs the private path (deducted from the @mem argument). The actual creation of the path is done in the only caller qemuProcessBuildDestroyMemoryPaths(). The rule for the first case (@def) and the second case (@mem) is the same (domain has a DIMM device that has HP requested) and is written twice. Move the logic into a function to deduplicate the code. Signed-off-by: Michal Privoznik --- src/qemu/qemu_process.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7feb35e609..6a223e18c2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3863,6 +3863,27 @@ qemuProcessReconnectCheckMemAliasOrderMismatch(virDo= mainObjPtr vm) } =20 =20 +static bool +qemuProcessDomainMemoryDefNeedHugepagesPath(const virDomainMemoryDef *mem, + const long system_pagesize) +{ + switch (mem->model) { + case VIR_DOMAIN_MEMORY_MODEL_DIMM: + return mem->pagesize && + mem->pagesize !=3D system_pagesize; + + case VIR_DOMAIN_MEMORY_MODEL_NONE: + case VIR_DOMAIN_MEMORY_MODEL_NVDIMM: + case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM: + case VIR_DOMAIN_MEMORY_MODEL_LAST: + /* None of these can be backed by hugepages. */ + return false; + } + + return false; +} + + static bool qemuProcessNeedHugepagesPath(virDomainDefPtr def, virDomainMemoryDefPtr mem) @@ -3879,16 +3900,12 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, } =20 for (i =3D 0; i < def->nmems; i++) { - if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && - def->mems[i]->pagesize && - def->mems[i]->pagesize !=3D system_pagesize) + if (qemuProcessDomainMemoryDefNeedHugepagesPath(def->mems[i], syst= em_pagesize)) return true; } =20 if (mem && - mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_DIMM && - mem->pagesize && - mem->pagesize !=3D system_pagesize) + qemuProcessDomainMemoryDefNeedHugepagesPath(mem, system_pagesize)) return true; =20 return false; --=20 2.26.2