From patchwork Tue Dec 15 02:19:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 7850971 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CC09F9F32E for ; Tue, 15 Dec 2015 02:20:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E023E20381 for ; Tue, 15 Dec 2015 02:20:11 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 00A53201CD for ; Tue, 15 Dec 2015 02:20:11 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EA0161A206B; Mon, 14 Dec 2015 18:20:10 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ml01.01.org (Postfix) with ESMTP id 480031A2101 for ; Mon, 14 Dec 2015 18:20:09 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 14 Dec 2015 18:20:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,429,1444719600"; d="scan'208";a="873688726" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.136]) by fmsmga002.fm.intel.com with ESMTP; 14 Dec 2015 18:20:08 -0800 Subject: [ndctl PATCH 3/3] ndctl: add support for the namespace 'mode' attribute From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 14 Dec 2015 18:19:42 -0800 Message-ID: <20151215021942.37242.305.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20151215021746.37242.59572.stgit@dwillia2-desk3.jf.intel.com> References: <20151215021746.37242.59572.stgit@dwillia2-desk3.jf.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The three modes for a namespace are: 1/ 'memory': the kernel has the infrastructure to support the usage of DAX mappings of this namespace in any context. In contrast to a 'raw' pmem namespace that, for example, does not support direct I/O in current kernels. 2/ 'safe': the namespace is being fronted by a btt to provide atomic sector udpates. 3/ 'raw': Neither of the above two modes, this namespace may tear sectors on interrupted writes or fail direct I/O requests. Signed-off-by: Dan Williams --- lib/libndctl.c | 26 ++++++++++++++++++++++++++ lib/libndctl.sym | 1 + lib/test-dax-dev.c | 5 +++++ lib/test-libndctl.c | 13 +++++++++++++ 4 files changed, 45 insertions(+) diff --git a/lib/libndctl.c b/lib/libndctl.c index c0730690ed79..22bd2c123415 100644 --- a/lib/libndctl.c +++ b/lib/libndctl.c @@ -2868,6 +2868,32 @@ NDCTL_EXPORT const char *ndctl_namespace_get_block_device(struct ndctl_namespace return ndns->bdev ? ndns->bdev : ""; } +NDCTL_EXPORT enum ndctl_namespace_mode ndctl_namespace_get_mode( + struct ndctl_namespace *ndns) +{ + struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns); + char *path = ndns->ndns_buf; + int len = ndns->buf_len; + char buf[SYSFS_ATTR_SIZE]; + + if (snprintf(path, len, "%s/mode", ndns->ndns_path) >= len) { + err(ctx, "%s: buffer too small!\n", + ndctl_namespace_get_devname(ndns)); + return -ENOMEM; + } + + if (sysfs_read_attr(ctx, path, buf) < 0) + return -ENXIO; + + if (strcmp("memory", buf) == 0) + return NDCTL_NS_MODE_MEMORY; + if (strcmp("raw", buf) == 0) + return NDCTL_NS_MODE_RAW; + if (strcmp("safe", buf) == 0) + return NDCTL_NS_MODE_SAFE; + return -ENXIO; +} + NDCTL_EXPORT int ndctl_namespace_is_valid(struct ndctl_namespace *ndns) { struct ndctl_region *region = ndctl_namespace_get_region(ndns); diff --git a/lib/libndctl.sym b/lib/libndctl.sym index 9cb2f0002c52..fe89fa26348e 100644 --- a/lib/libndctl.sym +++ b/lib/libndctl.sym @@ -132,6 +132,7 @@ global: ndctl_namespace_get_id; ndctl_namespace_get_devname; ndctl_namespace_get_block_device; + ndctl_namespace_get_mode; ndctl_region_get_nstype; ndctl_namespace_get_type; ndctl_namespace_get_type_name; diff --git a/lib/test-dax-dev.c b/lib/test-dax-dev.c index 3ca7cef0f71c..a83a589700c6 100755 --- a/lib/test-dax-dev.c +++ b/lib/test-dax-dev.c @@ -34,6 +34,7 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test) struct ndctl_bus *bus; struct ndctl_region *region; struct ndctl_namespace *ndns; + struct ndctl_namespace_mode mode; if (!ndctl_test_attempt(test, KERNEL_VERSION(4, 3, 0))) return 77; @@ -56,6 +57,10 @@ static int emit_e820_device(int loglevel, struct ndctl_test *test) if (!ndns) goto out; + mode = ndctl_namespace_get_mode(ndns); + if (mode >= 0 && mode != NDCTL_NS_MODE_MEMORY) + goto out; + bdev = ndctl_namespace_get_block_device(ndns); if (!bdev) goto out; diff --git a/lib/test-libndctl.c b/lib/test-libndctl.c index 5acf971a1fb7..b6720ed59d95 100644 --- a/lib/test-libndctl.c +++ b/lib/test-libndctl.c @@ -575,6 +575,7 @@ static int __check_pfn_create(struct ndctl_region *region, uuid_t uuid) { struct ndctl_pfn *pfn_seed = ndctl_region_get_pfn_seed(region); + enum ndctl_namespace_mode mode; struct ndctl_pfn *pfn; const char *devname; int fd, retry = 10; @@ -600,6 +601,12 @@ static int __check_pfn_create(struct ndctl_region *region, ndctl_pfn_delete(pfn); return 0; } + + mode = ndctl_namespace_get_mode(ndns); + if (mode >= 0 && mode != NDCTL_NS_MODE_MEMORY) + fprintf(stderr, "%s: expected memory mode got: %d\n", + devname, mode); + if (namespace->ro == (rc == 0)) { fprintf(stderr, "%s: expected pfn enable %s, %s read-%s\n", devname, @@ -718,6 +725,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace for (i = 0; i < btt_s->num_sector_sizes; i++) { struct ndctl_namespace *ns_seed = ndctl_region_get_namespace_seed(region); struct ndctl_btt *btt_seed = ndctl_region_get_btt_seed(region); + enum ndctl_namespace_mode mode; btt = get_idle_btt(region); if (!btt) @@ -737,6 +745,11 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace goto err; } + mode = ndctl_namespace_get_mode(ndns); + if (mode >= 0 && mode != NDCTL_NS_MODE_SAFE) + fprintf(stderr, "%s: expected safe mode got: %d\n", + devname, mode); + if (btt_seed == ndctl_region_get_btt_seed(region) && btt == btt_seed) { fprintf(stderr, "%s: failed to advance btt seed\n",