diff mbox series

[ndctl,v7,11/13] contrib/ndctl: fix region-id completions for daxctl

Message ID 20190724215741.18556-12-vishal.l.verma@intel.com (mailing list archive)
State Superseded
Headers show
Series daxctl: add a new reconfigure-device command | expand

Commit Message

Verma, Vishal L July 24, 2019, 9:57 p.m. UTC
The completion helpers for daxctl assumed the region arguments for
specifying daxctl regions were the same as ndctl regions, i.e.
"regionX". This is not true - daxctl region arguments are a simple
numeric 'id'.

Add a new helper __daxctl_get_regions() to complete daxctl region IDs
properly.

While at it, fix a useless use of 'echo' in __daxctl_get_devs() and
quoting in __daxctl_comp_options()

Fixes: d6790a32f32c ("daxctl: Add bash-completion")
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 contrib/ndctl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Dan Williams July 26, 2019, 2:55 a.m. UTC | #1
On Wed, Jul 24, 2019 at 2:58 PM Vishal Verma <vishal.l.verma@intel.com> wrote:
>
> The completion helpers for daxctl assumed the region arguments for
> specifying daxctl regions were the same as ndctl regions, i.e.
> "regionX". This is not true - daxctl region arguments are a simple
> numeric 'id'.

Oh, that's an unfortunate difference, but too late to change now I
think, good find.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Verma, Vishal L July 26, 2019, 11:30 p.m. UTC | #2
On Thu, 2019-07-25 at 19:55 -0700, Dan Williams wrote:
> On Wed, Jul 24, 2019 at 2:58 PM Vishal Verma <vishal.l.verma@intel.com
> > wrote:
> > The completion helpers for daxctl assumed the region arguments for
> > specifying daxctl regions were the same as ndctl regions, i.e.
> > "regionX". This is not true - daxctl region arguments are a simple
> > numeric 'id'.
> 
> Oh, that's an unfortunate difference, but too late to change now I
> think, good find.
> 
> Reviewed-by: Dan Williams <dan.j.williams@intel.com>

Yep - though I think I like --region=0 better than --region=region0,
less redundancy.  But agreed, probably too late to change.

Thanks for reviewing these!
Dan Williams July 26, 2019, 11:44 p.m. UTC | #3
On Fri, Jul 26, 2019 at 4:30 PM Verma, Vishal L
<vishal.l.verma@intel.com> wrote:
>
>
> On Thu, 2019-07-25 at 19:55 -0700, Dan Williams wrote:
> > On Wed, Jul 24, 2019 at 2:58 PM Vishal Verma <vishal.l.verma@intel.com
> > > wrote:
> > > The completion helpers for daxctl assumed the region arguments for
> > > specifying daxctl regions were the same as ndctl regions, i.e.
> > > "regionX". This is not true - daxctl region arguments are a simple
> > > numeric 'id'.
> >
> > Oh, that's an unfortunate difference, but too late to change now I
> > think, good find.
> >
> > Reviewed-by: Dan Williams <dan.j.williams@intel.com>
>
> Yep - though I think I like --region=0 better than --region=region0,
> less redundancy.  But agreed, probably too late to change.

We could teach it to allow both. Something for the backlog, but at
least the kernel is using a common number allocator for pmem regions
and hmem regions.
diff mbox series

Patch

diff --git a/contrib/ndctl b/contrib/ndctl
index 396a344..cacee2d 100755
--- a/contrib/ndctl
+++ b/contrib/ndctl
@@ -531,8 +531,14 @@  _ndctl()
 
 __daxctl_get_devs()
 {
-	local opts="--devices $*"
-	echo "$(daxctl list $opts | grep -E "^\s*\"chardev\":" | cut -d\" -f4)"
+	local opts=("--devices" "$*")
+	daxctl list "${opts[@]}" | grep -E "^\s*\"chardev\":" | cut -d'"' -f4
+}
+
+__daxctl_get_regions()
+{
+	local opts=("--regions" "$*")
+	daxctl list "${opts[@]}" | grep -E "^\s*\"id\":" | grep -Eo "[0-9]+"
 }
 
 __daxctlcomp()
@@ -561,10 +567,10 @@  __daxctl_comp_options()
 		local cur_arg=${cur##*=}
 		case $cur_subopt in
 		--region)
-			opts=$(__ndctl_get_regions -i)
+			opts="$(__daxctl_get_regions -i)"
 			;;
 		--dev)
-			opts=$(__daxctl_get_devs -i)
+			opts="$(__daxctl_get_devs -i)"
 			;;
 		*)
 			return