From patchwork Mon Jan 9 10:34:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13093266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3EB1C67871 for ; Mon, 9 Jan 2023 10:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236602AbjAIKl0 (ORCPT ); Mon, 9 Jan 2023 05:41:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237085AbjAIKk7 (ORCPT ); Mon, 9 Jan 2023 05:40:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B2CA18B06; Mon, 9 Jan 2023 02:34:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 055AA60FE2; Mon, 9 Jan 2023 10:34:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96203C433D2; Mon, 9 Jan 2023 10:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673260469; bh=tJgXQU7aw+sYd4bKZCRSXTdjRzA7cTugn3JZ8xQX1Ps=; h=From:To:Cc:Subject:Date:From; b=NASPP9oIsENX+YJbHlxgX+qw1IDr4y6iodFqZ70/fT2cK39JaQXYZe1xliraXXxSg GFeyF6vY9xyIiqmobrpJc3hi6/5DAoGetfVN2MgRBoqdfvptbsgk39bw0htdCEXqN0 3PhVtQO0cKEne0uWGFJCuMMMM8ie9zzkzbEP7MtNLbyDxKgDh32OrVj+ejECK+eJM5 /pN5u7UI5Os+erUwOZ6B7tk6vj/+3OJzvcxKTdkl05zR5jD4h/Y91CTL/B6zthwI+8 69uMPJKKItfyEqQFO9SnDLEQZcl/Y2mTyRmg332+uWdmXBWCTN0UF0BUY092QJ6ZV/ KMHMoBMdGsqJQ== From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH] generic: test lseek with seek data mode on a one byte file Date: Mon, 9 Jan 2023 10:34:15 +0000 Message-Id: <2ba1050ace4aa65eff3082580b449fe1e97a3c5b.1673260375.git.fdmanana@suse.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Test that seeking for data on a 1 byte file works correctly, the returned offset should be 0 if the start offset is 0. This is a regression test motivated by a btrfs bug introduced in kernel 6.1, which got recently fixed by the following kernel commit: 2f2e84ca6066 ("btrfs: fix off-by-one in delalloc search during lseek") Signed-off-by: Filipe Manana Reviewed-by: David Disseldorp --- src/seek_sanity_test.c | 36 ++++++++++++++++++++++++++++++++++++ tests/generic/706 | 36 ++++++++++++++++++++++++++++++++++++ tests/generic/706.out | 2 ++ 3 files changed, 74 insertions(+) create mode 100755 tests/generic/706 create mode 100644 tests/generic/706.out diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c index 8a586f74..48b3ccc0 100644 --- a/src/seek_sanity_test.c +++ b/src/seek_sanity_test.c @@ -292,6 +292,41 @@ out: return ret; } +/* + * Test seeking for data on a 1 byte file, both when there's delalloc and also + * after delalloc is flushed. + */ +static int test22(int fd, int testnum) +{ + const char buf = 'X'; + int ret; + + ret = do_pwrite(fd, &buf, 1, 0); + if (ret) + return ret; + + /* + * Our file as a size of 1 byte and that byte is in delalloc. Seeking + * for data, with a start offset of 0, should return file offset 0. + */ + ret = do_lseek(testnum, 1, fd, 1, SEEK_DATA, 0, 0); + if (ret) + return ret; + + /* Flush all delalloc. */ + ret = fsync(fd); + if (ret) { + fprintf(stderr, "fsync failed: %s (%d)\n", strerror(errno), errno); + return ret; + } + + /* + * We should get the same result we got when we had delalloc, 0 is the + * offset with data. + */ + return do_lseek(testnum, 2, fd, 1, SEEK_DATA, 0, 0); +} + /* * Make sure hole size is properly reported when punched in the middle of a file */ @@ -1131,6 +1166,7 @@ struct testrec seek_tests[] = { { 19, test19, "Test file SEEK_DATA from middle of a large hole" }, { 20, test20, "Test file SEEK_DATA from middle of a huge hole" }, { 21, test21, "Test file SEEK_HOLE that was created by PUNCH_HOLE" }, + { 22, test22, "Test a 1 byte file" }, }; static int run_test(struct testrec *tr) diff --git a/tests/generic/706 b/tests/generic/706 new file mode 100755 index 00000000..b3e7aa7c --- /dev/null +++ b/tests/generic/706 @@ -0,0 +1,36 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 706 +# +# Test that seeking for data on a 1 byte file works correctly, the returned +# offset should be 0 if the start offset is 0. +# +. ./common/preamble +_begin_fstest auto quick seek + +[ $FSTYP == "btrfs" ] && + _fixed_by_kernel_commit 2f2e84ca6066 \ + "btrfs: fix off-by-one in delalloc search during lseek" + +_supported_fs generic +_require_test +_require_seek_data_hole +_require_test_program "seek_sanity_test" + +test_file=$TEST_DIR/seek_sanity_testfile.$seq + +_cleanup() +{ + cd / + rm -f $tmp.* + rm -f $test_file +} + +_run_seek_sanity_test -s 22 -e 22 $test_file > $seqres.full 2>&1 || + _fail "seek sanity check failed!" + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/706.out b/tests/generic/706.out new file mode 100644 index 00000000..577697c6 --- /dev/null +++ b/tests/generic/706.out @@ -0,0 +1,2 @@ +QA output created by 706 +Silence is golden