From patchwork Thu May 11 16:48:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 9722579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BCAC360236 for ; Thu, 11 May 2017 16:48:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A80B9286CF for ; Thu, 11 May 2017 16:48:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CB7C286D5; Thu, 11 May 2017 16:48:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 028CF286CF for ; Thu, 11 May 2017 16:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757934AbdEKQsV (ORCPT ); Thu, 11 May 2017 12:48:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:34418 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757894AbdEKQsU (ORCPT ); Thu, 11 May 2017 12:48:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BBC29AC9E; Thu, 11 May 2017 16:48:18 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 4E5181E11BB; Thu, 11 May 2017 18:48:18 +0200 (CEST) From: Jan Kara To: fstests@vger.kernel.org Cc: , , Jan Kara Subject: [PATCH] generic/285: Add more SEEK_HOLE tests Date: Thu, 11 May 2017 18:48:09 +0200 Message-Id: <20170511164809.29739-1-jack@suse.cz> X-Mailer: git-send-email 2.12.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add tests for bugs found in ext4 & xfs SEEK_HOLE implementations fixed by following patches: xfs: Fix missed holes in SEEK_HOLE implementation ext4: Fix SEEK_HOLE Signed-off-by: Jan Kara --- src/seek_sanity_test.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c index a6dd48cc257b..86a9397fa7e9 100644 --- a/src/seek_sanity_test.c +++ b/src/seek_sanity_test.c @@ -246,6 +246,100 @@ out: } /* + * test file with unwritten extents, only have pagevec worth of dirty pages + * in page cache, a hole and then another page. + */ +static int test14(int fd, int testnum) +{ + int ret = 0; + char *buf = NULL; + int bufsz = sysconf(_SC_PAGE_SIZE) * 14; + int filsz = 4 << 20; + + /* HOLE - unwritten DATA in dirty page */ + /* Each unit is bufsz */ + buf = do_malloc(bufsz); + if (!buf) + goto out; + memset(buf, 'a', bufsz); + + /* preallocate 4M space to file */ + ret = do_fallocate(fd, 0, filsz, 0); + if (ret < 0) { + /* Report success if fs doesn't support fallocate */ + if (errno == EOPNOTSUPP) { + fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n"); + ret = 0; + } + goto out; + } + + ret = do_pwrite(fd, buf, bufsz, 0); + if (ret) + goto out; + + ret = do_pwrite(fd, buf, bufsz, 3 * bufsz); + if (ret) + goto out; + + /* offset at the beginning */ + ret += do_lseek(testnum, 1, fd, filsz, SEEK_HOLE, 0, bufsz); + ret += do_lseek(testnum, 2, fd, filsz, SEEK_HOLE, 1, bufsz); + ret += do_lseek(testnum, 2, fd, filsz, SEEK_HOLE, 3 * bufsz, 4 * bufsz); + ret += do_lseek(testnum, 3, fd, filsz, SEEK_DATA, 0, 0); + ret += do_lseek(testnum, 4, fd, filsz, SEEK_DATA, 1, 1); + ret += do_lseek(testnum, 3, fd, filsz, SEEK_DATA, bufsz, 3 * bufsz); + +out: + do_free(buf); + return ret; +} + +/* + * test file with unwritten extents, only have pagevec worth of dirty pages + * in page cache. + */ +static int test13(int fd, int testnum) +{ + int ret = 0; + char *buf = NULL; + int bufsz = sysconf(_SC_PAGE_SIZE) * 14; + int filsz = 4 << 20; + + /* HOLE - unwritten DATA in dirty page */ + /* Each unit is bufsz */ + buf = do_malloc(bufsz); + if (!buf) + goto out; + memset(buf, 'a', bufsz); + + /* preallocate 4M space to file */ + ret = do_fallocate(fd, 0, filsz, 0); + if (ret < 0) { + /* Report success if fs doesn't support fallocate */ + if (errno == EOPNOTSUPP) { + fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n"); + ret = 0; + } + goto out; + } + + ret = do_pwrite(fd, buf, bufsz, 0); + if (ret) + goto out; + + /* offset at the beginning */ + ret += do_lseek(testnum, 1, fd, filsz, SEEK_HOLE, 0, bufsz); + ret += do_lseek(testnum, 2, fd, filsz, SEEK_HOLE, 1, bufsz); + ret += do_lseek(testnum, 3, fd, filsz, SEEK_DATA, 0, 0); + ret += do_lseek(testnum, 4, fd, filsz, SEEK_DATA, 1, 1); + +out: + do_free(buf); + return ret; +} + +/* * Test huge file to check for overflows of block counts due to usage of * 32-bit types. */ @@ -678,6 +772,8 @@ struct testrec seek_tests[] = { { 10, test10, "Test a huge file for offset overflow" }, { 11, test11, "Test a huge file for block number signed" }, { 12, test12, "Test a huge file for block number overflow" }, + { 13, test13, "Test file with unwritten extents, only have pagevec dirty pages" }, + { 14, test14, "Test file with unwritten extents, small hole after pagevec dirty pages" }, }; static int run_test(struct testrec *tr)