Skip to contentSkip to conversation

ndctl, bash_completion: add completion for --sector-size=

PATCH In review Vishal Verma 2 participants 2 messages Aug 25, 2017 – Aug 29, 2017 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ndctl, bash_completion: add completion for --sector-size=

Sector size options were missing completion. Add completion based on the mode of the namespace if specified. 'raw' and 'memory' can only do 512 or 4096, where as with 'sector', more sector sizes are possible. 'dax' doesn't accept a sector size option, so refrain from completing that.

$ ndctl create-namespace --mode=sector --sector-size=
4096   4104   4160   4224   512    520    528
$ ndctl create-namespace --mode=dax --sector-size=
<blank>
$ ndctl create-namespace --mode=raw --sector-size=
4096   512

When no mode has been specified yet, it is open game, and everything is shown.

$ ndctl create-namespace --sector-size=
4096   4104   4160   4224   512    520    528
---
 contrib/ndctl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
contrib/ndctl +14 -0
index e77d680..9410572 100755
@@ -141,6 +141,17 @@ __ndctl_get_dimms()
 	echo "$(ndctl list $opts | grep -E "^\s*\"dev\":" | cut -d\" -f4)"
 }
 
+__ndctl_get_sector_sizes()
+{
+	if [[ "$mode_filter" == @(raw|memory) ]]; then
+		echo "512 4096"
+	elif [[ "$mode_filter" == @(dax) ]]; then
+		return
+	else
+		echo "512 520 528 4096 4104 4160 4224"
+	fi
+}
+
 __ndctl_file_comp()
 {
 	local cur="$1"
@@ -182,6 +193,9 @@ __ndctl_comp_options()
 				opts="raw sector"
 			fi
 			;;
+		--sector-size)
+			opts=$(__ndctl_get_sector_sizes)
+			;;
 		--map)
 			opts="mem dev"
 			;;
Signature · 1 line
2.9.3
#1 lore raw
Quoted 14 lines · Vishal Verma

Sector size options were missing completion. Add completion based on the mode of the namespace if specified. 'raw' and 'memory' can only do 512 or 4096, where as with 'sector', more sector sizes are possible. 'dax' doesn't accept a sector size option, so refrain from completing that.

$ ndctl create-namespace --mode=sector --sector-size=
4096   4104   4160   4224   512    520    528
$ ndctl create-namespace --mode=dax --sector-size=
<blank>
$ ndctl create-namespace --mode=raw --sector-size=
4096   512
Quoted 7 lines

When no mode has been specified yet, it is open game, and everything is shown.

$ ndctl create-namespace --sector-size=
4096   4104   4160   4224   512    520    528

Looks good to me, applied.