lkml.org 
[lkml]   [2021]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
SubjectRe: [PATCH v2] KVM: selftests: Make sure kvm_create_max_vcpus test won't hit RLIMIT_NOFILE
From
On 11/24/21 19:50, Sean Christopherson wrote:
>> + if (rl.rlim_cur < nr_fds_wanted) {
>> + rl.rlim_cur = nr_fds_wanted;
>> +
>> + if (rl.rlim_max < nr_fds_wanted)
>> + rl.rlim_max = nr_fds_wanted;
> Nit, this could use max().

If the hard limit is too low, the right thing to do is to skip the test:

--- a/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
+++ b/tools/testing/selftests/kvm/kvm_create_max_vcpus.c
@@ -59,11 +59,19 @@ int main(int argc, char *argv[])

if (rl.rlim_cur < nr_fds_wanted) {
rl.rlim_cur = nr_fds_wanted;
-
- if (rl.rlim_max < nr_fds_wanted)
+ if (rl.rlim_max < nr_fds_wanted) {
+ int old_rlim_max = rl.rlim_max;
rl.rlim_max = nr_fds_wanted;

- TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!");
+ int r = setrlimit(RLIMIT_NOFILE, &rl);
+ if (r < 0) {
+ printf("RLIMIT_NOFILE hard limit is too low (%d, wanted %d)\n",
+ old_rlim_max, nr_fds_wanted);
+ exit(KSFT_SKIP);
+ }
+ } else {
+ TEST_ASSERT(!setrlimit(RLIMIT_NOFILE, &rl), "setrlimit() failed!");
+ }
}

/*
Nevertheless, thanks for the fix and the review! (I might have missed it
if it wasn't for your remark).

Paolo
> Reviewed-and-tested-by: Sean Christopherson<seanjc@google.com>
>

\
 
 \ /
  Last update: 2021-11-26 13:37    [W:0.051 / U:1.932 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site