From patchwork Sat Jul 27 21:39:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D64B1399 for ; Sat, 27 Jul 2019 21:53:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55F8E289CC for ; Sat, 27 Jul 2019 21:53:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A515289F2; Sat, 27 Jul 2019 21:53:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 14CE3289CC for ; Sat, 27 Jul 2019 21:53:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9BF22212E15B1; Sat, 27 Jul 2019 14:56:12 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1344F212B9A9D for ; Sat, 27 Jul 2019 14:56:10 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:43 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="161739670" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:43 -0700 Subject: [ndctl PATCH v2 01/26] ndctl/dimm: Add 'flags' field to read-labels output From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:26 -0700 Message-ID: <156426356654.531577.6142389862764297120.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Recent discussions on some platform implementations setting the LOCAL bit in namespace labels makes it apparent that this field should be decoded in the json representation. Signed-off-by: Dan Williams --- ndctl/dimm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index b2b09b6aa9a2..8946dc74fe41 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -141,6 +141,11 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm, break; json_object_object_add(jlabel, "nlabel", jobj); + jobj = json_object_new_int64(le64_to_cpu(nslabel.flags)); + if (!jobj) + break; + json_object_object_add(jlabel, "flags", jobj); + jobj = json_object_new_int64(le64_to_cpu(nslabel.isetcookie)); if (!jobj) break; From patchwork Sat Jul 27 21:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9428112C for ; Sat, 27 Jul 2019 21:53:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C10E4289CC for ; Sat, 27 Jul 2019 21:53:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B57E0289F2; Sat, 27 Jul 2019 21:53:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 579C6289CC for ; Sat, 27 Jul 2019 21:53:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E0C2C212E15B7; Sat, 27 Jul 2019 14:56:16 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1458E212E1591 for ; Sat, 27 Jul 2019 14:56:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:48 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="175977492" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:48 -0700 Subject: [ndctl PATCH v2 02/26] ndctl/dimm: Add --human support to read-labels From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:31 -0700 Message-ID: <156426357173.531577.2988157861473659679.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Allow for easier comparisons between 'read-labels' output and list. Signed-off-by: Dan Williams --- Documentation/ndctl/ndctl-read-labels.txt | 7 +++++++ ndctl/dimm.c | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Documentation/ndctl/ndctl-read-labels.txt b/Documentation/ndctl/ndctl-read-labels.txt index 0127e15f0721..756713ee12d7 100644 --- a/Documentation/ndctl/ndctl-read-labels.txt +++ b/Documentation/ndctl/ndctl-read-labels.txt @@ -27,6 +27,13 @@ include::labels-options.txt[] parse the label data into json assuming the 'NVDIMM Namespace Specification' format. +-u:: +--human:: + enable json output and convert number formats to human readable + strings, for example show the size in terms of "KB", "MB", "GB", etc + instead of a signed 64-bit numbers per the JSON interchange + format (implies --json). + include::../copyright.txt[] SEE ALSO diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 8946dc74fe41..5f05a75f00eb 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -51,6 +51,7 @@ static struct parameters { bool overwrite; bool zero_key; bool master_pass; + bool human; bool force; bool json; bool verbose; @@ -80,7 +81,7 @@ static int action_zero(struct ndctl_dimm *dimm, struct action_context *actx) } static struct json_object *dump_label_json(struct ndctl_dimm *dimm, - struct ndctl_cmd *cmd_read, ssize_t size) + struct ndctl_cmd *cmd_read, ssize_t size, unsigned long flags) { struct json_object *jarray = json_object_new_array(); struct json_object *jlabel = NULL; @@ -141,12 +142,13 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm, break; json_object_object_add(jlabel, "nlabel", jobj); - jobj = json_object_new_int64(le64_to_cpu(nslabel.flags)); + jobj = util_json_object_hex(le32_to_cpu(nslabel.flags), flags); if (!jobj) break; json_object_object_add(jlabel, "flags", jobj); - jobj = json_object_new_int64(le64_to_cpu(nslabel.isetcookie)); + jobj = util_json_object_hex(le64_to_cpu(nslabel.isetcookie), + flags); if (!jobj) break; json_object_object_add(jlabel, "isetcookie", jobj); @@ -156,12 +158,12 @@ static struct json_object *dump_label_json(struct ndctl_dimm *dimm, break; json_object_object_add(jlabel, "lbasize", jobj); - jobj = json_object_new_int64(le64_to_cpu(nslabel.dpa)); + jobj = util_json_object_hex(le64_to_cpu(nslabel.dpa), flags); if (!jobj) break; json_object_object_add(jlabel, "dpa", jobj); - jobj = json_object_new_int64(le64_to_cpu(nslabel.rawsize)); + jobj = util_json_object_size(le64_to_cpu(nslabel.rawsize), flags); if (!jobj) break; json_object_object_add(jlabel, "rawsize", jobj); @@ -266,6 +268,7 @@ static struct json_object *dump_index_json(struct ndctl_cmd *cmd_read, ssize_t s static struct json_object *dump_json(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd_read, ssize_t size) { + unsigned long flags = param.human ? UTIL_JSON_HUMAN : 0; struct json_object *jdimm = json_object_new_object(); struct json_object *jlabel, *jobj, *jindex; @@ -274,7 +277,7 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, jindex = dump_index_json(cmd_read, size); if (!jindex) goto err_jindex; - jlabel = dump_label_json(dimm, cmd_read, size); + jlabel = dump_label_json(dimm, cmd_read, size, flags); if (!jlabel) goto err_jlabel; @@ -1046,7 +1049,8 @@ OPT_BOOLEAN('v',"verbose", ¶m.verbose, "turn on debug") #define READ_OPTIONS() \ OPT_STRING('o', "output", ¶m.outfile, "output-file", \ "filename to write label area contents"), \ -OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json") +OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json"), \ +OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats (implies --json)") #define WRITE_OPTIONS() \ OPT_STRING('i', "input", ¶m.infile, "input-file", \ @@ -1156,7 +1160,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, return -EINVAL; } - if (param.json) { + if (param.json || param.human) { actx.jdimms = json_object_new_array(); if (!actx.jdimms) return -ENOMEM; From patchwork Sat Jul 27 21:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E4671399 for ; Sat, 27 Jul 2019 21:53:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05EE6289CC for ; Sat, 27 Jul 2019 21:53:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE544289F2; Sat, 27 Jul 2019 21:53:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 9A267289CC for ; Sat, 27 Jul 2019 21:53:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 31693212E2583; Sat, 27 Jul 2019 14:56:22 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 40218212E15B5 for ; Sat, 27 Jul 2019 14:56:21 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:54 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="346216671" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:54 -0700 Subject: [ndctl PATCH v2 03/26] ndctl/build: Drop -Wpointer-arith From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:36 -0700 Message-ID: <156426357691.531577.10926120390253347067.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP It is common kernel practice to do pointer arithmetic on (void *). Drop this warning for ndctl. Signed-off-by: Dan Williams --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6dca96eda395..4737cfff77f2 100644 --- a/configure.ac +++ b/configure.ac @@ -207,7 +207,6 @@ my_CFLAGS="\ -Wmissing-declarations \ -Wmissing-prototypes \ -Wnested-externs \ --Wpointer-arith \ -Wshadow \ -Wsign-compare \ -Wstrict-prototypes \ From patchwork Sat Jul 27 21:39:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C6C91399 for ; Sat, 27 Jul 2019 21:54:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EECE289CC for ; Sat, 27 Jul 2019 21:54:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FA83289F2; Sat, 27 Jul 2019 21:54:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id CE6F8289CC for ; Sat, 27 Jul 2019 21:54:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 629CE212E2582; Sat, 27 Jul 2019 14:56:27 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0F903212E15B5 for ; Sat, 27 Jul 2019 14:56:26 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:59 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="322416297" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:53:59 -0700 Subject: [ndctl PATCH v2 04/26] ndctl/namespace: Add read-infoblock command From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:42 -0700 Message-ID: <156426358204.531577.5297230715816068527.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Namespaces may contain an info-block that correlates with the possible modes of a namespace: 'sector', 'fsdax', or 'devdax'. Provide a command that can temporarily convert the namespace into 'raw' mode to read the info-block. Also, similar to 'read-labels' provide a facility to decode the info-block into json. Signed-off-by: Dan Williams --- Documentation/ndctl/Makefile.am | 3 Documentation/ndctl/ndctl-read-infoblock.txt | 94 ++++++ ndctl/action.h | 1 ndctl/builtin.h | 1 ndctl/check.c | 20 - ndctl/namespace.c | 401 ++++++++++++++++++++++++++ ndctl/namespace.h | 51 +++ ndctl/ndctl.c | 1 util/fletcher.h | 1 util/size.h | 1 10 files changed, 552 insertions(+), 22 deletions(-) create mode 100644 Documentation/ndctl/ndctl-read-infoblock.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index fb46d7c87938..ef22f6de390e 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -55,7 +55,8 @@ man1_MANS = \ ndctl-freeze-security.1 \ ndctl-sanitize-dimm.1 \ ndctl-load-keys.1 \ - ndctl-wait-overwrite.1 + ndctl-wait-overwrite.1 \ + ndctl-read-infoblock.1 CLEANFILES = $(man1_MANS) diff --git a/Documentation/ndctl/ndctl-read-infoblock.txt b/Documentation/ndctl/ndctl-read-infoblock.txt new file mode 100644 index 000000000000..92ae95befd38 --- /dev/null +++ b/Documentation/ndctl/ndctl-read-infoblock.txt @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-read-infoblock(1) +======================= + +NAME +---- +ndctl-read-infoblock - read and optionally parse the info-block a namespace + +SYNOPSIS +-------- +[verse] +'ndctl read-infoblock' [..] [] + +DESCRIPTION +----------- +As described in the theory of operation section of +linkndctl:ndctl-create-namespace[1], the raw capacity of a namespace may +encapsulate a personality, or mode of operation. Specifically, the mode +may be set to one of "sector", "fsdax", and "devdax". Each of those +modes is defined by an info-block format that uniquely identifies the +mode of operation. The read-infoblock command knows the location +(relative to the start of the namespace) and field definition of those +data structures. + +Note that unlike a partition table info-block is not exposed by default, +so the namespace needs to be disabled before the info-block can be +accessed. + +EXAMPLE +------- + +[verse] +# ndctl disable-namespace namespace0.0 +disabled 1 namespace +# ndctl read-infoblock -j namespace0.0 +[ + { + "dev":"namespace0.0", + "signature":"NVDIMM_PFN_INFO", + "uuid":"56b11990-66b1-4d91-9cac-ca084c051259", + "parent_uuid":"00000000-0000-0000-0000-000000000000", + "flags":0, + "version":"1.3", + "dataoff":69206016, + "npfns":1031680, + "mode":2, + "start_pad":0, + "end_trunc":0, + "align":2097152 + } +] + + +OPTIONS +------- +:: + One or more 'namespaceX.Y' device names. The keyword 'all' can be specified to + operate on every namespace in the system, optionally filtered by bus id (see + --bus= option), or region id (see --region= option). + +-V:: +--verify:: + Attempt to validate that the info-block is self consistent by + validating the embedded checksum, and that info-block formats + that contain a 'parent-uuid' attribute also match the base-uuid + of the namespace. + +-o:: +--output:: + Output file + +-j:: +--json:: + Parse the info-block data into json. +-u:: +--human:: + Enable json output and convert number formats to human readable + strings, for example show the size in terms of "KB", "MB", "GB", etc + instead of a signed 64-bit numbers per the JSON interchange + format (implies --json). + +-r:: +--region=:: +include::xable-region-options.txt[] + + +include::../copyright.txt[] + +SEE ALSO +-------- +linkndctl:ndctl-create-namespace[1], +http://www.uefi.org/sites/default/files/resources/UEFI_Spec_2_7.pdf[UEFI NVDIMM Label Protocol] + diff --git a/ndctl/action.h b/ndctl/action.h index 50da010ae826..636524c01f20 100644 --- a/ndctl/action.h +++ b/ndctl/action.h @@ -14,5 +14,6 @@ enum device_action { ACTION_WAIT, ACTION_START, ACTION_CLEAR, + ACTION_READ_INFOBLOCK, }; #endif /* __NDCTL_ACTION_H__ */ diff --git a/ndctl/builtin.h b/ndctl/builtin.h index 94ab3177e9b6..aa41ad01a84c 100644 --- a/ndctl/builtin.h +++ b/ndctl/builtin.h @@ -8,6 +8,7 @@ int cmd_create_nfit(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_enable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_create_namespace(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_destroy_namespace(int argc, const char **argv, struct ndctl_ctx *ctx); +int cmd_read_infoblock(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_disable_namespace(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_check_namespace(int argc, const char **argv, struct ndctl_ctx *ctx); int cmd_clear_errors(int argc, const char **argv, struct ndctl_ctx *ctx); diff --git a/ndctl/check.c b/ndctl/check.c index 8a7125053865..3b384c091af5 100644 --- a/ndctl/check.c +++ b/ndctl/check.c @@ -297,24 +297,6 @@ static int btt_log_read(struct arena_info *a, u32 lane, struct log_entry *ent) return 0; } -static int btt_checksum_verify(struct btt_sb *btt_sb) -{ - uint64_t sum; - le64 sum_save; - - BUILD_BUG_ON(sizeof(struct btt_sb) != SZ_4K); - - sum_save = btt_sb->checksum; - btt_sb->checksum = 0; - sum = fletcher64(btt_sb, sizeof(*btt_sb), 1); - if (sum != sum_save) - return 1; - /* restore the checksum in the buffer */ - btt_sb->checksum = sum_save; - - return 0; -} - /* * Never pass a mmapped buffer to this as it will attempt to write to * the buffer, and we want writes to only happened in a controlled fashion. @@ -330,7 +312,7 @@ static int btt_info_verify(struct btt_chk *bttc, struct btt_sb *btt_sb) if (uuid_compare(bttc->parent_uuid, btt_sb->parent_uuid) != 0) return -ENXIO; - if (btt_checksum_verify(btt_sb)) + if (!verify_infoblock_checksum((union info_block *) btt_sb)) return -ENXIO; return 0; diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 58a9e3c53474..9eec313c2d5b 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -21,6 +21,7 @@ #include #include "action.h" +#include "namespace.h" #include #include #include @@ -41,6 +42,9 @@ static struct parameters { bool do_scan; bool mode_default; bool autolabel; + bool verify; + bool human; + bool json; const char *bus; const char *map; const char *type; @@ -52,6 +56,8 @@ static struct parameters { const char *reconfig; const char *sector_size; const char *align; + const char *outfile; + const char *infile; } param = { .autolabel = true, }; @@ -80,6 +86,13 @@ struct parsed_parameters { bool autolabel; }; +#define pr_verbose(fmt, ...) \ + ({if (verbose) { \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ + } else { \ + do { } while (0); \ + }}) + #define debug(fmt, ...) \ ({if (verbose) { \ fprintf(stderr, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__); \ @@ -124,6 +137,16 @@ OPT_BOOLEAN('f', "force", &force, "check namespace even if currently active") #define CLEAR_OPTIONS() \ OPT_BOOLEAN('s', "scrub", &scrub, "run a scrub to find latent errors") +#define READ_INFOBLOCK_OPTIONS() \ +OPT_FILENAME('o', "output", ¶m.outfile, "output-file", \ + "filename to write info-block contents"), \ +OPT_FILENAME('i', "input", ¶m.infile, "input-file", \ + "filename to read info-block instead of a namespace"), \ +OPT_BOOLEAN('V', "verify", ¶m.verify, \ + "validate parent uuid, and info-block checksum" ), \ +OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json"), \ +OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats (implies --json)") + static const struct option base_options[] = { BASE_OPTIONS(), OPT_END(), @@ -154,6 +177,12 @@ static const struct option clear_options[] = { OPT_END(), }; +static const struct option read_infoblock_options[] = { + BASE_OPTIONS(), + READ_INFOBLOCK_OPTIONS(), + OPT_END(), +}; + static int set_defaults(enum device_action mode) { int rc = 0; @@ -298,18 +327,30 @@ static const char *parse_namespace_options(int argc, const char **argv, case ACTION_CLEAR: action_string = "clear errors for"; break; + case ACTION_READ_INFOBLOCK: + action_string = "read-infoblock"; + break; default: action_string = "<>"; break; } - error("specify a namespace to %s, or \"all\"\n", action_string); - rc = -EINVAL; + + if ((mode == ACTION_READ_INFOBLOCK && !param.infile) + || mode != ACTION_READ_INFOBLOCK) { + error("specify a namespace to %s, or \"all\"\n", action_string); + rc = -EINVAL; + } } for (i = mode == ACTION_CREATE ? 0 : 1; i < argc; i++) { error("unknown extra parameter \"%s\"\n", argv[i]); rc = -EINVAL; } + if (mode == ACTION_READ_INFOBLOCK && param.infile && argc) { + error("specify a namespace, or --file, not both\n"); + rc = -EINVAL; + } + if (rc) { usage_with_options(u, options); return NULL; /* we won't return from usage_with_options() */ @@ -1313,10 +1354,319 @@ static int namespace_clear_bb(struct ndctl_namespace *ndns) return 0; } +struct read_infoblock_ctx { + struct json_object *jblocks; + FILE *f_out; +}; + +#define parse_field(sb, field) \ + jobj = json_object_new_int(le32_to_cpu((sb)->field)); \ + if (!jobj) \ + goto err; \ + json_object_object_add(jblock, #field, jobj); + +#define parse_hex(sb, field, sz) \ + jobj = util_json_object_hex(le##sz##_to_cpu((sb)->field), flags); \ + if (!jobj) \ + goto err; \ + json_object_object_add(jblock, #field, jobj); + + +static json_object *btt_parse(struct btt_sb *btt_sb, struct ndctl_namespace *ndns, + const char *path, unsigned long flags) +{ + uuid_t uuid; + char str[40]; + struct json_object *jblock, *jobj; + const char *cmd = "read-info-block"; + const bool verify = param.verify; + + if (verify && !verify_infoblock_checksum((union info_block *) btt_sb)) { + pr_verbose("%s: %s checksum verification failed\n", cmd, __func__); + return NULL; + } + + if (ndns) { + ndctl_namespace_get_uuid(ndns, uuid); + if (verify && !uuid_is_null(uuid) && memcmp(uuid, btt_sb->parent_uuid, + sizeof(uuid) != 0)) { + pr_verbose("%s: %s uuid verification failed\n", cmd, __func__); + return NULL; + } + } + + jblock = json_object_new_object(); + if (!jblock) + return NULL; + + if (ndns) { + jobj = json_object_new_string(ndctl_namespace_get_devname(ndns)); + if (!jobj) + goto err; + json_object_object_add(jblock, "dev", jobj); + } else { + jobj = json_object_new_string(path); + if (!jobj) + goto err; + json_object_object_add(jblock, "file", jobj); + } + + jobj = json_object_new_string((char *) btt_sb->signature); + if (!jobj) + goto err; + json_object_object_add(jblock, "signature", jobj); + + uuid_unparse((void *) btt_sb->uuid, str); + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "uuid", jobj); + + uuid_unparse((void *) btt_sb->parent_uuid, str); + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "parent_uuid", jobj); + + jobj = util_json_object_hex(le32_to_cpu(btt_sb->flags), flags); + if (!jobj) + goto err; + json_object_object_add(jblock, "flags", jobj); + + if (snprintf(str, 4, "%d.%d", btt_sb->version_major, + btt_sb->version_minor) >= 4) + goto err; + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "version", jobj); + + parse_field(btt_sb, external_lbasize); + parse_field(btt_sb, external_nlba); + parse_field(btt_sb, internal_lbasize); + parse_field(btt_sb, internal_nlba); + parse_field(btt_sb, nfree); + parse_field(btt_sb, infosize); + parse_hex(btt_sb, nextoff, 64); + parse_hex(btt_sb, dataoff, 64); + parse_hex(btt_sb, mapoff, 64); + parse_hex(btt_sb, logoff, 64); + parse_hex(btt_sb, info2off, 64); + + return jblock; +err: + pr_verbose("%s: failed to create json representation\n", cmd); + json_object_put(jblock); + return NULL; +} + +static json_object *pfn_parse(struct pfn_sb *pfn_sb, struct ndctl_namespace *ndns, + const char *path, unsigned long flags) +{ + uuid_t uuid; + char str[40]; + struct json_object *jblock, *jobj; + const char *cmd = "read-info-block"; + const bool verify = param.verify; + + if (verify && !verify_infoblock_checksum((union info_block *) pfn_sb)) { + pr_verbose("%s: %s checksum verification failed\n", cmd, __func__); + return NULL; + } + + if (ndns) { + ndctl_namespace_get_uuid(ndns, uuid); + if (verify && !uuid_is_null(uuid) && memcmp(uuid, pfn_sb->parent_uuid, + sizeof(uuid) != 0)) { + pr_verbose("%s: %s uuid verification failed\n", cmd, __func__); + return NULL; + } + } + + jblock = json_object_new_object(); + if (!jblock) + return NULL; + + if (ndns) { + jobj = json_object_new_string(ndctl_namespace_get_devname(ndns)); + if (!jobj) + goto err; + json_object_object_add(jblock, "dev", jobj); + } else { + jobj = json_object_new_string(path); + if (!jobj) + goto err; + json_object_object_add(jblock, "file", jobj); + } + + jobj = json_object_new_string((char *) pfn_sb->signature); + if (!jobj) + goto err; + json_object_object_add(jblock, "signature", jobj); + + uuid_unparse((void *) pfn_sb->uuid, str); + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "uuid", jobj); + + uuid_unparse((void *) pfn_sb->parent_uuid, str); + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "parent_uuid", jobj); + + jobj = util_json_object_hex(le32_to_cpu(pfn_sb->flags), flags); + if (!jobj) + goto err; + json_object_object_add(jblock, "flags", jobj); + + if (snprintf(str, 4, "%d.%d", pfn_sb->version_major, + pfn_sb->version_minor) >= 4) + goto err; + jobj = json_object_new_string(str); + if (!jobj) + goto err; + json_object_object_add(jblock, "version", jobj); + + parse_hex(pfn_sb, dataoff, 64); + parse_hex(pfn_sb, npfns, 64); + parse_field(pfn_sb, mode); + parse_hex(pfn_sb, start_pad, 32); + parse_hex(pfn_sb, end_trunc, 32); + parse_hex(pfn_sb, align, 32); + + return jblock; +err: + pr_verbose("%s: failed to create json representation\n", cmd); + json_object_put(jblock); + return NULL; +} + +#define INFOBLOCK_SZ SZ_8K + +static int parse_namespace_infoblock(char *_buf, struct ndctl_namespace *ndns, + const char *path, struct read_infoblock_ctx *ri_ctx) +{ + int rc; + void *buf = _buf; + unsigned long flags = param.human ? UTIL_JSON_HUMAN : 0; + struct btt_sb *btt1_sb = buf + SZ_4K, *btt2_sb = buf; + struct json_object *jblock = NULL, *jblocks = ri_ctx->jblocks; + struct pfn_sb *pfn_sb = buf + SZ_4K, *dax_sb = buf + SZ_4K; + + if (!param.json && !param.human) { + rc = fwrite(buf, 1, INFOBLOCK_SZ, ri_ctx->f_out); + if (rc != INFOBLOCK_SZ) + return -EIO; + fflush(ri_ctx->f_out); + return 0; + } + + if (!jblocks) { + jblocks = json_object_new_array(); + if (!jblocks) + return -ENOMEM; + ri_ctx->jblocks = jblocks; + } + + if (memcmp(btt1_sb->signature, BTT_SIG, BTT_SIG_LEN) == 0) { + jblock = btt_parse(btt1_sb, ndns, path, flags); + if (jblock) + json_object_array_add(jblocks, jblock); + } + + if (memcmp(btt2_sb->signature, BTT_SIG, BTT_SIG_LEN) == 0) { + jblock = btt_parse(btt2_sb, ndns, path, flags); + if (jblock) + json_object_array_add(jblocks, jblock); + } + + if (memcmp(pfn_sb->signature, PFN_SIG, PFN_SIG_LEN) == 0) { + jblock = pfn_parse(pfn_sb, ndns, path, flags); + if (jblock) + json_object_array_add(jblocks, jblock); + } + + if (memcmp(dax_sb->signature, DAX_SIG, PFN_SIG_LEN) == 0) { + jblock = pfn_parse(dax_sb, ndns, path, flags); + if (jblock) + json_object_array_add(jblocks, jblock); + } + + return 0; +} + +static int file_read_infoblock(const char *path, struct ndctl_namespace *ndns, + struct read_infoblock_ctx *ri_ctx) +{ + const char *devname = ndns ? ndctl_namespace_get_devname(ndns) : ""; + const char *cmd = "read-info-block"; + void *buf = NULL; + int fd = -1, rc; + + buf = calloc(1, INFOBLOCK_SZ); + if (!buf) + return -ENOMEM; + + fd = open(path, O_RDONLY|O_EXCL); + if (fd < 0) { + pr_verbose("%s: %s failed to open %s: %s\n", + cmd, devname, path, strerror(errno)); + rc = -errno; + goto out; + } + + rc = read(fd, buf, INFOBLOCK_SZ); + if (rc < 0) { + pr_verbose("%s: %s failed to read %s: %s\n", + cmd, devname, path, strerror(errno)); + rc = -errno; + goto out; + } + + rc = parse_namespace_infoblock(buf, ndns, path, ri_ctx); +out: + free(buf); + if (fd >= 0) + close(fd); + return rc; +} + +static int namespace_read_infoblock(struct ndctl_namespace *ndns, + struct read_infoblock_ctx *ri_ctx) +{ + int rc; + char path[50]; + const char *cmd = "read-info-block"; + const char *devname = ndctl_namespace_get_devname(ndns); + + if (ndctl_namespace_is_active(ndns)) { + pr_verbose("%s: %s enabled, must be disabled\n", cmd, devname); + return -EBUSY; + } + + ndctl_namespace_set_raw_mode(ndns, 1); + rc = ndctl_namespace_enable(ndns); + if (rc < 0) { + pr_verbose("%s: %s failed to enable\n", cmd, devname); + goto out; + } + + sprintf(path, "/dev/%s", ndctl_namespace_get_block_device(ndns)); + rc = file_read_infoblock(path, ndns, ri_ctx); + +out: + ndctl_namespace_set_raw_mode(ndns, 0); + ndctl_namespace_disable_invalidate(ndns); + return rc; +} + static int do_xaction_namespace(const char *namespace, enum device_action action, struct ndctl_ctx *ctx, int *processed) { + struct read_infoblock_ctx ri_ctx = { 0 }; struct ndctl_namespace *ndns, *_n; struct ndctl_region *region; const char *ndns_name; @@ -1325,6 +1675,26 @@ static int do_xaction_namespace(const char *namespace, *processed = 0; + if (action == ACTION_READ_INFOBLOCK) { + if (!param.outfile) + ri_ctx.f_out = stdout; + else { + ri_ctx.f_out = fopen(param.outfile, "w+"); + if (!ri_ctx.f_out) { + fprintf(stderr, "failed to open: %s: (%s)\n", + param.outfile, strerror(errno)); + return -errno; + } + } + + if (param.infile) { + rc = file_read_infoblock(param.infile, NULL, &ri_ctx); + if (ri_ctx.jblocks) + util_display_json_array(ri_ctx.f_out, ri_ctx.jblocks, 0); + return rc; + } + } + if (!namespace && action != ACTION_CREATE) return rc; @@ -1403,6 +1773,11 @@ static int do_xaction_namespace(const char *namespace, if (rc == 0) *processed = 1; return rc; + case ACTION_READ_INFOBLOCK: + rc = namespace_read_infoblock(ndns, &ri_ctx); + if (rc == 0) + (*processed)++; + break; default: rc = -EINVAL; break; @@ -1411,6 +1786,12 @@ static int do_xaction_namespace(const char *namespace, } } + if (ri_ctx.jblocks) + util_display_json_array(ri_ctx.f_out, ri_ctx.jblocks, 0); + + if (ri_ctx.f_out && ri_ctx.f_out != stdout) + fclose(ri_ctx.f_out); + return rc; } @@ -1523,3 +1904,19 @@ int cmd_clear_errors(int argc , const char **argv, struct ndctl_ctx *ctx) cleared == 1 ? "" : "s"); return rc; } + +int cmd_read_infoblock(int argc , const char **argv, struct ndctl_ctx *ctx) +{ + char *xable_usage = "ndctl read-info-block []"; + const char *namespace = parse_namespace_options(argc, argv, + ACTION_READ_INFOBLOCK, read_infoblock_options, + xable_usage); + int read, rc; + + rc = do_xaction_namespace(namespace, ACTION_READ_INFOBLOCK, ctx, &read); + if (rc < 0) + fprintf(stderr, "error checking namespaces: %s\n", + strerror(-rc)); + fprintf(stderr, "read %d namespace%s\n", read, read == 1 ? "" : "s"); + return rc; +} diff --git a/ndctl/namespace.h b/ndctl/namespace.h index bc210857642f..861dfbfa5127 100644 --- a/ndctl/namespace.h +++ b/ndctl/namespace.h @@ -13,7 +13,9 @@ #ifndef __NDCTL_NAMESPACE_H__ #define __NDCTL_NAMESPACE_H__ #include +#include #include +#include #include #include @@ -202,4 +204,53 @@ struct arena_map { struct btt_sb *info2; size_t info2_len; }; + +#define PFN_SIG_LEN 16 +#define PFN_SIG "NVDIMM_PFN_INFO\0" +#define DAX_SIG "NVDIMM_DAX_INFO\0" + +struct pfn_sb { + u8 signature[PFN_SIG_LEN]; + u8 uuid[16]; + u8 parent_uuid[16]; + le32 flags; + le16 version_major; + le16 version_minor; + le64 dataoff; /* relative to namespace_base + start_pad */ + le64 npfns; + le32 mode; + /* minor-version-1 additions for section alignment */ + le32 start_pad; + le32 end_trunc; + /* minor-version-2 record the base alignment of the mapping */ + le32 align; + u8 padding[4000]; + le64 checksum; +}; + +union info_block { + struct pfn_sb pfn_sb; + struct btt_sb btt_sb; +}; + +static inline bool verify_infoblock_checksum(union info_block *sb) +{ + uint64_t sum; + le64 sum_save; + + BUILD_BUG_ON(sizeof(union info_block) != SZ_4K); + + /* all infoblocks share the btt_sb layout for checksum */ + sum_save = sb->btt_sb.checksum; + sb->btt_sb.checksum = 0; + sum = fletcher64(&sb->btt_sb, sizeof(*sb), 1); + if (sum != sum_save) + return false; + /* restore the checksum in the buffer */ + sb->btt_sb.checksum = sum_save; + + return true; +} + + #endif /* __NDCTL_NAMESPACE_H__ */ diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index 6c4975c9f841..5c9c424dcae6 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -73,6 +73,7 @@ static struct cmd_struct commands[] = { { "disable-namespace", { cmd_disable_namespace } }, { "create-namespace", { cmd_create_namespace } }, { "destroy-namespace", { cmd_destroy_namespace } }, + { "read-infoblock", { cmd_read_infoblock } }, { "check-namespace", { cmd_check_namespace } }, { "clear-errors", { cmd_clear_errors } }, { "enable-region", { cmd_enable_region } }, diff --git a/util/fletcher.h b/util/fletcher.h index 54e2ecf5d6ed..8fccac4ec758 100644 --- a/util/fletcher.h +++ b/util/fletcher.h @@ -1,6 +1,7 @@ #ifndef _NDCTL_FLETCHER_H_ #define _NDCTL_FLETCHER_H_ +#include #include #include diff --git a/util/size.h b/util/size.h index 34fac58d6945..2426fef74b3c 100644 --- a/util/size.h +++ b/util/size.h @@ -16,6 +16,7 @@ #define SZ_1K 0x00000400 #define SZ_4K 0x00001000 +#define SZ_8K 0x00002000 #define SZ_1M 0x00100000 #define SZ_2M 0x00200000 #define SZ_4M 0x00400000 From patchwork Sat Jul 27 21:39:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E80F112C for ; Sat, 27 Jul 2019 21:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86C46289CC for ; Sat, 27 Jul 2019 21:54:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AE6E289F2; Sat, 27 Jul 2019 21:54:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 37697289CC for ; Sat, 27 Jul 2019 21:54:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1D53212E2586; Sat, 27 Jul 2019 14:56:32 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B586A212E15BE for ; Sat, 27 Jul 2019 14:56:31 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:04 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="173436269" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:04 -0700 Subject: [ndctl PATCH v2 05/26] ndctl/test: Update dax-dev to handle multiple e820 ranges From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:47 -0700 Message-ID: <156426358717.531577.8906778081129951458.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Establish a convention that the first, lowest-index, region on the e820 bus always enables in fsdax mode without need for an nd_pfn instance. This is in preparation for a defining a collision test that requires multiple section-mis-aligned regions defined by memmap=nn!ss. Signed-off-by: Dan Williams --- test/dax-dev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/dax-dev.c b/test/dax-dev.c index 0183b7af2052..49ccaa334e31 100644 --- a/test/dax-dev.c +++ b/test/dax-dev.c @@ -33,17 +33,28 @@ struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx) struct ndctl_bus *bus; struct ndctl_dax *dax; struct ndctl_pfn *pfn; - struct ndctl_region *region; struct ndctl_namespace *ndns; enum ndctl_namespace_mode mode; + struct ndctl_region *region, *min = NULL; bus = ndctl_bus_get_by_provider(ctx, "e820"); if (!bus) goto out; - region = ndctl_region_get_first(bus); - if (!region) + ndctl_region_foreach(bus, region) { + if (!min) { + min = region; + continue; + } + if (ndctl_region_get_id(region) < ndctl_region_get_id(min)) + min = region; + } + if (!min) goto out; + region = min; + + /* attempt to re-enable the region if a previous test disabled it */ + ndctl_region_enable(region); ndns = ndctl_namespace_get_first(region); if (!ndns) From patchwork Sat Jul 27 21:39:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0379E1399 for ; Sat, 27 Jul 2019 21:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03E3289CC for ; Sat, 27 Jul 2019 21:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4A25289F2; Sat, 27 Jul 2019 21:54:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id AC8C7289CC for ; Sat, 27 Jul 2019 21:54:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 07F14212E2591; Sat, 27 Jul 2019 14:56:38 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0032B212E15B5 for ; Sat, 27 Jul 2019 14:56:36 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:09 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="182272379" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:09 -0700 Subject: [ndctl PATCH v2 06/26] ndctl/test: Make dax.sh more robust vs small namespaces From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:52 -0700 Message-ID: <156426359229.531577.14331405344075253387.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP If the namespace returned by test/dax-dev is too small ext4 may default to a 1K block-size. A 1K block-size precludes dax operation, so force a 4K block-size in all cases. Signed-off-by: Dan Williams --- test/dax.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dax.sh b/test/dax.sh index d38fd01acb07..e703e1222dee 100755 --- a/test/dax.sh +++ b/test/dax.sh @@ -47,7 +47,7 @@ json=$($NDCTL list -N -n $dev) eval $(json2var <<< "$json") rc=1 -mkfs.ext4 /dev/$blockdev +mkfs.ext4 -b 4096 /dev/$blockdev mount /dev/$blockdev $MNT -o dax fallocate -l 1GiB $MNT/$FILE run_test @@ -59,7 +59,7 @@ eval $(json2var <<< "$json") [ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 #note the blockdev returned from ndctl create-namespace lacks the /dev prefix -mkfs.ext4 /dev/$blockdev +mkfs.ext4 -b 4096 /dev/$blockdev mount /dev/$blockdev $MNT -o dax fallocate -l 1GiB $MNT/$FILE run_test From patchwork Sat Jul 27 21:39:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B63B112C for ; Sat, 27 Jul 2019 21:54:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 320AE289CC for ; Sat, 27 Jul 2019 21:54:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 241A7289F2; Sat, 27 Jul 2019 21:54:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D95E0289CC for ; Sat, 27 Jul 2019 21:54:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 490D4212E2597; Sat, 27 Jul 2019 14:56:43 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 67E75212E259D for ; Sat, 27 Jul 2019 14:56:41 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:14 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="254770049" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:14 -0700 Subject: [ndctl PATCH v2 07/26] ndctl/namespace: Always zero info-blocks From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:39:57 -0700 Message-ID: <156426359741.531577.6721558516702343422.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Do not gate zeroing on whether a namespace is claimed by a personality. The namespace might not have been able to be claimed due to info-block corruption. Signed-off-by: Dan Williams --- ndctl/namespace.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 9eec313c2d5b..645aa14882bb 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -930,9 +930,6 @@ static int namespace_destroy(struct ndctl_region *region, struct ndctl_namespace *ndns) { const char *devname = ndctl_namespace_get_devname(ndns); - struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns); - struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns); - struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns); bool did_zero = false; int rc; @@ -954,13 +951,11 @@ static int namespace_destroy(struct ndctl_region *region, ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_RAW); - if (pfn || btt || dax) { - rc = zero_info_block(ndns); - if (rc < 0) - return rc; - if (rc == 0) - did_zero = true; - } + rc = zero_info_block(ndns); + if (rc < 0) + return rc; + if (rc == 0) + did_zero = true; switch (ndctl_namespace_get_type(ndns)) { case ND_DEVICE_NAMESPACE_PMEM: From patchwork Sat Jul 27 21:40:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7262112C for ; Sat, 27 Jul 2019 21:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E044289CC for ; Sat, 27 Jul 2019 21:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9292A289F2; Sat, 27 Jul 2019 21:54:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 0C1B9289CC for ; Sat, 27 Jul 2019 21:54:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 95319212E259C; Sat, 27 Jul 2019 14:56:49 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2F42C212E259D for ; Sat, 27 Jul 2019 14:56:47 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:20 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="171014224" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:20 -0700 Subject: [ndctl PATCH v2 08/26] ndctl/dimm: Support small label reads/writes From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:02 -0700 Message-ID: <156426360258.531577.4845341973289339875.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP The initial ndctl label read/write implementation assumed that label read / writes were relatively inexpensive, but that assumption is invalid in practice. The process of reading a full label area can take 10s of seconds. Implement ndctl_cmd_cfg_{read,write}_set_extent() to trim the label read/write commands to a range smaller than the full label area. Signed-off-by: Dan Williams --- ndctl/lib/libndctl.c | 107 +++++++++++++++++++++++++++++++++++++++++------- ndctl/lib/libndctl.sym | 2 + ndctl/lib/private.h | 1 ndctl/libndctl.h | 4 ++ 4 files changed, 99 insertions(+), 15 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 81e155171c8c..c1ecdd8c9c61 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -2582,6 +2582,7 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_read(struct ndctl_cmd *cfg cmd->get_data->in_offset = 0; cmd->get_data->in_length = cfg_size->get_size->max_xfer; cmd->firmware_status = &cmd->get_data->status; + cmd->iter.init_offset = 0; cmd->iter.offset = &cmd->get_data->in_offset; cmd->iter.xfer = &cmd->get_data->in_length; cmd->iter.max_xfer = cfg_size->get_size->max_xfer; @@ -2593,10 +2594,43 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_read(struct ndctl_cmd *cfg free(cmd); return NULL; } + cmd->source = cfg_size; + ndctl_cmd_ref(cfg_size); return cmd; } +static void iter_set_extent(struct ndctl_cmd_iter *iter, unsigned int len, + unsigned int offset) +{ + iter->init_offset = offset; + *iter->offset = offset; + *iter->xfer = min(iter->max_xfer, len); + iter->total_xfer = len; +} + +NDCTL_EXPORT int ndctl_cmd_cfg_read_set_extent(struct ndctl_cmd *cfg_read, + unsigned int len, unsigned int offset) +{ + struct ndctl_ctx *ctx = ndctl_bus_get_ctx(cmd_to_bus(cfg_read)); + struct ndctl_cmd *cfg_size = cfg_read->source; + + if (cfg_read->type != ND_CMD_GET_CONFIG_DATA + || cfg_read->status <= 0) { + dbg(ctx, "expected unsubmitted cfg_read command\n"); + return -EINVAL; + } + + if (offset + len > cfg_size->get_size->config_size) { + dbg(ctx, "read %d from %d exceeds %d\n", len, offset, + cfg_size->get_size->config_size); + return -EINVAL; + } + + iter_set_extent(&cfg_read->iter, len, offset); + return 0; +} + NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_write(struct ndctl_cmd *cfg_read) { struct ndctl_ctx *ctx = ndctl_bus_get_ctx(cmd_to_bus(cfg_read)); @@ -2632,10 +2666,11 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_write(struct ndctl_cmd *cf cmd->type = ND_CMD_SET_CONFIG_DATA; cmd->size = size; cmd->status = 1; - cmd->set_data->in_offset = 0; + cmd->set_data->in_offset = cfg_read->iter.init_offset; cmd->set_data->in_length = cfg_read->iter.max_xfer; cmd->firmware_status = (u32 *) (cmd->cmd_buf + sizeof(struct nd_cmd_set_config_hdr) + cfg_read->iter.max_xfer); + cmd->iter.init_offset = cfg_read->iter.init_offset; cmd->iter.offset = &cmd->set_data->in_offset; cmd->iter.xfer = &cmd->set_data->in_length; cmd->iter.max_xfer = cfg_read->iter.max_xfer; @@ -2657,18 +2692,33 @@ NDCTL_EXPORT unsigned int ndctl_cmd_cfg_size_get_size(struct ndctl_cmd *cfg_size return 0; } +static ssize_t iter_access(struct ndctl_cmd_iter *iter, unsigned int len, + unsigned int offset) +{ + if (offset < iter->init_offset + || offset > iter->init_offset + iter->total_xfer + || len + offset < len) + return -EINVAL; + if (len + offset > iter->init_offset + iter->total_xfer) + len = iter->total_xfer - offset; + return len; +} + NDCTL_EXPORT ssize_t ndctl_cmd_cfg_read_get_data(struct ndctl_cmd *cfg_read, - void *buf, unsigned int len, unsigned int offset) + void *buf, unsigned int _len, unsigned int offset) { + struct ndctl_cmd_iter *iter; + ssize_t len; + if (cfg_read->type != ND_CMD_GET_CONFIG_DATA || cfg_read->status > 0) return -EINVAL; if (cfg_read->status < 0) return cfg_read->status; - if (offset > cfg_read->iter.total_xfer || len + offset < len) - return -EINVAL; - if (len + offset > cfg_read->iter.total_xfer) - len = cfg_read->iter.total_xfer - offset; - memcpy(buf, cfg_read->iter.total_buf + offset, len); + + iter = &cfg_read->iter; + len = iter_access(&cfg_read->iter, _len, offset); + if (len >= 0) + memcpy(buf, iter->total_buf + offset, len); return len; } @@ -2681,29 +2731,56 @@ NDCTL_EXPORT ssize_t ndctl_cmd_cfg_read_get_size(struct ndctl_cmd *cfg_read) return cfg_read->iter.total_xfer; } +NDCTL_EXPORT int ndctl_cmd_cfg_write_set_extent(struct ndctl_cmd *cfg_write, + unsigned int len, unsigned int offset) +{ + struct ndctl_ctx *ctx = ndctl_bus_get_ctx(cmd_to_bus(cfg_write)); + struct ndctl_cmd *cfg_size, *cfg_read; + + if (cfg_write->type != ND_CMD_SET_CONFIG_DATA + || cfg_write->status <= 0) { + dbg(ctx, "expected unsubmitted cfg_write command\n"); + return -EINVAL; + } + + cfg_read = cfg_write->source; + cfg_size = cfg_read->source; + + if (offset + len > cfg_size->get_size->config_size) { + dbg(ctx, "write %d from %d exceeds %d\n", len, offset, + cfg_size->get_size->config_size); + return -EINVAL; + } + + iter_set_extent(&cfg_write->iter, len, offset); + return 0; +} + NDCTL_EXPORT ssize_t ndctl_cmd_cfg_write_set_data(struct ndctl_cmd *cfg_write, - void *buf, unsigned int len, unsigned int offset) + void *buf, unsigned int _len, unsigned int offset) { + ssize_t len; + if (cfg_write->type != ND_CMD_SET_CONFIG_DATA || cfg_write->status < 1) return -EINVAL; if (cfg_write->status < 0) return cfg_write->status; - if (offset > cfg_write->iter.total_xfer || len + offset < len) - return -EINVAL; - if (len + offset > cfg_write->iter.total_xfer) - len = cfg_write->iter.total_xfer - offset; - memcpy(cfg_write->iter.total_buf + offset, buf, len); + len = iter_access(&cfg_write->iter, _len, offset); + if (len >= 0) + memcpy(cfg_write->iter.total_buf + offset, buf, len); return len; } NDCTL_EXPORT ssize_t ndctl_cmd_cfg_write_zero_data(struct ndctl_cmd *cfg_write) { + struct ndctl_cmd_iter *iter = &cfg_write->iter; + if (cfg_write->type != ND_CMD_SET_CONFIG_DATA || cfg_write->status < 1) return -EINVAL; if (cfg_write->status < 0) return cfg_write->status; - memset(cfg_write->iter.total_buf, 0, cfg_write->iter.total_xfer); - return cfg_write->iter.total_xfer; + memset(iter->total_buf + iter->init_offset, 0, iter->total_xfer); + return iter->total_xfer; } NDCTL_EXPORT void ndctl_cmd_unref(struct ndctl_cmd *cmd) diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 297f03d7ae39..e79b31c71ae6 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -409,4 +409,6 @@ global: LIBNDCTL_20 { global: ndctl_bus_poll_scrub_completion; + ndctl_cmd_cfg_read_set_extent; + ndctl_cmd_cfg_write_set_extent; } LIBNDCTL_19; diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index 2ddc1d2c34f8..3fc0290ff6a7 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -254,6 +254,7 @@ struct ndctl_cmd { int status; u32 *firmware_status; struct ndctl_cmd_iter { + u32 init_offset; u32 *offset; u32 *xfer; /* pointer to xfer length in cmd */ u8 *data; /* pointer to the data buffer location in cmd */ diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index e378802ee4c1..310814fe924c 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -321,6 +321,10 @@ unsigned int ndctl_cmd_cfg_size_get_size(struct ndctl_cmd *cfg_size); ssize_t ndctl_cmd_cfg_read_get_data(struct ndctl_cmd *cfg_read, void *buf, unsigned int len, unsigned int offset); ssize_t ndctl_cmd_cfg_read_get_size(struct ndctl_cmd *cfg_read); +int ndctl_cmd_cfg_read_set_extent(struct ndctl_cmd *cfg_read, + unsigned int len, unsigned int offset); +int ndctl_cmd_cfg_write_set_extent(struct ndctl_cmd *cfg_write, + unsigned int len, unsigned int offset); ssize_t ndctl_cmd_cfg_write_set_data(struct ndctl_cmd *cfg_write, void *buf, unsigned int len, unsigned int offset); ssize_t ndctl_cmd_cfg_write_zero_data(struct ndctl_cmd *cfg_write); From patchwork Sat Jul 27 21:40:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C6FE1399 for ; Sat, 27 Jul 2019 21:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64991289CC for ; Sat, 27 Jul 2019 21:54:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58F95289F2; Sat, 27 Jul 2019 21:54:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 55F33289CC for ; Sat, 27 Jul 2019 21:54:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D7B5E212E2585; Sat, 27 Jul 2019 14:56:54 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0947B212E15A7 for ; Sat, 27 Jul 2019 14:56:53 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:26 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="172675766" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:25 -0700 Subject: [ndctl PATCH v2 09/26] ndctl/dimm: Minimize data-transfer for init-labels From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:08 -0700 Message-ID: <156426360847.531577.7776763835929401977.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Currently init-labels implementation reads the entire namespace-label capacity, initializes just the namespace index, and then writes the entire label capacity. It turns out that DIMM label-area access methods can be exceedingly slow. For example, the time to read the entire label area on a single dimm: 2s, but the time to just read the index block space: 45ms. Signed-off-by: Dan Williams --- ndctl/dimm.c | 2 +- ndctl/lib/dimm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++--- ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 5f05a75f00eb..be03d9b810bd 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -982,7 +982,7 @@ static int __action_init(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd_read; int rc; - cmd_read = ndctl_dimm_read_labels(dimm); + cmd_read = ndctl_dimm_read_label_index(dimm); if (!cmd_read) return -ENXIO; diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index 22cf4e10b56c..9c5a34e542c3 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -370,14 +370,15 @@ static struct namespace_label *label_base(struct nvdimm_data *ndd) return (struct namespace_label *) base; } -static void init_ndd(struct nvdimm_data *ndd, struct ndctl_cmd *cmd_read) +static void init_ndd(struct nvdimm_data *ndd, struct ndctl_cmd *cmd_read, + struct ndctl_cmd *cmd_size) { ndctl_cmd_unref(ndd->cmd_read); memset(ndd, 0, sizeof(*ndd)); ndd->cmd_read = cmd_read; ndctl_cmd_ref(cmd_read); ndd->data = cmd_read->iter.total_buf; - ndd->config_size = cmd_read->iter.total_xfer; + ndd->config_size = cmd_size->get_size->config_size; ndd->ns_current = -1; ndd->ns_next = -1; } @@ -490,6 +491,52 @@ NDCTL_EXPORT int ndctl_dimm_validate_labels(struct ndctl_dimm *dimm) return label_validate(&dimm->ndd); } +NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_label_index(struct ndctl_dimm *dimm) +{ + struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_cmd *cmd_size, *cmd_read; + struct nvdimm_data *ndd = &dimm->ndd; + int rc; + + rc = ndctl_bus_wait_probe(bus); + if (rc < 0) + return NULL; + + cmd_size = ndctl_dimm_cmd_new_cfg_size(dimm); + if (!cmd_size) + return NULL; + rc = ndctl_cmd_submit_xlat(cmd_size); + if (rc < 0) + goto out_size; + + cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); + if (!cmd_read) + goto out_size; + /* + * To calc the namespace index size use the minimum label + * size which corresponds to the maximum namespace index size. + */ + init_ndd(ndd, cmd_read, cmd_size); + ndd->nslabel_size = 128; + rc = ndctl_cmd_cfg_read_set_extent(cmd_read, + sizeof_namespace_index(ndd) * 2, 0); + if (rc < 0) + goto out_size; + + rc = ndctl_cmd_submit_xlat(cmd_read); + if (rc < 0) + goto out_read; + ndctl_cmd_unref(cmd_size); + + return cmd_read; + + out_read: + ndctl_cmd_unref(cmd_read); + out_size: + ndctl_cmd_unref(cmd_size); + return NULL; +} + NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) { struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); @@ -515,7 +562,7 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) goto out_read; ndctl_cmd_unref(cmd_size); - init_ndd(&dimm->ndd, cmd_read); + init_ndd(&dimm->ndd, cmd_read, cmd_size); return cmd_read; diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index e79b31c71ae6..3cd431a90e55 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -411,4 +411,5 @@ global: ndctl_bus_poll_scrub_completion; ndctl_cmd_cfg_read_set_extent; ndctl_cmd_cfg_write_set_extent; + ndctl_dimm_read_label_index; } LIBNDCTL_19; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 310814fe924c..8aa4b8bbe6c2 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -308,6 +308,7 @@ struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_read(struct ndctl_cmd *cfg_size); struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_write(struct ndctl_cmd *cfg_read); int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm); struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm); +struct ndctl_cmd *ndctl_dimm_read_label_index(struct ndctl_dimm *dimm); int ndctl_dimm_validate_labels(struct ndctl_dimm *dimm); enum ndctl_namespace_version { NDCTL_NS_VERSION_1_1, From patchwork Sat Jul 27 21:40:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5801B1399 for ; Sat, 27 Jul 2019 21:54:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DDF8289CC for ; Sat, 27 Jul 2019 21:54:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F466289F2; Sat, 27 Jul 2019 21:54:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 919BB289CC for ; Sat, 27 Jul 2019 21:54:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 25E9F212E25AA; Sat, 27 Jul 2019 14:57:00 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AEAB4212E15B4 for ; Sat, 27 Jul 2019 14:56:58 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:31 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="370587148" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:31 -0700 Subject: [ndctl PATCH v2 10/26] ndctl/dimm: Add offset and size options to {read, write, zero}-labels From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:13 -0700 Message-ID: <156426361393.531577.10073127425253098897.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Allow for more precision in label utilities, i.e. stop operating over the entire label area. Signed-off-by: Dan Williams --- Documentation/ndctl/labels-options.txt | 9 ++++++ ndctl/dimm.c | 49 ++++++++++++++++++++++++-------- ndctl/lib/dimm.c | 36 ++++++++++++++++++++---- ndctl/lib/libndctl.sym | 2 + ndctl/lib/private.h | 3 -- ndctl/libndctl.h | 4 +++ util/util.h | 4 +++ 7 files changed, 86 insertions(+), 21 deletions(-) diff --git a/Documentation/ndctl/labels-options.txt b/Documentation/ndctl/labels-options.txt index 539ace079557..4aee37969fd5 100644 --- a/Documentation/ndctl/labels-options.txt +++ b/Documentation/ndctl/labels-options.txt @@ -5,6 +5,15 @@ operate on every dimm in the system, optionally filtered by bus id (see --bus= option). +-s:: +--size=:: + Limit the operation to the given number of bytes. A size of 0 + indicates to operate over the entire label capacity. + +-O:: +--offset=:: + Begin the operation at the given offset into the label area. + -b:: --bus=:: Limit operation to memory devices (dimms) that are on the given bus. diff --git a/ndctl/dimm.c b/ndctl/dimm.c index be03d9b810bd..603e112f9568 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -47,6 +47,8 @@ static struct parameters { const char *infile; const char *labelversion; const char *kek; + unsigned len; + unsigned offset; bool crypto_erase; bool overwrite; bool zero_key; @@ -77,7 +79,7 @@ static int action_enable(struct ndctl_dimm *dimm, struct action_context *actx) static int action_zero(struct ndctl_dimm *dimm, struct action_context *actx) { - return ndctl_dimm_zero_labels(dimm); + return ndctl_dimm_zero_label_extent(dimm, param.len, param.offset); } static struct json_object *dump_label_json(struct ndctl_dimm *dimm, @@ -299,15 +301,17 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, return NULL; } -static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size, int rw) +static int rw_bin(FILE *f, struct ndctl_cmd *cmd, ssize_t size, + unsigned int start_offset, int rw) { char buf[4096]; ssize_t offset, write = 0; - for (offset = 0; offset < size; offset += sizeof(buf)) { + for (offset = start_offset; offset < start_offset + size; + offset += sizeof(buf)) { ssize_t len = min_t(ssize_t, sizeof(buf), size - offset), rc; - if (rw) { + if (rw == WRITE) { len = fread(buf, 1, len, f); if (len == 0) break; @@ -343,9 +347,9 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx) return -EBUSY; } - cmd_read = ndctl_dimm_read_labels(dimm); + cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, param.offset); if (!cmd_read) - return -ENXIO; + return -EINVAL; cmd_write = ndctl_dimm_cmd_new_cfg_write(cmd_read); if (!cmd_write) { @@ -354,7 +358,7 @@ static int action_write(struct ndctl_dimm *dimm, struct action_context *actx) } size = ndctl_cmd_cfg_read_get_size(cmd_read); - rc = rw_bin(actx->f_in, cmd_write, size, 1); + rc = rw_bin(actx->f_in, cmd_write, size, param.offset, WRITE); /* * If the dimm is already disabled the kernel is not holding a cached @@ -381,9 +385,9 @@ static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) ssize_t size; int rc = 0; - cmd_read = ndctl_dimm_read_labels(dimm); + cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, param.offset); if (!cmd_read) - return -ENXIO; + return -EINVAL; size = ndctl_cmd_cfg_read_get_size(cmd_read); if (actx->jdimms) { @@ -394,7 +398,7 @@ static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) else rc = -ENOMEM; } else - rc = rw_bin(actx->f_out, cmd_read, size, 0); + rc = rw_bin(actx->f_out, cmd_read, size, param.offset, READ); ndctl_cmd_unref(cmd_read); @@ -1082,18 +1086,31 @@ OPT_BOOLEAN('z', "zero-key", ¶m.zero_key, \ OPT_BOOLEAN('m', "master-passphrase", ¶m.master_pass, \ "use master passphrase") +#define LABEL_OPTIONS() \ +OPT_UINTEGER('s', "size", ¶m.len, "number of label bytes to operate"), \ +OPT_UINTEGER('O', "offset", ¶m.offset, \ + "offset into the label area to start operation") + static const struct option read_options[] = { BASE_OPTIONS(), + LABEL_OPTIONS(), READ_OPTIONS(), OPT_END(), }; static const struct option write_options[] = { BASE_OPTIONS(), + LABEL_OPTIONS(), WRITE_OPTIONS(), OPT_END(), }; +static const struct option zero_options[] = { + BASE_OPTIONS(), + LABEL_OPTIONS(), + OPT_END(), +}; + static const struct option update_options[] = { BASE_OPTIONS(), UPDATE_OPTIONS(), @@ -1136,6 +1153,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, NULL }; unsigned long id; + bool json = false; argc = parse_options(argc, argv, options, u, 0); @@ -1160,7 +1178,14 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, return -EINVAL; } - if (param.json || param.human) { + json = param.json || param.human; + if (action == action_read && json && (param.len || param.offset)) { + fprintf(stderr, "--size and --offset are incompatible with --json\n"); + usage_with_options(u, options); + return -EINVAL; + } + + if (json) { actx.jdimms = json_object_new_array(); if (!actx.jdimms) return -ENOMEM; @@ -1294,7 +1319,7 @@ int cmd_read_labels(int argc, const char **argv, struct ndctl_ctx *ctx) int cmd_zero_labels(int argc, const char **argv, struct ndctl_ctx *ctx) { - int count = dimm_action(argc, argv, ctx, action_zero, base_options, + int count = dimm_action(argc, argv, ctx, action_zero, zero_options, "ndctl zero-labels [..] []"); fprintf(stderr, "zeroed %d nmem%s\n", count >= 0 ? count : 0, diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index 9c5a34e542c3..28b1dfb0bdfa 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -537,7 +537,8 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_label_index(struct ndctl_dimm *di return NULL; } -NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) +NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_label_extent( + struct ndctl_dimm *dimm, unsigned int len, unsigned int offset) { struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); struct ndctl_cmd *cmd_size, *cmd_read; @@ -557,13 +558,25 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); if (!cmd_read) goto out_size; + + /* + * For ndctl_read_labels() compat, enable subsequent calls that + * will manipulate labels + */ + if (len == 0 && offset == 0) + init_ndd(&dimm->ndd, cmd_read, cmd_size); + + if (len == 0) + len = cmd_size->get_size->config_size; + rc = ndctl_cmd_cfg_read_set_extent(cmd_read, len, offset); + if (rc < 0) + goto out_size; + rc = ndctl_cmd_submit_xlat(cmd_read); if (rc < 0) goto out_read; ndctl_cmd_unref(cmd_size); - init_ndd(&dimm->ndd, cmd_read, cmd_size); - return cmd_read; out_read: @@ -573,15 +586,21 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) return NULL; } -NDCTL_EXPORT int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm) +NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_read_label_extent(dimm, 0, 0); +} + +NDCTL_EXPORT int ndctl_dimm_zero_label_extent(struct ndctl_dimm *dimm, + unsigned int len, unsigned int offset) { struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); struct ndctl_cmd *cmd_read, *cmd_write; int rc; - cmd_read = ndctl_dimm_read_labels(dimm); + cmd_read = ndctl_dimm_read_label_extent(dimm, len, offset); if (!cmd_read) - return -ENXIO; + return -EINVAL; if (ndctl_dimm_is_active(dimm)) { dbg(ctx, "%s: regions active, abort label write\n", @@ -623,6 +642,11 @@ NDCTL_EXPORT int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm) return rc; } +NDCTL_EXPORT int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm) +{ + return ndctl_dimm_zero_label_extent(dimm, 0, 0); +} + NDCTL_EXPORT unsigned long ndctl_dimm_get_available_labels( struct ndctl_dimm *dimm) { diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 3cd431a90e55..895fb358c43a 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -412,4 +412,6 @@ global: ndctl_cmd_cfg_read_set_extent; ndctl_cmd_cfg_write_set_extent; ndctl_dimm_read_label_index; + ndctl_dimm_read_label_extent; + ndctl_dimm_zero_label_extent; } LIBNDCTL_19; diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index 3fc0290ff6a7..1f6a01c55377 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -242,9 +242,6 @@ struct ndctl_namespace { * * A command may only specify one of @source, or @iter.total_buf, not both. */ -enum { - READ, WRITE, -}; struct ndctl_cmd { struct ndctl_dimm *dimm; struct ndctl_bus *bus; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 8aa4b8bbe6c2..c9d0dc120d3b 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -307,8 +307,12 @@ struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_size(struct ndctl_dimm *dimm); struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_read(struct ndctl_cmd *cfg_size); struct ndctl_cmd *ndctl_dimm_cmd_new_cfg_write(struct ndctl_cmd *cfg_read); int ndctl_dimm_zero_labels(struct ndctl_dimm *dimm); +int ndctl_dimm_zero_label_extent(struct ndctl_dimm *dimm, + unsigned int len, unsigned int offset); struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm); struct ndctl_cmd *ndctl_dimm_read_label_index(struct ndctl_dimm *dimm); +struct ndctl_cmd *ndctl_dimm_read_label_extent(struct ndctl_dimm *dimm, + unsigned int len, unsigned int offset); int ndctl_dimm_validate_labels(struct ndctl_dimm *dimm); enum ndctl_namespace_version { NDCTL_NS_VERSION_1_1, diff --git a/util/util.h b/util/util.h index 001707e8b159..54c6ef18b6d7 100644 --- a/util/util.h +++ b/util/util.h @@ -73,6 +73,10 @@ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +enum { + READ, WRITE, +}; + static inline const char *skip_prefix(const char *str, const char *prefix) { size_t len = strlen(prefix); From patchwork Sat Jul 27 21:40:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6567D112C for ; Sat, 27 Jul 2019 21:54:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CA6D289CC for ; Sat, 27 Jul 2019 21:54:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50D5A289F2; Sat, 27 Jul 2019 21:54:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 0135C289CC for ; Sat, 27 Jul 2019 21:54:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 84090212E25AF; Sat, 27 Jul 2019 14:57:05 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 602EE212E15B4 for ; Sat, 27 Jul 2019 14:57:04 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:37 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="369983286" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:37 -0700 Subject: [ndctl PATCH v2 11/26] ndctl/dimm: Limit read-labels with --index option From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:19 -0700 Message-ID: <156426361963.531577.9756735022332101876.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Provide a capability to limit the read-labels payload to just the index-block data space. Signed-off-by: Dan Williams --- ndctl/dimm.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 603e112f9568..c7ad621367e9 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -55,6 +55,7 @@ static struct parameters { bool master_pass; bool human; bool force; + bool index; bool json; bool verbose; } param = { @@ -276,27 +277,26 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, if (!jdimm) return NULL; - jindex = dump_index_json(cmd_read, size); - if (!jindex) - goto err_jindex; - jlabel = dump_label_json(dimm, cmd_read, size, flags); - if (!jlabel) - goto err_jlabel; jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); if (!jobj) - goto err_jobj; - + goto err; json_object_object_add(jdimm, "dev", jobj); + + jindex = dump_index_json(cmd_read, size); + if (!jindex) + goto err; json_object_object_add(jdimm, "index", jindex); + if (param.index) + return jdimm; + + jlabel = dump_label_json(dimm, cmd_read, size, flags); + if (!jlabel) + goto err; json_object_object_add(jdimm, "label", jlabel); - return jdimm; - err_jobj: - json_object_put(jlabel); - err_jlabel: - json_object_put(jindex); - err_jindex: + return jdimm; +err: json_object_put(jdimm); return NULL; } @@ -385,7 +385,11 @@ static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) ssize_t size; int rc = 0; - cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, param.offset); + if (param.index) + cmd_read = ndctl_dimm_read_label_index(dimm); + else + cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, + param.offset); if (!cmd_read) return -EINVAL; @@ -1054,7 +1058,8 @@ OPT_BOOLEAN('v',"verbose", ¶m.verbose, "turn on debug") OPT_STRING('o', "output", ¶m.outfile, "output-file", \ "filename to write label area contents"), \ OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json"), \ -OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats (implies --json)") +OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats (implies --json)"), \ +OPT_BOOLEAN('I', "index", ¶m.index, "limit read to the index block area") #define WRITE_OPTIONS() \ OPT_STRING('i', "input", ¶m.infile, "input-file", \ @@ -1185,6 +1190,12 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, return -EINVAL; } + if (param.index && param.len) { + fprintf(stderr, "pick either --size, or --index, not both\n"); + usage_with_options(u, options); + return -EINVAL; + } + if (json) { actx.jdimms = json_object_new_array(); if (!actx.jdimms) From patchwork Sat Jul 27 21:40:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8902B1399 for ; Sat, 27 Jul 2019 21:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81A86289CC for ; Sat, 27 Jul 2019 21:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 762B8289F2; Sat, 27 Jul 2019 21:54:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 3ADE3289CC for ; Sat, 27 Jul 2019 21:54:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C4380212E25AE; Sat, 27 Jul 2019 14:57:11 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2F2EA212E258A for ; Sat, 27 Jul 2019 14:57:09 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:43 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="194804318" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:42 -0700 Subject: [ndctl PATCH v2 12/26] ndctl/namespace: Minimize label data transfer for autolabel From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:25 -0700 Message-ID: <156426362517.531577.97948221719947571.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Use the new ndctl_dimm_read_label_index() helper to minimize the amount of label I/O needed to execute an autolabel event. Signed-off-by: Dan Williams --- ndctl/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 645aa14882bb..a3963d79831a 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -1029,7 +1029,7 @@ retry: int num_labels, avail; ndctl_cmd_unref(cmd_read); - cmd_read = ndctl_dimm_read_labels(dimm); + cmd_read = ndctl_dimm_read_label_index(dimm); if (!cmd_read) continue; From patchwork Sat Jul 27 21:40:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFC051399 for ; Sat, 27 Jul 2019 21:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D75BF289CC for ; Sat, 27 Jul 2019 21:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB708289F2; Sat, 27 Jul 2019 21:54:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 75B62289CC for ; Sat, 27 Jul 2019 21:54:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0AE6A212E2594; Sat, 27 Jul 2019 14:57:17 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6D56E212E2590 for ; Sat, 27 Jul 2019 14:57:15 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:48 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="178765165" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:48 -0700 Subject: [ndctl PATCH v2 13/26] ndctl/namespace: Disable autorecovery of create-namespace failures From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:30 -0700 Message-ID: <156426363088.531577.18014256906347104823.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Add an option to disable the behavior of cleaning up namespaces that failed creation. This is useful for doing forensics on the label and info-block state after the failure with assurances that the kernel has not made further modifications. Signed-off-by: Dan Williams --- Documentation/ndctl/ndctl-create-namespace.txt | 9 +++++++++ ndctl/namespace.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Documentation/ndctl/ndctl-create-namespace.txt b/Documentation/ndctl/ndctl-create-namespace.txt index 343733dedfd9..ed936c87e483 100644 --- a/Documentation/ndctl/ndctl-create-namespace.txt +++ b/Documentation/ndctl/ndctl-create-namespace.txt @@ -203,6 +203,15 @@ OPTIONS ndctl init-labels all ndctl enable-region all +-R:: +--autorecover:: +--no-autorecover:: + By default, if a namespace creation attempt fails, ndctl will + cleanup the partially initialized namespace. Use + --no-autorecover to disable this behavior for debug and + development scenarios where it useful to have the label and + info-block state preserved after a failure. + -v:: --verbose:: Emit debug messages for the namespace creation process diff --git a/ndctl/namespace.c b/ndctl/namespace.c index a3963d79831a..58fec194ab94 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -43,6 +43,7 @@ static struct parameters { bool mode_default; bool autolabel; bool verify; + bool autorecover; bool human; bool json; const char *bus; @@ -60,6 +61,7 @@ static struct parameters { const char *infile; } param = { .autolabel = true, + .autorecover = true, }; void builtin_xaction_namespace_reset(void) @@ -84,6 +86,7 @@ struct parsed_parameters { unsigned long sector_size; unsigned long align; bool autolabel; + bool autorecover; }; #define pr_verbose(fmt, ...) \ @@ -127,7 +130,8 @@ OPT_STRING('t', "type", ¶m.type, "type", \ OPT_STRING('a', "align", ¶m.align, "align", \ "specify the namespace alignment in bytes (default: 2M)"), \ OPT_BOOLEAN('f', "force", &force, "reconfigure namespace even if currently active"), \ -OPT_BOOLEAN('L', "autolabel", ¶m.autolabel, "automatically initialize labels") +OPT_BOOLEAN('L', "autolabel", ¶m.autolabel, "automatically initialize labels"), \ +OPT_BOOLEAN('R', "autorecover", ¶m.autorecover, "automatically cleanup on failure") #define CHECK_OPTIONS() \ OPT_BOOLEAN('R', "repair", &repair, "perform metadata repairs"), \ @@ -444,7 +448,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_pfn, set_align, pfn, p->align); try(ndctl_pfn, set_namespace, pfn, ndns); rc = ndctl_pfn_enable(pfn); - if (rc) + if (rc && p->autorecover) ndctl_pfn_set_namespace(pfn, NULL); } else if (p->mode == NDCTL_NS_MODE_DAX) { struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); @@ -455,7 +459,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_dax, set_align, dax, p->align); try(ndctl_dax, set_namespace, dax, ndns); rc = ndctl_dax_enable(dax); - if (rc) + if (rc && p->autorecover) ndctl_dax_set_namespace(dax, NULL); } else if (p->mode == NDCTL_NS_MODE_SAFE) { struct ndctl_btt *btt = ndctl_region_get_btt_seed(region); @@ -798,6 +802,7 @@ static int validate_namespace_options(struct ndctl_region *region, p->autolabel = param.autolabel; + p->autorecover = param.autorecover; return 0; } @@ -852,7 +857,7 @@ static int namespace_create(struct ndctl_region *region) } rc = setup_namespace(region, ndns, &p); - if (rc) { + if (rc && p.autorecover) { ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_RAW); ndctl_namespace_delete(ndns); } From patchwork Sat Jul 27 21:40:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34758112C for ; Sat, 27 Jul 2019 21:54:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CF1A289CC for ; Sat, 27 Jul 2019 21:54:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 214D028A0B; Sat, 27 Jul 2019 21:54:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D0F97289D2 for ; Sat, 27 Jul 2019 21:54:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4F8C5212E25B8; Sat, 27 Jul 2019 14:57:23 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3DE18212E2590 for ; Sat, 27 Jul 2019 14:57:21 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:54 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="198966346" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:54 -0700 Subject: [ndctl PATCH v2 14/26] ndctl/namespace: Handle 'create-namespace' in label-less mode From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:36 -0700 Message-ID: <156426363655.531577.4504452379578995249.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP A common confusion with ndctl is that 'create-namespace' does not work in the label-less case. In the label-less case there is no capacity to allocate as the size if already hard-coded by the region boundary. However, users typically do something like the following in the label-less case: # ndctl list { "dev":"namespace1.0", "mode":"raw", "size":"127.00 GiB (136.37 GB)", "sector_size":512, "blockdev":"pmem1" } # ndctl destroy-namespace namespace1.0 -f destroyed 1 namespace # ndctl create-namespace failed to create namespace: Resource temporarily unavailable In other words they destroy the raw mode namespace that they don't want, and seek to create a new default configuration namespace. Since there is no "available_capacity" in the label-less case the 'create' attempt fails. Fix this by recognizing that the user wants a default sized namespace and just reconfigure the raw namespace. Signed-off-by: Dan Williams --- ndctl/namespace.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 58fec194ab94..e5a2b1341cdb 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -837,9 +837,13 @@ static int namespace_create(struct ndctl_region *region) return -EAGAIN; } - available = ndctl_region_get_max_available_extent(region); - if (available == ULLONG_MAX) - available = ndctl_region_get_available_size(region); + 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); From patchwork Sat Jul 27 21:40:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77B6D112C for ; Sat, 27 Jul 2019 21:55:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DDBE289CC for ; Sat, 27 Jul 2019 21:55:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CF87289F2; Sat, 27 Jul 2019 21:55:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1AE40289CC for ; Sat, 27 Jul 2019 21:55:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7D678212E25BE; Sat, 27 Jul 2019 14:57:28 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 007D9212E259E for ; Sat, 27 Jul 2019 14:57:26 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:00 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="190061089" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:54:59 -0700 Subject: [ndctl PATCH v2 15/26] ndctl/dimm: Fix init-labels success reporting From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:42 -0700 Message-ID: <156426364243.531577.13465180915476535003.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP When a DIMM is disabled due to a label parsing issue "ndctl init-labels" mis-reports the status of the init-labels command: # ndctl init-labels all -f initialized 1 nmem [root@dwillia2-dev ndctl]# ndctl list -Di [ { "dev":"nmem1", "id":"8680-57341200", "handle":2, "phys_id":0, "state":"disabled" }, { "dev":"nmem0", "id":"8680-56341200", "handle":1, "phys_id":0 } ] # ndctl init-labels nmem1 -f initialized 1020 nmems Catch any positive return from action_init() as success: # ndctl init-labels all -f initialized 2 nmems # ndctl init-labels nmem1 -f initialized 1 nmem Reported-by: Jane Chu Signed-off-by: Dan Williams --- ndctl/dimm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index c7ad621367e9..5e6fa19bab15 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -1035,7 +1035,7 @@ static int __action_init(struct ndctl_dimm *dimm, out: ndctl_cmd_unref(cmd_read); - return rc; + return rc >= 0 ? 0 : rc; } static int action_init(struct ndctl_dimm *dimm, struct action_context *actx) From patchwork Sat Jul 27 21:40:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 867D31399 for ; Sat, 27 Jul 2019 21:55:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D810289CC for ; Sat, 27 Jul 2019 21:55:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71579289F2; Sat, 27 Jul 2019 21:55:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B041289CC for ; Sat, 27 Jul 2019 21:55:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C5FFE212E46E1; Sat, 27 Jul 2019 14:57:32 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 99B57212E46E7 for ; Sat, 27 Jul 2019 14:57:31 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:04 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="164999484" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:04 -0700 Subject: [ndctl PATCH v2 16/26] ndctl/test: Fix device-dax bus-model detection From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:47 -0700 Message-ID: <156426364779.531577.16728668403285407838.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Don't look for bus-model patches on pre-v5.1 kernels. Signed-off-by: Dan Williams --- test/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/core.c b/test/core.c index b9e3bbf7d7a9..888f5d8c0e42 100644 --- a/test/core.c +++ b/test/core.c @@ -168,6 +168,16 @@ int nfit_test_init(struct kmod_ctx **ctx, struct kmod_module **mod, && !ndctl_test_attempt(test, KERNEL_VERSION(4, 7, 0))) continue; + + /* + * Skip device-dax bus-model modules on pre-v5.1 + */ + if ((strstr(name, "dax_pmem_core") + || strstr(name, "dax_pmem_compat")) + && !ndctl_test_attempt(test, + KERNEL_VERSION(5, 1, 0))) + continue; + retry: rc = kmod_module_new_from_name(*ctx, name, mod); if (rc) { From patchwork Sat Jul 27 21:40:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E53801399 for ; Sat, 27 Jul 2019 21:55:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCB70289CC for ; Sat, 27 Jul 2019 21:55:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0D8D289F2; Sat, 27 Jul 2019 21:55:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 7EBC8289CC for ; Sat, 27 Jul 2019 21:55:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 10CFE212E46E5; Sat, 27 Jul 2019 14:57:38 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 259BC212E259E for ; Sat, 27 Jul 2019 14:57:37 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:10 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="161739904" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:09 -0700 Subject: [ndctl PATCH v2 17/26] ndctl/test: Checkout device-mapper + dax operation From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:52 -0700 Message-ID: <156426365289.531577.3024221395183254159.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Given recent kernel changes broke the device-mapper use case, introduce a basic unit test to prevent this from regressing in the future. Signed-off-by: Dan Williams --- test/Makefile.am | 1 + test/dm.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100755 test/dm.sh diff --git a/test/Makefile.am b/test/Makefile.am index 874c4bbfaa90..2a1e03d26f6c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -49,6 +49,7 @@ TESTS +=\ dax.sh \ device-dax \ device-dax-fio.sh \ + dm.sh \ mmap.sh if ENABLE_KEYUTILS diff --git a/test/dm.sh b/test/dm.sh new file mode 100755 index 000000000000..fb498c95a29b --- /dev/null +++ b/test/dm.sh @@ -0,0 +1,75 @@ +#!/bin/bash -x +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2015-2019 Intel Corporation. All rights reserved. + +set -e + +SKIP=77 +FAIL=1 +SUCCESS=0 + +. ./common + +MNT=test_dax_mnt +TEST_DM_PMEM=/dev/mapper/test_pmem +NAME=$(basename $TEST_DM_PMEM) + +mkdir -p $MNT + +TEST_SIZE=$((1<<30)) + +rc=$FAIL +cleanup() { + if [ $rc -ne $SUCCESS ]; then + echo "test/dm.sh: failed at line $1" + fi + if mountpoint -q $MNT; then + umount $MNT + fi + + if [ -L $TEST_DM_PMEM ]; then + dmsetup remove $TEST_DM_PMEM + fi + rmdir $MNT + # opportunistic cleanup, not fatal if these fail + namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") + for i in $namespaces + do + if ! $NDCTL destroy-namespace -f $i; then + echo "test/sub-section.sh: cleanup() failed to destroy $i" + fi + done + exit $rc +} + +trap 'err $LINENO cleanup' ERR + +dev="x" +json=$($NDCTL create-namespace -b ACPI.NFIT -s $TEST_SIZE -t pmem -m fsdax -n "$NAME") +eval $(echo $json | json2var ) +[ $dev = "x" ] && echo "fail: $LINENO" && exit 1 +[ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 + +pmem0=/dev/$blockdev +size0=$((size/512)) + +json=$($NDCTL create-namespace -b ACPI.NFIT -s $TEST_SIZE -t pmem -m fsdax -n "$NAME") +eval $(echo $json | json2var ) +[ $dev = "x" ] && echo "fail: $LINENO" && exit 1 +[ $mode != "fsdax" ] && echo "fail: $LINENO" && exit 1 + +pmem1=/dev/$blockdev +size1=$((size/512)) + +cat < X-Patchwork-Id: 11062727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4885C112C for ; Sat, 27 Jul 2019 21:55:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FF90289CC for ; Sat, 27 Jul 2019 21:55:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34567289F2; Sat, 27 Jul 2019 21:55:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D240A289CC for ; Sat, 27 Jul 2019 21:55:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5C2DB212E46EA; Sat, 27 Jul 2019 14:57:43 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DE7FB212E259E for ; Sat, 27 Jul 2019 14:57:41 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:15 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="175977682" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:15 -0700 Subject: [ndctl PATCH v2 18/26] ndctl/test: Exercise sub-section sized namespace creation/deletion From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:40:58 -0700 Message-ID: <156426365799.531577.4076109633772194960.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP For kernels that have removed the section-aligned namespace constraint validate that multiple namespaces can be created / deleted that collide within a given section. While this test acts on the ACPI.NFIT bus it is not marked "destructive" because it only operates in available capacity and marks each namespace created with a unique volume name ("subsection-test"). Signed-off-by: Dan Williams --- test/Makefile.am | 1 + test/sub-section.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 test/sub-section.sh diff --git a/test/Makefile.am b/test/Makefile.am index 2a1e03d26f6c..decc8377258a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -45,6 +45,7 @@ if ENABLE_DESTRUCTIVE TESTS +=\ blk-ns \ pmem-ns \ + sub-section.sh \ dax-dev \ dax.sh \ device-dax \ diff --git a/test/sub-section.sh b/test/sub-section.sh new file mode 100755 index 000000000000..c624fbdb2ce0 --- /dev/null +++ b/test/sub-section.sh @@ -0,0 +1,78 @@ +#!/bin/bash -x + +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2015-2019 Intel Corporation. All rights reserved. + +set -e + +SKIP=77 +FAIL=1 +SUCCESS=0 + +. ./common + +check_min_kver "5.3" || do_skip "may lack align sub-section hotplug support" + +MNT=test_dax_mnt +mkdir -p $MNT + +TEST_SIZE=$((16<<20)) +MIN_AVAIL=$((TEST_SIZE*4)) +MAX_NS=10 +NAME="subsection-test" + +ndctl list -N | jq -r ".[] | select(.name==\"subsection-test\") | .dev" + +rc=$FAIL +cleanup() { + if [ $rc -ne $SUCCESS ]; then + echo "test/sub-section.sh: failed at line $1" + fi + if mountpoint -q $MNT; then + umount $MNT + fi + rmdir $MNT + # opportunistic cleanup, not fatal if these fail + namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") + for i in $namespaces + do + if ! $NDCTL destroy-namespace -f $i; then + echo "test/sub-section.sh: cleanup() failed to destroy $i" + fi + done + exit $rc +} + +trap 'err $LINENO cleanup' ERR + +json=$($NDCTL list -R -b ACPI.NFIT) +region=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].dev") +avail=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].available_size") +if [ -z $region ]; then + exit $SKIP +fi + +iter=$((avail/TEST_SIZE)) +if [ $iter -gt $MAX_NS ]; then + iter=$MAX_NS; +fi + +for i in $(seq 1 $iter) +do + json=$($NDCTL create-namespace -s $TEST_SIZE --no-autorecover -r $region -n "$NAME") + dev=$(echo $json | jq -r ".blockdev") + mkfs.ext4 -b 4096 /dev/$dev + mount -o dax /dev/$dev $MNT + umount $MNT +done + +namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") +for i in $namespaces +do + $NDCTL disable-namespace $i + $NDCTL enable-namespace $i + $NDCTL destroy-namespace $i -f +done + +rc=$SUCCESS +cleanup $LINENO From patchwork Sat Jul 27 21:41:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D5BA1399 for ; Sat, 27 Jul 2019 21:55:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 140E2289CC for ; Sat, 27 Jul 2019 21:55:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08310289F2; Sat, 27 Jul 2019 21:55:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 47962289CC for ; Sat, 27 Jul 2019 21:55:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C8D1E212E46EE; Sat, 27 Jul 2019 14:57:48 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 85C9F212E25B5 for ; Sat, 27 Jul 2019 14:57:47 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:20 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="346216792" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:20 -0700 Subject: [ndctl PATCH v2 19/26] ndctl/namespace: Kill off the legacy mode names From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:03 -0700 Message-ID: <156426366309.531577.11554918086632763562.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP The command line interface switched to "fsdax", "devdax", and "sector" for the mode names. Kill off the remaining instances of "memory", "dax", and "safe". Signed-off-by: Dan Williams --- ndctl/lib/libndctl.c | 4 ++- ndctl/libndctl.h | 1 + ndctl/namespace.c | 66 +++++++++++++++++++++++++------------------------- test/libndctl.c | 6 ++--- util/filter.c | 4 ++- util/json.c | 4 ++- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index c1ecdd8c9c61..e81d64dc8aa8 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -3405,7 +3405,7 @@ static const char *enforce_id_to_name(enum ndctl_namespace_mode mode) { static const char *id_to_name[] = { [NDCTL_NS_MODE_MEMORY] = "pfn", - [NDCTL_NS_MODE_SAFE] = "btt", /* TODO: convert to btt2 */ + [NDCTL_NS_MODE_SECTOR] = "btt", /* TODO: convert to btt2 */ [NDCTL_NS_MODE_RAW] = "", [NDCTL_NS_MODE_DAX] = "dax", [NDCTL_NS_MODE_UNKNOWN] = "", @@ -3728,7 +3728,7 @@ NDCTL_EXPORT enum ndctl_namespace_mode ndctl_namespace_get_mode( if (strcmp("raw", buf) == 0) return NDCTL_NS_MODE_RAW; if (strcmp("safe", buf) == 0) - return NDCTL_NS_MODE_SAFE; + return NDCTL_NS_MODE_SECTOR; return -ENXIO; } diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index c9d0dc120d3b..f3f2ef66c5a8 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -472,6 +472,7 @@ enum ndctl_namespace_mode { NDCTL_NS_MODE_MEMORY, NDCTL_NS_MODE_FSDAX = NDCTL_NS_MODE_MEMORY, NDCTL_NS_MODE_SAFE, + NDCTL_NS_MODE_SECTOR = NDCTL_NS_MODE_SAFE, NDCTL_NS_MODE_RAW, NDCTL_NS_MODE_DAX, NDCTL_NS_MODE_DEVDAX = NDCTL_NS_MODE_DAX, diff --git a/ndctl/namespace.c b/ndctl/namespace.c index e5a2b1341cdb..f958726a994d 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -225,9 +225,9 @@ static int set_defaults(enum device_action mode) } } else if (!param.reconfig && param.type) { if (strcmp(param.type, "pmem") == 0) - param.mode = "memory"; + param.mode = "fsdax"; else - param.mode = "safe"; + param.mode = "sector"; param.mode_default = true; } @@ -242,9 +242,9 @@ static int set_defaults(enum device_action mode) } if (!param.reconfig && param.mode - && strcmp(param.mode, "memory") != 0 - && strcmp(param.mode, "dax") != 0) { - error("--map only valid for an dax mode pmem namespace\n"); + && strcmp(param.mode, "fsdax") != 0 + && strcmp(param.mode, "devdax") != 0) { + error("--map only valid for an devdax mode pmem namespace\n"); rc = -EINVAL; } } else if (!param.reconfig) @@ -252,8 +252,8 @@ static int set_defaults(enum device_action mode) /* check for incompatible mode and type combinations */ if (param.type && param.mode && strcmp(param.type, "blk") == 0 - && (strcmp(param.mode, "memory") == 0 - || strcmp(param.mode, "dax") == 0)) { + && (strcmp(param.mode, "fsdax") == 0 + || strcmp(param.mode, "devdax") == 0)) { error("only 'pmem' namespaces support dax operation\n"); rc = -ENXIO; } @@ -377,7 +377,7 @@ do { \ static bool do_setup_pfn(struct ndctl_namespace *ndns, struct parsed_parameters *p) { - if (p->mode != NDCTL_NS_MODE_MEMORY) + if (p->mode != NDCTL_NS_MODE_FSDAX) return false; /* @@ -385,7 +385,7 @@ static bool do_setup_pfn(struct ndctl_namespace *ndns, * instance, and a pfn device is required to place the memmap * array in device memory. */ - if (!ndns || ndctl_namespace_get_mode(ndns) != NDCTL_NS_MODE_MEMORY + if (!ndns || ndctl_namespace_get_mode(ndns) != NDCTL_NS_MODE_FSDAX || p->loc == NDCTL_PFN_LOC_PMEM) return true; @@ -419,7 +419,7 @@ static int setup_namespace(struct ndctl_region *region, if (i < num) try(ndctl_namespace, set_sector_size, ndns, p->sector_size); - else if (p->mode == NDCTL_NS_MODE_SAFE) + else if (p->mode == NDCTL_NS_MODE_SECTOR) /* pass, the btt sector_size will override */; else if (p->sector_size != 512) { error("%s: sector_size: %ld not supported\n", @@ -450,7 +450,7 @@ static int setup_namespace(struct ndctl_region *region, rc = ndctl_pfn_enable(pfn); if (rc && p->autorecover) ndctl_pfn_set_namespace(pfn, NULL); - } else if (p->mode == NDCTL_NS_MODE_DAX) { + } else if (p->mode == NDCTL_NS_MODE_DEVDAX) { struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); try(ndctl_dax, set_uuid, dax, uuid); @@ -461,7 +461,7 @@ static int setup_namespace(struct ndctl_region *region, rc = ndctl_dax_enable(dax); if (rc && p->autorecover) ndctl_dax_set_namespace(dax, NULL); - } else if (p->mode == NDCTL_NS_MODE_SAFE) { + } else if (p->mode == NDCTL_NS_MODE_SECTOR) { struct ndctl_btt *btt = ndctl_region_get_btt_seed(region); /* @@ -560,28 +560,28 @@ static int validate_namespace_options(struct ndctl_region *region, if (param.mode) { if (strcmp(param.mode, "memory") == 0) - p->mode = NDCTL_NS_MODE_MEMORY; + p->mode = NDCTL_NS_MODE_FSDAX; else if (strcmp(param.mode, "sector") == 0) - p->mode = NDCTL_NS_MODE_SAFE; + p->mode = NDCTL_NS_MODE_SECTOR; else if (strcmp(param.mode, "safe") == 0) - p->mode = NDCTL_NS_MODE_SAFE; + p->mode = NDCTL_NS_MODE_SECTOR; else if (strcmp(param.mode, "dax") == 0) - p->mode = NDCTL_NS_MODE_DAX; + p->mode = NDCTL_NS_MODE_DEVDAX; else p->mode = NDCTL_NS_MODE_RAW; if (ndctl_region_get_type(region) != ND_DEVICE_REGION_PMEM - && (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX)) { + && (p->mode == NDCTL_NS_MODE_FSDAX + || p->mode == NDCTL_NS_MODE_DEVDAX)) { debug("blk %s does not support %s mode\n", region_name, - p->mode == NDCTL_NS_MODE_MEMORY + p->mode == NDCTL_NS_MODE_FSDAX ? "fsdax" : "devdax"); return -EAGAIN; } } else if (ndns) p->mode = ndctl_namespace_get_mode(ndns); - if (p->mode == NDCTL_NS_MODE_MEMORY) { + if (p->mode == NDCTL_NS_MODE_FSDAX) { pfn = ndctl_region_get_pfn_seed(region); if (!pfn && param.mode_default) { debug("%s fsdax mode not available\n", region_name); @@ -590,7 +590,7 @@ static int validate_namespace_options(struct ndctl_region *region, /* * NB: We only fail validation if a pfn-specific option is used */ - } else if (p->mode == NDCTL_NS_MODE_DAX) { + } else if (p->mode == NDCTL_NS_MODE_DEVDAX) { dax = ndctl_region_get_dax_seed(region); if (!dax) { error("Kernel does not support devdax mode\n"); @@ -602,7 +602,7 @@ static int validate_namespace_options(struct ndctl_region *region, int i, alignments; switch (p->mode) { - case NDCTL_NS_MODE_MEMORY: + case NDCTL_NS_MODE_FSDAX: if (!pfn) { error("Kernel does not support setting an alignment in fsdax mode\n"); return -EINVAL; @@ -611,13 +611,13 @@ static int validate_namespace_options(struct ndctl_region *region, alignments = ndctl_pfn_get_num_alignments(pfn); break; - case NDCTL_NS_MODE_DAX: + case NDCTL_NS_MODE_DEVDAX: alignments = ndctl_dax_get_num_alignments(dax); break; default: error("%s mode does not support setting an alignment\n", - p->mode == NDCTL_NS_MODE_SAFE + p->mode == NDCTL_NS_MODE_SECTOR ? "sector" : "raw"); return -ENXIO; } @@ -626,7 +626,7 @@ static int validate_namespace_options(struct ndctl_region *region, for (i = 0; i < alignments; i++) { uint64_t a; - if (p->mode == NDCTL_NS_MODE_MEMORY) + if (p->mode == NDCTL_NS_MODE_FSDAX) a = ndctl_pfn_get_supported_alignment(pfn, i); else a = ndctl_dax_get_supported_alignment(dax, i); @@ -645,7 +645,7 @@ static int validate_namespace_options(struct ndctl_region *region, * one. If we don't then use PAGE_SIZE so the size_align * checking works. */ - if (p->mode == NDCTL_NS_MODE_MEMORY) { + if (p->mode == NDCTL_NS_MODE_FSDAX) { /* * The initial pfn device support in the kernel didn't * have the 'align' sysfs attribute and assumed a 2MB @@ -656,7 +656,7 @@ static int validate_namespace_options(struct ndctl_region *region, p->align = ndctl_pfn_get_align(pfn); else p->align = SZ_2M; - } else if (p->mode == NDCTL_NS_MODE_DAX) { + } else if (p->mode == NDCTL_NS_MODE_DEVDAX) { /* * device dax mode was added after the align attribute * so checking for it is unnecessary. @@ -717,7 +717,7 @@ static int validate_namespace_options(struct ndctl_region *region, p->sector_size = parse_size64(param.sector_size); btt = ndctl_region_get_btt_seed(region); - if (p->mode == NDCTL_NS_MODE_SAFE) { + if (p->mode == NDCTL_NS_MODE_SECTOR) { if (!btt) { debug("%s: does not support 'sector' mode\n", region_name); @@ -757,7 +757,7 @@ static int validate_namespace_options(struct ndctl_region *region, * sector size, otherwise fall back to what the * namespace supports. */ - if (btt && p->mode == NDCTL_NS_MODE_SAFE) + if (btt && p->mode == NDCTL_NS_MODE_SECTOR) p->sector_size = ndctl_btt_get_sector_size(btt); else p->sector_size = ndctl_namespace_get_sector_size(ndns); @@ -784,14 +784,14 @@ static int validate_namespace_options(struct ndctl_region *region, else p->loc = NDCTL_PFN_LOC_PMEM; - if (ndns && p->mode != NDCTL_NS_MODE_MEMORY - && p->mode != NDCTL_NS_MODE_DAX) { + if (ndns && p->mode != NDCTL_NS_MODE_FSDAX + && p->mode != NDCTL_NS_MODE_DEVDAX) { debug("%s: --map= only valid for fsdax mode namespace\n", ndctl_namespace_get_devname(ndns)); return -EINVAL; } - } else if (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX) + } else if (p->mode == NDCTL_NS_MODE_FSDAX + || p->mode == NDCTL_NS_MODE_DEVDAX) p->loc = NDCTL_PFN_LOC_PMEM; if (!pfn && do_setup_pfn(ndns, p)) { diff --git a/test/libndctl.c b/test/libndctl.c index 02bb9ccaa465..daddbf919b79 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -1080,7 +1080,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace devname = ndctl_btt_get_devname(btt); ndctl_btt_set_uuid(btt, btt_s->uuid); ndctl_btt_set_sector_size(btt, btt_s->sector_sizes[i]); - rc = ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_SAFE); + rc = ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_SECTOR); if (ndctl_test_attempt(test, KERNEL_VERSION(4, 13, 0)) && rc < 0) { fprintf(stderr, "%s: failed to enforce btt mode\n", devname); goto err; @@ -1100,7 +1100,7 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace /* prior to v4.5 the mode attribute did not exist */ if (ndctl_test_attempt(test, KERNEL_VERSION(4, 5, 0))) { mode = ndctl_namespace_get_mode(ndns); - if (mode >= 0 && mode != NDCTL_NS_MODE_SAFE) + if (mode >= 0 && mode != NDCTL_NS_MODE_SECTOR) fprintf(stderr, "%s: expected safe mode got: %d\n", devname, mode); } @@ -1474,7 +1474,7 @@ static int check_btt_autodetect(struct ndctl_bus *bus, mode = ndctl_namespace_get_enforce_mode(ndns); if (ndctl_test_attempt(test, KERNEL_VERSION(4, 13, 0)) - && mode != NDCTL_NS_MODE_SAFE) { + && mode != NDCTL_NS_MODE_SECTOR) { fprintf(stderr, "%s expected enforce_mode btt\n", devname); return -ENXIO; } diff --git a/util/filter.c b/util/filter.c index 1734bce537f1..ce6239fbac3b 100644 --- a/util/filter.c +++ b/util/filter.c @@ -345,9 +345,9 @@ static enum ndctl_namespace_mode mode_to_type(const char *mode) else if (strcasecmp(mode, "fsdax") == 0) return NDCTL_NS_MODE_MEMORY; else if (strcasecmp(mode, "sector") == 0) - return NDCTL_NS_MODE_SAFE; + return NDCTL_NS_MODE_SECTOR; else if (strcasecmp(mode, "safe") == 0) - return NDCTL_NS_MODE_SAFE; + return NDCTL_NS_MODE_SECTOR; else if (strcasecmp(mode, "dax") == 0) return NDCTL_NS_MODE_DAX; else if (strcasecmp(mode, "devdax") == 0) diff --git a/util/json.c b/util/json.c index babdc8c47565..3e171e7672ae 100644 --- a/util/json.c +++ b/util/json.c @@ -904,7 +904,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, jobj = json_object_new_string("devdax"); loc = ndctl_dax_get_location(dax); break; - case NDCTL_NS_MODE_SAFE: + case NDCTL_NS_MODE_SECTOR: if (!btt) goto err; jobj = json_object_new_string("sector"); @@ -920,7 +920,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, if (jobj) json_object_object_add(jndns, "mode", jobj); - if ((mode != NDCTL_NS_MODE_SAFE) && (mode != NDCTL_NS_MODE_RAW)) { + if ((mode != NDCTL_NS_MODE_SECTOR) && (mode != NDCTL_NS_MODE_RAW)) { jobj = json_object_new_string(locations[loc]); if (jobj) json_object_object_add(jndns, "map", jobj); From patchwork Sat Jul 27 21:41:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D30A1399 for ; Sat, 27 Jul 2019 21:55:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14C00289CC for ; Sat, 27 Jul 2019 21:55:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 092D4289F2; Sat, 27 Jul 2019 21:55:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8AAEF289CC for ; Sat, 27 Jul 2019 21:55:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1AD70212E46F3; Sat, 27 Jul 2019 14:57:54 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4E39D212E259E for ; Sat, 27 Jul 2019 14:57:52 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:25 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="322416440" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:25 -0700 Subject: [ndctl PATCH v2 20/26] ndctl/namespace: Introduce mode-to-name and name-to-mode helpers From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:08 -0700 Message-ID: <156426366820.531577.12558755097769166345.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Before open coding yet another translation between modes and their text name, introduce a util_nsmode() and util_nsmode_name() helpers. Consolidate the existing mode_to_type() helper into the new common / public util. Signed-off-by: Dan Williams --- ndctl/namespace.c | 39 +++++++-------------------------------- util/filter.c | 42 +++++++++++++++++++++++++++--------------- util/filter.h | 3 +++ 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index f958726a994d..43a5fccac491 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -205,21 +205,7 @@ static int set_defaults(enum device_action mode) param.type = "pmem"; if (param.mode) { - if (strcmp(param.mode, "safe") == 0) - /* pass */; - else if (strcmp(param.mode, "sector") == 0) - param.mode = "safe"; /* pass */ - else if (strcmp(param.mode, "memory") == 0) - /* pass */; - else if (strcmp(param.mode, "fsdax") == 0) - param.mode = "memory"; /* pass */ - else if (strcmp(param.mode, "raw") == 0) - /* pass */; - else if (strcmp(param.mode, "dax") == 0) - /* pass */; - else if (strcmp(param.mode, "devdax") == 0) - param.mode = "dax"; /* pass */ - else { + if (util_nsmode(param.mode) == NDCTL_NS_MODE_UNKNOWN) { error("invalid mode '%s'\n", param.mode); rc = -EINVAL; } @@ -285,7 +271,7 @@ static int set_defaults(enum device_action mode) rc = -EINVAL; } } else if (((param.type && strcmp(param.type, "blk") == 0) - || (param.mode && strcmp(param.mode, "safe") == 0))) { + || util_nsmode(param.mode) == NDCTL_NS_MODE_SECTOR)) { /* default sector size for blk-type or safe-mode */ param.sector_size = "4096"; } @@ -559,23 +545,12 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.mode) { - if (strcmp(param.mode, "memory") == 0) - p->mode = NDCTL_NS_MODE_FSDAX; - else if (strcmp(param.mode, "sector") == 0) - p->mode = NDCTL_NS_MODE_SECTOR; - else if (strcmp(param.mode, "safe") == 0) - p->mode = NDCTL_NS_MODE_SECTOR; - else if (strcmp(param.mode, "dax") == 0) - p->mode = NDCTL_NS_MODE_DEVDAX; - else - p->mode = NDCTL_NS_MODE_RAW; - + p->mode = util_nsmode(param.mode); if (ndctl_region_get_type(region) != ND_DEVICE_REGION_PMEM && (p->mode == NDCTL_NS_MODE_FSDAX || p->mode == NDCTL_NS_MODE_DEVDAX)) { debug("blk %s does not support %s mode\n", region_name, - p->mode == NDCTL_NS_MODE_FSDAX - ? "fsdax" : "devdax"); + util_nsmode_name(p->mode)); return -EAGAIN; } } else if (ndns) @@ -593,7 +568,8 @@ static int validate_namespace_options(struct ndctl_region *region, } else if (p->mode == NDCTL_NS_MODE_DEVDAX) { dax = ndctl_region_get_dax_seed(region); if (!dax) { - error("Kernel does not support devdax mode\n"); + error("Kernel does not support %s mode\n", + util_nsmode_name(p->mode)); return -ENODEV; } } @@ -617,8 +593,7 @@ static int validate_namespace_options(struct ndctl_region *region, default: error("%s mode does not support setting an alignment\n", - p->mode == NDCTL_NS_MODE_SECTOR - ? "sector" : "raw"); + util_nsmode_name(p->mode)); return -ENXIO; } diff --git a/util/filter.c b/util/filter.c index ce6239fbac3b..e4b1885b26f8 100644 --- a/util/filter.c +++ b/util/filter.c @@ -335,29 +335,41 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, return NULL; } -static enum ndctl_namespace_mode mode_to_type(const char *mode) +enum ndctl_namespace_mode util_nsmode(const char *mode) { if (!mode) - return -ENXIO; - + return NDCTL_NS_MODE_UNKNOWN; if (strcasecmp(mode, "memory") == 0) - return NDCTL_NS_MODE_MEMORY; - else if (strcasecmp(mode, "fsdax") == 0) - return NDCTL_NS_MODE_MEMORY; - else if (strcasecmp(mode, "sector") == 0) + return NDCTL_NS_MODE_FSDAX; + if (strcasecmp(mode, "fsdax") == 0) + return NDCTL_NS_MODE_FSDAX; + if (strcasecmp(mode, "sector") == 0) return NDCTL_NS_MODE_SECTOR; - else if (strcasecmp(mode, "safe") == 0) + if (strcasecmp(mode, "safe") == 0) return NDCTL_NS_MODE_SECTOR; - else if (strcasecmp(mode, "dax") == 0) - return NDCTL_NS_MODE_DAX; - else if (strcasecmp(mode, "devdax") == 0) - return NDCTL_NS_MODE_DAX; - else if (strcasecmp(mode, "raw") == 0) + if (strcasecmp(mode, "dax") == 0) + return NDCTL_NS_MODE_DEVDAX; + if (strcasecmp(mode, "devdax") == 0) + return NDCTL_NS_MODE_DEVDAX; + if (strcasecmp(mode, "raw") == 0) return NDCTL_NS_MODE_RAW; return NDCTL_NS_MODE_UNKNOWN; } +const char *util_nsmode_name(enum ndctl_namespace_mode mode) +{ + static const char *modes[] = { + [NDCTL_NS_MODE_FSDAX] = "fsdax", + [NDCTL_NS_MODE_DEVDAX] = "devdax", + [NDCTL_NS_MODE_RAW] = "raw", + [NDCTL_NS_MODE_SECTOR] = "sector", + [NDCTL_NS_MODE_UNKNOWN] = "unknown", + }; + + return modes[mode]; +} + int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx, struct util_filter_params *param) { @@ -380,7 +392,7 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx, type = ND_DEVICE_REGION_BLK; } - if (mode_to_type(param->mode) == NDCTL_NS_MODE_UNKNOWN) { + if (param->mode && util_nsmode(param->mode) == NDCTL_NS_MODE_UNKNOWN) { error("invalid mode: '%s'\n", param->mode); return -EINVAL; } @@ -458,7 +470,7 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx, continue; mode = ndctl_namespace_get_mode(ndns); - if (param->mode && mode_to_type(param->mode) != mode) + if (param->mode && util_nsmode(param->mode) != mode) continue; fctx->filter_namespace(ndns, fctx); diff --git a/util/filter.h b/util/filter.h index c2cdddf5be54..55f78f2a4cf7 100644 --- a/util/filter.h +++ b/util/filter.h @@ -38,6 +38,9 @@ struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev, const char *ident); +enum ndctl_namespace_mode util_nsmode(const char *mode); +const char *util_nsmode_name(enum ndctl_namespace_mode mode); + struct json_object; /* json object hierarchy for the util_filter_walk() performed by cmd_list() */ From patchwork Sat Jul 27 21:41:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CA4A112C for ; Sat, 27 Jul 2019 21:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 445F7289CC for ; Sat, 27 Jul 2019 21:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 368A3289F2; Sat, 27 Jul 2019 21:55:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D6E26289CC for ; Sat, 27 Jul 2019 21:55:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 69C29212E25B6; Sat, 27 Jul 2019 14:57:59 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 93C92212E259E for ; Sat, 27 Jul 2019 14:57:57 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:30 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="173436463" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:30 -0700 Subject: [ndctl PATCH v2 21/26] ndctl/namespace: Validate namespace size within validate_namespace_options() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:13 -0700 Message-ID: <156426367330.531577.13173216611909512565.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP 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 --- ndctl/namespace.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 43a5fccac491..69900c4e4e60 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -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, From patchwork Sat Jul 27 21:41:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B0BC1399 for ; Sat, 27 Jul 2019 21:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 751A6209CE for ; Sat, 27 Jul 2019 21:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65FEE22B27; Sat, 27 Jul 2019 21:55:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 198DE209CE for ; Sat, 27 Jul 2019 21:55:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A5137212E46E0; Sat, 27 Jul 2019 14:58:03 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 95370212E259E for ; Sat, 27 Jul 2019 14:58:02 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:35 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="182272570" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:35 -0700 Subject: [ndctl PATCH v2 22/26] ndctl/namespace: Clarify 16M minimum size requirement From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:18 -0700 Message-ID: <156426367840.531577.5216422482939398348.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP The kernel enforces a minimum size for any "claimed" namespace i.e. any namespace that is wrapped in an address abstraction like the btt or devdax. The "no such device or address" default print is confusing, so replace with an explicit error message. Reported-by: Jane Chu Signed-off-by: Dan Williams --- ndctl/namespace.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 69900c4e4e60..75ea366574f8 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -534,6 +534,7 @@ static int validate_namespace_options(struct ndctl_region *region, unsigned long long size_align, units = 1, resource; struct ndctl_pfn *pfn = NULL; struct ndctl_dax *dax = NULL; + bool default_size = false; unsigned int ways; int rc = 0; @@ -548,10 +549,13 @@ static int validate_namespace_options(struct ndctl_region *region, p->size = __parse_size64(param.size, &units); else if (ndns) p->size = ndctl_namespace_get_size(ndns); + else + default_size = true; /* * Validate available capacity in the create case, in the - * reconfigure case the capacity is already allocated. + * reconfigure case the capacity is already allocated. A default + * size will be established from available capacity. */ if (!ndns) { rc = validate_available_capacity(region, p); @@ -719,6 +723,21 @@ static int validate_namespace_options(struct ndctl_region *region, return -EINVAL; } + /* + * Catch attempts to create sub-16M namespaces to match the + * kernel's restriction (see nd_namespace_store()) + */ + if (p->size < SZ_16M && p->mode != NDCTL_NS_MODE_RAW) { + if (default_size) { + debug("%s: insufficient capacity for mode: %s\n", + region_name, util_nsmode_name(p->mode)); + return -EAGAIN; + } + error("'--size=' must be >= 16MiB for '%s' mode\n", + util_nsmode_name(p->mode)); + return -EINVAL; + } + if (param.sector_size) { struct ndctl_btt *btt; int num, i; From patchwork Sat Jul 27 21:41:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C696B112C for ; Sat, 27 Jul 2019 21:55:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE714209CE for ; Sat, 27 Jul 2019 21:55:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B20B122B27; Sat, 27 Jul 2019 21:55:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 77EF8209CE for ; Sat, 27 Jul 2019 21:55:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 05A9F212E25BB; Sat, 27 Jul 2019 14:58:09 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A9783212E25AC for ; Sat, 27 Jul 2019 14:58:07 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:40 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="254770174" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:40 -0700 Subject: [ndctl PATCH v2 23/26] ndctl/namespace: Report ENOSPC when regions are full From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:23 -0700 Message-ID: <156426368351.531577.5819409272263585965.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP The create-namespace error message: failed to create namespace: Resource temporarily unavailable ...is misleading because the lack of capacity is permanent until the user frees up space. Trap EAGAIN and translate to ENOSPC in case the region capacity search fails: failed to create namespace: No space left on device Signed-off-by: Dan Williams --- ndctl/namespace.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 75ea366574f8..f215f77a94e1 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -1806,6 +1806,15 @@ static int do_xaction_namespace(const char *namespace, if (ri_ctx.f_out && ri_ctx.f_out != stdout) fclose(ri_ctx.f_out); + if (action == ACTION_CREATE && rc == -EAGAIN) { + /* + * Namespace creation searched through all candidate + * regions and all of them said "nope, I don't have + * enough capacity", so report -ENOSPC + */ + rc = -ENOSPC; + } + return rc; } From patchwork Sat Jul 27 21:41:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37E2A112C for ; Sat, 27 Jul 2019 21:55:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F5D7209CE for ; Sat, 27 Jul 2019 21:55:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 237A622B27; Sat, 27 Jul 2019 21:55:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id BA1AC209CE for ; Sat, 27 Jul 2019 21:55:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4D53B212E25AC; Sat, 27 Jul 2019 14:58:14 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 05E1E212E259E for ; Sat, 27 Jul 2019 14:58:12 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:46 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="171014347" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:46 -0700 Subject: [ndctl PATCH v2 24/26] ndctl/test: Regression test 'failed to track' From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:28 -0700 Message-ID: <156426368860.531577.4971154560351562053.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Exercise the failing condition behind kernel commit c4703ce11c23 "libnvdimm/namespace: Fix label tracking error", i.e. rename (change uuid) allocated namespace capacity. Signed-off-by: Dan Williams --- test/Makefile.am | 3 ++- test/track-uuid.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 test/track-uuid.sh diff --git a/test/Makefile.am b/test/Makefile.am index decc8377258a..782b01cc4a97 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -25,7 +25,8 @@ TESTS =\ inject-smart.sh \ monitor.sh \ max_available_extent_ns.sh \ - pfn-meta-errors.sh + pfn-meta-errors.sh \ + track-uuid.sh check_PROGRAMS =\ libndctl \ diff --git a/test/track-uuid.sh b/test/track-uuid.sh new file mode 100755 index 000000000000..ece11193f01d --- /dev/null +++ b/test/track-uuid.sh @@ -0,0 +1,41 @@ +#!/bin/bash -Ex + +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2018 Intel Corporation. All rights reserved. + +blockdev="" +rc=77 + +. ./common + +set -e +trap 'err $LINENO' ERR + +# setup (reset nfit_test dimms) +modprobe nfit_test +$NDCTL disable-region -b $NFIT_TEST_BUS0 all +$NDCTL zero-labels -b $NFIT_TEST_BUS0 all +$NDCTL enable-region -b $NFIT_TEST_BUS0 all + +rc=1 + +# create a fsdax namespace and clear errors (if any) +dev="x" +json=$($NDCTL create-namespace -b $NFIT_TEST_BUS0 -t pmem -m raw) +eval "$(echo "$json" | json2var)" +[ $dev = "x" ] && echo "fail: $LINENO" && exit 1 + +$NDCTL disable-namespace $dev +# On broken kernels this reassignment of capacity triggers a warning +# with the following signature, and results in ENXIO. +# WARNING: CPU: 11 PID: 1378 at drivers/nvdimm/label.c:721 __pmem_label_update+0x55d/0x570 [libnvdimm] +# Call Trace: +# nd_pmem_namespace_label_update+0xd6/0x160 [libnvdimm] +# uuid_store+0x15c/0x170 [libnvdimm] +# kernfs_fop_write+0xf0/0x1a0 +# __vfs_write+0x26/0x150 +uuidgen > /sys/bus/nd/devices/$dev/uuid +$NDCTL enable-namespace $dev + +_cleanup +exit 0 From patchwork Sat Jul 27 21:41:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76B0A112C for ; Sat, 27 Jul 2019 21:55:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E9D8209CE for ; Sat, 27 Jul 2019 21:55:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FC0F22B27; Sat, 27 Jul 2019 21:55:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C353209CE for ; Sat, 27 Jul 2019 21:55:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A11A2212E4705; Sat, 27 Jul 2019 14:58:20 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A39E1212E259E for ; Sat, 27 Jul 2019 14:58:18 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:51 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="172675893" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:51 -0700 Subject: [ndctl PATCH v2 25/26] ndctl/namespace: Continue region search on 'missing seed' event From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:34 -0700 Message-ID: <156426369414.531577.11315264374951747460.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Consider a scenario where one region is in an error state but another is not: # ndctl list -Ru [ { "dev":"region3", "size":"127.00 GiB (136.37 GB)", "available_size":0, "max_available_extent":0, "type":"pmem", "persistence_domain":"unknown" }, { "dev":"region2", "size":"127.00 GiB (136.37 GB)", "available_size":"127.00 GiB (136.37 GB)", "max_available_extent":"127.00 GiB (136.37 GB)", "type":"pmem", "iset_id":"0xba90120012b4dc", "persistence_domain":"unknown" } ] # ndctl create-namespace -m devdax -v [..] namespace_create:887: region3: no idle namespace seed failed to create namespace: No such device Instead of failing when probing region3 for capacity, fallback to region2. # ndctl create-namespace -m devdax { "dev":"namespace2.0", "mode":"devdax", "map":"dev", "size":"125.01 GiB (134.23 GB)", "uuid":"c3fa7d2f-6c20-4762-9aa8-627d06275e03", "daxregion":{ "id":2, "size":"125.01 GiB (134.23 GB)", "align":2097152, "devices":[ { "chardev":"dax2.0", "size":"125.01 GiB (134.23 GB)" } ] }, "align":2097152 } Signed-off-by: Dan Williams --- ndctl/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index f215f77a94e1..bbc9107c6baa 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -867,7 +867,7 @@ static int namespace_create(struct ndctl_region *region) if (!ndns || is_namespace_active(ndns)) { debug("%s: no %s namespace seed\n", devname, ndns ? "idle" : "available"); - return -ENODEV; + return -EAGAIN; } rc = setup_namespace(region, ndns, &p); From patchwork Sat Jul 27 21:41:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11062743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD8941399 for ; Sat, 27 Jul 2019 21:55:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0243209CE for ; Sat, 27 Jul 2019 21:55:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BF9322B27; Sat, 27 Jul 2019 21:55:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 5FDE8209CE for ; Sat, 27 Jul 2019 21:55:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E7950212E46FB; Sat, 27 Jul 2019 14:58:25 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E8647212E259E for ; Sat, 27 Jul 2019 14:58:23 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:57 -0700 X-IronPort-AV: E=Sophos;i="5.64,315,1559545200"; d="scan'208";a="370587301" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jul 2019 14:55:56 -0700 Subject: [ndctl PATCH v2 26/26] ndctl/monitor: Allow monitor to be manually moved to the background From: Dan Williams To: linux-nvdimm@lists.01.org Date: Sat, 27 Jul 2019 14:41:39 -0700 Message-ID: <156426369946.531577.16184152092730982222.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156426356088.531577.14828880045306313118.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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-Virus-Scanned: ClamAV using ClamSMTP Currently attempting to place the monitor into the background results in an epoll error: # ndctl monitor -b nfit_test.0 ^Z [1]+ Stopped ndctl monitor -b nfit_test.0 # bg [1]+ ndctl monitor -b nfit_test.0 & epoll_wait error This error is simply a wakeup from a signal EINTR, so allow the monitor to continue assuming the signal is not fatal. Signed-off-by: Dan Williams --- ndctl/monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 6829a6b28b58..88adf3e5d6ff 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -357,8 +357,8 @@ static int monitor_event(struct ndctl_ctx *ctx, while (1) { did_fail = 0; nfds = epoll_wait(epollfd, events, mfa->num_dimm, -1); - if (nfds <= 0) { - err(&monitor, "epoll_wait error\n"); + if (nfds <= 0 && errno != EINTR) { + err(&monitor, "epoll_wait error: (%s)\n", strerror(errno)); rc = -errno; goto out; }