* [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache
@ 2018-04-06 21:24 Vishal Verma
2018-04-06 21:24 ` [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl Vishal Verma
2018-04-08 17:49 ` [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Dan Williams
0 siblings, 2 replies; 4+ messages in thread
From: Vishal Verma @ 2018-04-06 21:24 UTC (permalink / raw)
To: linux-nvdimm
Add APIs to get the state of write_cache for pmem namespaces, and also
to enable or disable the write_cache.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
ndctl/lib/libndctl.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++
ndctl/lib/libndctl.sym | 3 ++
ndctl/libndctl.h | 3 ++
3 files changed, 82 insertions(+)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 580a450..1f59e2a 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -3918,6 +3918,82 @@ NDCTL_EXPORT int ndctl_namespace_get_numa_node(struct ndctl_namespace *ndns)
return ndns->numa_node;
}
+static int __ndctl_namespace_set_write_cache(struct ndctl_namespace *ndns,
+ int state)
+{
+ struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
+ struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
+ char buf[SYSFS_ATTR_SIZE];
+ int len = ndns->buf_len;
+ const char *bdev;
+ char path[50];
+
+ if (state != 1 && state != 0)
+ return -ENXIO;
+ if (pfn)
+ bdev = ndctl_pfn_get_block_device(pfn);
+ else
+ bdev = ndctl_namespace_get_block_device(ndns);
+
+ if (!bdev)
+ return -ENXIO;
+
+ if (snprintf(path, len, "/sys/block/%s/dax/write_cache", bdev) >= len) {
+ err(ctx, "%s: buffer too small!\n",
+ ndctl_namespace_get_devname(ndns));
+ return -ENXIO;
+ }
+
+ sprintf(buf, "%d\n", state);
+ return sysfs_write_attr(ctx, path, buf);
+}
+
+NDCTL_EXPORT int ndctl_namespace_enable_write_cache(
+ struct ndctl_namespace *ndns)
+{
+ return __ndctl_namespace_set_write_cache(ndns, 1);
+}
+
+NDCTL_EXPORT int ndctl_namespace_disable_write_cache(
+ struct ndctl_namespace *ndns)
+{
+ return __ndctl_namespace_set_write_cache(ndns, 0);
+}
+
+NDCTL_EXPORT int ndctl_namespace_write_cache_is_enabled(
+ struct ndctl_namespace *ndns)
+{
+ struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
+ struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
+ int len = ndns->buf_len, wc;
+ char buf[SYSFS_ATTR_SIZE];
+ const char *bdev;
+ char path[50];
+
+ if (pfn)
+ bdev = ndctl_pfn_get_block_device(pfn);
+ else
+ bdev = ndctl_namespace_get_block_device(ndns);
+
+ if (!bdev)
+ return -ENXIO;
+
+ if (snprintf(path, len, "/sys/block/%s/dax/write_cache", bdev) >= len) {
+ err(ctx, "%s: buffer too small!\n",
+ ndctl_namespace_get_devname(ndns));
+ return -ENXIO;
+ }
+
+ if (sysfs_read_attr(ctx, path, buf) < 0)
+ return -ENXIO;
+
+ if (sscanf(buf, "%d", &wc) == 1)
+ if (wc)
+ return 1;
+
+ return 0;
+}
+
NDCTL_EXPORT int ndctl_namespace_delete(struct ndctl_namespace *ndns)
{
struct ndctl_region *region = ndctl_namespace_get_region(ndns);
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index 3209aef..4709c47 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -352,4 +352,7 @@ global:
ndctl_dimm_fw_update_supported;
ndctl_region_get_persistence_domain;
ndctl_bus_get_persistence_domain;
+ ndctl_namespace_write_cache_is_enabled;
+ ndctl_namespace_enable_write_cache;
+ ndctl_namespace_disable_write_cache;
} LIBNDCTL_14;
diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
index 684fcd4..1ecbabb 100644
--- a/ndctl/libndctl.h
+++ b/ndctl/libndctl.h
@@ -490,6 +490,9 @@ struct ndctl_bb *ndctl_namespace_injection_get_next_bb(
for (bb = ndctl_namespace_injection_get_first_bb(ndns); \
bb != NULL; \
bb = ndctl_namespace_injection_get_next_bb(ndns, bb))
+int ndctl_namespace_write_cache_is_enabled(struct ndctl_namespace *ndns);
+int ndctl_namespace_enable_write_cache(struct ndctl_namespace *ndns);
+int ndctl_namespace_disable_write_cache(struct ndctl_namespace *ndns);
struct ndctl_btt;
struct ndctl_btt *ndctl_btt_get_first(struct ndctl_region *region);
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl
2018-04-06 21:24 [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Vishal Verma
@ 2018-04-06 21:24 ` Vishal Verma
2018-04-08 17:48 ` Dan Williams
2018-04-08 17:49 ` [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Dan Williams
1 sibling, 1 reply; 4+ messages in thread
From: Vishal Verma @ 2018-04-06 21:24 UTC (permalink / raw)
To: linux-nvdimm
in check_namespaces(), add a step to validate the write_cache status and
controls for the namespaces that support it. Also add a negative test
for the namespaces that don't have a write_cache (blk, sector etc),
making sure the APIs fail as expected.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
test/libndctl.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/test/libndctl.c b/test/libndctl.c
index a66bcb7..72271f4 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -1614,6 +1614,56 @@ static int validate_bdev(const char *devname, struct ndctl_btt *btt,
return rc;
}
+static int validate_write_cache(struct ndctl_namespace *ndns)
+{
+ const char *devname = ndctl_namespace_get_devname(ndns);
+ int wc, mode, type, rc;
+
+ type = ndctl_namespace_get_type(ndns);
+ mode = ndctl_namespace_get_mode(ndns);
+ wc = ndctl_namespace_write_cache_is_enabled(ndns);
+
+ if ((type == ND_DEVICE_NAMESPACE_PMEM || type == ND_DEVICE_NAMESPACE_IO) &&
+ (mode == NDCTL_NS_MODE_FSDAX || mode == NDCTL_NS_MODE_RAW)) {
+ if (wc != 1) {
+ fprintf(stderr, "%s: expected write_cache enabled\n",
+ devname);
+ return -ENXIO;
+ }
+ rc = ndctl_namespace_disable_write_cache(ndns);
+ if (rc) {
+ fprintf(stderr, "%s: failed to disable write_cache\n",
+ devname);
+ return rc;
+ }
+ rc = ndctl_namespace_write_cache_is_enabled(ndns);
+ if (rc != 0) {
+ fprintf(stderr, "%s: write_cache could not be disabled\n",
+ devname);
+ return rc;
+ }
+ rc = ndctl_namespace_enable_write_cache(ndns);
+ if (rc) {
+ fprintf(stderr, "%s: failed to re-enable write_cache\n",
+ devname);
+ return rc;
+ }
+ rc = ndctl_namespace_write_cache_is_enabled(ndns);
+ if (rc != 1) {
+ fprintf(stderr, "%s: write_cache could not be re-enabled\n",
+ devname);
+ return rc;
+ }
+ } else {
+ if (wc == 0 || wc == 1) {
+ fprintf(stderr, "%s: expected write_cache to be absent\n",
+ devname);
+ return -ENXIO;
+ }
+ }
+ return 0;
+}
+
static int check_namespaces(struct ndctl_region *region,
struct namespace **namespaces, enum ns_mode mode)
{
@@ -1787,6 +1837,13 @@ static int check_namespaces(struct ndctl_region *region,
break;
}
+ rc = validate_write_cache(ndns);
+ if (rc) {
+ fprintf(stderr, "%s: %s validate_write_cache failed\n",
+ __func__, devname);
+ break;
+ }
+
if (ndctl_namespace_disable_invalidate(ndns) < 0) {
fprintf(stderr, "%s: failed to disable\n", devname);
rc = -ENXIO;
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl
2018-04-06 21:24 ` [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl Vishal Verma
@ 2018-04-08 17:48 ` Dan Williams
0 siblings, 0 replies; 4+ messages in thread
From: Dan Williams @ 2018-04-08 17:48 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm
On Fri, Apr 6, 2018 at 2:24 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> in check_namespaces(), add a step to validate the write_cache status and
> controls for the namespaces that support it. Also add a negative test
> for the namespaces that don't have a write_cache (blk, sector etc),
> making sure the APIs fail as expected.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Looks good,
Reviewed-by: Dan Wiiliams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache
2018-04-06 21:24 [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Vishal Verma
2018-04-06 21:24 ` [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl Vishal Verma
@ 2018-04-08 17:49 ` Dan Williams
1 sibling, 0 replies; 4+ messages in thread
From: Dan Williams @ 2018-04-08 17:49 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm
On Fri, Apr 6, 2018 at 2:24 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> Add APIs to get the state of write_cache for pmem namespaces, and also
> to enable or disable the write_cache.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Looks good,
Reviewed-by: Dan Wiiliams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-08 17:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 21:24 [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Vishal Verma
2018-04-06 21:24 ` [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl Vishal Verma
2018-04-08 17:48 ` Dan Williams
2018-04-08 17:49 ` [ndctl PATCH 1/2] libndctl: Add APIs for query and control of write_cache Dan Williams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).