Re: [PATCH v2] KVM: selftests: Make sure kvm_create_max_vcpus test won't hit RLIMIT_NOFILE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux