From owner-svn-src-all@freebsd.org Fri Feb 10 02:57:39 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5CAC8CD9167; Fri, 10 Feb 2017 02:57:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 370431999; Fri, 10 Feb 2017 02:57:39 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1A2vcbK010569; Fri, 10 Feb 2017 02:57:38 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1A2vcKJ010565; Fri, 10 Feb 2017 02:57:38 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201702100257.v1A2vcKJ010565@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Fri, 10 Feb 2017 02:57:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r313517 - in stable/10: contrib/netbsd-tests/lib/libc/sys lib/libc/tests/sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Feb 2017 02:57:39 -0000 Author: ngie Date: Fri Feb 10 02:57:37 2017 New Revision: 313517 URL: https://svnweb.freebsd.org/changeset/base/313517 Log: MFC r309373: r309373 (by bdrewery): Fix setrlimit_test:setrlimit_memlock when the system has exceeded vm.max_wired. This uses the same fix as r294894 did for the mlock test. The code from that commit is moved into a common object file which PROGS supports building first. Added: stable/10/lib/libc/tests/sys/mlock_helper.c - copied unchanged from r309373, head/lib/libc/tests/sys/mlock_helper.c Modified: stable/10/contrib/netbsd-tests/lib/libc/sys/t_mlock.c stable/10/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c stable/10/lib/libc/tests/sys/Makefile Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/netbsd-tests/lib/libc/sys/t_mlock.c ============================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Fri Feb 10 02:55:33 2017 (r313516) +++ stable/10/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Fri Feb 10 02:57:37 2017 (r313517) @@ -50,86 +50,13 @@ __RCSID("$NetBSD: t_mlock.c,v 1.6 2016/0 #include #define _KMEMUSER #include + +void set_vm_max_wired(int); +void restore_vm_max_wired(void); #endif static long page = 0; -#ifdef __FreeBSD__ -#define VM_MAX_WIRED "vm.max_wired" - -static void -vm_max_wired_sysctl(int *old_value, int *new_value) -{ - size_t old_len; - size_t new_len = (new_value == NULL ? 0 : sizeof(int)); - - if (old_value == NULL) - printf("Setting the new value to %d\n", *new_value); - else { - ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, NULL, &old_len, - new_value, new_len) == 0, - "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); - } - - ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, old_value, &old_len, - new_value, new_len) == 0, - "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); - - if (old_value != NULL) - printf("Saved the old value (%d)\n", *old_value); -} - -static void -set_vm_max_wired(int new_value) -{ - FILE *fp; - int old_value; - - fp = fopen(VM_MAX_WIRED, "w"); - if (fp == NULL) { - atf_tc_skip("could not open %s for writing: %s", - VM_MAX_WIRED, strerror(errno)); - return; - } - - vm_max_wired_sysctl(&old_value, NULL); - - ATF_REQUIRE_MSG(fprintf(fp, "%d", old_value) > 0, - "saving %s failed", VM_MAX_WIRED); - - fclose(fp); - - vm_max_wired_sysctl(NULL, &new_value); -} - -static void -restore_vm_max_wired(void) -{ - FILE *fp; - int saved_max_wired; - - fp = fopen(VM_MAX_WIRED, "r"); - if (fp == NULL) { - perror("fopen failed\n"); - return; - } - - if (fscanf(fp, "%d", &saved_max_wired) != 1) { - perror("fscanf failed\n"); - fclose(fp); - return; - } - - fclose(fp); - printf("old value in %s: %d\n", VM_MAX_WIRED, saved_max_wired); - - if (saved_max_wired == 0) /* This will cripple the test host */ - return; - - vm_max_wired_sysctl(NULL, &saved_max_wired); -} -#endif - ATF_TC(mlock_clip); ATF_TC_HEAD(mlock_clip, tc) { Modified: stable/10/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c ============================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c Fri Feb 10 02:55:33 2017 (r313516) +++ stable/10/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c Fri Feb 10 02:57:37 2017 (r313517) @@ -50,6 +50,11 @@ __RCSID("$NetBSD: t_setrlimit.c,v 1.5 20 #include #include +#ifdef __FreeBSD__ +void set_vm_max_wired(int); +void restore_vm_max_wired(void); +#endif + static void sighandler(int); static const char path[] = "setrlimit"; @@ -238,10 +243,18 @@ sighandler(int signo) _exit(EXIT_SUCCESS); } +#ifdef __FreeBSD__ +ATF_TC_WITH_CLEANUP(setrlimit_memlock); +#else ATF_TC(setrlimit_memlock); +#endif ATF_TC_HEAD(setrlimit_memlock, tc) { atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_MEMLOCK"); +#ifdef __FreeBSD__ + atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects"); + atf_tc_set_md_var(tc, "require.user", "root"); +#endif } ATF_TC_BODY(setrlimit_memlock, tc) @@ -252,6 +265,11 @@ ATF_TC_BODY(setrlimit_memlock, tc) pid_t pid; int sta; +#ifdef __FreeBSD__ + /* Set max_wired really really high to avoid EAGAIN */ + set_vm_max_wired(INT_MAX); +#endif + page = sysconf(_SC_PAGESIZE); ATF_REQUIRE(page >= 0); @@ -295,6 +313,14 @@ ATF_TC_BODY(setrlimit_memlock, tc) atf_tc_fail("RLIMIT_MEMLOCK not enforced"); } +#ifdef __FreeBSD__ +ATF_TC_CLEANUP(setrlimit_memlock, tc) +{ + + restore_vm_max_wired(); +} +#endif + ATF_TC(setrlimit_nofile_1); ATF_TC_HEAD(setrlimit_nofile_1, tc) { Modified: stable/10/lib/libc/tests/sys/Makefile ============================================================================== --- stable/10/lib/libc/tests/sys/Makefile Fri Feb 10 02:55:33 2017 (r313516) +++ stable/10/lib/libc/tests/sys/Makefile Fri Feb 10 02:57:37 2017 (r313517) @@ -68,6 +68,9 @@ LDADD.timer_create_test+= -lrt .include "../Makefile.netbsd-tests" +SRCS.mlock_test+= mlock_helper.c +SRCS.setrlimit_test+= mlock_helper.c + .if ${COMPILER_TYPE} == "gcc" WARNS?= 3 .else Copied: stable/10/lib/libc/tests/sys/mlock_helper.c (from r309373, head/lib/libc/tests/sys/mlock_helper.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/10/lib/libc/tests/sys/mlock_helper.c Fri Feb 10 02:57:37 2017 (r313517, copy of r309373, head/lib/libc/tests/sys/mlock_helper.c) @@ -0,0 +1,114 @@ +/*- + * Copyright (C) 2016 Bryan Drewery + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Helper for mlock(3) to avoid EAGAIN errors + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include +#include +#include +#include + +#define VM_MAX_WIRED "vm.max_wired" + +static void +vm_max_wired_sysctl(int *old_value, int *new_value) +{ + size_t old_len; + size_t new_len = (new_value == NULL ? 0 : sizeof(int)); + + if (old_value == NULL) + printf("Setting the new value to %d\n", *new_value); + else { + ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, NULL, &old_len, + new_value, new_len) == 0, + "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); + } + + ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, old_value, &old_len, + new_value, new_len) == 0, + "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); + + if (old_value != NULL) + printf("Saved the old value (%d)\n", *old_value); +} + +void +set_vm_max_wired(int new_value) +{ + FILE *fp; + int old_value; + + fp = fopen(VM_MAX_WIRED, "w"); + if (fp == NULL) { + atf_tc_skip("could not open %s for writing: %s", + VM_MAX_WIRED, strerror(errno)); + return; + } + + vm_max_wired_sysctl(&old_value, NULL); + + ATF_REQUIRE_MSG(fprintf(fp, "%d", old_value) > 0, + "saving %s failed", VM_MAX_WIRED); + + fclose(fp); + + vm_max_wired_sysctl(NULL, &new_value); +} + +void +restore_vm_max_wired(void) +{ + FILE *fp; + int saved_max_wired; + + fp = fopen(VM_MAX_WIRED, "r"); + if (fp == NULL) { + perror("fopen failed\n"); + return; + } + + if (fscanf(fp, "%d", &saved_max_wired) != 1) { + perror("fscanf failed\n"); + fclose(fp); + return; + } + + fclose(fp); + printf("old value in %s: %d\n", VM_MAX_WIRED, saved_max_wired); + + if (saved_max_wired == 0) /* This will cripple the test host */ + return; + + vm_max_wired_sysctl(NULL, &saved_max_wired); +}