From patchwork Tue Dec 6 05:43:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9486723 X-Mozilla-Keys: nonjunk Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sandeen.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM, RP_MATCHES_RCVD, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-HP: BAYES_00=-1.9,DKIM_ADSP_CUSTOM_MED=0.001,DKIM_SIGNED=0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001,RCVD_IN_DNSWL_HI=-5, RCVD_IN_SORBS_SPAM=0.5,RP_MATCHES_RCVD=-0.1,T_DKIM_INVALID=0.01 X-Original-To: sandeen@sandeen.net Delivered-To: sandeen@sandeen.net Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by sandeen.net (Postfix) with ESMTP id A829D47968A for ; Tue, 6 Dec 2016 00:01:59 -0600 (CST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751662AbcLFGC4 (ORCPT ); Tue, 6 Dec 2016 01:02:56 -0500 Received: from mail-wj0-f194.google.com ([209.85.210.194]:33980 "EHLO mail-wj0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751636AbcLFGC4 (ORCPT ); Tue, 6 Dec 2016 01:02:56 -0500 Received: by mail-wj0-f194.google.com with SMTP id xy5so42132668wjc.1; Mon, 05 Dec 2016 22:02:55 -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; bh=LcqANsYn6dufNHL4A5o9W4Yd2J5uPEpI2wn0OSS8GQY=; b=eoUlF5AKgW6JhvcPscOZSL31vH/UehsNw4jlxNWx2mzJZRGI7tX8S4bOXPynkWIooE NJKXtLvCWbPNof0qG42uthTXIJKr+q5pajMN+VEB8u3fzMGd2bx04uDOPaBj08Cd5Ay+ DGqqAGu38w5Td6UcMcazPYwLmPCXZBA9x7bLKRmOkt8kAkds7W5IgD79EeffcoepyMhC c1YOh504IICSqb8DnqiZS9VfQkCr/icXP4qipSpBeq0GrHYHr8LBN21Ai4oGtXwIOSUs bdaO6VLplqxtv98ujYYWPQ1PZDtpMtHsrZnT9rIkCSk5RCFQz62j/0u/xCZR3VZ8M5m6 PLJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LcqANsYn6dufNHL4A5o9W4Yd2J5uPEpI2wn0OSS8GQY=; b=m5S/uX/tqwIkjWVlm4exbGdnP72awAliuuG06X25q0tR3BtXdfNFs2ditjtWhE7suH neGfqV6RtjnY+45v4VzmP6rjGJz+hubOs67geUWfMCafvcYptv65CMq/VfCwca/5GvZg F2IwAQEIhtfN66ANIcMa/6ZWA+pePYyLlp6cjBd/DtCKU0xkEj+jJlegiZMIiZ9viT83 Xe4mcDcB1OjkEMPkQ141tRTeioG7YDDhr9sBCgQ/YvUJpGxtLXw5MqqC+6IcSN8FcB9r AjQMLzGwIWFGpgES5ymYYol2DLUpaVO9cNDn/bjzKF9z19lTDnsMVu9KA9MebH6HAY7A 2NqQ== X-Gm-Message-State: AKaTC01HPQ5h0fIIlCq1Fc4ISndgkXXD4v9MT3BdEjg5p/XQoraGuiAZjryCEEvL/ErWGg== X-Received: by 10.194.0.197 with SMTP id 5mr5183149wjg.175.1481003060516; Mon, 05 Dec 2016 21:44:20 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-177-89-54.red.bezeqint.net. [79.177.89.54]) by smtp.gmail.com with ESMTPSA id f10sm23787513wjl.28.2016.12.05.21.44.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 21:44:19 -0800 (PST) From: Amir Goldstein To: Dave Chinner Cc: Eric Sandeen , Eryu Guan , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v4] xfs_io: support -c "open foo" command Date: Tue, 6 Dec 2016 07:43:58 +0200 Message-Id: <1481003038-23740-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org There is an undocumented and possibly unused feature in xfs_io where all commands are executed per file when multiple files are provided in the args list. This feature creates ambiguity when trying to execute commands such as "open" and "file" from command line and result in an endless loop in the command loop code, e.g.: xfs_io -r -c "open -f bar" -c print foo bar: Too many open files [000] foo (foreign,non-sync,non-direct,read-only) 001 bar (foreign,non-sync,non-direct,read-write) 002 bar (foreign,non-sync,non-direct,read-write) 003 bar (foreign,non-sync,non-direct,read-write) 004 bar (foreign,non-sync,non-direct,read-write) 005 bar (foreign,non-sync,non-direct,read-write) 006 bar (foreign,non-sync,non-direct,read-write) Also, when running xfs_io -c without any file args, xfs_io exits without doing anything. This behavior is also undocumented and makes very little sense. Change the behavior of xfs_io, so commands given with -c are executed exactly once, regardless of the number of file args. This enables writing proper xfs_io scripts in command line, which include "open" and "file" commands. Update the man page and usage to reflect the fact that multiple as well as zero file args can be given in args list. This change does not modify the behavior of xfs_io in the most commonly used case of single file argument in command line and no "open" and "file" commands in command line. Signed-off-by: Amir Goldstein --- io/init.c | 11 ++++++----- man/man8/xfs_io.8 | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) v4: - Allow multiple file args - Update man page and usage to allow multiple file args and spell out the expected behavior in this case v3: - Forbid multiple file args - Update man page and usage to allow no file arg - Add endless loop bug report to commit message v2: - Fix the case of multiple file args v1: - Fix the case of zero file args diff --git a/io/init.c b/io/init.c index a9191cf..54b998c 100644 --- a/io/init.c +++ b/io/init.c @@ -34,7 +34,7 @@ void usage(void) { fprintf(stderr, - _("Usage: %s [-adfinrRstVx] [-m mode] [-p prog] [-c cmd]... file\n"), + _("Usage: %s [-adfinrRstVx] [-m mode] [-p prog] [-c cmd]... [file]...\n"), progname); exit(1); } @@ -90,14 +90,15 @@ init_commands(void) cowextsize_init(); } +/* + * Return true for first call and false for the next call, + * to execute each command just once. + */ static int init_args_command( int index) { - if (index >= filecount) - return 0; - file = &filetable[index++]; - return index; + return !index; } static int diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 885df7f..f61eee6 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -11,8 +11,9 @@ xfs_io \- debug the I/O path of an XFS filesystem ] ... [ .B \-p .I prog -] +] [ .I file +] ... .br .B xfs_io \-V .SH DESCRIPTION @@ -42,7 +43,11 @@ the default value is .B \-f Create .I file -if it does not already exist. +if it does not already exist. Multiple +.I file +arguments may be given. The files are open before the +.B \-c +commands are executed. .TP .B \-r Open