From nobody Mon Feb 9 09:32:28 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=1615297664; cv=none; d=zohomail.com; s=zohoarc; b=i7oPlXnWk6a0yCbpTRNP3xD4Q59hi7RoISgsLaeoiX22smYkiwA6RtPjvLkenk8wJKaAheFM4Mt7R73KXvTt/nnfiCiUsrDoHgj2eLBCtgLGpCMhlL+9rep7sRaz2282XSfr1w572N5qk1fzT7LUIpmsTJ8AfRU71cqBwdHCqgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615297664; 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=PCvkY3dCytJjiwnw1l48Tb76gKghtHLrxx58WikQHvs=; b=lKSmbcMiuUInv3nwNWKjFzDYj4KAOykDcQKP02pauOyWXo3yQBWght/7EvJ4jMMAfQT5qLtQ9FWMGAcgy8gtFDkEl2FTFK6Ntice8QKvdD/6w8LwcGEy4jU1ZPwUuGmjyW4wGqKOlCi9SGHXfL11kWOahhgErXiFSQCvT284/w4= 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 1615297664165667.0010350934859; Tue, 9 Mar 2021 05:47:44 -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-321-jnWBcHHaP9qMDwVA0FEyDQ-1; Tue, 09 Mar 2021 08:47:40 -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 02232101F01A; Tue, 9 Mar 2021 13:47:34 +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 CDB8F60C17; Tue, 9 Mar 2021 13:47:33 +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 8CEF357DC7; Tue, 9 Mar 2021 13:47:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 129DlMmM013249 for ; Tue, 9 Mar 2021 08:47:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id F1B155C261; Tue, 9 Mar 2021 13:47:21 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.196.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09C425C233 for ; Tue, 9 Mar 2021 13:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615297663; 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=PCvkY3dCytJjiwnw1l48Tb76gKghtHLrxx58WikQHvs=; b=gZAgp2Ly8qsULMMwDLeB/x6NtuBXqR1cQfQ18Fnyc8Z1n1VMh6ooQRkPs3KOkbQrVdu56o O545PgVvAY7v1JAV4Xrm6+pjSrsw5Rbhgo9GuVV6LnoerK8gThIzb6BNQHAL2GVJqtwmeB 9bt6wUg+dfDTLlW1ykDnRLAzn8OSuro= X-MC-Unique: jnWBcHHaP9qMDwVA0FEyDQ-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/4] qemu: Refactor qemuDomainAdjustMaxMemLock() Date: Tue, 9 Mar 2021 14:47:08 +0100 Message-Id: <20210309134709.44613-4-abologna@redhat.com> In-Reply-To: <20210309134709.44613-1-abologna@redhat.com> References: <20210309134709.44613-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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-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 Reviewed-by: Michal Privoznik --- 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