diff mbox

[ndctl] ndctl: fix the default BTT sector size for reconfig

Message ID 20180129202236.9744-1-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit e77e2b0c50a9
Headers show

Commit Message

Verma, Vishal L Jan. 29, 2018, 8:22 p.m. UTC
reconfig attempted to reuse the 'previous' value for sector-size when
reconfiguring to a BTT mode or blk type namespace, but this may not
always be valid (for example when coming from a memory mode namespace).
Instead, when reconfiguring to BTT or blk, always default to 4096
unless a sector size is explicitly provided.

Cc: Dan Williams <dan.j.williams@intel.com>
Reported-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Tested-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/namespace.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Dan Williams Jan. 29, 2018, 8:46 p.m. UTC | #1
On Mon, Jan 29, 2018 at 12:22 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> reconfig attempted to reuse the 'previous' value for sector-size when
> reconfiguring to a BTT mode or blk type namespace, but this may not
> always be valid (for example when coming from a memory mode namespace).
> Instead, when reconfiguring to BTT or blk, always default to 4096
> unless a sector size is explicitly provided.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Reported-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Tested-by: Dave Jiang <dave.jiang@intel.com>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
>  ndctl/namespace.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index c793ba3..ceb9e7a 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -244,12 +244,10 @@ static int set_defaults(enum device_action mode)
>                         error("invalid sector size: %s\n", param.sector_size);
>                         rc = -EINVAL;
>                 }
> -       } else if (!param.reconfig
> -                       && ((param.type && strcmp(param.type, "blk") == 0)
> -                               || (param.mode
> -                                       && strcmp(param.mode, "safe") == 0))) {
> -                       /* default sector size for blk-type or safe-mode */
> -                       param.sector_size = "4096";
> +       } else if (((param.type && strcmp(param.type, "blk") == 0)
> +                       || (param.mode && strcmp(param.mode, "safe") == 0))) {
> +               /* default sector size for blk-type or safe-mode */
> +               param.sector_size = "4096";

Looks good to me.
Ross Zwisler Jan. 29, 2018, 9:25 p.m. UTC | #2
On Mon, Jan 29, 2018 at 01:22:36PM -0700, Vishal Verma wrote:
> reconfig attempted to reuse the 'previous' value for sector-size when
> reconfiguring to a BTT mode or blk type namespace, but this may not
> always be valid (for example when coming from a memory mode namespace).
> Instead, when reconfiguring to BTT or blk, always default to 4096
> unless a sector size is explicitly provided.
> 
> Cc: Dan Williams <dan.j.williams@intel.com>
> Reported-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Tested-by: Dave Jiang <dave.jiang@intel.com>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Yep, this both allows the btt namespace creation to continue and, if the user
does actually specify a bogus sector size, i.e.: 

# ./ndctl/ndctl create-namespace -f -e namespace0.0 --mode=sector -l0
failed to reconfigure namespace: Invalid argument

It prevents us from leaving our namespace in a zombie state where it is still
there but doesn't show up in 'ndctl list'.

Tested-by: Ross Zwisler <ross.zwisler@linux.intel.com>
diff mbox

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index c793ba3..ceb9e7a 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -244,12 +244,10 @@  static int set_defaults(enum device_action mode)
 			error("invalid sector size: %s\n", param.sector_size);
 			rc = -EINVAL;
 		}
-	} else if (!param.reconfig
-			&& ((param.type && strcmp(param.type, "blk") == 0)
-				|| (param.mode
-					&& strcmp(param.mode, "safe") == 0))) {
-			/* default sector size for blk-type or safe-mode */
-			param.sector_size = "4096";
+	} else if (((param.type && strcmp(param.type, "blk") == 0)
+			|| (param.mode && strcmp(param.mode, "safe") == 0))) {
+		/* default sector size for blk-type or safe-mode */
+		param.sector_size = "4096";
 	}
 
 	return rc;