@@ -3586,6 +3586,12 @@ NDCTL_EXPORT int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *nd
return ndns->lbasize.num;
}
+NDCTL_EXPORT int ndctl_namespace_supports_sector_size(
+ struct ndctl_namespace *ndns, unsigned long size)
+{
+ return sizes_contains(&ndns->lbasize, size);
+}
+
NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
unsigned int sector_size)
{
@@ -3912,6 +3918,12 @@ NDCTL_EXPORT int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt)
return btt->lbasize.num;
}
+NDCTL_EXPORT int ndctl_btt_supports_sector_size(
+ struct ndctl_btt *btt, unsigned long size)
+{
+ return sizes_contains(&btt->lbasize, size);
+}
+
NDCTL_EXPORT struct ndctl_namespace *ndctl_btt_get_namespace(struct ndctl_btt *btt)
{
struct ndctl_ctx *ctx = ndctl_btt_get_ctx(btt);
@@ -192,6 +192,7 @@ global:
ndctl_namespace_get_sector_size;
ndctl_namespace_get_num_sector_sizes;
ndctl_namespace_set_sector_size;
+ ndctl_namespace_supports_sector_size;
ndctl_namespace_get_raw_mode;
ndctl_namespace_set_raw_mode;
ndctl_namespace_get_numa_node;
@@ -204,6 +205,7 @@ global:
ndctl_btt_get_supported_sector_size;
ndctl_btt_get_sector_size;
ndctl_btt_get_num_sector_sizes;
+ ndctl_btt_supports_sector_size;
ndctl_btt_get_namespace;
ndctl_btt_get_uuid;
ndctl_btt_get_size;
@@ -513,6 +513,8 @@ int ndctl_namespace_set_size(struct ndctl_namespace *ndns,
unsigned long long size);
unsigned int ndctl_namespace_get_supported_sector_size(
struct ndctl_namespace *ndns, int i);
+int ndctl_namespace_supports_sector_size(
+ struct ndctl_namespace *ndns, unsigned long size);
unsigned int ndctl_namespace_get_sector_size(struct ndctl_namespace *ndns);
int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *ndns);
int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
@@ -538,6 +540,7 @@ struct ndctl_ctx *ndctl_btt_get_ctx(struct ndctl_btt *btt);
struct ndctl_bus *ndctl_btt_get_bus(struct ndctl_btt *btt);
struct ndctl_region *ndctl_btt_get_region(struct ndctl_btt *btt);
unsigned int ndctl_btt_get_id(struct ndctl_btt *btt);
+int ndctl_btt_supports_sector_size(struct ndctl_btt *btt, unsigned long size);
unsigned int ndctl_btt_get_supported_sector_size(struct ndctl_btt *btt, int i);
unsigned int ndctl_btt_get_sector_size(struct ndctl_btt *btt);
int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt);
@@ -570,25 +570,21 @@ static int validate_namespace_options(struct ndctl_region *region,
}
if (param.sector_size) {
- struct ndctl_btt *btt;
- int num, i;
+ unsigned long long size = parse_size64(param.sector_size);
- p->sector_size = parse_size64(param.sector_size);
- btt = ndctl_region_get_btt_seed(region);
if (p->mode == NDCTL_NS_MODE_SAFE) {
+ struct ndctl_btt *btt =
+ ndctl_region_get_btt_seed(region);
+
if (!btt) {
debug("%s: does not support 'sector' mode\n",
region_name);
return -EINVAL;
}
- num = ndctl_btt_get_num_sector_sizes(btt);
- for (i = 0; i < num; i++)
- if (ndctl_btt_get_supported_sector_size(btt, i)
- == p->sector_size)
- break;
- if (i >= num) {
+
+ if (!ndctl_btt_supports_sector_size(btt, size)) {
debug("%s: does not support btt sector_size %lu\n",
- region_name, p->sector_size);
+ region_name, size);
return -EINVAL;
}
} else {
@@ -596,17 +592,15 @@ static int validate_namespace_options(struct ndctl_region *region,
if (!seed)
seed = ndctl_region_get_namespace_seed(region);
- num = ndctl_namespace_get_num_sector_sizes(seed);
- for (i = 0; i < num; i++)
- if (ndctl_namespace_get_supported_sector_size(seed, i)
- == p->sector_size)
- break;
- if (i >= num) {
+
+ if (!ndctl_namespace_supports_sector_size(seed, size)) {
debug("%s: does not support namespace sector_size %lu\n",
- region_name, p->sector_size);
+ region_name, size);
return -EINVAL;
}
}
+
+ p->sector_size = size;
} else if (ndns) {
struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
libndctl now has the ndctl_{dax|pfn}_supports_align() helper functions for checking if PFN and DAX regions support a given alignment. The sector size of a BTT region is similar to the region alignment so add an equivilent helper to maintain a consistent API across region types. Adds: ndctl_namespace_supports_sector_size() ndctl_btt_supports_sector_size() Signed-off-by: Oliver O'Halloran <oohall@gmail.com> --- ndctl/lib/libndctl.c | 12 ++++++++++++ ndctl/lib/libndctl.sym | 2 ++ ndctl/libndctl.h.in | 3 +++ ndctl/namespace.c | 30 ++++++++++++------------------ 4 files changed, 29 insertions(+), 18 deletions(-)