From patchwork Mon Dec 5 20:39:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9461485 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 64CF560236 for ; Mon, 5 Dec 2016 20:39:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52A4227E71 for ; Mon, 5 Dec 2016 20:39:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4461B27F82; Mon, 5 Dec 2016 20:39:57 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 9B23D27E71 for ; Mon, 5 Dec 2016 20:39:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751786AbcLEUjv (ORCPT ); Mon, 5 Dec 2016 15:39:51 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36115 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751378AbcLEUjv (ORCPT ); Mon, 5 Dec 2016 15:39:51 -0500 Received: by mail-wm0-f67.google.com with SMTP id m203so17987456wma.3; Mon, 05 Dec 2016 12:39:50 -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=DHLgq6JNrAJeFJIExSCxnee54Ww4DsK5wNnShNZjBLs=; b=mgIeUv3NdWFNTMFqmvGFsRjNml6IW6OOvOd+nGFoPNqCLuBeMI+umiAU3tH63jRM/B jUL8UruMojo/2Ku7B0Gp3Ze2nmtgBt9mA7RERcAINqW1ybl7lQxOXxKtmBIPLl2gEsYP Wey9b2/guUPBSn6fXk3B6JBHlltN3/hrl41eIbNWoVseZYUG5oIeNvBnbrElKFg/cc2s RKkysi9B1+wyu4nsDkJtISEAZgSMuW+M5IdLL99sGZjQJRHRAB4Br+WpH2HHr1DOH9pw IkdykGoI/RJTMfgBGlkDweeXfW4m0jVtsmeTUUbAQGRJcBowbARvSmbjWQA9gw7OF6IP db+g== 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=DHLgq6JNrAJeFJIExSCxnee54Ww4DsK5wNnShNZjBLs=; b=QzZoBdWl0keAiCQjUonkNg6hOBCa8sCDBJLpfIr5BHas5z3Hh5VnYD/77M8zEOlw7p erI20wQZCLrBlw1Dih7uqVaqPShKbQI5BPhOkNKmJkwNVRff9FjG1ftl9Xcso/vI26rI t5LiM+nAU6cvYOQx2EU+5vvFBqDqS7OMLOiR6bYIGYTYxht9liZ1ZmxdmXSdlgfF8whx 45UvBfvL4AuZrQBxY1fxM8wYLY51YIHRq5nNHxNQOBo1+xNS++PMR2G8tm6qZKyo53Ue 7jhFZCEbgqHDvs6B7qRbK3KTmOu1EHQBuydqsk5EEwMgodvDUGOCcfwB9r9YcnhNlltq SJsw== X-Gm-Message-State: AKaTC001S5Jqu+hHSr9f2zJlm4Pwo09YoUKIhHdn7nVdBd8kVTbCq13aoj7iX0vIRzF7oA== X-Received: by 10.28.45.142 with SMTP id t136mr12337654wmt.110.1480970389380; Mon, 05 Dec 2016 12:39:49 -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 pd2sm22131965wjb.31.2016.12.05.12.39.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Dec 2016 12:39:48 -0800 (PST) From: Amir Goldstein To: Dave Chinner Cc: Eric Sandeen , Eryu Guan , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v3] xfs_io: support -c "open foo" command Date: Mon, 5 Dec 2016 22:39:26 +0200 Message-Id: <1480970366-23648-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 to accept zero or one file in args list and forbid multiple files in args list. If more than a single file is given in args list, xfs_io exits and prints usage info. The usage info and man page were both modified to reflect this change. Commands given with -c are executed exactly once, regardless if a file was provided in args list or not. This enables writing proper xfs_io scripts in command line, which include "open" and "file" commands. 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 | 15 ++++++++++----- man/man8/xfs_io.8 | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) 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..d5993a4 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 once. + */ static int init_args_command( int index) { - if (index >= filecount) - return 0; - file = &filetable[index++]; - return index; + return !index; } static int @@ -203,6 +204,10 @@ init( } } + /* Multiple file args is not supported */ + if (optind + 1 < argc) + usage(); + while (optind < argc) { if ((c = openfile(argv[optind], &geometry, flags, mode)) < 0) exit(1); diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 885df7f..a0c6d17 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