From nobody Mon Feb 9 19:53:07 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=1614971736; cv=none; d=zohomail.com; s=zohoarc; b=MeYuRz4Urtrt+/fDZZp/Uy6sLHgcl2AqINMgr1dLi4OlkaZ8iuh5oOF5ASX9eaLMa7FGKTGf+ThteQEP4bswvQJp54FIexqmA5vP4URspjGSqJzFi2UZWhdnB0hMflMILwfqhyKAQMdpB235KztWWUmGi/NsX03EPGf1gByjvyo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971736; 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=NxIq4xaFMPlT1rQQwZ1tBh1ifMFCUBOEwYIGJ2kYtwM=; b=AJLJZTWtBpZHrcR75SHFqV+7QkbJ3og+rf3nW8nQ7up9ehxb6L8uqEzamwUuWVthFRBQ/LuiaozA2DL6Cnb3dP+Jf/N/wSiOapo8xt0XKtdC7mNETrvxPSkb4uOK3AzpGG8780DdFs0DMdt2Mn5xXBUUm3uHhvhUdY0jDPPhluU= 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 1614971736965894.3346129831049; Fri, 5 Mar 2021 11:15:36 -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-564-ygGjxuyfNo2LpyznZtT6MA-1; Fri, 05 Mar 2021 14:15:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F54B1842146; Fri, 5 Mar 2021 19:15:26 +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 55F3E1053B20; Fri, 5 Mar 2021 19:15:26 +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 E4D971801016; Fri, 5 Mar 2021 19:15:25 +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 125JEUY7001885 for ; Fri, 5 Mar 2021 14:14:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 021CA5D6DC; Fri, 5 Mar 2021 19:14:30 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57D0F5D6B1 for ; Fri, 5 Mar 2021 19:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971735; 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=NxIq4xaFMPlT1rQQwZ1tBh1ifMFCUBOEwYIGJ2kYtwM=; b=J1djOodtJx5Tn5R8HtTsVhfqG0A27EJ/VYpEywstqzpqx3HlIvvOq9zBWEc0b8mnS5AfzK saJQGSmytLOldSXnIBBjt9QG3882PilsWYFJmcJex5Bt7Sd3Tkg6mowMarvwa7ifvtg665 owkFv8SfI1G/NszO3JuamHd1lagWjQE= X-MC-Unique: ygGjxuyfNo2LpyznZtT6MA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 14/17] qemu: Refactor qemuDomainAdjustMaxMemLock() Date: Fri, 5 Mar 2021 20:14:01 +0100 Message-Id: <20210305191404.529903-15-abologna@redhat.com> In-Reply-To: <20210305191404.529903-1-abologna@redhat.com> References: <20210305191404.529903-1-abologna@redhat.com> 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.84 on 10.5.11.22 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" Store the current memory locking limit and the desired one separately, which will help with later changes. Signed-off-by: Andrea Bolognani --- src/qemu/qemu_domain.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1e9178764b..f8b0e1a62a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9239,27 +9239,29 @@ int qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, bool forceVFIO) { - unsigned long long bytes =3D 0; + unsigned long long currentMemLock =3D 0; + unsigned long long desiredMemLock =3D 0; =20 - bytes =3D qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO); + desiredMemLock =3D qemuDomainGetMemLockLimitBytes(vm->def, forceVFIO); + if (virProcessGetMaxMemLock(vm->pid, ¤tMemLock) < 0) + return -1; =20 - if (bytes) { + if (desiredMemLock > 0) { /* If this is the first time adjusting the limit, save the current * value so that we can restore it once memory locking is no longer * required */ - if (!vm->originalMemlock) { - if (virProcessGetMaxMemLock(vm->pid, &(vm->originalMemlock)) <= 0) - return -1; + if (vm->originalMemlock =3D=3D 0) { + vm->originalMemlock =3D currentMemLock; } } else { /* Once memory locking is no longer required, we can restore the * original, usually very low, limit */ - bytes =3D vm->originalMemlock; + desiredMemLock =3D vm->originalMemlock; vm->originalMemlock =3D 0; } =20 - if (bytes > 0 && - virProcessSetMaxMemLock(vm->pid, bytes) < 0) { + if (desiredMemLock > 0 && + virProcessSetMaxMemLock(vm->pid, desiredMemLock) < 0) { return -1; } =20 --=20 2.26.2