@@ -4231,6 +4231,22 @@ NDCTL_EXPORT unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn)
return pfn->align;
}
+NDCTL_EXPORT int ndctl_pfn_has_align(struct ndctl_pfn *pfn)
+{
+ struct ndctl_ctx *ctx = ndctl_pfn_get_ctx(pfn);
+ char *path = pfn->pfn_buf;
+ int len = pfn->buf_len;
+ struct stat st;
+
+ if (snprintf(path, len, "%s/align", pfn->pfn_path) >= len) {
+ err(ctx, "%s: buffer too small!\n",
+ ndctl_pfn_get_devname(pfn));
+ return 0;
+ }
+
+ return stat(path, &st) == 0;
+}
+
NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align)
{
struct ndctl_ctx *ctx = ndctl_pfn_get_ctx(pfn);
@@ -231,6 +231,7 @@ global:
ndctl_pfn_get_align;
ndctl_pfn_get_size;
ndctl_pfn_get_resource;
+ ndctl_pfn_has_align;
ndctl_pfn_set_align;
ndctl_pfn_set_namespace;
ndctl_pfn_get_bus;
@@ -566,6 +566,7 @@ int ndctl_pfn_set_location(struct ndctl_pfn *pfn, enum ndctl_pfn_loc loc);
enum ndctl_pfn_loc ndctl_pfn_get_location(struct ndctl_pfn *pfn);
int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu);
void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu);
+int ndctl_pfn_has_align(struct ndctl_pfn *pfn);
int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align);
unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn);
unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn);
In support of preventing create-namespace attempts to write the 'align' attribute on kernels that do not have the capability, add this detection api. We would not have needed this if ndctl_pfn_get_align() returned -ENOENT instead of zero, live and learn. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- ndctl/lib/libndctl.c | 16 ++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h.in | 1 + 3 files changed, 18 insertions(+)