[ndctl,09/36] ndctl/namespace: Check for region alignment violations
diff mbox series

Message ID 158300765145.2141307.14325031909413548404.stgit@dwillia2-desk3.amr.corp.intel.com
State New
Headers show
Series
  • Multiple topics / backlog for v68
Related show

Commit Message

Dan Williams Feb. 29, 2020, 8:20 p.m. UTC
With the new kernel updates to enforce wider alignment constraints by
default ndctl has the ability to validate alignments problems before the
kernel fails the namespace instantiation. Teach create-namespace to
check the size argument against the region alignment rather than waiting
for the kernel to fail the operation:

Before:
#  ndctl create-namespace -m fsdax -s 1073750016 -a 4k
failed to create namespace: Invalid argument

After:
#  ndctl create-namespace -m fsdax -s 1073750016 -a 4k
  Error: create namespace: region2: align setting is 0x1000000 size 0x40002000 is misaligned

Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/namespace.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Patch
diff mbox series

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index b967e9be578f..c4aab94abcd4 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -652,6 +652,14 @@  static int validate_namespace_options(struct ndctl_region *region,
 		}
 	}
 
+	region_align = ndctl_region_get_align(region);
+	if (region_align < ULONG_MAX && p->size % region_align) {
+		err("%s: align setting is %#lx size %#llx is misaligned\n",
+				ndctl_region_get_devname(region), region_align,
+				p->size);
+		return -EINVAL;
+	}
+
 	size_align = p->align;
 
 	/* (re-)validate that the size satisfies the alignment */