From nobody Wed Feb 8 16:50:06 2023 X-Original-To: dev-commits-src-all@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 4PBmFV6JDXz3ndxS; Wed, 8 Feb 2023 16:50:06 +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 4PBmFV4Twxz3QsG; Wed, 8 Feb 2023 16:50:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675875006; 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=Z5UWsnN0hVb4x3Hm9wvOrDoBO8aL1bc0yjO5PjOB3MU=; b=GlCYz0pFoT7erp5li0w55emA6wCLZSRhpRZOh5wHkCbdsDbN0msan0WrlK/kjfkXo/i3tO ZTHD0W3dpikos1lNRHCMe9zn7HZKXCbmYEBfmtVf0uEfWpC1PX0ZA1pHz4K310MPmcdSLH 8S2TEy0PkfPCPzpQHUGaIS1e07EJCo8IRpRlBq9AZv7TbumPFrXS+Rulp1RK6z9UA2Ttaw AS86iYTAP9rt3wkFjSDJBu+dyM7mqQfs0OfWjftyV2vuz5o8YWFeIljJIcNwZo/ytEFNe/ SD0mTtkX3QeHMoro/bjMyjCBhVflqgJxfHornAMe5Y+pmEuu+QFm2VFwQqpUhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675875006; 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=Z5UWsnN0hVb4x3Hm9wvOrDoBO8aL1bc0yjO5PjOB3MU=; b=gdaa1McE10E1JK7iEYvICc3yE0b+Pd9An2uP11DVUchiSgsTSv6r9r5YAddzzND6/qWaAt kvOfsgIU/c/SCIG6cmpVwkZo56tyveBoEQ0UICoH3+GIHRRsPiDdwhjVeEYvJG74YMVSgO obSkTGjJQQMywb+sT0fxaPdmKp0+OFu0faIzvmjhKNB5FiXKns66JvNUC+whg3HKepcCbr Az/z5kI0bUYRrGprmBNoV6oHGg7+kEsC9Q+RpHKv5UgxNkdB8zvSsOyR2lKXHwPyfzfa+y iSCcQj0gLQtcELN2XWJ/4D6vtYt07YiIkmeO+lLz7SyqXC5FTWsWWed+1Rp3NA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675875006; a=rsa-sha256; cv=none; b=rU/jowN+1nLQONeQdQWHfPlHN2H6QXMQuDFtRMWEIO7TnBzsSpShUcFo4XmQ8a3kHa8hbV 06jS2N60DMEBFZhxGGO9BI4Abn6otryk06rRm6Bm6mZcAioAMeneNpzDMBa3B0NPe4Ra8P 1hqv2YhzUI5Xu/cb7RKdupm5N5Yt9QjUaCzBLwoEy0oBN+mqbaOla0AALSmWG2clFItWJU D8HRXL3xgO0oWqG0TsL/hhPJdpdlb12wmUYRJg2DCj1jjqdr/TmhH7rLVBRYzq80pUH3CN 1eCC/bWbH+mC5pA2UfCJ8I67FP2pFfalHp+6WY0WUm1eUbYJMMggvtuuwhScgw== 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 4PBmFV3YFhz145g; Wed, 8 Feb 2023 16:50:06 +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 318Go6We095902; Wed, 8 Feb 2023 16:50:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 318Go6Bd095899; Wed, 8 Feb 2023 16:50:06 GMT (envelope-from git) Date: Wed, 8 Feb 2023 16:50:06 GMT Message-Id: <202302081650.318Go6Bd095899@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 8b418c83d175 - main - cp: Adjust the sparse file tests. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8b418c83d175fde3b1f65210509ddcf2ac248d9f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8b418c83d175fde3b1f65210509ddcf2ac248d9f commit 8b418c83d175fde3b1f65210509ddcf2ac248d9f Author: Dag-Erling Smørgrav AuthorDate: 2023-02-08 16:49:29 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-02-08 16:49:50 +0000 cp: Adjust the sparse file tests. * The sparsity check was ineffective: it compared the apparent size in bytes to the actual size in blocks. Instead, write a tool that reliably detects sparseness. * Some of the seq commands were missing an argument. * Based on empirical evidence, 1 MB holes are not necessarily large enough to be preserved by the underlying filesystem. Increase the hole size to 16 MB. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: cracauer Differential Revision: https://reviews.freebsd.org/D38414 --- bin/cp/tests/Makefile | 2 ++ bin/cp/tests/cp_test.sh | 46 +++++++++++++++---------------- bin/cp/tests/sparse.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 23 deletions(-) diff --git a/bin/cp/tests/Makefile b/bin/cp/tests/Makefile index faad22df713a..1e480ad706d1 100644 --- a/bin/cp/tests/Makefile +++ b/bin/cp/tests/Makefile @@ -3,5 +3,7 @@ PACKAGE= tests ATF_TESTS_SH= cp_test +PROGS+= sparse +BINDIR= ${TESTSDIR} .include diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh index 932bd2221ba3..559a5ecc3c00 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -201,7 +201,7 @@ recursive_link_Lflag_body() file_is_sparse() { - atf_check test "$(stat -f "%b" "$1")" != "$(stat -f "%z" "$1")" + atf_check ${0%/*}/sparse "$1" } files_are_equal() @@ -213,8 +213,8 @@ files_are_equal() atf_test_case sparse_leading_hole sparse_leading_hole_body() { - # A one-megabyte hole followed by one megabyte of data - truncate -s 1M foo + # A 16-megabyte hole followed by one megabyte of data + truncate -s 16M foo seq -f%015g 65536 >>foo file_is_sparse foo @@ -227,14 +227,14 @@ atf_test_case sparse_multiple_holes sparse_multiple_holes_body() { # Three one-megabyte blocks of data preceded, separated, and - # followed by one-megabyte holes - truncate -s 1M foo - seq -f%015g >>foo - truncate -s 3M foo - seq -f%015g >>foo - truncate -s 5M foo - seq -f%015g >>foo - truncate -s 7M foo + # followed by 16-megabyte holes + truncate -s 16M foo + seq -f%015g 65536 >>foo + truncate -s 33M foo + seq -f%015g 65536 >>foo + truncate -s 50M foo + seq -f%015g 65536 >>foo + truncate -s 67M foo file_is_sparse foo atf_check cp foo bar @@ -245,8 +245,8 @@ sparse_multiple_holes_body() atf_test_case sparse_only_hole sparse_only_hole_body() { - # A one-megabyte hole - truncate -s 1M foo + # A 16-megabyte hole + truncate -s 16M foo file_is_sparse foo atf_check cp foo bar @@ -258,14 +258,14 @@ atf_test_case sparse_to_dev sparse_to_dev_body() { # Three one-megabyte blocks of data preceded, separated, and - # followed by one-megabyte holes - truncate -s 1M foo - seq -f%015g >>foo - truncate -s 3M foo - seq -f%015g >>foo - truncate -s 5M foo - seq -f%015g >>foo - truncate -s 7M foo + # followed by 16-megabyte holes + truncate -s 16M foo + seq -f%015g 65536 >>foo + truncate -s 33M foo + seq -f%015g 65536 >>foo + truncate -s 50M foo + seq -f%015g 65536 >>foo + truncate -s 67M foo file_is_sparse foo atf_check -o file:foo cp foo /dev/stdout @@ -274,9 +274,9 @@ sparse_to_dev_body() atf_test_case sparse_trailing_hole sparse_trailing_hole_body() { - # One megabyte of data followed by a one-megabyte hole + # One megabyte of data followed by a 16-megabyte hole seq -f%015g 65536 >foo - truncate -s 2M foo + truncate -s 17M foo file_is_sparse foo atf_check cp foo bar diff --git a/bin/cp/tests/sparse.c b/bin/cp/tests/sparse.c new file mode 100644 index 000000000000..78957581a56c --- /dev/null +++ b/bin/cp/tests/sparse.c @@ -0,0 +1,73 @@ +/*- + * Copyright (c) 2023 Klara, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +static bool verbose; + +/* + * Returns true if the file named by its argument is sparse, i.e. if + * seeking to SEEK_HOLE returns a different value than seeking to + * SEEK_END. + */ +static bool +sparse(const char *filename) +{ + off_t hole, end; + int fd; + + if ((fd = open(filename, O_RDONLY)) < 0 || + (hole = lseek(fd, 0, SEEK_HOLE)) < 0 || + (end = lseek(fd, 0, SEEK_END)) < 0) + err(1, "%s", filename); + close(fd); + if (end > hole) { + if (verbose) + printf("%s: hole at %zu\n", filename, (size_t)hole); + return (true); + } + return (false); +} + +static void +usage(void) +{ + + fprintf(stderr, "usage: sparse [-v] file [...]\n"); + exit(EX_USAGE); +} + +int +main(int argc, char *argv[]) +{ + int opt, rv; + + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': + verbose = true; + break; + default: + usage(); + break; + } + } + argc -= optind; + argv += optind; + if (argc == 0) + usage(); + rv = EXIT_SUCCESS; + while (argc-- > 0) + if (!sparse(*argv++)) + rv = EXIT_FAILURE; + exit(rv); +}