From patchwork Wed Jul 28 21:16:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12406775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAC6BC4338F for ; Wed, 28 Jul 2021 21:16:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF47561039 for ; Wed, 28 Jul 2021 21:16:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231350AbhG1VQD (ORCPT ); Wed, 28 Jul 2021 17:16:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:34112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231574AbhG1VQC (ORCPT ); Wed, 28 Jul 2021 17:16:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E219460462; Wed, 28 Jul 2021 21:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627506961; bh=DkWT6rjh86jW2G/80m6SmC3IJ3CJ2h//RuwmciulVPA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PqHhWW2SemLsiiysuzuB55NA3z1hXMUGqIlJ+mcJFJIWpBrMeGkBALD3fPsZMzBuq 37ZEkR0x0B0aUiSpTTomQJtQZkBDceveeZy1mMNN7smrb0XSgxAESPjRvoh5neYn4p KVsmV9h7XMTVbl3eXMEiz+D/vD1dp2AIR8/JRotQZmoSdq73fJWHZ1KW6C+/Y19wxI bKlY5EiwgZ7Ew63rr5szoaxjUqfCHOw5aJ8FdIMx8pVljPrzQPozWejkzuhgibO8Wg gRVJvl4BQADl4DOtxDkDvoBq3ODFv8IY27e8L5wnhFdaijDVbTWpbi536oJzHkm7no A76MzWtKuCFoA== Subject: [PATCH 1/2] xfs_io: fix broken funshare_cmd usage From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Christoph Hellwig , Carlos Maiolino , linux-xfs@vger.kernel.org Date: Wed, 28 Jul 2021 14:16:00 -0700 Message-ID: <162750696066.44508.13287474216659665234.stgit@magnolia> In-Reply-To: <162750695515.44508.15362873895872268737.stgit@magnolia> References: <162750695515.44508.15362873895872268737.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create a funshare_cmd and use that to store information about the xfs_io funshare command instead of overwriting the contents of fzero_cmd. This fixes confusing output like: $ xfs_io -c 'fzero 2 3 --help' / fzero: invalid option -- '-' funshare off len -- unshares shared blocks within the range Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- io/prealloc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/io/prealloc.c b/io/prealloc.c index 382e8119..2ae8afe9 100644 --- a/io/prealloc.c +++ b/io/prealloc.c @@ -43,6 +43,7 @@ static cmdinfo_t fpunch_cmd; static cmdinfo_t fcollapse_cmd; static cmdinfo_t finsert_cmd; static cmdinfo_t fzero_cmd; +static cmdinfo_t funshare_cmd; #endif static int @@ -467,14 +468,14 @@ prealloc_init(void) _("zeroes space and eliminates holes by preallocating"); add_command(&fzero_cmd); - fzero_cmd.name = "funshare"; - fzero_cmd.cfunc = funshare_f; - fzero_cmd.argmin = 2; - fzero_cmd.argmax = 2; - fzero_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK; - fzero_cmd.args = _("off len"); - fzero_cmd.oneline = + funshare_cmd.name = "funshare"; + funshare_cmd.cfunc = funshare_f; + funshare_cmd.argmin = 2; + funshare_cmd.argmax = 2; + funshare_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK; + funshare_cmd.args = _("off len"); + funshare_cmd.oneline = _("unshares shared blocks within the range"); - add_command(&fzero_cmd); + add_command(&funshare_cmd); #endif /* HAVE_FALLOCATE */ } From patchwork Wed Jul 28 21:16:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12406777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82867C4338F for ; Wed, 28 Jul 2021 21:16:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B890600CD for ; Wed, 28 Jul 2021 21:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbhG1VQI (ORCPT ); Wed, 28 Jul 2021 17:16:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:34138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231574AbhG1VQI (ORCPT ); Wed, 28 Jul 2021 17:16:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 648F76101B; Wed, 28 Jul 2021 21:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627506966; bh=+F+Pu7IQYvEfKsPuebgniOoXUTI14TBGxKpxyo0iI9k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KcYbTzEyqlcOujTfK0tb0B+zwO5rxnaVeFYDhF3Fsz0klGcyt/BT3wn5+c0tDWC/p bG9y/tP5Q9zJYw1bpuNcmKOVOKSZ0WdVcE3ImX8X5jy+5eXG4ci4A7OWCL6tIaDIYk dhtWEC4kmEBQqP+8K+9kUE4ZpRuRIz5RYkbVQzcsKwwFNqyHwxssFe6cL5gOgjuUWZ fY9FCI3viCxdSIfGE4aaDurDafthb3LhurvCfbgl2lbcn+DJihpRsQbSao8+NBc/6Z GIXI3wF/lDcV7U2y4WjZhSGHD3TblPf1p+agrjGxKelPu+21ZNUZhLXWVaq7O04ppw WgUZl/f4QyCIg== Subject: [PATCH 2/2] xfs_io: clean up the funshare command a bit From: "Darrick J. Wong" To: sandeen@sandeen.net, djwong@kernel.org Cc: Carlos Maiolino , linux-xfs@vger.kernel.org Date: Wed, 28 Jul 2021 14:16:06 -0700 Message-ID: <162750696612.44508.4433629680409310292.stgit@magnolia> In-Reply-To: <162750695515.44508.15362873895872268737.stgit@magnolia> References: <162750695515.44508.15362873895872268737.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add proper argument parsing to the funshare command so that when you pass it nonexistent --help it will print the help instead of complaining that it can't convert that to a number. Signed-off-by: Darrick J. Wong Reviewed-by: Carlos Maiolino --- io/prealloc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/io/prealloc.c b/io/prealloc.c index 2ae8afe9..a8831c1b 100644 --- a/io/prealloc.c +++ b/io/prealloc.c @@ -346,16 +346,24 @@ funshare_f( char **argv) { xfs_flock64_t segment; + int c; int mode = FALLOC_FL_UNSHARE_RANGE; - int index = 1; - if (!offset_length(argv[index], argv[index + 1], &segment)) { + while ((c = getopt(argc, argv, "")) != EOF) { + switch (c) { + default: + command_usage(&funshare_cmd); + } + } + if (optind != argc - 2) + return command_usage(&funshare_cmd); + + if (!offset_length(argv[optind], argv[optind + 1], &segment)) { exitcode = 1; return 0; } - if (fallocate(file->fd, mode, - segment.l_start, segment.l_len)) { + if (fallocate(file->fd, mode, segment.l_start, segment.l_len)) { perror("fallocate"); exitcode = 1; return 0;