From nobody Sat May 4 17:02:36 2024 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=1614971729; cv=none; d=zohomail.com; s=zohoarc; b=ZmBoxbZkxtHqT/xvIJHj/IOOoiz8rQDpPiHsbGcaydzo61stLA487V7nGLazwUIU92YpVbHObnVzET9opaSqSTGo8fmDIHHOV5bCF5ovqs/jN20bRU2C2MsVj4n2TivqtP6GuntSc7AW0K2GJD1i8kBhQMIWAhuJHrwzcHXKSFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971729; 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=3hJerjYwj/ouv3ZP2KFimG5T4Kasj8ImyOHNufWmlSA=; b=mpv3uHMCCZhketEHswlG6JKgqNg0T24NlRdn1F4M5j0zTAHjls6Bppv6UhO/N5YAtzVdUFMfk1twn70y3UrrBaiv//a/ccqHmzTKUsISpkps4F0xjZIBbCJ2pWMblEWZzRuryJ32jq14Xs30Dv9TX+zKy8kbKsFR47vrJl3qNdM= 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 1614971729422575.5129654765889; Fri, 5 Mar 2021 11:15:29 -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-467-egTqiRH2OuyGkeT0NwbCSw-1; Fri, 05 Mar 2021 14:15:24 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3033814315; Fri, 5 Mar 2021 19:15:17 +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 A349C5D9CC; Fri, 5 Mar 2021 19:15:17 +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 671B31809C8E; Fri, 5 Mar 2021 19:15:17 +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 125JECDG001697 for ; Fri, 5 Mar 2021 14:14:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id BA8475D6DC; Fri, 5 Mar 2021 19:14:12 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1FE845D6B1 for ; Fri, 5 Mar 2021 19:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971726; 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=3hJerjYwj/ouv3ZP2KFimG5T4Kasj8ImyOHNufWmlSA=; b=CDX6CKDa1uxcKdz7qVtRH0QyLklZczrJkaa8SUr3H51zDlRo1ko3/y9i4Dzw1KZhtbfy2e urCieYWTDrxUGedJAjwDBKzRrEhZasJb6hOzIxrYJSz/rnonyKvXy81+wQ47nu5byeSv0l aA0oBn5cIIJobyNPbClac2zSxusvrzw= X-MC-Unique: egTqiRH2OuyGkeT0NwbCSw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 01/17] util: Document limit-related functions Date: Fri, 5 Mar 2021 20:13:48 +0100 Message-Id: <20210305191404.529903-2-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.79 on 10.5.11.14 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" We're going to change their behavior, so it's good to have the current one documented to serve as baseline. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 69d64e9466..9fe75d54d6 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -739,6 +739,15 @@ virProcessPrLimit(pid_t pid G_GNUC_UNUSED, #endif =20 #if WITH_SETRLIMIT && defined(RLIMIT_MEMLOCK) +/** + * virProcessSetMaxMemLock: + * @pid: process to be changed (0 for the current process) + * @bytes: new limit (0 for no change) + * + * Sets a new limit on the amount of locked memory for a process. + * + * Returns: 0 on success, <0 on failure. + */ int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes) { @@ -791,6 +800,15 @@ virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsig= ned long long bytes) #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_MEMLOCK)) */ =20 #if WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK) +/** + * virProcessGetMaxMemLock: + * @pid: process to be queried (0 for the current process) + * @bytes: return location for the limit + * + * Obtain the current limit on the amount of locked memory for a process. + * + * Returns: 0 on success, <0 on failure. + */ int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) @@ -843,6 +861,16 @@ virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, #endif /* ! (WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_NPROC) +/** + * virProcessSetMaxProcesses: + * @pid: process to be changed (0 for the current process) + * @procs: new limit (0 for no change) + * + * Sets a new limit on the amount of processes for the user the + * process is running as. + * + * Returns: 0 on success, <0 on failure. + */ int virProcessSetMaxProcesses(pid_t pid, unsigned int procs) { @@ -883,6 +911,15 @@ virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, uns= igned int procs) #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_NPROC)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_NOFILE) +/** + * virProcessSetMaxFiles: + * @pid: process to be changed (0 for the current process) + * @files: new limit (0 for no change) + * + * Sets a new limit on the number of opened files for a process. + * + * Returns: 0 on success, <0 on failure. + */ int virProcessSetMaxFiles(pid_t pid, unsigned int files) { @@ -931,6 +968,15 @@ virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, unsigne= d int files) #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_CORE) +/** + * virProcessSetMaxCoreSize: + * @pid: process to be changed (0 for the current process) + * @bytes: new limit (0 to disable core dumps) + * + * Sets a new limit on the size of core dumps for a process. + * + * Returns: 0 on success, <0 on failure. + */ int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes) { --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971730; cv=none; d=zohomail.com; s=zohoarc; b=oLyPGw/xfky1YQLYfpDchE9fw/M5vM7XLkTWBxGnbiY3oOOXRi058JbUAyGPnYL5JHT8rcAB3MmiHv9QKaCTbNKTjNlKCMYHo44Q/gfbJGeG18XZPc1XmDuFm94t6IdRMHqgo/b+MQR/gIl3MF3zomUEEFN/WvQw5i4K3Zovc9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971730; 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=zd146M5IFbtb8G9OHGsTxR/gcj3JwWt4saQb0GsK4Ts=; b=TJ/1TSdSHiYaNK7J+Ktn7vzbRpOlfq4HcEgy5KuaqrD1+HSrrtahI3UzBF4yt0zq8MTyB1HaXvF6JEoJmt7AZ5cM3q2DO0devQQN8ZrBcAiMf7qiXCQ6HIT2sH1RVRw7YH+Hu3hkKuo11DCk099i1a5qrgB78mwImle9hXgTV78= 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 1614971730639331.6061831908537; Fri, 5 Mar 2021 11:15:30 -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-279-H5CiogN4OdSbaNi5CBdhEw-1; Fri, 05 Mar 2021 14:15:27 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B289D1084D79; Fri, 5 Mar 2021 19:15:20 +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 855DA6268D; Fri, 5 Mar 2021 19:15:20 +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 4F89357DC3; Fri, 5 Mar 2021 19:15:20 +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 125JEDkU001711 for ; Fri, 5 Mar 2021 14:14:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id C81875D6DC; Fri, 5 Mar 2021 19:14:13 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29B455D6B1 for ; Fri, 5 Mar 2021 19:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971729; 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=zd146M5IFbtb8G9OHGsTxR/gcj3JwWt4saQb0GsK4Ts=; b=XZ56Igtxk3r/3DEkl4GSQAjYdKbNRJAGQw9Pa/juFaisS5rFiD+fY4fgn+ui0qCNW2nZ1W 8prIuHj4yk7dosD9Ri0AOZ4ljZWiZBjmguEi51H3meUVmSrH4wwBukcbKBJXVkv5RdL5UV kkrgcAN25RRr94P1bRYvwD63rUi+2wQ= X-MC-Unique: H5CiogN4OdSbaNi5CBdhEw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 02/17] util: Simplify stubs Date: Fri, 5 Mar 2021 20:13:49 +0100 Message-Id: <20210305191404.529903-3-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.79 on 10.5.11.15 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" Calling a stub should always result in ENOSYS being raised, regardless of what arguments are passed to it. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 9fe75d54d6..e01ff25540 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -850,11 +850,8 @@ virProcessGetMaxMemLock(pid_t pid, #else /* ! (WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK)) */ int virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, - unsigned long long *bytes) + unsigned long long *bytes G_GNUC_UNUSED) { - if (!bytes) - return 0; - virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; } @@ -900,11 +897,9 @@ virProcessSetMaxProcesses(pid_t pid, unsigned int proc= s) } #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_NPROC)) */ int -virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, unsigned int procs) +virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, + unsigned int procs G_GNUC_UNUSED) { - if (procs =3D=3D 0) - return 0; - virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; } @@ -957,11 +952,9 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) } #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ int -virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, unsigned int files) +virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, + unsigned int files G_GNUC_UNUSED) { - if (files =3D=3D 0) - return 0; - virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; } @@ -1004,11 +997,8 @@ virProcessSetMaxCoreSize(pid_t pid, unsigned long lon= g bytes) #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_CORE)) */ int virProcessSetMaxCoreSize(pid_t pid G_GNUC_UNUSED, - unsigned long long bytes) + unsigned long long bytes G_GNUC_UNUSED) { - if (bytes =3D=3D 0) - return 0; - virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; } --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971764; cv=none; d=zohomail.com; s=zohoarc; b=Q+nDszs8S4WpXuoSi1t9VB2SWZrFLH0RLpQf86IFgPEZAEyZzocSGGIBK74Ak/s+BmbTHua8Jc7PnY73OXwa02jwVOLCtzJw+h6AlE12uY4Y1QJmaJ+er7E+gcEdYU+vWgKfSKv9hRy7rWPzlms5yE+WHkTHIpecJ1mQjy7UCTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971764; 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=lgvLC+FZ+JLZJUL8WMwnctL4DZo5zCO6njS83cUXTpo=; b=kUpo43Ak5ce/xOAqXKP65HAJT9SlZqmd6OZIW9qRfoKnReyWu+kiextVvg09IH0+4Of5g1rx0cUfc5FZOzZ5hChA7NlZCxuZWPtYCIDtsLUzzfc9HqPgGY6Xn0nAXXjf8vPi5oN3983kHktgNFIGL0KJt5WRIVSD2GoJPNlGUww= 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 1614971764410535.7428092484174; Fri, 5 Mar 2021 11:16:04 -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-528-QGDHJ_CxMqi_W9PZyh9r_Q-1; Fri, 05 Mar 2021 14:15:33 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 732938015A0; Fri, 5 Mar 2021 19:15:23 +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 5034A12C53; Fri, 5 Mar 2021 19:15:23 +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 158581803B33; Fri, 5 Mar 2021 19:15:23 +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 125JEELn001716 for ; Fri, 5 Mar 2021 14:14:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id D5E515D6DC; Fri, 5 Mar 2021 19:14:14 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38D565D6B1 for ; Fri, 5 Mar 2021 19:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971763; 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=lgvLC+FZ+JLZJUL8WMwnctL4DZo5zCO6njS83cUXTpo=; b=PhCUTqaW1ak+O6aVy1Q92713YSAwWgiX4xwQwKxEUVik4wnUM4/mgBGYPdlEVDTmtOlpzb NowhqIUoOfYQgO9biy1nlQSGCTVNwQ3u3ugCqocRnSiOA7Cg9iyEm1cVSMfO1WMzluQL9h 08KtAgM7eufuFJEtGIDGpzcNkb4bR7s= X-MC-Unique: QGDHJ_CxMqi_W9PZyh9r_Q-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 03/17] util: Always pass a pid to virProcessSetMax*() Date: Fri, 5 Mar 2021 20:13:50 +0100 Message-Id: <20210305191404.529903-4-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.79 on 10.5.11.14 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" Currently, the functions accept either an explicit pid or zero, in which case the current process should be modified: the latter might sound like a convenient little feature, but in reality obtaining the pid of the current process is a single additional function call away, so it hardly makes a difference. Removing the few cases in which we're passing zero will allow us to simplify and improve the functions later. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/vircommand.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 1a4b77ea24..3eef0767bb 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -780,11 +780,13 @@ virExec(virCommandPtr cmd) } } =20 + pid =3D getpid(); + if (cmd->pidfile) { int pidfilefd =3D -1; char c; =20 - pidfilefd =3D virPidFileAcquirePath(cmd->pidfile, false, getpid()); + pidfilefd =3D virPidFileAcquirePath(cmd->pidfile, false, pid); if (pidfilefd < 0) goto fork_error; if (virSetInherit(pidfilefd, true) < 0) { @@ -804,14 +806,14 @@ virExec(virCommandPtr cmd) /* pidfilefd is intentionally leaked. */ } =20 - if (virProcessSetMaxMemLock(0, cmd->maxMemLock) < 0) + if (virProcessSetMaxMemLock(pid, cmd->maxMemLock) < 0) goto fork_error; - if (virProcessSetMaxProcesses(0, cmd->maxProcesses) < 0) + if (virProcessSetMaxProcesses(pid, cmd->maxProcesses) < 0) goto fork_error; - if (virProcessSetMaxFiles(0, cmd->maxFiles) < 0) + if (virProcessSetMaxFiles(pid, cmd->maxFiles) < 0) goto fork_error; if (cmd->setMaxCore && - virProcessSetMaxCoreSize(0, cmd->maxCore) < 0) + virProcessSetMaxCoreSize(pid, cmd->maxCore) < 0) goto fork_error; =20 if (cmd->hook) { --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971716; cv=none; d=zohomail.com; s=zohoarc; b=ZB4oGcfSAu2AV+9GQoJfn1+bhVHNZBm8APseLwkeHQICQoYCABrViFobh0L29Q2qdo/1rseVbmvgz4EYqeaJFXcWTdhHY5WryXG9mF2cUotfDhcgj5y2SEgUbGwMS1++QROtUAD/DnO1cnzkcHL0q96F65LQBuAMvghr9rqlyfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971716; 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=aNhjG7h2MnhRv3XN+wmT2Ear7gCwM3sNk7o5e2vSpWk=; b=UXW8rgs63VDyHlU7pBKTCs3AjJEjynV1FhzhnfKfeq01bOli47JngPFWkPrloT/MxOM0z71RkwZEVxmpjsVi1Ab11d8g2JyR/aB9Q4/S5k3cBYCSeTpm+aUOmkwNTiZLMh/mCIcKmUrE/Dy7P+RnV5nvJ2ARGxQstfwM/y7rTQo= 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 1614971716279350.5217544271817; Fri, 5 Mar 2021 11:15:16 -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-476-pMj8P6tpNlqfGpjsGPr8dg-1; Fri, 05 Mar 2021 14:15:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33F9480432A; Fri, 5 Mar 2021 19:15:07 +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 05B1A5C1BD; Fri, 5 Mar 2021 19:15:06 +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 BD94E85FC; Fri, 5 Mar 2021 19:15:05 +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 125JEGrF001740 for ; Fri, 5 Mar 2021 14:14:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4AF175D6DC; Fri, 5 Mar 2021 19:14:16 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47AD85D6B1 for ; Fri, 5 Mar 2021 19:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971715; 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=aNhjG7h2MnhRv3XN+wmT2Ear7gCwM3sNk7o5e2vSpWk=; b=ZofB4KQKGzNw2iaZkSH1nn0PkJ3yE3LJnR/W3kxYbzoZe+rTRfnPs009AJ40aon1hMH+/z NmOk9iUFDorruudn70/A2H64Y+629SSJiIyRgAmeLx56ECy7hTzw5IT8RguPNT82fiOqtB fJh+YTKYR1ZSYX0emVFlFp6EBYaNU2E= X-MC-Unique: pMj8P6tpNlqfGpjsGPr8dg-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 04/17] util: Introduce virProcess{Get,Set}Limit() Date: Fri, 5 Mar 2021 20:13:51 +0100 Message-Id: <20210305191404.529903-5-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.79 on 10.5.11.16 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" These functions abstract part of the existing logic, which is the same in all virProcessSetMax*() functions, and changes it so that which underlying syscall is used depends on their availability rather than on the context in which they are called: since prlimit() and {g,s}etrlimit() have slightly different requirements, using the same one every single time should make for a more consistent experience. As part of the change, we also remove the special case for passing zero to virProcessSetMax*() functions: we have removed all callers that depended on that functionality in the previous commit, so this is now safe to do and makes the semantics simpler. This commit is better viewed with 'git show -w'. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 175 +++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 80 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index e01ff25540..38b248217e 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -738,10 +738,66 @@ virProcessPrLimit(pid_t pid G_GNUC_UNUSED, } #endif =20 +#if WITH_GETRLIMIT +static int +virProcessGetRLimit(int resource, + struct rlimit *old_limit) +{ + return getrlimit(resource, old_limit); +} +#endif /* WITH_GETRLIMIT */ + +#if WITH_SETRLIMIT +static int +virProcessSetRLimit(int resource, + const struct rlimit *new_limit) +{ + return setrlimit(resource, new_limit); +} +#endif /* WITH_SETRLIMIT */ + +#if WITH_GETRLIMIT +static int +virProcessGetLimit(pid_t pid, + int resource, + struct rlimit *old_limit) +{ + pid_t current_pid =3D getpid(); + bool same_process =3D (pid =3D=3D current_pid); + + if (virProcessPrLimit(pid, resource, NULL, old_limit) =3D=3D 0) + return 0; + + if (same_process && virProcessGetRLimit(resource, old_limit) =3D=3D 0) + return 0; + + return -1; +} +#endif /* WITH_GETRLIMIT */ + +#if WITH_SETRLIMIT +static int +virProcessSetLimit(pid_t pid, + int resource, + const struct rlimit *new_limit) +{ + pid_t current_pid =3D getpid(); + bool same_process =3D (pid =3D=3D current_pid); + + if (virProcessPrLimit(pid, resource, new_limit, NULL) =3D=3D 0) + return 0; + + if (same_process && virProcessSetRLimit(resource, new_limit) =3D=3D 0) + return 0; + + return -1; +} +#endif /* WITH_SETRLIMIT */ + #if WITH_SETRLIMIT && defined(RLIMIT_MEMLOCK) /** * virProcessSetMaxMemLock: - * @pid: process to be changed (0 for the current process) + * @pid: process to be changed * @bytes: new limit (0 for no change) * * Sets a new limit on the amount of locked memory for a process. @@ -765,21 +821,11 @@ virProcessSetMaxMemLock(pid_t pid, unsigned long long= bytes) else rlim.rlim_cur =3D rlim.rlim_max =3D RLIM_INFINITY; =20 - if (pid =3D=3D 0) { - if (setrlimit(RLIMIT_MEMLOCK, &rlim) < 0) { - virReportSystemError(errno, - _("cannot limit locked memory to %llu"), - bytes); - return -1; - } - } else { - if (virProcessPrLimit(pid, RLIMIT_MEMLOCK, &rlim, NULL) < 0) { - virReportSystemError(errno, - _("cannot limit locked memory " - "of process %lld to %llu"), - (long long int)pid, bytes); - return -1; - } + if (virProcessSetLimit(pid, RLIMIT_MEMLOCK, &rlim) < 0) { + virReportSystemError(errno, + _("cannot limit locked memory " + "of process %lld to %llu"), + (long long int)pid, bytes); } =20 VIR_DEBUG("Locked memory for process %lld limited to %llu bytes", @@ -802,7 +848,7 @@ virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsign= ed long long bytes) #if WITH_GETRLIMIT && defined(RLIMIT_MEMLOCK) /** * virProcessGetMaxMemLock: - * @pid: process to be queried (0 for the current process) + * @pid: process to be queried * @bytes: return location for the limit * * Obtain the current limit on the amount of locked memory for a process. @@ -818,21 +864,12 @@ virProcessGetMaxMemLock(pid_t pid, if (!bytes) return 0; =20 - if (pid =3D=3D 0) { - if (getrlimit(RLIMIT_MEMLOCK, &rlim) < 0) { - virReportSystemError(errno, - "%s", - _("cannot get locked memory limit")); - return -1; - } - } else { - if (virProcessPrLimit(pid, RLIMIT_MEMLOCK, NULL, &rlim) < 0) { - virReportSystemError(errno, - _("cannot get locked memory limit " - "of process %lld"), - (long long int) pid); - return -1; - } + if (virProcessGetLimit(pid, RLIMIT_MEMLOCK, &rlim) < 0) { + virReportSystemError(errno, + _("cannot get locked memory limit " + "of process %lld"), + (long long int) pid); + return -1; } =20 /* virProcessSetMaxMemLock() sets both rlim_cur and rlim_max to the @@ -860,7 +897,7 @@ virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, #if WITH_SETRLIMIT && defined(RLIMIT_NPROC) /** * virProcessSetMaxProcesses: - * @pid: process to be changed (0 for the current process) + * @pid: process to be changed * @procs: new limit (0 for no change) * * Sets a new limit on the amount of processes for the user the @@ -877,21 +914,13 @@ virProcessSetMaxProcesses(pid_t pid, unsigned int pro= cs) return 0; =20 rlim.rlim_cur =3D rlim.rlim_max =3D procs; - if (pid =3D=3D 0) { - if (setrlimit(RLIMIT_NPROC, &rlim) < 0) { - virReportSystemError(errno, - _("cannot limit number of subprocesses to= %u"), - procs); - return -1; - } - } else { - if (virProcessPrLimit(pid, RLIMIT_NPROC, &rlim, NULL) < 0) { - virReportSystemError(errno, - _("cannot limit number of subprocesses " - "of process %lld to %u"), - (long long int)pid, procs); - return -1; - } + + if (virProcessSetLimit(pid, RLIMIT_NPROC, &rlim) < 0) { + virReportSystemError(errno, + _("cannot limit number of subprocesses " + "of process %lld to %u"), + (long long int)pid, procs); + return -1; } return 0; } @@ -908,7 +937,7 @@ virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, #if WITH_SETRLIMIT && defined(RLIMIT_NOFILE) /** * virProcessSetMaxFiles: - * @pid: process to be changed (0 for the current process) + * @pid: process to be changed * @files: new limit (0 for no change) * * Sets a new limit on the number of opened files for a process. @@ -932,22 +961,15 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) * behavior. */ rlim.rlim_cur =3D rlim.rlim_max =3D files + 1; - if (pid =3D=3D 0) { - if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) { - virReportSystemError(errno, - _("cannot limit number of open files to %= u"), - files); - return -1; - } - } else { - if (virProcessPrLimit(pid, RLIMIT_NOFILE, &rlim, NULL) < 0) { - virReportSystemError(errno, - _("cannot limit number of open files " - "of process %lld to %u"), - (long long int)pid, files); - return -1; - } + + if (virProcessSetLimit(pid, RLIMIT_NOFILE, &rlim) < 0) { + virReportSystemError(errno, + _("cannot limit number of open files " + "of process %lld to %u"), + (long long int)pid, files); + return -1; } + return 0; } #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ @@ -963,7 +985,7 @@ virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, #if WITH_SETRLIMIT && defined(RLIMIT_CORE) /** * virProcessSetMaxCoreSize: - * @pid: process to be changed (0 for the current process) + * @pid: process to be changed * @bytes: new limit (0 to disable core dumps) * * Sets a new limit on the size of core dumps for a process. @@ -976,22 +998,15 @@ virProcessSetMaxCoreSize(pid_t pid, unsigned long lon= g bytes) struct rlimit rlim; =20 rlim.rlim_cur =3D rlim.rlim_max =3D bytes; - if (pid =3D=3D 0) { - if (setrlimit(RLIMIT_CORE, &rlim) < 0) { - virReportSystemError(errno, - _("cannot limit core file size to %llu"), - bytes); - return -1; - } - } else { - if (virProcessPrLimit(pid, RLIMIT_CORE, &rlim, NULL) < 0) { - virReportSystemError(errno, - _("cannot limit core file size " - "of process %lld to %llu"), - (long long int)pid, bytes); - return -1; - } + + if (virProcessSetLimit(pid, RLIMIT_CORE, &rlim) < 0) { + virReportSystemError(errno, + _("cannot limit core file size " + "of process %lld to %llu"), + (long long int)pid, bytes); + return -1; } + return 0; } #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_CORE)) */ --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971729; cv=none; d=zohomail.com; s=zohoarc; b=IWkVpeJ5ccq62HmD70IWckZUIAweIxqylGJDR2hz15Qwr6sCn+vIE4mKCYKlFsz4J0npZrWd43OkTQdtwBqtE9o34sU+2De8sAbb1oRkwW7+C5jXb3kyZBuRXhii2DlNF9KFed7E2tzCVYINMN6bkDHsKmQj6QXACFJFQ1OG8Zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971729; 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=Jkh1hkqTR6owMD0SeeR5WKZiG7j9g+P5LHtVzh9FygQ=; b=U/ERpwIQVwGC6QCj34winH0juAV6sf6Vr/eG7GCn8FDE9vpo3v9C/BA2t8KpUrwkplHCIL0JeGlqB5j5tVtAwsi5mBUuSLT1jn+8XVTMKgqXyBAUFg0r31FdGMBT9YxyH9SAUQTprldrqt2kmzbxiKN3rGPJhxZOEJxFN4pGS68= 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 1614971729312433.17386033815717; Fri, 5 Mar 2021 11:15:29 -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-bD_6pu3BNPO1G5QeVrMUhA-1; Fri, 05 Mar 2021 14:15:24 -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 C8F5480006E; Fri, 5 Mar 2021 19:15:17 +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 A475910023BE; Fri, 5 Mar 2021 19:15:17 +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 69B801800658; Fri, 5 Mar 2021 19:15:17 +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 125JEHFO001754 for ; Fri, 5 Mar 2021 14:14:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 55C745D6DC; Fri, 5 Mar 2021 19:14:17 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AE3055D6B1 for ; Fri, 5 Mar 2021 19:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971727; 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=Jkh1hkqTR6owMD0SeeR5WKZiG7j9g+P5LHtVzh9FygQ=; b=dmSX7uCojkeZAJoHdj0jAUtiFe+dj/+KHcHgiHErA86NGtc/YuPozTQunGFhaPM/2YPXZi WDa3uZceDSue+WcjieX6UBTCL2aKr54ovg5Rdg4buL+mhb/51pWkhg5FxacdIStrFtMPpk NCWkpEo99aKW3BFWFd/t7f0zwY5a3lQ= X-MC-Unique: bD_6pu3BNPO1G5QeVrMUhA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 05/17] qemu: Make some minor tweaks Date: Fri, 5 Mar 2021 20:13:52 +0100 Message-Id: <20210305191404.529903-6-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" Doing this now will make the next changes nicer. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d3208e5203..1e1df6da64 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7013,10 +7013,13 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; =20 virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData); + virCommandSetUmask(cmd, 0x002); + + VIR_DEBUG("Setting up process limits"); + virCommandSetMaxProcesses(cmd, cfg->maxProcesses); virCommandSetMaxFiles(cmd, cfg->maxFiles); virCommandSetMaxCoreSize(cmd, cfg->maxCore); - virCommandSetUmask(cmd, 0x002); =20 VIR_DEBUG("Setting up security labelling"); if (qemuSecuritySetChildProcessLabel(driver->securityManager, --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971741; cv=none; d=zohomail.com; s=zohoarc; b=U08/2QpCFewuVAIK/6jskeYAcuFMvGLXtwj/Ln2IIG0ujbZd6sORWwSCcfDqCfmxcDJNtV6mmsSvnm72PlPxIQjOEJM/8+humc5ysiFXPu0KaZ1WIUJ4mA9qmTj6FfpwgwSzxCfv2Fz3k9HvjHp+6DQwXi2it94MCcWMjXKxYGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971741; 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=r84FuvWJhZSpOJmhUVWA51OAzz/r9ZttEpo9nE/74I4=; b=PgKbyAW6GlKO1NEpTL6rSSrJwHf11fhCdGdy3FmRmAw7wCw9d5GsBYDk6diNiu8pc7YciKkGhPys1gCBfiVEoXPKzBWtB+tQ/YcokhQBca935tTMzy4VZxdaTF+ROvH/T2rJmG1Dhan/0Hm9GUc43VtTUVhKiJiIdddJSDK4PNU= 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 1614971741734933.1653597872399; Fri, 5 Mar 2021 11:15:41 -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-33-2or_IzrFMfuH4me-fomPvQ-1; Fri, 05 Mar 2021 14:15:38 -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 7653480433B; 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 3FBD51042A83; 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 D4F0E1801017; 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 125JEItr001767 for ; Fri, 5 Mar 2021 14:14:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 60E9B5D6DC; Fri, 5 Mar 2021 19:14:18 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9A695D6B1 for ; Fri, 5 Mar 2021 19:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971740; 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=r84FuvWJhZSpOJmhUVWA51OAzz/r9ZttEpo9nE/74I4=; b=J9yWnyGjd7TgXP8nBfpqGODCLv5WWavlRDSFe42sRbe+OnfLXazIM10hNxkSWqUvDkNgyK OH4jAjEtIkSO3eYah1Bx34rmWWp/IptZ2mSTY6opBU6bZqQYzPBKYZiB+6+hgN8RRAeNMD B7JQuGIU05o8SuTDx2t/Af7Sue+lYyM= X-MC-Unique: 2or_IzrFMfuH4me-fomPvQ-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 06/17] qemu: Set all limits at the same time Date: Fri, 5 Mar 2021 20:13:53 +0100 Message-Id: <20210305191404.529903-7-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" qemuProcessLaunch() is the correct place to set process limits, and in fact is where we were dealing with almost all of them, but the memory locking limit was handled in qemuBuildCommandLine() instead for some reason. The code is rewritten so that the desired limit is calculated and applied in separated steps, which will help with further changes, but this doesn't alter the behavior. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/qemu/qemu_command.c | 4 ---- src/qemu/qemu_process.c | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f255b0f881..348e7488f7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10121,10 +10121,6 @@ qemuBuildCommandLine(virQEMUDriverPtr driver, qemuBuildVsockCommandLine(cmd, def, def->vsock, qemuCaps) < 0) return NULL; =20 - /* In some situations, eg. VFIO passthrough, QEMU might need to lock a - * significant amount of memory, so we need to set the limit according= ly */ - virCommandSetMaxMemLock(cmd, qemuDomainGetMemLockLimitBytes(def, false= )); - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MSG_TIMESTAMP) && cfg->logTimestamp) virCommandAddArgList(cmd, "-msg", "timestamp=3Don", NULL); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1e1df6da64..92e33707c0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6920,6 +6920,7 @@ qemuProcessLaunch(virConnectPtr conn, g_autoptr(virQEMUDriverConfig) cfg =3D NULL; size_t nnicindexes =3D 0; g_autofree int *nicindexes =3D NULL; + unsigned long long maxMemLock =3D 0; =20 VIR_DEBUG("conn=3D%p driver=3D%p vm=3D%p name=3D%s if=3D%d asyncJob=3D= %d " "incoming.launchURI=3D%s incoming.deferredURI=3D%s " @@ -7017,6 +7018,11 @@ qemuProcessLaunch(virConnectPtr conn, =20 VIR_DEBUG("Setting up process limits"); =20 + /* In some situations, eg. VFIO passthrough, QEMU might need to lock a + * significant amount of memory, so we need to set the limit according= ly */ + maxMemLock =3D qemuDomainGetMemLockLimitBytes(vm->def, false); + + virCommandSetMaxMemLock(cmd, maxMemLock); virCommandSetMaxProcesses(cmd, cfg->maxProcesses); virCommandSetMaxFiles(cmd, cfg->maxFiles); virCommandSetMaxCoreSize(cmd, cfg->maxCore); --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971712; cv=none; d=zohomail.com; s=zohoarc; b=Dcu8H5im/6wCEAoORshhzIDcRDTrT5IH9INV8SoZdO23fdP81vHbr8HH9z0wZQtqnNy6mvUjNHa6gAdE3WP3FY5xph0Z0FA1faeCOC2gJ9oJQiAoXf2o//ddsJ53k7Hjb9QTirzE60xY1Bq4cbIUoWLJd5B3p3GdU/Bn9YMLn8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971712; 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=sES2kbtjTpbius6hnt7uyr1VsAR9ge4hWirWR3CSGLE=; b=mqGWI4ZXqg7wrMfn19xYvxApm8f+5K0n2w8xX8gpiynKVI2eLzVmChNOdgTJRkzoryq2sxyihqnpYU/nmFWlO/PBx6UyIo9VR7aS+BzZegQM3eJje3Ak7sqcEjRc0JvZeO/Ya97CRLeoPnXopGRn5BOQ3TSWMNN3Y2VxRClXxD4= 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 1614971712966936.698953007985; Fri, 5 Mar 2021 11:15:12 -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-383-M_6IiyosMeeoQu4gf338NQ-1; Fri, 05 Mar 2021 14:15:09 -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 0AD911084D6B; Fri, 5 Mar 2021 19:15:03 +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 0560560843; Fri, 5 Mar 2021 19:15:00 +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 8744E18095C9; Fri, 5 Mar 2021 19:14:55 +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 125JEJpS001777 for ; Fri, 5 Mar 2021 14:14:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 694765D6DC; Fri, 5 Mar 2021 19:14:19 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1B405D6B1 for ; Fri, 5 Mar 2021 19:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971711; 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=sES2kbtjTpbius6hnt7uyr1VsAR9ge4hWirWR3CSGLE=; b=dsutazLUMpKOyn2ZfHxH5LlHZHBkCj5nI0H+tC0SKmGyyqfqkDRSuVoaATFWqKeicMDfF3 oULBTZmfwkSp7/mY+p97x10Kf8+XlFf0lSkMwDxf0VSRxci852CTDrc8btZauOJMqtdh8L u+eh1L5nz5Z9REYhIpJBAy5ZIcsxY/M= X-MC-Unique: M_6IiyosMeeoQu4gf338NQ-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 07/17] util: Have virCommand remember whether limits are set Date: Fri, 5 Mar 2021 20:13:54 +0100 Message-Id: <20210305191404.529903-8-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.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" Currently this only happens for the core size, but we want the behavior to be consistent for other limits as well. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/vircommand.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 3eef0767bb..044c5e0500 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -132,8 +132,11 @@ struct _virCommand { bool reap; bool rawStatus; =20 + bool setMaxMemLock; unsigned long long maxMemLock; + bool setMaxProcesses; unsigned int maxProcesses; + bool setMaxFiles; unsigned int maxFiles; bool setMaxCore; unsigned long long maxCore; @@ -806,11 +809,14 @@ virExec(virCommandPtr cmd) /* pidfilefd is intentionally leaked. */ } =20 - if (virProcessSetMaxMemLock(pid, cmd->maxMemLock) < 0) + if (cmd->setMaxMemLock && + virProcessSetMaxMemLock(pid, cmd->maxMemLock) < 0) goto fork_error; - if (virProcessSetMaxProcesses(pid, cmd->maxProcesses) < 0) + if (cmd->setMaxProcesses && + virProcessSetMaxProcesses(pid, cmd->maxProcesses) < 0) goto fork_error; - if (virProcessSetMaxFiles(pid, cmd->maxFiles) < 0) + if (cmd->setMaxFiles && + virProcessSetMaxFiles(pid, cmd->maxFiles) < 0) goto fork_error; if (cmd->setMaxCore && virProcessSetMaxCoreSize(pid, cmd->maxCore) < 0) @@ -1149,6 +1155,7 @@ virCommandSetMaxMemLock(virCommandPtr cmd, unsigned l= ong long bytes) return; =20 cmd->maxMemLock =3D bytes; + cmd->setMaxMemLock =3D true; } =20 void @@ -1158,6 +1165,7 @@ virCommandSetMaxProcesses(virCommandPtr cmd, unsigned= int procs) return; =20 cmd->maxProcesses =3D procs; + cmd->setMaxProcesses =3D true; } =20 void @@ -1167,6 +1175,7 @@ virCommandSetMaxFiles(virCommandPtr cmd, unsigned int= files) return; =20 cmd->maxFiles =3D files; + cmd->setMaxFiles =3D true; } =20 void virCommandSetMaxCoreSize(virCommandPtr cmd, unsigned long long bytes) --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971730; cv=none; d=zohomail.com; s=zohoarc; b=aYZLtO7YVjAsfcX+0NOzV47ZLdE7re8OVCNgbFI+Z9gcs1Mn2xDbyAwIcoWXkR7XWiOLDdTVE9pKxXrKkBFz5n4cTWkN30yj1Qm0Zl7EtXYmys6hPUISdgwPeab37+7COHnJLdXc7U4uMl5TeTkMGTzXgiFY59DAFiEQToUAEYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971730; 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=HLN8XmDv3GWen98KR+Zkuq1EfWNjz25BVy74vEFGEX0=; b=j+opIVlMEk+SX3oNmBQVeZcMH+zcsBlA7IP8cA5K2i7B/kCM6HrIbeIJTHyK1QnElFnShWr0S5t0YQUN8wYyEWOuOWRkhhQXErTOjRDRQVkbQAnbGPl3gJWns6sGOf4Bstkdxzhj8dabSvZXZQQF7yCu9a5tG16/wKWOTXZd0Jg= 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 161497173055388.97631463527637; Fri, 5 Mar 2021 11:15:30 -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-281-mZ8Wk9s-PVedUWsRQz9S5Q-1; Fri, 05 Mar 2021 14:15:27 -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 BDCBC26860; Fri, 5 Mar 2021 19:15:20 +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 91FFE101F516; Fri, 5 Mar 2021 19:15:20 +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 54C0857DC4; Fri, 5 Mar 2021 19:15:20 +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 125JEKrA001783 for ; Fri, 5 Mar 2021 14:14:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 72EA85D6DC; Fri, 5 Mar 2021 19:14:20 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD30F5D6B1 for ; Fri, 5 Mar 2021 19:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971729; 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=HLN8XmDv3GWen98KR+Zkuq1EfWNjz25BVy74vEFGEX0=; b=DBjp1rC5XGZ3oaK3/m9FbUga5iLwNcdXCoAGcApdnLeMYY0uiui38EJY4pr2tA+AH2AlPq +ok9//89kbl8ENUUkwlVhrot8xuFSpBdAI9e50YeJxHat4nwu2t+HhTWCReabuG8psKxBN haSHJds+xINtx1e081BmYPaLIEXq2x4= X-MC-Unique: mZ8Wk9s-PVedUWsRQz9S5Q-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 08/17] qemu: Set limits only when explicitly asked to do so Date: Fri, 5 Mar 2021 20:13:55 +0100 Message-Id: <20210305191404.529903-9-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" The current code is written under the assumption that, for all limits except the core size, asking for the limit to be set to zero is a no-op, and so the operation is performed unconditionally. While this is the behavior we want for the QEMU driver, the virCommand and virProcess facilities are generic, and should not implement this kind of policy: asking for a limit to be set to zero should result in that limit being set to zero every single time. Add some checks in the QEMU driver, effectively moving the policy where it belongs. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 5 +++-- src/qemu/qemu_migration.c | 2 ++ src/qemu/qemu_process.c | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 17fa71c21b..54d8bd0d3a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9259,9 +9259,10 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, vm->original_memlock =3D 0; } =20 - /* Trying to set the memory locking limit to zero is a no-op */ - if (virProcessSetMaxMemLock(vm->pid, bytes) < 0) + if (bytes > 0 && + virProcessSetMaxMemLock(vm->pid, bytes) < 0) { return -1; + } =20 return 0; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d7231f68ae..e44931dcfa 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2950,6 +2950,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, } =20 if (STREQ_NULLABLE(protocol, "rdma") && + vm->def->mem.hard_limit > 0 && virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit << 10) < = 0) { goto stopjob; } @@ -4199,6 +4200,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver, switch (spec->destType) { case MIGRATION_DEST_HOST: if (STREQ(spec->dest.host.protocol, "rdma") && + vm->def->mem.hard_limit > 0 && virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit << 10= ) < 0) { goto exit_monitor; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 92e33707c0..c05cbe3570 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7022,9 +7022,18 @@ qemuProcessLaunch(virConnectPtr conn, * significant amount of memory, so we need to set the limit according= ly */ maxMemLock =3D qemuDomainGetMemLockLimitBytes(vm->def, false); =20 - virCommandSetMaxMemLock(cmd, maxMemLock); - virCommandSetMaxProcesses(cmd, cfg->maxProcesses); - virCommandSetMaxFiles(cmd, cfg->maxFiles); + /* For all these settings, zero indicates that the limit should + * not be set explicitly and the default/inherited limit should + * be applied instead */ + if (maxMemLock > 0) + virCommandSetMaxMemLock(cmd, maxMemLock); + if (cfg->maxProcesses > 0) + virCommandSetMaxProcesses(cmd, cfg->maxProcesses); + if (cfg->maxFiles > 0) + virCommandSetMaxFiles(cmd, cfg->maxFiles); + + /* In this case, however, zero means that core dumps should be + * disabled, and so we always need to set the limit explicitly */ virCommandSetMaxCoreSize(cmd, cfg->maxCore); =20 VIR_DEBUG("Setting up security labelling"); --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971735; cv=none; d=zohomail.com; s=zohoarc; b=YuePuJE/a8upkMdfvtWMoPSYAkrKHYyUsU0sfXSXmF5BMmFuaKYNVIHx5fJehRu89IWnuakjLPBPpyzcdsk+AOzpJDFqbvHIImaUoT+/Q2foLJij/gTgZzynlGWSVbYHdb7hJbgLX5S3Tj0R6+GanSttj7g67erVuwI9L7tku7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971735; 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=kl9zme2xMWg5QXfzPH5l5t1Hw7ZAVmPM1eSoWaUa/kI=; b=C0oU5Z0j2wsvEiu/pUmo9RtJKbcR5SdWHBxHmgbabq6wR8uhn1Ps8nzQ03n0sFP2VcHDjk0lCqXVS5vQaxbmLrp0vsVVdtjzAmH+r00JZ3okKqJxxkUVnaClYefpu7t3U8wyC0OlRCwOCB6NMnexvFSIUu+46c+u7jP7GOseS9s= 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 1614971735411407.8528305771516; Fri, 5 Mar 2021 11:15:35 -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-24-9-GlHNzeMgqKFkvoQ8RqoA-1; Fri, 05 Mar 2021 14:15:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94AB61084D72; Fri, 5 Mar 2021 19:15:23 +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 707DF5C1C2; Fri, 5 Mar 2021 19:15:23 +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 355D457DC7; Fri, 5 Mar 2021 19:15:23 +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 125JELKv001808 for ; Fri, 5 Mar 2021 14:14:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7EEF85D6DC; Fri, 5 Mar 2021 19:14:21 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4D8A5D6B1 for ; Fri, 5 Mar 2021 19:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971734; 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=kl9zme2xMWg5QXfzPH5l5t1Hw7ZAVmPM1eSoWaUa/kI=; b=J+UKkol39thaG7+ANIpsjRTsL5tQAt2oCPTfK6QFZljFYyQpwEoBp9Rm6G2XZta3qsixeA Ejx4+LF0GHuPOQqgf2WwW63G7+ZpmHlDQaYhVfGUDIMI+1LM5yrbvCPkePSJL7Anuh/5x8 jqxAhaisWY1tRDP00/RW5RzZYab17tQ= X-MC-Unique: 9-GlHNzeMgqKFkvoQ8RqoA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 09/17] util: Don't special-case setting a limit to zero Date: Fri, 5 Mar 2021 20:13:56 +0100 Message-Id: <20210305191404.529903-10-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.79 on 10.5.11.16 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" This behavior reflects the needs of the QEMU driver and has no place in a generic module such as virProcess. Thanks to the changes made with the previous commit, it is now safe to remove these checks and make all virProcessSetMax*() functions finally behave the same way. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 38b248217e..abce522bf3 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -798,7 +798,7 @@ virProcessSetLimit(pid_t pid, /** * virProcessSetMaxMemLock: * @pid: process to be changed - * @bytes: new limit (0 for no change) + * @bytes: new limit * * Sets a new limit on the amount of locked memory for a process. * @@ -809,9 +809,6 @@ virProcessSetMaxMemLock(pid_t pid, unsigned long long b= ytes) { struct rlimit rlim; =20 - if (bytes =3D=3D 0) - return 0; - /* We use VIR_DOMAIN_MEMORY_PARAM_UNLIMITED internally to represent * unlimited memory amounts, but setrlimit() and prlimit() use * RLIM_INFINITY for the same purpose, so we need to translate between @@ -898,7 +895,7 @@ virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, /** * virProcessSetMaxProcesses: * @pid: process to be changed - * @procs: new limit (0 for no change) + * @procs: new limit * * Sets a new limit on the amount of processes for the user the * process is running as. @@ -910,9 +907,6 @@ virProcessSetMaxProcesses(pid_t pid, unsigned int procs) { struct rlimit rlim; =20 - if (procs =3D=3D 0) - return 0; - rlim.rlim_cur =3D rlim.rlim_max =3D procs; =20 if (virProcessSetLimit(pid, RLIMIT_NPROC, &rlim) < 0) { @@ -938,7 +932,7 @@ virProcessSetMaxProcesses(pid_t pid G_GNUC_UNUSED, /** * virProcessSetMaxFiles: * @pid: process to be changed - * @files: new limit (0 for no change) + * @files: new limit * * Sets a new limit on the number of opened files for a process. * @@ -949,9 +943,6 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) { struct rlimit rlim; =20 - if (files =3D=3D 0) - return 0; - /* Max number of opened files is one greater than actual limit. See * man setrlimit. * --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971726; cv=none; d=zohomail.com; s=zohoarc; b=WgSb9XD8zgnMT2tRg4LMHPGW1YDiZM/n7OnGQGkYa0545pRlzs+zeAaVfkznXdvhejuuJLi9dc06pHNKuXfxNc5SdO7sAeHHGRjl3qcA5w6O3ZWT8KAhelIEt2tPw4FCc0n29HsFBsO0dlVmXHv9GXfyCU5upXuMFdT4auWyHRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971726; 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=/umiBwSCc49aU/Wt135G858S8V4vLOeZ6LBpeyaF2Wc=; b=kU5i2LgR6rXwpUZLRkqFUc/PbaYuIWArOtTiV2uvs422O6IO8mS2Pdz6xUrOuQKBSP48WNL70p2+dhocwfq30T0A4BDm/fQLoTQtjR2nSNpaBjqlAckQBCecJf+lE7s+PaXuIk6UcztNGyKgbBUCIpTgIgSyiTIq4aUUHpHNnfY= 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 16149717267751017.7099125408541; Fri, 5 Mar 2021 11:15:26 -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-510-pxkStBRGP1KC3idGrd9w8g-1; Fri, 05 Mar 2021 14:15:23 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0747B1084D69; Fri, 5 Mar 2021 19:15:18 +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 D96115C1BD; Fri, 5 Mar 2021 19:15:17 +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 9DEAD18077BF; Fri, 5 Mar 2021 19:15:17 +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 125JEMPF001817 for ; Fri, 5 Mar 2021 14:14:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id A7CB15D6DC; Fri, 5 Mar 2021 19:14:22 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 066115D6B1 for ; Fri, 5 Mar 2021 19:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971725; 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=/umiBwSCc49aU/Wt135G858S8V4vLOeZ6LBpeyaF2Wc=; b=GzEhRNV0bPF1+jmG9rBFkmsstNDlC1Z1uATEBhrqf67BDOOZjKtnMwGTo60uYUmZC5EGp+ kNwA0auXM0OjVL5mlb8+JfMVOP2VaUkbyG5UdTd+xsBQBf2pRAeVYOTdYWPNbjaOd4tHCk aMkj3yCOUAhpjmpxdozzEAPqs0FOomA= X-MC-Unique: pxkStBRGP1KC3idGrd9w8g-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 10/17] conf: Rename original_memlock -> originalMemlock Date: Fri, 5 Mar 2021 20:13:57 +0100 Message-Id: <20210305191404.529903-11-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.79 on 10.5.11.16 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" That's more consistent with our usual naming convention. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/conf/domain_conf.h | 4 ++-- src/qemu/qemu_domain.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 930eed60de..7d208d881c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2807,8 +2807,8 @@ struct _virDomainObj { size_t ndeprecations; char **deprecations; =20 - unsigned long long original_memlock; /* Original RLIMIT_MEMLOCK, zero = if no - * restore will be required later= */ + unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero i= f no + * restore will be required later = */ }; =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainObj, virObjectUnref); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 54d8bd0d3a..73e2473dce 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9248,15 +9248,15 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, * value so that we can restore it once memory locking is no longer * required. Failing to obtain the current limit is not a critical * failure, it just means we'll be unable to lower it later */ - if (!vm->original_memlock) { - if (virProcessGetMaxMemLock(vm->pid, &(vm->original_memlock)) = < 0) - vm->original_memlock =3D 0; + if (!vm->originalMemlock) { + if (virProcessGetMaxMemLock(vm->pid, &(vm->originalMemlock)) <= 0) + vm->originalMemlock =3D 0; } } else { /* Once memory locking is no longer required, we can restore the * original, usually very low, limit */ - bytes =3D vm->original_memlock; - vm->original_memlock =3D 0; + bytes =3D vm->originalMemlock; + vm->originalMemlock =3D 0; } =20 if (bytes > 0 && --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=W6TQZt0WmCP4fCnN6x9QizR1BSXcHImUZY08AlVpo52neJ58O3Vh6p7gnFIkYo8UmalYidp6gJsB40wkzrGKLYBR0D33bIlWJG54A57PvgwkiZvNcf5rHk0+ZSswspvF2tkbhngMcPl/2qyW++/FU4YYo+5EFbEosdXX6bUOv4w= 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=K//sK1/BSJZqF9mVfRAF2Vibk/nNZDEdy3mfAGYGETw=; b=fA4ypLn4bsujy5f0lvmJaLNDt0pn0KMukNs6RhZnOutuN5riP9P5v4yhSP/Vv4zgMArL/E/v+jqtgg06ZPJ2u74hw0hbfMfDk2pX1zs9qx/ei5aPRqcld3JoKecFSF7EMck3Zu9IfvX6hRyvLskiYGBZlSc9N11X1UOdDYMZnoc= 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 1614971736165127.70520921631146; 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-324-gIhcO824NmCJ0FiUqPawew-1; Fri, 05 Mar 2021 14:15:31 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13BAB8143F1; Fri, 5 Mar 2021 19:15:21 +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 D30FB1971A; Fri, 5 Mar 2021 19:15:20 +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 8AEFB180100F; Fri, 5 Mar 2021 19:15:20 +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 125JENHw001840 for ; Fri, 5 Mar 2021 14:14:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id B219D5D6DC; Fri, 5 Mar 2021 19:14:23 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1894B5D6B1 for ; Fri, 5 Mar 2021 19:14:22 +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=K//sK1/BSJZqF9mVfRAF2Vibk/nNZDEdy3mfAGYGETw=; b=dImTqUQjq59RkbBbL2Z3a8OBkcUJ5BO2wbn4EDZXkoD00AiaeYqSn+kY2SpqKcroxZn6dW pJe5JSo+ZR2yEuSjHfBH2A70lm+r0PkQwFX/0mRIq+dHMKHf4n6cmGkoK9Fze4X21eoIIa eEHgHFjrxMGw6b/MA6quArTgIndUkMo= X-MC-Unique: gIhcO824NmCJ0FiUqPawew-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 11/17] tests: Mock virProcessGetMaxMemLock() Date: Fri, 5 Mar 2021 20:13:58 +0100 Message-Id: <20210305191404.529903-12-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.23 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" Up until now we've implicitly relied on the fact that failures reported from this function were simply ignored, but that's about to change and so we need a proper mock. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.h | 2 +- tests/virprocessmock.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/virprocess.h b/src/util/virprocess.h index 34210d6c9d..dbf4148e90 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -79,7 +79,7 @@ int virProcessSetMaxProcesses(pid_t pid, unsigned int pro= cs); int virProcessSetMaxFiles(pid_t pid, unsigned int files); int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes); =20 -int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes); +int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) G_GNUC_N= O_INLINE; =20 /* Callback to run code within the mount namespace tied to the given * pid. This function must use only async-signal-safe functions, as diff --git a/tests/virprocessmock.c b/tests/virprocessmock.c index c9386d757a..0356ff2f70 100644 --- a/tests/virprocessmock.c +++ b/tests/virprocessmock.c @@ -21,6 +21,13 @@ #include #include "virprocess.h" =20 +int +virProcessGetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long *bytes= G_GNUC_UNUSED) +{ + *bytes =3D 0; + return 0; +} + int virProcessSetMaxMemLock(pid_t pid G_GNUC_UNUSED, unsigned long long bytes = G_GNUC_UNUSED) { --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971772; cv=none; d=zohomail.com; s=zohoarc; b=GONxzWxcZq7uLs4DD/RPJvJHRQtT3bTeKvzPfXNIoNQCF3HcjbUKKzIC2Saif8kLjsFDHLkjWqAxTmIvk4EJh3tLbPgw53mIKdGAre4hHmgN/ljxiFRIgpdQpQ9SsTZhGfEPqVkY+aTJeTLEK+c5kUgOeIFhm7ZZSpzNxA9Upfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971772; 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=sVWULxKy+Fq8rTwVRzuz20BXCQsDfXNbGMi6HbOmncU=; b=Spa4EFKpHk+bEj8FzXKRvK2QZ2a7e3eYN5GxgUhSJWxRYU+dPcJh2g6heIaGo+pUyuXyOA35EepmvLDx1TWGC+AwZTFm1PykGk18qgFJC25UjYtq43ubLaHrtDEa2KrxUJY9nXneE1NeY6b0IAEc7L/wQjk/FT4ohUZ1osoA2YI= 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 1614971772966609.5559017959415; Fri, 5 Mar 2021 11:16:12 -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-227-V4136_38MjCI_frqXm3klw-1; Fri, 05 Mar 2021 14:15:36 -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 BD33E1005D58; Fri, 5 Mar 2021 19:15:23 +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 95A6A37DD; Fri, 5 Mar 2021 19:15:23 +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 5E91B57DC6; Fri, 5 Mar 2021 19:15:23 +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 125JEOgA001848 for ; Fri, 5 Mar 2021 14:14:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id C15105D6DC; Fri, 5 Mar 2021 19:14:24 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 216F95D6B1 for ; Fri, 5 Mar 2021 19:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971771; 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=sVWULxKy+Fq8rTwVRzuz20BXCQsDfXNbGMi6HbOmncU=; b=JH67GmqiVasjkIqMmNPSX7kRyGNSrzqePImLrvz9qT3lQMHETyPi2FLl+hRBgIEafmSz8q 2d5yW9Ve8qOCQulPdj+K0zrgyBDqd2o1YZ/g7wZomOVu7roclbq9mjxFTUjey/W+cYfn7o j8lTXPkvm+1QGYkD6ZLxImjvxjadkaY= X-MC-Unique: V4136_38MjCI_frqXm3klw-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 12/17] util: Try to get limits from /proc Date: Fri, 5 Mar 2021 20:13:59 +0100 Message-Id: <20210305191404.529903-13-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.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" Calling prlimit() requires elevated privileges, specifically CAP_SYS_RESOURCE, and getrlimit() only works for the current process which is too limiting for our needs; /proc/$pid/limits, on the other hand, can be read by any process, so implement parsing that file as a fallback for when prlimit() fails. This is useful in containerized environments. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/util/virprocess.c | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index abce522bf3..e62ec379a6 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -757,6 +757,95 @@ virProcessSetRLimit(int resource, #endif /* WITH_SETRLIMIT */ =20 #if WITH_GETRLIMIT +static const char* +virProcessLimitResourceToLabel(int resource) +{ + switch (resource) { +# if defined(RLIMIT_MEMLOCK) + case RLIMIT_MEMLOCK: + return "Max locked memory"; +# endif /* defined(RLIMIT_MEMLOCK) */ + +# if defined(RLIMIT_NPROC) + case RLIMIT_NPROC: + return "Max processes"; +# endif /* defined(RLIMIT_NPROC) */ + +# if defined(RLIMIT_NOFILE) + case RLIMIT_NOFILE: + return "Max open files"; +# endif /* defined(RLIMIT_NOFILE) */ + +# if defined(RLIMIT_CORE) + case RLIMIT_CORE: + return "Max core file size"; +# endif /* defined(RLIMIT_CORE) */ + + default: + return NULL; + } +} + +static int +virProcessGetLimitFromProc(pid_t pid, + int resource, + struct rlimit *limit) +{ + g_autofree char *procfile =3D NULL; + g_autofree char *buf =3D NULL; + g_auto(GStrv) lines =3D NULL; + const char *label; + size_t len; + size_t i; + + if (!(label =3D virProcessLimitResourceToLabel(resource))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown resource %d requested for process %lld"), + resource, (long long)pid); + return -1; + } + + procfile =3D g_strdup_printf("/proc/%lld/limits", (long long)pid); + + if (!g_file_get_contents(procfile, &buf, &len, NULL)) + return -1; + + if (!(lines =3D g_strsplit(buf, "\n", 0))) + return -1; + + for (i =3D 0; lines[i]; i++) { + g_autofree char *softLimit =3D NULL; + g_autofree char *hardLimit =3D NULL; + char *line =3D lines[i]; + unsigned long long tmp; + + if (!STRPREFIX(line, label)) + continue; + + line +=3D strlen(label); + + if (sscanf(line, "%ms %ms %*s", &softLimit, &hardLimit) < 2) + return -1; + + if (STREQ(softLimit, "unlimited")) { + limit->rlim_cur =3D RLIM_INFINITY; + } else { + if (virStrToLong_ull(softLimit, NULL, 10, &tmp) < 0) + return -1; + limit->rlim_cur =3D tmp; + } + if (STREQ(hardLimit, "unlimited")) { + limit->rlim_max =3D RLIM_INFINITY; + } else { + if (virStrToLong_ull(hardLimit, NULL, 10, &tmp) < 0) + return -1; + limit->rlim_max =3D tmp; + } + } + + return 0; +} + static int virProcessGetLimit(pid_t pid, int resource, @@ -768,6 +857,15 @@ virProcessGetLimit(pid_t pid, if (virProcessPrLimit(pid, resource, NULL, old_limit) =3D=3D 0) return 0; =20 + /* For whatever reason, using prlimit() on another process - even + * when it's just to obtain the current limit rather than changing + * it - requires CAP_SYS_RESOURCE, which we might not have in a + * containerized environment; on the other hand, no particular + * permission is needed to poke around /proc, so try that if going + * through the syscall didn't work */ + if (virProcessGetLimitFromProc(pid, resource, old_limit) =3D=3D 0) + return 0; + if (same_process && virProcessGetRLimit(resource, old_limit) =3D=3D 0) return 0; =20 --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971742; cv=none; d=zohomail.com; s=zohoarc; b=NRdXhQAhL9en27qD9hSz15TIgZErHX4B68dMsRf9LZu4mFMs0tmC+CL5WcUyfP5HxxLEgVfRHAWB1MQemdVTyF0amD5lxqlmREMygEZdqmc3r6qi3DGjPwUILh9ltruDSATUlwhUYEtctGLk9rnP6ARSx1qzHBoNSRfvPV0b/Fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971742; 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=PJeOSXW+I4TdpPdK2LVne/eS2DhNjvwyzbbRfAfReZA=; b=NXrqPcacsifDD5uKZLkCHB9B4fVPbpYH9KM8LskV+VGXt249uzWEn4xm6fsDcz6TQCj34bZDuBfMHDRfOZDMCNy9PyXQfgsOM4I9uhpXrRtCc8yJehX3TVEZHBW+U/IUbvwcZJ8XH+qI16USgooOWGbSwoOcG3fHiIxfl6mKkpY= 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 16149717424391011.0236169358565; Fri, 5 Mar 2021 11:15:42 -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-165-cU5C3yeBOce3iUIl4BzPBQ-1; Fri, 05 Mar 2021 14:15:39 -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 62265184215C; Fri, 5 Mar 2021 19:15:31 +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 38BA5100EADF; Fri, 5 Mar 2021 19:15:31 +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 ECF9057DCE; Fri, 5 Mar 2021 19:15:30 +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 125JEPWP001858 for ; Fri, 5 Mar 2021 14:14:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id D2E9E5D6DC; Fri, 5 Mar 2021 19:14:25 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 334895D6B1 for ; Fri, 5 Mar 2021 19:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971741; 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=PJeOSXW+I4TdpPdK2LVne/eS2DhNjvwyzbbRfAfReZA=; b=R5zt5TBRth2TWPEsUlnmnR0zagdOfwrXKYBdu0QYDOgK8yQpjpAJ8sb5XA2jBS6jxlRhdZ 2civVyPV6kv3TRZeX63shbyb4JmH8HdG/HGlXLVLVY9qf0T3w4nxMNvTr9jZKmiy+z1qEg ihVc3f/C1Bk5jGb5ghFoixG2uwr51sU= X-MC-Unique: cU5C3yeBOce3iUIl4BzPBQ-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 13/17] qemu: Don't ignore virProcessGetMaxMemLock() errors Date: Fri, 5 Mar 2021 20:14:00 +0100 Message-Id: <20210305191404.529903-14-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" Now that we've implemented a fallback for the function that obtains the information from /proc, there is no reason we would get a failure unless there's something seriously wrong with the environment we're running in, in which case we're better off reporting the issue to the user rather than pretending everything is fine. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 73e2473dce..1e9178764b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9246,11 +9246,10 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, if (bytes) { /* 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. Failing to obtain the current limit is not a critical - * failure, it just means we'll be unable to lower it later */ + * required */ if (!vm->originalMemlock) { if (virProcessGetMaxMemLock(vm->pid, &(vm->originalMemlock)) <= 0) - vm->originalMemlock =3D 0; + return -1; } } else { /* Once memory locking is no longer required, we can restore the --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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 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 From nobody Sat May 4 17:02:36 2024 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=1614971829; cv=none; d=zohomail.com; s=zohoarc; b=LJ3fRUm1Q8ZZhLEkgLHk28kUm9zcLFby+wRGqvn8IuV8aEpd6u3QA44D6vOC8RvAPNh6FKfOy1jAEix65uJDE7DqMu10pCGUXOfuzXfkaGNJ5zsgtdnCjK2j/3bCo/3IA1DWCrzrwOd6nB7bA92fSq5FRFhqMB+iBvotSvbH+/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971829; 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=yoMrQW7+a8ZHI3uZ0+uoSPSB/RJi3nJ6HXAs1uNa55c=; b=eCvuSBik4FP7cpNmjKgfqVEDA+TfdkA7b4COYdg/kOV+xL+SAYJJPSlVV3yx9nZsVNzFRvJE0cj6XS4Wq6A+g3DUbZAbIdXgJECPprUPwgyBOakG9XCMFb1FMWvn4c62gS3H6GbBQEbKbk8rduCbkmqpgQJEH5bcIQ4q/Z86Vvw= 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 1614971829806287.09301062251006; Fri, 5 Mar 2021 11:17:09 -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-580-gWAhzkPQOwilvEsmEfy7_w-1; Fri, 05 Mar 2021 14:15:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9ACF51084D83; Fri, 5 Mar 2021 19:15:26 +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 7075919D7D; 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 3611957DCB; Fri, 5 Mar 2021 19:15:26 +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 125JEVXx001893 for ; Fri, 5 Mar 2021 14:14:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0D68D5D719; Fri, 5 Mar 2021 19:14:31 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 64FB65D6DC for ; Fri, 5 Mar 2021 19:14:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971828; 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=yoMrQW7+a8ZHI3uZ0+uoSPSB/RJi3nJ6HXAs1uNa55c=; b=fr1m8B7yvGJXkh/0LJFPZ7x0nQ/VWJBFJyQcdEao3P0IVxdLwiTsKQJCKY+U77anAui78R JEJ+hEF8uA/B0mECWl00o1+4q6zELt3PeWAiUSvlrd9lBer5os1JK8sPcU2JCyPlMxV0Dk 3hMoIGe/Uuk0oPZRvNYhjLD3r6huFDE= X-MC-Unique: gWAhzkPQOwilvEsmEfy7_w-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 15/17] qemu: Add external_limit_manager config knob Date: Fri, 5 Mar 2021 20:14:02 +0100 Message-Id: <20210305191404.529903-16-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.23 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" This will be useful when libvirtd is running in a containerized environment with limited capabilities, and in order to make things like VFIO device assignment still work an external privileged process changes the limits from outside of the container. KubeVirt is an example of this setup. Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/qemu/libvirtd_qemu.aug | 1 + src/qemu/qemu.conf | 12 ++++++++++++ src/qemu/qemu_conf.c | 4 ++++ src/qemu/qemu_conf.h | 1 + src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 19 insertions(+) diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 3c1045858b..f1b024a37f 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -104,6 +104,7 @@ module Libvirtd_qemu =3D | str_entry "slirp_helper" | str_entry "dbus_daemon" | bool_entry "set_process_name" + | bool_entry "external_limit_manager" | int_entry "max_processes" | int_entry "max_files" | limits_entry "max_core" diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 0c1054f198..15cbc3ba38 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -662,6 +662,18 @@ # #set_process_name =3D 1 =20 +# If enabled, libvirt will not attempt to change process limits (as +# configured with the max_processes, max_files and max_core settings +# below) itself but will instead expect an external entity to perform +# this task. +# +# This also applies to the memory locking limit, which cannot be +# configured here and is instead calculated dynamically based on the +# exact guest configuration: if an external limit manager is in use, +# then libvirt will merely check that the limit has been set +# appropriately. +# +#external_limit_manager =3D 1 =20 # If max_processes is set to a positive integer, libvirt will use # it to set the maximum number of processes that can be run by qemu diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 2bbc75024c..ee95c124dd 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -673,6 +673,10 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfi= gPtr cfg, =20 if (virConfGetValueBool(conf, "set_process_name", &cfg->setProcessName= ) < 0) return -1; + + if (virConfGetValueBool(conf, "external_limit_manager", &cfg->external= LimitManager) < 0) + return -1; + if (virConfGetValueUInt(conf, "max_processes", &cfg->maxProcesses) < 0) return -1; if (virConfGetValueUInt(conf, "max_files", &cfg->maxFiles) < 0) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 7025b5222e..15e0353253 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -176,6 +176,7 @@ struct _virQEMUDriverConfig { bool nogfxAllowHostAudio; bool setProcessName; =20 + bool externalLimitManager; unsigned int maxProcesses; unsigned int maxFiles; unsigned int maxThreadsPerProc; diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qe= mu.aug.in index 9310dcec1c..73be55febe 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -77,6 +77,7 @@ module Test_libvirtd_qemu =3D { "hugetlbfs_mount" =3D "/dev/hugepages" } { "bridge_helper" =3D "/usr/libexec/qemu-bridge-helper" } { "set_process_name" =3D "1" } +{ "external_limit_manager" =3D "1" } { "max_processes" =3D "0" } { "max_files" =3D "0" } { "max_threads_per_process" =3D "0" } --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971741; cv=none; d=zohomail.com; s=zohoarc; b=e2WUSZkPoIES7THapMww6R0ZZXocS957GsTpY+0h00ognOxFYtBJT1D1noc/I/1NnVT7cEa4hMCl5/bYeWu4v7Qg8Oy0U+cTx4gRLTK/UfeE58T/zyPzwk7ipP5MgBQRDpv20TNYj1Qr1iaZjklLVMEFWglM4POExpZWE/KHksk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971741; 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=B0CelQ0MQskM/HeXLb9Hl/BAyHOIUYmFKnDvQmOYkR4=; b=Yu/VvUXWuYp1we2wD4FUdxu7k038FpViQ1iY1/K1UO+JfcZyI5ag2y7PqD6S4mXvZQWW6Vt65o2K01T6xscUD6hscwxtaXx9xN1JGqA7ykXTzmrg9UH3qhYsg4po8w9MJLSfM5Au16rzXTVbPr9IYZb7mnOxIFxl2x3bq0+n8DM= 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 1614971741239438.09051931884346; Fri, 5 Mar 2021 11:15:41 -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-593-zd6Y2S7fPjibQ2LzoFyEnA-1; Fri, 05 Mar 2021 14:15:38 -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 28B5D1084D7A; Fri, 5 Mar 2021 19:15:29 +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 0540F37DD; Fri, 5 Mar 2021 19:15:29 +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 C40DD1809C86; Fri, 5 Mar 2021 19:15:28 +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 125JEWtQ001903 for ; Fri, 5 Mar 2021 14:14:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1737A5D6B1; Fri, 5 Mar 2021 19:14:32 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 728185D72F for ; Fri, 5 Mar 2021 19:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971740; 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=B0CelQ0MQskM/HeXLb9Hl/BAyHOIUYmFKnDvQmOYkR4=; b=cmt8tgDDo+Y3ogqIe9Y+NaHqGkNkAFUR6XLoWto9mwWfxFMXT5EeSkIeT77oXBUuWNRMW7 q4uTSqJdfM22jOz0/Jfi39PbbvENC+6yEn5lVydj429lJ9QPVWGJDmJLZb4s9l5FBGnd5X Tz+AqhWTVYR6YZrDSpWnJyuMxFNqPkg= X-MC-Unique: zd6Y2S7fPjibQ2LzoFyEnA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 16/17] qemu: Wire up external limit manager Date: Fri, 5 Mar 2021 20:14:03 +0100 Message-Id: <20210305191404.529903-17-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.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" When the config knob is enabled, we simply skip the part where limits are set; for the memory locking limit, which can change dynamically over the lifetime of the guest, we still make sure that the external process has set it correctly and error out if that turns out not to be the case This commit is better viewed with 'git show -w'. https://bugzilla.redhat.com/show_bug.cgi?id=3D1916346 Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- src/conf/domain_conf.h | 1 + src/qemu/qemu_domain.c | 39 ++++++++++++++++++++++-------------- src/qemu/qemu_process.c | 44 +++++++++++++++++++++++------------------ 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7d208d881c..d1333020e1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2807,6 +2807,7 @@ struct _virDomainObj { size_t ndeprecations; char **deprecations; =20 + bool externalLimitManager; /* Whether process limits are handled outsi= de of libvirt */ unsigned long long originalMemlock; /* Original RLIMIT_MEMLOCK, zero i= f no * restore will be required later = */ }; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f8b0e1a62a..0d9adb2f9c 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9246,23 +9246,32 @@ qemuDomainAdjustMaxMemLock(virDomainObjPtr vm, if (virProcessGetMaxMemLock(vm->pid, ¤tMemLock) < 0) return -1; =20 - 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 =3D=3D 0) { - vm->originalMemlock =3D currentMemLock; + if (!vm->externalLimitManager) { + if (desiredMemLock > 0) { + /* If this is the first time adjusting the limit, save the cur= rent + * value so that we can restore it once memory locking is no l= onger + * required */ + if (vm->originalMemlock =3D=3D 0) { + vm->originalMemlock =3D currentMemLock; + } + } else { + /* Once memory locking is no longer required, we can restore t= he + * original, usually very low, limit */ + desiredMemLock =3D vm->originalMemlock; + vm->originalMemlock =3D 0; } - } else { - /* Once memory locking is no longer required, we can restore the - * original, usually very low, limit */ - desiredMemLock =3D vm->originalMemlock; - vm->originalMemlock =3D 0; - } =20 - if (desiredMemLock > 0 && - virProcessSetMaxMemLock(vm->pid, desiredMemLock) < 0) { - return -1; + if (desiredMemLock > 0 && + virProcessSetMaxMemLock(vm->pid, desiredMemLock) < 0) { + return -1; + } + } else { + if (currentMemLock < desiredMemLock) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("insufficient memlock limit (%llu < %llu)"), + currentMemLock, desiredMemLock); + return -1; + } } =20 return 0; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c05cbe3570..2eac3934c7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7016,25 +7016,31 @@ qemuProcessLaunch(virConnectPtr conn, virCommandSetPreExecHook(cmd, qemuProcessHook, &hookData); virCommandSetUmask(cmd, 0x002); =20 - VIR_DEBUG("Setting up process limits"); - - /* In some situations, eg. VFIO passthrough, QEMU might need to lock a - * significant amount of memory, so we need to set the limit according= ly */ - maxMemLock =3D qemuDomainGetMemLockLimitBytes(vm->def, false); - - /* For all these settings, zero indicates that the limit should - * not be set explicitly and the default/inherited limit should - * be applied instead */ - if (maxMemLock > 0) - virCommandSetMaxMemLock(cmd, maxMemLock); - if (cfg->maxProcesses > 0) - virCommandSetMaxProcesses(cmd, cfg->maxProcesses); - if (cfg->maxFiles > 0) - virCommandSetMaxFiles(cmd, cfg->maxFiles); - - /* In this case, however, zero means that core dumps should be - * disabled, and so we always need to set the limit explicitly */ - virCommandSetMaxCoreSize(cmd, cfg->maxCore); + if (cfg->externalLimitManager) { + VIR_DEBUG("Not setting up process limits (handled externally)"); + + vm->externalLimitManager =3D true; + } else { + VIR_DEBUG("Setting up process limits"); + + /* In some situations, eg. VFIO passthrough, QEMU might need to lo= ck a + * significant amount of memory, so we need to set the limit accor= dingly */ + maxMemLock =3D qemuDomainGetMemLockLimitBytes(vm->def, false); + + /* For all these settings, zero indicates that the limit should + * not be set explicitly and the default/inherited limit should + * be applied instead */ + if (maxMemLock > 0) + virCommandSetMaxMemLock(cmd, maxMemLock); + if (cfg->maxProcesses > 0) + virCommandSetMaxProcesses(cmd, cfg->maxProcesses); + if (cfg->maxFiles > 0) + virCommandSetMaxFiles(cmd, cfg->maxFiles); + + /* In this case, however, zero means that core dumps should be + * disabled, and so we always need to set the limit explicitly */ + virCommandSetMaxCoreSize(cmd, cfg->maxCore); + } =20 VIR_DEBUG("Setting up security labelling"); if (qemuSecuritySetChildProcessLabel(driver->securityManager, --=20 2.26.2 From nobody Sat May 4 17:02:36 2024 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=1614971747; cv=none; d=zohomail.com; s=zohoarc; b=gSvz/pFNUEOHV5HAd8nmGy60lHNBRM5giWlQi9DD5vypJ2tRvjF8VF4PXPPYr10R6zbZgtMSVlLbeDxsZKZgPILikr3AgSrDiAeGPIQO6Oln2tJsFFkCWzKyeoIXMA9pV5Ao6lQMoNeZIZxlkYCjdIOYSBM66n87bdyC4NjLTDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614971747; 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=pKfUJ4xMuYmzjqacpBmbcgvtMDarGE/HS9yegQhHX+I=; b=PRoOe/HnXRkdWdHsFufsApmE6nGjZ+S7sK99Cj1Gutmz0rr2rnLBuBCZ1e0FUWg6lBCTFfsfTu9GlCmVmWoo9iB+nh3A2pFAy5xjvOJcWm7bJLhL6/KMnxUQOzRXPEHnXZmsHmACLMcakEZbppyeDgUdRYgHhk9BNz812++TYFA= 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 1614971747863867.1354876927368; Fri, 5 Mar 2021 11:15:47 -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-486-dWrtBi9fNy21x3JSIzNxQA-1; Fri, 05 Mar 2021 14:15:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28F5088128E; Fri, 5 Mar 2021 19:15:32 +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 E53BE62954; Fri, 5 Mar 2021 19:15:31 +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 AE50F57DD2; Fri, 5 Mar 2021 19:15:31 +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 125JEXuq001914 for ; Fri, 5 Mar 2021 14:14:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7EDEF5D6DC; Fri, 5 Mar 2021 19:14:33 +0000 (UTC) Received: from harajuku.usersys.redhat.com (unknown [10.40.194.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 927685D6B1 for ; Fri, 5 Mar 2021 19:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614971746; 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=pKfUJ4xMuYmzjqacpBmbcgvtMDarGE/HS9yegQhHX+I=; b=Ck0T/pqli7OTBU2M9uUbyFiS9z/82138aO+LuwnXZSOt3fR/AlcMQ7NUe8PxWXY7DFlG7Z K+IWFetLc76jS2DzjJyQV3dRY3AH1nZKfC+5VS/F5Rj28fqsgccAEoaqumjto5uZb14+lM Cv5PjcCyNyhLUqo8iGV4H/ThWcJE33o= X-MC-Unique: dWrtBi9fNy21x3JSIzNxQA-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 17/17] news: Document external limit manager feature Date: Fri, 5 Mar 2021 20:14:04 +0100 Message-Id: <20210305191404.529903-18-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.79 on 10.5.11.15 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" Signed-off-by: Andrea Bolognani Reviewed-by: Michal Privoznik --- NEWS.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index bd40373a80..3a3e3962c2 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -13,6 +13,16 @@ v7.2.0 (unreleased) =20 * **New features** =20 + * qemu: Allow process limits to be managed by an external process + + Whereas in traditional virtualization scenarios libvirt takes full + reponsibility of setting up the environment for a QEMU process, when i= t's + used as part of things like KubeVirt some of these tasks are delegated= to + external, more privileged processes. + + The ``external_limit_manager`` feature can now be enabled in ``qemu.co= nf`` + to tell libvirt that it shouldn't attempt to set process limits itself. + * **Improvements** =20 * **Bug fixes** --=20 2.26.2