From nobody Sat Feb 24 05:47:58 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ThbWf6pKsz5C4qh; Sat, 24 Feb 2024 05:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ThbWf63k2z41Sq; Sat, 24 Feb 2024 05:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708753678; h=from:from: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; bh=elTYegsiNX03cE/nxi8lbEzWdiiphVzB2kmyeEVG87s=; b=ea+F3K5SDvGLu/ak4xpLjqjWMtcrEAjek5mEj6zPIl4OV1YxLCikB4+VTX7r40B8UewQ0I dBwDbewopzOrr8lrBO7gApx6YJw5eRrKC1NKgWHbhBNza+bFyp+jiiK0UZmjwYpl8S+CXW +2KlPwZlfmop8gMXdzJOWCcL56n0qdo+NFExDPWGSZvbpdvQ4xm7tQla+XucIGXdJMJico HslGnPcH8OaC92lD4dxeqHiGG8jOE9oVznEBjF1VzZvqB7zM5nbH3XyWWqMpaNIS1F6ACQ EoOnrM4IhMvO50F32SwRVDQdq7I4SgdQtgX+yJN34IaK2Bd/IH+Yh5kkcD6rpA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708753678; a=rsa-sha256; cv=none; b=JevwXi1A+k5jRQtUltAGAQVKyhPBn5ipM3i9TGNOopx7uA67VK6uDv0NKE+HbOs4WohqjS Ka9UmtoeLEKaS4g/mGs+RigiCFQQorCMD+DhQwaKhOEgKrfJP1uW9dW+NIkR4AmKsCKCRm fadG0QOKYh7t++EjvtJgKI8XUkPPV98YUQs8X8uVvROsCRfIRHNK99wROcfR+e1cFOvtVW 9h9pArtHekhB09UeuayE9Q3vQb0LnM6Fdrz9ewoHnx547Tg39jMicwEH8znv4nLn83QVwR zG2S1OFK+34syTWuJY1X5cFYEuhub+SalSjI+gSgOYxfnVjlKQu64FhTZmdHFg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708753678; h=from:from: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; bh=elTYegsiNX03cE/nxi8lbEzWdiiphVzB2kmyeEVG87s=; b=HIx4VxNCgr1NqeJZwEFeDZXhFQkfugQcnOd2gDG3+pt5//wHfLoITj4pFxt1m/kjJc23Kd vEeTzLkeNCZQEQE0bbF6m1s2f+efn118UTApsAUQyeZjug06DhG1NNyr6I1cM2PW2n9yvR 8dw8L7NAQXAcTjO/GOhfh1MS7Vb5IlWDUTZUdBrd0suOOvrzTqEJlRZkkl5KduUCp9kRM0 dhoLLs54AyaZsf/mRoywQlGRJ+zkkJHDsgG6IHaTkybOJHLEZkBIay7uIV568JsS7aMZIy 9H+jU/VOqt5uZ9e59zBSgfb47p/XDXXynBuEhbT5xpSbOz1UdPe/vqv+owg0ng== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ThbWf54bbzns2; Sat, 24 Feb 2024 05:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41O5lwe6020742; Sat, 24 Feb 2024 05:47:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41O5lwiT020739; Sat, 24 Feb 2024 05:47:58 GMT (envelope-from git) Date: Sat, 24 Feb 2024 05:47:58 GMT Message-Id: <202402240547.41O5lwiT020739@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Peter Holm Subject: git: 1ec33855a82b - main - stress2: Added a new NFS test scenario List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pho X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1ec33855a82b6e937bcb5412f5b5ea971b3df375 Auto-Submitted: auto-generated The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=1ec33855a82b6e937bcb5412f5b5ea971b3df375 commit 1ec33855a82b6e937bcb5412f5b5ea971b3df375 Author: Peter Holm AuthorDate: 2024-02-24 05:47:12 +0000 Commit: Peter Holm CommitDate: 2024-02-24 05:47:12 +0000 stress2: Added a new NFS test scenario --- tools/test/stress2/misc/mmap44.sh | 255 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) diff --git a/tools/test/stress2/misc/mmap44.sh b/tools/test/stress2/misc/mmap44.sh new file mode 100755 index 000000000000..5865491e1dea --- /dev/null +++ b/tools/test/stress2/misc/mmap44.sh @@ -0,0 +1,255 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Peter Holm +# +# 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. +# + +# Demonstrate issue described in: +# [Bug 276002] nfscl: data corruption using both copy_file_range and mmap'd I/O + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg +set -u +prog=$(basename "$0" .sh) +log=/tmp/$prog.log +grep -q $mntpoint /etc/exports || + { echo "$mntpoint missing from /etc/exports"; exit 0; } + +cat > /tmp/$prog.c < +#include + +#include +#include +#include +#include +#include +#include +#include + +static off_t siz; +static pthread_mutex_t write_mutex; +static int fd, go; +static char *cp; + +static void * +memread(void *arg __unused) +{ + int i; + char c; + + while (go == 1) { + i = arc4random() % siz; + c = cp[i]; + if (c != 0x77) /* No unused vars here */ + usleep(arc4random() % 400); + } + return (0); +} + +static void * +memwrite(void *arg __unused) +{ + int i; + char c; + + while (go == 1) { + i = arc4random() % siz; + pthread_mutex_lock(&write_mutex); + c = cp[i]; + cp[i] = 0xee; /* This value seems to linger with NFS */ + cp[i] = c; + pthread_mutex_unlock(&write_mutex); + usleep(arc4random() % 400); + } + return (0); +} + +static void * +wr(void *arg __unused) +{ + off_t pos; + int r, s; + char buf[1024]; + + while (go == 1) { + s = arc4random() % sizeof(buf) + 1; + pos = arc4random() % (siz - s); + pthread_mutex_lock(&write_mutex); + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek(%d)", (int)pos); + if ((r = read(fd, buf, s)) != s) { + fprintf(stderr, "r = %d, s = %d, pos = %d\n", r, s, (int)pos); + err(1, "read():2"); + } + if (lseek(fd, pos, SEEK_SET) == -1) + err(1, "lseek(%d)", (int)pos); + if (write(fd, buf, s) != s) + err(1, "write()"); + pthread_mutex_unlock(&write_mutex); + usleep(arc4random() % 400); + } + return (0); +} + +static void * +s1(void *arg __unused) +{ + + while (go == 1) { + if (fdatasync(fd) == -1) + err(1, "fdatasync()"); + usleep(arc4random() % 1000); + } + return (0); +} + +static void * +s2(void *arg __unused) +{ + + while (go == 1) { + if (fsync(fd) == -1) + err(1, "fdatasync()"); + usleep(arc4random() % 1000); + } + return (0); +} + +static void * +tr(void *arg __unused) +{ + int i, s; + char buf[1024]; + + memset(buf, 0x5a, sizeof(buf)); + while (go == 1) { + pthread_mutex_lock(&write_mutex); + if (lseek(fd, arc4random() % siz, SEEK_END) == -1) + err(1, "lseek() END"); + s = sizeof(buf); + for (i = 0; i < 50; i++) { + if (write(fd, buf, s) != s) + warn("write()"); + } + if (ftruncate(fd, siz) == -1) + err(1, "truncate()"); + pthread_mutex_unlock(&write_mutex); + usleep(arc4random() % 400); + } + return (0); +} + +int +main(int argc, char *argv[]) +{ + struct stat st; + pthread_t tp[6]; + int e, i; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + if ((fd = open(argv[1], O_RDWR)) == -1) + err(1, "open(%s)", argv[1]); + if (fstat(fd, &st) == -1) + err(1, "stat(%s)", argv[1]); + siz = st.st_size; + cp = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (cp == MAP_FAILED) + err(1, "mmap()"); + + go = 1; + pthread_mutex_init(&write_mutex, NULL); + if ((e = pthread_create(&tp[0], NULL, memwrite, NULL)) != 0) + errc(1, e, "pthread_create"); + if ((e = pthread_create(&tp[1], NULL, memread, NULL)) != 0) + errc(1, e, "pthread_create"); + if ((e = pthread_create(&tp[2], NULL, wr, NULL)) != 0) + errc(1, e, "pthread_create"); + if ((e = pthread_create(&tp[3], NULL, s1, NULL)) != 0) + errc(1, e, "pthread_create"); + if ((e = pthread_create(&tp[4], NULL, s2, NULL)) != 0) + errc(1, e, "pthread_create"); + if ((e = pthread_create(&tp[5], NULL, tr, NULL)) != 0) + errc(1, e, "pthread_create"); + + sleep(60); + go = 0; + for (i = 0; i < (int)(sizeof(tp) / sizeof(tp[0])); i++) + pthread_join(tp[i], NULL); + if (munmap(cp, siz) == -1) + err(1, "munmap()"); + close(fd); +} +EOF +mycc -o /tmp/$prog -Wall -Wextra -O0 /tmp/$prog.c -lpthread || exit 1 + +mycc -o /tmp/serial -Wall -Wextra -O2 ../tools/serial.c || exit 1 +mount | grep -q "on $mntpoint " && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart +mdconfig -s 5g -u $mdstart +newfs -n $newfs_flags /dev/md$mdstart > /dev/null +mount /dev/md$mdstart $mntpoint + +mp2=${mntpoint}2 +mkdir -p $mp2 +mount | grep -q "on $mp2 " && umount -f $mp2 +mount -t nfs 127.0.0.1:$mntpoint $mp2; s=$? +sleep .2 + +here=`pwd` +mount | grep $mntpoint +cd $mp2 +$here/../testcases/swap/swap -t 5m -i 20 > /dev/null & +sleep 2 + +size=262144 +/tmp/serial file $size +cp file file.orig + +s=0 +/tmp/$prog file || s=1 + +while pgrep -q swap; do pkill swap; done +wait +if ! cmp -s file.orig file; then + od -t x1 file.orig > /var/tmp/$prog.file1 + od -t x1 file > /var/tmp/$prog.file2 + diff /var/tmp/$prog.file1 /var/tmp/$prog.file2 > $log + head -20 $log + rm /var/tmp/$prog.file1 /var/tmp/$prog.file2 + ls -ls file.orig file + s=2 +fi + +cd $here +umount $mp2 +umount $mntpoint +mdconfig -d -u $mdstart +rm -f /tmp/serial /tmp/$prog /tmp/$prog.c $log +exit $s