From patchwork Sat Feb 21 15:45:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 5859951 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0DCEE9F30C for ; Sat, 21 Feb 2015 15:50:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1356020465 for ; Sat, 21 Feb 2015 15:50:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE78420456 for ; Sat, 21 Feb 2015 15:50:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752504AbbBUPtx (ORCPT ); Sat, 21 Feb 2015 10:49:53 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:38105 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752223AbbBUPtt (ORCPT ); Sat, 21 Feb 2015 10:49:49 -0500 Received: by padbj1 with SMTP id bj1so15769151pad.5; Sat, 21 Feb 2015 07:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GLgKUo+/MJ/xSc+5uOdIptbfrT4cYMwK3+7U5BiC8II=; b=aoWqltRB8K5pooR82sRibDxqStRQzAAM9ezidzV/UqjfxsONFDI7xItvv8IVY5dkPz a76xPYeS1CHpfOvQFtPfRtTr1cY0fIHd5Y2tn00RKUS3Xa/4ruS8cQ4aCW5SfLNvLP// bxqCJhVhk+s3LxxuRNrPjKFs/Bx9C+5cMuTXfGHqFLKLpD8IMgihyR/i+wG6uhP/9fXw W02mRDPgRwbf4kz+VRAPO5dQTh9m9pPrecff3TU4FooOnSCRppRO2+CiuMMTZIP3rzFp nTJlnnEZJishruaYY3e3TSVIo1AKuFR2cnhcWNSC7eNYgrQfhoB0gWxqrK7P9GKiUIY5 ak4Q== X-Received: by 10.68.233.232 with SMTP id tz8mr5102108pbc.166.1424533788103; Sat, 21 Feb 2015 07:49:48 -0800 (PST) Received: from linkinjeon-Aspire-One-522.kornet ([125.129.25.112]) by mx.google.com with ESMTPSA id fc6sm187055pab.6.2015.02.21.07.49.42 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 21 Feb 2015 07:49:47 -0800 (PST) From: Namjae Jeon To: david@fromorbit.com, tytso@mit.edu Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, xfs@oss.sgi.com, a.sangwan@samsung.com, bfoster@redhat.com, mtk.manpages@gmail.com, linux-man@vger.kernel.org, linux-api@vger.kernel.org, Namjae Jeon , Namjae Jeon Subject: [PATCH v10 11/12] xfstests: fsx: Add fallocate insert range operation Date: Sun, 22 Feb 2015 00:45:53 +0900 Message-Id: <1424533554-28024-12-git-send-email-linkinjeon@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1424533554-28024-1-git-send-email-linkinjeon@gmail.com> References: <1424533554-28024-1-git-send-email-linkinjeon@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Namjae Jeon This commit adds fallocate FALLOC_FL_INSERT_RANGE support for fsx. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan Reviewed-by: Brian Foster --- ltp/fsx.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index 0bb8ae8..6da51e9 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -95,7 +95,8 @@ int logcount = 0; /* total ops */ #define OP_PUNCH_HOLE 6 #define OP_ZERO_RANGE 7 #define OP_COLLAPSE_RANGE 8 -#define OP_MAX_FULL 9 +#define OP_INSERT_RANGE 9 +#define OP_MAX_FULL 10 /* operation modifiers */ #define OP_CLOSEOPEN 100 @@ -146,6 +147,7 @@ int keep_size_calls = 1; /* -K flag disables */ int punch_hole_calls = 1; /* -H flag disables */ int zero_range_calls = 1; /* -z flag disables */ int collapse_range_calls = 1; /* -C flag disables */ +int insert_range_calls = 1; /* -I flag disables */ int mapped_reads = 1; /* -R flag disables it */ int fsxgoodfd = 0; int o_direct; /* -Z */ @@ -340,6 +342,14 @@ logdump(void) lp->args[0] + lp->args[1]) prt("\t******CCCC"); break; + case OP_INSERT_RANGE: + prt("INSERT 0x%x thru 0x%x\t(0x%x bytes)", + lp->args[0], lp->args[0] + lp->args[1] - 1, + lp->args[1]); + if (badoff >= lp->args[0] && badoff < + lp->args[0] + lp->args[1]) + prt("\t******IIII"); + break; case OP_SKIPPED: prt("SKIPPED (no operation)"); break; @@ -1014,6 +1024,59 @@ do_collapse_range(unsigned offset, unsigned length) } #endif +#ifdef FALLOC_FL_INSERT_RANGE +void +do_insert_range(unsigned offset, unsigned length) +{ + unsigned end_offset; + int mode = FALLOC_FL_INSERT_RANGE; + + if (length == 0) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping zero length insert range\n"); + log4(OP_SKIPPED, OP_INSERT_RANGE, offset, length); + return; + } + + if ((loff_t)offset >= file_size) { + if (!quiet && testcalls > simulatedopcount) + prt("skipping insert range behind EOF\n"); + log4(OP_SKIPPED, OP_INSERT_RANGE, offset, length); + return; + } + + log4(OP_INSERT_RANGE, offset, length, 0); + + if (testcalls <= simulatedopcount) + return; + + end_offset = offset + length; + if ((progressinterval && testcalls % progressinterval == 0) || + (debug && (monitorstart == -1 || monitorend == -1 || + end_offset <= monitorend))) { + prt("%lu insert\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls, + offset, offset+length, length); + } + if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) { + prt("insert range: %x to %x\n", offset, length); + prterr("do_insert_range: fallocate"); + report_failure(161); + } + + memmove(good_buf + end_offset, good_buf + offset, + file_size - offset); + memset(good_buf + offset, '\0', length); + file_size += length; +} + +#else +void +do_insert_range(unsigned offset, unsigned length) +{ + return; +} +#endif + #ifdef HAVE_LINUX_FALLOC_H /* fallocate is basically a no-op unless extending, then a lot like a truncate */ void @@ -1120,14 +1183,25 @@ docloseopen(void) } } -#define TRIM_OFF_LEN(off, len, size) \ -do { \ - if (size) \ - (off) %= (size); \ - else \ - (off) = 0; \ - if ((off) + (len) > (size)) \ - (len) = (size) - (off); \ + +#define TRIM_OFF(off, size) \ +do { \ + if (size) \ + (off) %= (size); \ + else \ + (off) = 0; \ +} while (0) + +#define TRIM_LEN(off, len, size) \ +do { \ + if ((off) + (len) > (size)) \ + (len) = (size) - (off); \ +} while (0) + +#define TRIM_OFF_LEN(off, len, size) \ +do { \ + TRIM_OFF(off, size); \ + TRIM_LEN(off, len, size); \ } while (0) void @@ -1195,6 +1269,12 @@ test(void) goto out; } break; + case OP_INSERT_RANGE: + if (!insert_range_calls) { + log4(OP_SKIPPED, OP_INSERT_RANGE, offset, size); + goto out; + } + break; } switch (op) { @@ -1247,6 +1327,22 @@ test(void) } do_collapse_range(offset, size); break; + case OP_INSERT_RANGE: + TRIM_OFF(offset, file_size); + TRIM_LEN(file_size, size, maxfilelen); + offset = offset & ~(block_size - 1); + size = size & ~(block_size - 1); + if (size == 0) { + log4(OP_SKIPPED, OP_INSERT_RANGE, offset, size); + goto out; + } + if (file_size + size > maxfilelen) { + log4(OP_SKIPPED, OP_INSERT_RANGE, offset, size); + goto out; + } + + do_insert_range(offset, size); + break; default: prterr("test: unknown operation"); report_failure(42); @@ -1310,6 +1406,9 @@ usage(void) #ifdef FALLOC_FL_COLLAPSE_RANGE " -C: Do not use collapse range calls\n" #endif +#ifdef FALLOC_FL_INSERT_RANGE +" -I: Do not use insert range calls\n" +#endif " -L: fsxLite - no file creations & no file size changes\n\ -N numops: total # operations to do (default infinity)\n\ -O: use oplen (see -o flag) for every op (default random)\n\ @@ -1496,7 +1595,7 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ - while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FKHzCLN:OP:RS:WZ")) + while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ")) != EOF) switch (ch) { case 'b': @@ -1605,6 +1704,9 @@ main(int argc, char **argv) case 'C': collapse_range_calls = 0; break; + case 'I': + insert_range_calls = 0; + break; case 'L': lite = 1; break; @@ -1766,6 +1868,8 @@ main(int argc, char **argv) zero_range_calls = test_fallocate(FALLOC_FL_ZERO_RANGE); if (collapse_range_calls) collapse_range_calls = test_fallocate(FALLOC_FL_COLLAPSE_RANGE); + if (insert_range_calls) + insert_range_calls = test_fallocate(FALLOC_FL_INSERT_RANGE); while (numops == -1 || numops--) test();