From patchwork Mon Jun 27 20:43:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 9201415 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 56E3A607D3 for ; Mon, 27 Jun 2016 20:44:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46488285B9 for ; Mon, 27 Jun 2016 20:44:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AD7F285C4; Mon, 27 Jun 2016 20:44:11 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6330285B9 for ; Mon, 27 Jun 2016 20:44:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 87B8E1A1DE8; Mon, 27 Jun 2016 13:44:44 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ml01.01.org (Postfix) with ESMTP id 56ED61A1DE8 for ; Mon, 27 Jun 2016 13:44:43 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 27 Jun 2016 13:44:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,537,1459839600"; d="scan'208";a="996087368" Received: from omniknight.lm.intel.com ([10.232.112.171]) by fmsmga001.fm.intel.com with ESMTP; 27 Jun 2016 13:44:08 -0700 From: Vishal Verma To: Subject: [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options Date: Mon, 27 Jun 2016 14:43:38 -0600 Message-Id: <1467060218-20256-1-git-send-email-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.5.5 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add three new 'filters' for mode, type, and idle. 'mode' and 'type' work with each other to prevent a blk namespace from showing modes like 'dax' or 'memory', or if those modes are specified, then limiting 'type' to 'pmem'. Also show completions for --map= only if mode is 'memory'. For idle filtering (typically relevant for 'ndctl list', only show idle {namespaces, regions} in the completion id a --idle has been specified on the command line so far. This makes sense because trying to list an idle namespace without --idle (even if you know that is the one you want) won't show any output withot --idle. Signed-off-by: Vishal Verma --- Applies on top of the last bash-completion patch: "ndctl: bash completion updates for the --namespace= filter" contrib/ndctl | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/contrib/ndctl b/contrib/ndctl index b7a82fc..15ca3bf 100755 --- a/contrib/ndctl +++ b/contrib/ndctl @@ -110,6 +110,8 @@ __ndctl_get_regions() { local opts="--regions $*" [ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter" + [ -n "$type_filter" ] && opts="$opts --type=$type_filter" + [ -n "$idle_filter" ] && opts="$opts --idle" echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)" } @@ -118,6 +120,8 @@ __ndctl_get_ns() opts="--namespaces $*" [ -n "$bus_filter" ] && opts="$opts --bus=$bus_filter" [ -n "$reg_filter" ] && opts="$opts --bus=$reg_filter" + [ -n "$type_filter" ] && opts="$opts --type=$type_filter" + [ -n "$idle_filter" ] && opts="$opts --idle" echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)" } @@ -147,7 +151,7 @@ __ndctl_comp_options() opts=$(__ndctl_get_dimms) ;; --namespace) - opts=$(__ndctl_get_ns -i) + opts=$(__ndctl_get_ns) ;; --reconfig) # It is ok to reconfig disabled namespaces @@ -155,12 +159,20 @@ __ndctl_comp_options() ;; --type) opts="pmem blk" + if [[ "$mode_filter" == @(dax|memory) ]]; then + opts="pmem" + fi ;; --mode) opts="raw sector memory dax" + if [[ "$type_filter" == "blk" ]]; then + opts="raw sector" + fi ;; --map) - opts="mem dev" + if [[ "$mode_filter" == "memory" ]]; then + opts="mem dev" + fi ;; *) return @@ -224,13 +236,13 @@ __ndctl_prev_skip_opts () done } -bus_filter='' -reg_filter='' - __ndctl_init_filters() { bus_filter='' reg_filter='' + type_filter='' + idle_filter='' + mode_filter='' for __word in "${words[@]}"; do if [[ "$__word" =~ --bus=(.*) ]]; then @@ -245,6 +257,15 @@ __ndctl_init_filters() local regions=$(__ndctl_get_regions -i) [[ "$regions" == *"$reg_filter"* ]] || reg_filter='' fi + if [[ "$__word" =~ --idle ]]; then + idle_filter="1" + fi + if [[ "$__word" =~ --type=(.*) ]]; then + type_filter="${BASH_REMATCH[1]}" + fi + if [[ "$__word" =~ --mode=(.*) ]]; then + mode_filter="${BASH_REMATCH[1]}" + fi done }