@@ -489,6 +489,29 @@ static int is_namespace_active(struct ndctl_namespace *ndns)
|| ndctl_namespace_get_btt(ndns));
}
+static int validate_available_capacity(struct ndctl_region *region,
+ struct parsed_parameters *p)
+{
+ unsigned long long available;
+
+ if (ndctl_region_get_nstype(region) == ND_DEVICE_NAMESPACE_IO)
+ available = ndctl_region_get_size(region);
+ else {
+ available = ndctl_region_get_max_available_extent(region);
+ if (available == ULLONG_MAX)
+ available = ndctl_region_get_available_size(region);
+ }
+ if (!available || p->size > available) {
+ debug("%s: insufficient capacity size: %llx avail: %llx\n",
+ ndctl_region_get_devname(region), p->size, available);
+ return -EAGAIN;
+ }
+
+ if (p->size == 0)
+ p->size = available;
+ return 0;
+}
+
/*
* validate_namespace_options - init parameters for setup_namespace
* @region: parent of the namespace to create / reconfigure
@@ -526,6 +549,16 @@ static int validate_namespace_options(struct ndctl_region *region,
else if (ndns)
p->size = ndctl_namespace_get_size(ndns);
+ /*
+ * Validate available capacity in the create case, in the
+ * reconfigure case the capacity is already allocated.
+ */
+ if (!ndns) {
+ rc = validate_available_capacity(region, p);
+ if (rc)
+ return rc;
+ }
+
if (param.uuid) {
if (uuid_parse(param.uuid, p->uuid) != 0) {
debug("%s: invalid uuid\n", __func__);
@@ -797,7 +830,6 @@ static struct ndctl_namespace *region_get_namespace(struct ndctl_region *region)
static int namespace_create(struct ndctl_region *region)
{
const char *devname = ndctl_region_get_devname(region);
- unsigned long long available;
struct ndctl_namespace *ndns;
struct parsed_parameters p;
int rc;
@@ -812,22 +844,6 @@ static int namespace_create(struct ndctl_region *region)
return -EAGAIN;
}
- if (ndctl_region_get_nstype(region) == ND_DEVICE_NAMESPACE_IO)
- available = ndctl_region_get_size(region);
- else {
- available = ndctl_region_get_max_available_extent(region);
- if (available == ULLONG_MAX)
- available = ndctl_region_get_available_size(region);
- }
- if (!available || p.size > available) {
- debug("%s: insufficient capacity size: %llx avail: %llx\n",
- devname, p.size, available);
- return -EAGAIN;
- }
-
- if (p.size == 0)
- p.size = available;
-
ndns = region_get_namespace(region);
if (!ndns || is_namespace_active(ndns)) {
debug("%s: no %s namespace seed\n", devname,
Currently validate_namespace_options() handles default option conversion for every namespace attribute except size. Move default size validation internal to that helper in advance of teaching ndctl to require namespace be at least 16M in size to host a metadata personality / address abstraction. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- ndctl/namespace.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-)