diff mbox

[ndctl] ndctl, create-namespace: trap and report invalid sector-size values

Message ID CAPcyv4iAGx8BSaZvjXhe-eoPah4EtQzbckgZfHW_a3us6QCH6w@mail.gmail.com (mailing list archive)
State Rejected
Headers show

Commit Message

Dan Williams Aug. 4, 2016, 5:59 p.m. UTC
On Thu, Aug 4, 2016 at 8:32 AM, Dan Williams <dan.j.williams@intel.com> wrote:
> While the kernel will prevent invalid configurations, the user
> experience of a kernel error message and disabling of the namespace is
> too harsh.  Trap and report these attempts to make create-namespace more
> user friendly.
>
>     # ndctl create-namespace -e namespace0.0 -m sector -l 513 -f -v
>     validate_namespace_options:437: region0: does not support btt sector_size 513
>     failed to reconfigure namespace
>
> Reported-by: Yi Zhang <yizhan@redhat.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  ndctl/builtin-xaction-namespace.c |   40 +++++++++++++++++++++++++++++++------
>  1 file changed, 34 insertions(+), 6 deletions(-)

Unit tests say we also need the following so that we don't try to set
a sector size on pmem namespaces.

 }
diff mbox

Patch

diff --git a/ndctl/builtin-xaction-namespace.c
b/ndctl/builtin-xaction-namespace.c
index e136bfdefa39..35345fb26ec3 100644
--- a/ndctl/builtin-xaction-namespace.c
+++ b/ndctl/builtin-xaction-namespace.c
@@ -210,8 +210,13 @@  static int set_defaults(enum namespace_action mode)
                        error("'pmem' namespaces do not support
setting 'sector size'\n");
                        rc = -EINVAL;
                }
-       } else if (!param.reconfig)
-               param.sector_size = "4096";
+       } 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";
+       }

        return rc;