From patchwork Tue Jun 13 06:59:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 107112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp352201vqr; Tue, 13 Jun 2023 00:06:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wZ+IFGmtgNg7eLvurp9UiOYMRSzgi94zHiqoV6G5skwEZW5ZdrArscA93Ty5InCAA9K3y X-Received: by 2002:aa7:c543:0:b0:514:8fdd:fc41 with SMTP id s3-20020aa7c543000000b005148fddfc41mr7166791edr.15.1686639971874; Tue, 13 Jun 2023 00:06:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686639971; cv=pass; d=google.com; s=arc-20160816; b=AhQT2UmnPmXGb00S6NKjhHoQ2wF1FJgfS991/5uOJAuUjcJcNmOnSyyMtzj87EWTBR EX/uuW19DfyU1JIkdpAtcqt41AQWZhDXrRV4XLzp2qAgfpaKYek940i7IKlZdYDJdWjI pXOWU/DgdQm9p7ZH9XgQhbUHnauyxna0UQJsVym+zGf/OTTnwTpBJ0o8Ys99uw07lInu 2NkbPVfdgEebVv/afIsdlAL4kxgZFc/b1dJuKRc1YenPeUcazMmWLpYtJr2DMzMyAVYF N8XhhlzDTKbV4iTYPufDGbUiQhFYavWs9vKcRa34yvsdhqusIu+308mqO713AbDZDMKi AdFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=1Oc4+e7EXhHKHV7K5cnyCAqrUF7nyWFB4xpnNKpo1xQ=; b=Kmyy1bbQcxvKII5KVQ6bKegaix1V3XXQDSzxxTLBkvP1wYQ3drOx2dAsrcIhGoeo8D ruxT9igCU0xVxIkaZRCTtBH+AdKTwebTJ8RAcoD7GK/m9GEK+wjNICWbi3BroYryLshq 43YOKbWER8ZyQIvsWiiCg7yU4a0DIs++WlPD78uqS84ypj0Z0BYBOlvfRONoFtVZzwl+ iJ2FfDnCfUTXH8O6MvUHRsc0FF9EqpsmlHOj3ZHM1+DvlAphmX3iFi+jMKRXSV4yod8L Wepx4nv850I7SBErNp8nHNcU146tLUlzOBP1TILnOA/8JOoDrTK2eB9uwlCLW+/D3t+R ZcmA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=mGk7Zv3L; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020aa7c585000000b005164ef74becsi6604891edq.106.2023.06.13.00.05.47; Tue, 13 Jun 2023 00:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=mGk7Zv3L; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240316AbjFMG75 (ORCPT + 99 others); Tue, 13 Jun 2023 02:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240348AbjFMG7t (ORCPT ); Tue, 13 Jun 2023 02:59:49 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2117.outbound.protection.outlook.com [40.107.117.117]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66450170C for ; Mon, 12 Jun 2023 23:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bnp7zlNQyOcaiQObXGltYOFLyaCSkMdRM4q9eR/hSAdxdzOMe/ym3xo4hIPToXU+Nh5HrUBws44rrH2bo8mjgjog/B8DdWBrdwRVxcnwBLeqkyFbGFX56S2KhS8HUpinEcmcy54aMcyeF4/Ax+Es/F10U+esf3vCnlBqN7SCKnHRbggPl/CU2GNcj5HGqJkYOHzAk88CyF4At06cbOTMeHCmZodgLLdjy9Q1mNq9n/tVOjp46HViCYvzyHotH7jAc4p6dBDUNsGnpr8/p+/oQLSHQeMI4tnwQZKPTRA1rFxGrLNJs2yxQJGnzGRXphvsrac+DsCo3U/UhrFSW7GEUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1Oc4+e7EXhHKHV7K5cnyCAqrUF7nyWFB4xpnNKpo1xQ=; b=F4ASci7ZbQgQsGS+DB8o72a50gSjEN346lyp0uzKPSLZBVFc7+Si41xfZMtSCQmO4hVgWhcO47NBUrKHv8TMwcRt1vORTo6MDy8PhIQnY8Ql2Zf23Dtn36q4hPAXqL7Ara51B+yqIZwSIwT585RfcVjAUbk3+zTHTO2qt8qnRda0q0tDDFN1BfDhOCvDL+lSYlZyLyDeATCgRYzreFor5Q4V7fzyAQhyV4CCQP2AUi+lJ3ErNBjM2ft3LewbDeooCLNEeHx9Hmp3NQjKF3V/DstG83uSSDXKU09vegKnQKLMy/eP6xb/o/6PGYAS5QFHrBpMgEQyHJvz6a3CFi7Gzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Oc4+e7EXhHKHV7K5cnyCAqrUF7nyWFB4xpnNKpo1xQ=; b=mGk7Zv3LW2fK3wFDqsss0s4uViZhfky7tQAF3RhSeYwdzwvrrHto7JYkDe8qJfwTe+GcUZFlTYkzPws2swUgxPi9Jy7QjDlVKh5JlnYWKj/18ND+JXisPKPH7+4qfDrC0SzkhcDiPbTRV/o3uLODG0t3aAxv51x+RA3DKYVEnSp4j7x7tBElYuJsLcJ71bz6xEH5qd3/VtNuuPUx6Z5lqRJCQ9t8pf3YQI3uA3IKpLC/08WG1QdUUEXEv5Yuj5x+3Dx431nKtd3hWZXBJ1CkEOcWKEyFO+zwjJuPlOJjMAxSZdIS6OFma9/EMgU2TaYS5xQzVIs8WUysoF7qt8Pmfw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TYZPR06MB4096.apcprd06.prod.outlook.com (2603:1096:400:2e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Tue, 13 Jun 2023 06:59:26 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965%3]) with mapi id 15.20.6455.039; Tue, 13 Jun 2023 06:59:26 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH v3] f2fs_io: expend fallocate command Date: Tue, 13 Jun 2023 14:59:10 +0800 Message-Id: <20230613065911.4304-1-frank.li@vivo.com> X-Mailer: git-send-email 2.39.0 X-ClientProxiedBy: SG2PR01CA0117.apcprd01.prod.exchangelabs.com (2603:1096:4:40::21) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TYZPR06MB4096:EE_ X-MS-Office365-Filtering-Correlation-Id: 90e894af-606f-472a-74cb-08db6bdbb993 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /lybIc3rqWhSKofmo0h721qXtTTRmE44UkP6fsNyD7ScNxhLnLFckjbv3rlc49sQ/ea4Jj1yat1Y47lwM+Pg3jkTx4I+7u+8VFcI5yYXhxEGjbLzMNLjOT+BtvXcf4Pos2pVH93FPTqaE9loAcaD+fNcQpu2+U+1RfrRq4m09ifJ+j4vI7v/141CqSuDv3bk/N7o8Fk4r9gnUICaOYes0gfoAFjwsQrwk3cVcipC/t3afFjW1r8UYq5Cc8rqdBK/du6Ae3sOnyKrlQ32LJuTIbJaXZf+a0QnnhTQ/cSlxrNTbctQ60WGuFTtRaOrlmYXZGyYZMOZnGqYvoug4YkN30TPaRHscFkG3UQqGZXmX3rKKzEoIb85jkiMCaqvEFvVtwkenMK9Xfd+a0uxZmgxRaiuQV0KShEqi0BMFnO+EBJUu1rjDtY3Bz9GOki9VEd2we9dike55Fy0TBLKvtL+/F4CNOWnh4woasJV+6NaDAWw54HwKp8pCNIwMwniYGghPy6UCXrCL5pOtz6eGF5Ca3WvfXD6NGfkmQRbPD28Qdnh0c57hCIThntRu64IJBOTFE2FHuRI85xNDwxqPRbp95dsPFwLl2ncENjJhlRIp09v66FblcDwTfduacFd9Jml X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(39850400004)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(86362001)(38100700002)(38350700002)(36756003)(478600001)(4326008)(6486002)(6666004)(8936002)(8676002)(2906002)(5660300002)(52116002)(66556008)(66946007)(66476007)(41300700001)(316002)(186003)(107886003)(6506007)(6512007)(1076003)(26005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zbE4BA2Mk84uk+vmNR5RGrOF5m3ml0baLjBQs0a2aNI2xPYzVJRg4swvGewX1Drs2madEOl+l4YXksZwB6VO4lEITlC0EP8WyIMe1D6SUW5uWUjlUIecMbC5KRtEo4upXoI4wAopRVbrf9IcHMUgV/VRwsFxuRvOSPjRwh8zzAAj6A95geVT+us0UEn7DgruTbG3qz4TJO4TXCFdsKQbT6TLCvoQQg3eNUh5mz1uDERcLD09yDiVwA0HM4WJfLBmGXTPf1IyvCkdd1jHfL85PPRth0vawe2qCrBHj2dc1A5TQzVu3mY4hei7Z3ynj2ePcDyiDihxGvit2v5cSty54/G1Cv9m57U1O8uUp/oWZWB+om3SUxFo5GtOHSfHd2GxICbructgrOZ3Mv2ZmZN+FL/g5QeudsXxNezUO875Equti2pE7m7/qq5mGB3QOUpm476kTBi8d/blJH86uxmTGOVoz/0quoaRjci9P0noofjRFKsbo77Fs3C/zvnMRZdRTgHkXnWM1jj/hLpOhNIsw5xUzna+HQfZefXrDLCL6eZgdTL5+IjxWygIDrt/yx8tPXtUx/4yzrlQLzA6dxb06O/pDylwjkOKJP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enant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2023 06:59:26.0968 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: STmn6fwZXErJFRlZigRVXqtuqAsCflwHZpm0LmjYq8sPnhkL9BMY2+kRE5aZKrMZCAHuiRK3NNUoM3MwwR/zBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB4096 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768570195233468146?= X-GMAIL-MSGID: =?utf-8?q?1768570195233468146?= Expend fallocate command to support more flags. Signed-off-by: Yangtao Li Reviewed-by: Chao Yu --- v3: -update man/f2fs_io.8 man/f2fs_io.8 | 19 ++++++++++++++++++- tools/f2fs_io/f2fs_io.c | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/man/f2fs_io.8 b/man/f2fs_io.8 index c5eadde..450f1b7 100644 --- a/man/f2fs_io.8 +++ b/man/f2fs_io.8 @@ -43,10 +43,27 @@ going down with fsck mark \fBpinfile\fR \fI[get|set] [file]\fR Get or set the pinning status on a file. .TP -\fBfallocate\fR \fI[keep_size] [offset] [length] [file]\fR +\fBfallocate\fR \fI[-c] [-i] [-p] [-z] [keep_size] [offset] [length] [file]\fR Request that space be allocated on a file. The .I keep_size parameter can be either 1 or 0. +The +.I pattern +parameter can be: +.RS 1.2in +.TP +.B -c +collapse range +.TP +.B -i +insert range +.TP +.B -p +punch hole +.TP +.B -z +zero range +.RE .TP \fBwrite\fR \fI[chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]\fR Write a given pattern to diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index 1774eca..b4e7307 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -413,9 +413,13 @@ static void do_pinfile(int argc, char **argv, const struct cmd_desc *cmd) #define fallocate_desc "fallocate" #define fallocate_help \ -"f2fs_io fallocate [keep_size] [offset] [length] [file]\n\n" \ +"f2fs_io fallocate [-c] [-i] [-p] [-z] [keep_size] [offset] [length] [file]\n\n" \ "fallocate given the file\n" \ " [keep_size] : 1 or 0\n" \ +" -c : collapse range\n" \ +" -i : insert range\n" \ +" -p : punch hole\n" \ +" -z : zero range\n" \ static void do_fallocate(int argc, char **argv, const struct cmd_desc *cmd) { @@ -423,20 +427,43 @@ static void do_fallocate(int argc, char **argv, const struct cmd_desc *cmd) off_t offset, length; struct stat sb; int mode = 0; + int c; - if (argc != 5) { + while ((c = getopt(argc, argv, "cipz")) != -1) { + switch (c) { + case 'c': + mode |= FALLOC_FL_COLLAPSE_RANGE; + break; + case 'i': + mode |= FALLOC_FL_INSERT_RANGE; + break; + case 'p': + mode |= FALLOC_FL_PUNCH_HOLE; + break; + case 'z': + mode |= FALLOC_FL_ZERO_RANGE; + break; + default: + fputs(cmd->cmd_help, stderr); + exit(2); + } + } + argc -= optind; + argv += optind; + + if (argc != 4) { fputs("Excess arguments\n\n", stderr); fputs(cmd->cmd_help, stderr); exit(1); } - if (!strcmp(argv[1], "1")) + if (!strcmp(argv[0], "1")) mode |= FALLOC_FL_KEEP_SIZE; - offset = atoi(argv[2]); - length = atoll(argv[3]); + offset = atoi(argv[1]); + length = atoll(argv[2]); - fd = xopen(argv[4], O_RDWR, 0); + fd = xopen(argv[3], O_RDWR, 0); if (fallocate(fd, mode, offset, length) != 0) die_errno("fallocate failed");