From nobody Sun Feb 8 13:16:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615982281; cv=none; d=zohomail.com; s=zohoarc; b=ULl5yFR+R9JYhZnzuzPzLG193FMJyTyvWdXW8FzI2vFG4YWmLOaI7kZBlOzjOB24ayYFyogRlP2FF/kLPTwfMwLitVXx6DTn/yv8/Ad01d4Mcgk4MiN082zbdfj9qsnVGqpqCDxXVu7AlZg//BU+UtAkggm9bmPzBzVVFYO0GgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615982281; 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=MvrbMBC0XaSYWSEQW+FA7SkG/4vW06t/D2uX9vp8zLI=; b=Jb0i6bJ1ytNzb/LxlYSA7CgT9B7Apg6xawYzzZSch0K2gZivWxGr3eEAk9H7jl9k6dWsepGhST6Iv9sFpWb3cmgB7J4ND9i/C6tZgXNQlI5SZ7Z052fh6Hl0xbe/dwJe/jhnyzACg3Not1JC+QYVnFNL3tPV7M7k/KtorD63iu8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615982281401268.0672777958322; Wed, 17 Mar 2021 04:58:01 -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-278-PFSg8--RNwypLVdHi6XRWQ-1; Wed, 17 Mar 2021 07:57:58 -0400 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 0FD60A0CA6; Wed, 17 Mar 2021 11:57:53 +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 DCD9C610F0; Wed, 17 Mar 2021 11:57:52 +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 976F74A7CA; Wed, 17 Mar 2021 11:57:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12HBvatM028249 for ; Wed, 17 Mar 2021 07:57:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9FB49101E249; Wed, 17 Mar 2021 11:57:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC5B81017CF5; Wed, 17 Mar 2021 11:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615982280; 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=MvrbMBC0XaSYWSEQW+FA7SkG/4vW06t/D2uX9vp8zLI=; b=Nt/5qhkdMy7JtFElvOOYe3lhPNmyAGWpI+kG0X35ea2GMBxYLgm1ShTnyXL2CZs70anO6P jpuG8VY3kOZGVeWnI3n+SYFuig9eR5D1wEsT4qiC2IEg9G1aJGuWFMzpXWinm9lvw55N2+ OX4/jFZOjP+V3C0lHWJybBuyT41zIUU= X-MC-Unique: PFSg8--RNwypLVdHi6XRWQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 02/15] qemu_process: Deduplicate code in qemuProcessNeedHugepagesPath() Date: Wed, 17 Mar 2021 12:57:12 +0100 Message-Id: <89983f23aba9d44d846d291ab3635bf9e4936eed.1615982004.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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.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-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 5f31260221..74667206b9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3862,6 +3862,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) @@ -3878,16 +3899,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