* [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options
@ 2016-06-27 20:43 Vishal Verma
2016-06-27 21:13 ` Dan Williams
0 siblings, 1 reply; 3+ messages in thread
From: Vishal Verma @ 2016-06-27 20:43 UTC (permalink / raw)
To: linux-nvdimm
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 <vishal.l.verma@intel.com>
---
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
}
--
2.5.5
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options
2016-06-27 20:43 [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options Vishal Verma
@ 2016-06-27 21:13 ` Dan Williams
2016-06-27 21:18 ` Verma, Vishal L
0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2016-06-27 21:13 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm@lists.01.org
On Mon, Jun 27, 2016 at 1:43 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> 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'.
--map= is also valid when the mode is 'dax'.
There's also an assumption in the --reconfig= case for
'create-namespace' that parameters are inherited from the target
namespace. For example, it might be surprising that completions are
not provided for --map= when the mode is implied by the provided
namespace.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options
2016-06-27 21:13 ` Dan Williams
@ 2016-06-27 21:18 ` Verma, Vishal L
0 siblings, 0 replies; 3+ messages in thread
From: Verma, Vishal L @ 2016-06-27 21:18 UTC (permalink / raw)
To: Williams, Dan J; +Cc: linux-nvdimm@lists.01.org
On Mon, 2016-06-27 at 14:13 -0700, Dan Williams wrote:
> On Mon, Jun 27, 2016 at 1:43 PM, Vishal Verma <vishal.l.verma@intel.co
> m> wrote:
> >
> > 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'.
> --map= is also valid when the mode is 'dax'.
>
> There's also an assumption in the --reconfig= case for
> 'create-namespace' that parameters are inherited from the target
> namespace. For example, it might be surprising that completions are
> not provided for --map= when the mode is implied by the provided
> namespace.
Good point - I guess then it makes sense to drop the checking entirely
for --map.. I'll send a v2.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-27 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-27 20:43 [ndctl PATCH] ndctl: make completion smarter wrt mode/type/idle options Vishal Verma
2016-06-27 21:13 ` Dan Williams
2016-06-27 21:18 ` Verma, Vishal L
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.