Messages in this thread Patch in this message | | | Date | Fri, 26 Nov 2021 13:32:34 +0100 | Subject | Re: [PATCH v2] KVM: selftests: Make sure kvm_create_max_vcpus test won't hit RLIMIT_NOFILE | From | Paolo Bonzini <> |
| |
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> >
| |