From nobody Sun Feb 8 06:05:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1687354470; cv=none; d=zohomail.com; s=zohoarc; b=lSto02GsX526XbNQ/KfEQkm5nBRE3ezzdPmcxaOX9f1LHV2FIvP8Q/Mb3o6bWlkdtm3dvBTUagn0a51iIy7qhMtQEr6E2xyIF4PtA7bTv5OueY/uIjyeYI8/0NKFvaFNCIZj/U1fSQiWskahoEWRkZwLPpFIaPKv4BgAis9lfiE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687354470; 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=oWr7hbkbYyPwMd57nXw86Vm9XcyzpBUQ3wNmz8jWWD0=; b=JWu0KDwe1dxgvj9Eg1oO5LkUbKr16/ze5qBwbMUapZB872CdIFAHyIQ0TVbcygHpxtiTcnnpeEnHTjEdFKgXBp/tdb+smc9Lau83mDaPA6mxezjiNTKIdawBlbuVsVOFf+Svm8pY3w7RsEU6BuduifRBOxPpPpXVhzsNRkjguVk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1687354470070520.5371391102987; Wed, 21 Jun 2023 06:34:30 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-67-5ysaFXJ1Og6KzzmEzRzd-Q-1; Wed, 21 Jun 2023 09:34:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 984808910FC; Wed, 21 Jun 2023 13:32:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4306540C2063; Wed, 21 Jun 2023 13:32:49 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8E9BC1946A41; Wed, 21 Jun 2023 13:32:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 28C9D1946586 for ; Wed, 21 Jun 2023 13:32:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 09CC9425356; Wed, 21 Jun 2023 13:32:37 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.28.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E912425357; Wed, 21 Jun 2023 13:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687354469; 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=oWr7hbkbYyPwMd57nXw86Vm9XcyzpBUQ3wNmz8jWWD0=; b=isYPJpfIzsdjC9LOcwbfWvgsIFyxIVRqufJVQln0YaFhreAlEW06jUJSWnpSqvoVQfsTEQ DcjSQG0BpgMtdIIQAbzRBy7DT1pqBOEgpTvP7Qt+XL0Dq96dsDnNv480OFm8xMlvwo+6Gv SgMobw4G0GN07eMsEy65kG4PFPObuy4= X-MC-Unique: 5ysaFXJ1Og6KzzmEzRzd-Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] util: add helper for raising the max files limit Date: Wed, 21 Jun 2023 14:32:27 +0100 Message-Id: <20230621133232.4156333-5-berrange@redhat.com> In-Reply-To: <20230621133232.4156333-1-berrange@redhat.com> References: <20230621133232.4156333-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687354471800100002 Historically the max files limit for processes has always been 1024, because going beyond this is incompatible with the select() function. None the less most apps these days will use poll() so should not be limited in this way. Since systemd >=3D 240, the hard limit will be 500k, while the soft limit remains at 1k. Applications which don't use select() should raise their soft limit to match the hard limit during their startup. This function provides a convenient helper to do this limit raising. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virprocess.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virprocess.h | 1 + 3 files changed, 36 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fb7ad9c855..3071dec13a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3171,6 +3171,7 @@ virPortAllocatorSetUsed; =20 # util/virprocess.h virProcessAbort; +virProcessActivateMaxFiles; virProcessExitWithStatus; virProcessGetAffinity; virProcessGetMaxMemLock; diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 0462ae8465..a26683f333 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1048,6 +1048,35 @@ virProcessSetMaxFiles(pid_t pid, unsigned int files) =20 return 0; } + +void +virProcessActivateMaxFiles(void) +{ + struct rlimit maxfiles =3D {0}; + + /* + * Ignore errors since we might be inside a container with seccomp + * filters and limits preset to suitable values. + */ + if (getrlimit(RLIMIT_NOFILE, &maxfiles) < 0) { + VIR_DEBUG("Unable to fetch process max files limit: %s", + g_strerror(errno)); + return; + } + + VIR_DEBUG("Initial max files was %llu", (unsigned long long)maxfiles.r= lim_cur); + + maxfiles.rlim_cur =3D maxfiles.rlim_max; + + if (setrlimit(RLIMIT_NOFILE, &maxfiles) < 0) { + VIR_DEBUG("Unable to set process max files limit to %llu: %s", + (unsigned long long)maxfiles.rlim_cur, g_strerror(errno)= ); + return; + } + + VIR_DEBUG("Raised max files to %llu", (unsigned long long)maxfiles.rli= m_cur); +} + #else /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ int virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, @@ -1056,6 +1085,11 @@ virProcessSetMaxFiles(pid_t pid G_GNUC_UNUSED, virReportSystemError(ENOSYS, "%s", _("Not supported on this platform")= ); return -1; } + +void +virProcessActivateMaxFiles(void) +{ +} #endif /* ! (WITH_SETRLIMIT && defined(RLIMIT_NOFILE)) */ =20 #if WITH_SETRLIMIT && defined(RLIMIT_CORE) diff --git a/src/util/virprocess.h b/src/util/virprocess.h index c18f87e80e..6008cca4af 100644 --- a/src/util/virprocess.h +++ b/src/util/virprocess.h @@ -81,6 +81,7 @@ int virProcessSetMaxMemLock(pid_t pid, unsigned long long= bytes) G_NO_INLINE; int virProcessSetMaxProcesses(pid_t pid, unsigned int procs); int virProcessSetMaxFiles(pid_t pid, unsigned int files); int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes); +void virProcessActivateMaxFiles(void); =20 int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) G_NO_INL= INE; =20 --=20 2.40.1