From nobody Mon Oct 24 07:48:59 2022 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 4MwnJX2Gkzz4fXKt; Mon, 24 Oct 2022 07:49:00 +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 4MwnJX1MxHz41NG; Mon, 24 Oct 2022 07:49:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666597740; 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=3rAHEql7O4Gm/edQj0fPTcOvwHyUFMQJ0c8tlrOjni4=; b=T22ndDGucFm9z526lFlwekLhY+ENLei/ofmvqevC2hgeiVam4VVzFHEpOR90FQC9e/3YJm +MuVRZwhUrIM+CMhzYY4tA/4rZFXryFT9IX9B3WOj6DuwXSTpq32KuEK2c7NTwyEK918Dc upG2p2jdUtLqqbv5arzR3X33Dloc5eKucVShctHPQZi6h9B63HKRlTKF/aaGZzyBY2DpGc yEy0DFR/Ze+PJyKLmyfz3T98tV4C51HwjfrFJ5T9/fStWlmSuJofuYgZi+ZNrN79S1n8X7 DsaDsbuegwladgCl4CHf32u1K0lBLF8eLPZE8HWkgRoHujftMEJY3lTk8pkOFw== 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 4MwnJX0KFnz195Z; Mon, 24 Oct 2022 07:49:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29O7mxP6004887; Mon, 24 Oct 2022 07:48:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29O7mxgF004886; Mon, 24 Oct 2022 07:48:59 GMT (envelope-from git) Date: Mon, 24 Oct 2022 07:48:59 GMT Message-Id: <202210240748.29O7mxgF004886@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: 799db59e9a5e - main - stress2: Update tool to list both DATA and HOLES in a file. Added a regression test. 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: 799db59e9a5ebdab8dd80084177778690955e66b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666597740; 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=3rAHEql7O4Gm/edQj0fPTcOvwHyUFMQJ0c8tlrOjni4=; b=vH15GB22proHtramCZ+CAxOELAnxX04DD2NMNrcIAM4V+0ol82HIWVUDfDP0wh0USxEmzJ MfbSFZSNbxeiy14RDNwag577lni+e/o08vvRmm3oBNG0uNa21V8jlNFhHJ4iFAtzv19hR/ BAV3YRrZqNIDTAewaR2wZcBAbIPqzwVfs4hDmqjjqX3pEC953p20NPFK8kyE199rGwsshi KRo4lk4Xt6rUwHe7L+QxKlY6g/Ae6CjRJDfxELEdGjh9aQbJAlPoTcNydoJmjMLIjp7Dvc mNHYp2I+aI/4WrLPIkBRAw/ZzmXlrZsdxztnpqg9lpzs44H1coIUwASuUMwmVA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666597740; a=rsa-sha256; cv=none; b=HFuK7brvvuKlS9Qb9UPiWmcROlM8H5cHYjos2wsg8OSROQgXNUuqGuoxFk7pnVJdoomSro lKBCO2lnpSDHzj8knBDS5MP6zqjSvm64OXnYOoQSJA08mtKD8s/AjJkvMHHPUD5NOmKXNS Ae7Xc/ZoEL0lB3mEbT13Fv7G34xv3knIxkVodG7ZDXHgQ9/L5sxgaYuX599ht//IFoxc2E T1BF3NOLb00mDSrwcUYc5QgcDgFOiN2r6iw36SE85Ac7y43UJJkghs/KQwsZfcvNUANKRc hhqX1N2CDDjpDhQ3e6gL7pf7HpYQLDPQfOYTu1IdU+6vEV1V83SfdX6Yg8eLPQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pho: URL: https://cgit.FreeBSD.org/src/commit/?id=799db59e9a5ebdab8dd80084177778690955e66b commit 799db59e9a5ebdab8dd80084177778690955e66b Author: Peter Holm AuthorDate: 2022-10-24 07:45:32 +0000 Commit: Peter Holm CommitDate: 2022-10-24 07:45:32 +0000 stress2: Update tool to list both DATA and HOLES in a file. Added a regression test. --- tools/test/stress2/misc/seekhole.sh | 77 +++++++++++++++++++++++++++++++++++++ tools/test/stress2/tools/lsholes.c | 59 +++++++++++++++++----------- 2 files changed, 114 insertions(+), 22 deletions(-) diff --git a/tools/test/stress2/misc/seekhole.sh b/tools/test/stress2/misc/seekhole.sh new file mode 100755 index 000000000000..4656094c1d53 --- /dev/null +++ b/tools/test/stress2/misc/seekhole.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2022 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. +# + +# A SEEK_HOLE / SEEK_DATA test scenario + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +prog=$(basename "$0" .sh) +exp=/tmp/$prog.exp +here=`pwd` +log=/tmp/$prog.log + +cc -o /tmp/lsholes -Wall -Wextra -O2 $here/../tools/lsholes.c | exit 1 +cat > $exp < /dev/null +mount /dev/md$mdstart $mntpoint +set +e + +file=$mntpoint/file +truncate -s 500m $file +bs=`getconf MIN_HOLE_SIZE $file` +printf "\001" | dd of=$file seek=$((0*bs)) bs=1 count=1 conv=notrunc status=none +printf "\002" | dd of=$file seek=$((2*bs)) bs=1 count=1 conv=notrunc status=none +printf "\003" | dd of=$file seek=$((4*bs)) bs=1 count=1 conv=notrunc status=none +s1=0 +s2=0 +/tmp/lsholes $file > $log 2>&1; s1=$? + +cat $log +cmp -s $exp $log || s2=1 + +umount $mntpoint +mdconfig -d -u $mdstart +rm -f /tmp/lsholes $exp $log +exit $((s1 + s2)) diff --git a/tools/test/stress2/tools/lsholes.c b/tools/test/stress2/tools/lsholes.c index a583c1315093..12f8576f3be7 100644 --- a/tools/test/stress2/tools/lsholes.c +++ b/tools/test/stress2/tools/lsholes.c @@ -40,7 +40,8 @@ main(int argc, char *argv[]) { struct stat st; off_t data, hole, pos; - long mx; + long mn; + intmax_t siz; int fd, n; char *name; @@ -54,33 +55,47 @@ main(int argc, char *argv[]) err(1, "open(%s)", name); if (fstat(fd, &st)) err(1, "fstat()"); - if ((mx = fpathconf(fd, _PC_MIN_HOLE_SIZE)) == -1) + if ((mn = fpathconf(fd, _PC_MIN_HOLE_SIZE)) == -1) err(1, "fpathconf()"); - fprintf(stderr, "file \"%s\" size = %jd, _PC_MIN_HOLE_SIZE = %ld\n", - name, (intmax_t)st.st_size, mx); + fprintf(stderr, "Min hole size is %ld, file size is %jd.\n", + mn, (intmax_t)st.st_size); n = 1; pos = 0; + while (pos < st.st_size) { - if ((hole = lseek(fd, pos, SEEK_HOLE)) == -1) + hole = lseek(fd, pos, SEEK_HOLE); + if (hole == -1 && errno != ENXIO) err(1, "lseek(SEEK_HOLE)"); - if ((data = lseek(fd, hole, SEEK_DATA)) == -1) { - if (errno == ENXIO) { - if (hole == st.st_size) - break; - fprintf(stderr, - "No data after hole @ %jd\n", - (intmax_t)hole); - break; - } - err(1, "lseek(SEEK_DATA)"); + data = lseek(fd, pos, SEEK_DATA); + if (data == -1 && errno != ENXIO) + err(1, "lseek(SEEK_data)"); + + if (hole >= 0 && data >= 0 && hole > data) { + siz = hole - data; + printf("data #%d @ %ld, size=%jd)\n", + n, (intmax_t)data, siz); + n++; + pos += siz; + } + if (hole >= 0 && data >= 0 && hole < data) { + siz = data - hole; + printf("hole #%d @ %ld, size=%jd\n", + n, (intmax_t)hole, siz); + n++; + pos += siz; + } + if (hole >= 0 && data == -1) { + siz = st.st_size - hole; + printf("hole #%d @ %ld, size=%jd\n", + n, (intmax_t)hole, siz); + n++; + pos += siz; } - pos = data; - printf("hole #%d @ %jd (0x%jx), size=%jd (0x%jx)\n", - n, (intmax_t)hole, (intmax_t)hole, (intmax_t)(data - hole), - (intmax_t)(data - hole)); - n++; } + if (hole == st.st_size) { + /* EOF */ + printf("hole #%d @ %ld, size=%jd\n", + n, (intmax_t)hole, 0L); + } close(fd); - if (hole != st.st_size) - errx(1, "No implicit hole at EOF"); }