From patchwork Tue Sep 18 20:10:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10604845 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 134A46CB for ; Tue, 18 Sep 2018 20:22:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01F402BDEA for ; Tue, 18 Sep 2018 20:22:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA3872BE04; Tue, 18 Sep 2018 20:22: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 EB3702BDEA for ; Tue, 18 Sep 2018 20:22:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AB70C21A07A80; Tue, 18 Sep 2018 13:22:41 -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.31; helo=mga06.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 52B0F21A07A80 for ; Tue, 18 Sep 2018 13:22:40 -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 orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2018 13:22:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,391,1531810800"; d="scan'208";a="258354086" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga005.jf.intel.com with ESMTP; 18 Sep 2018 13:22:35 -0700 Subject: [ndctl PATCH v3] ndctl: Introduce dirty-dimm command From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 18 Sep 2018 13:10:48 -0700 Message-ID: <153730141632.80980.3059811922733101240.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 Some DIMMs provide a facility to track dirty-shutdown events. The counter only rolls forward after the OS sets a latch. This allows the agent tracking dirty shutdowns to ignore events that occur while the capacity has not been written. For these DIMMs dirty-dimm will trigger the counter to roll to the next state. The shutdown state can be retrieved with 'ndctl list -DH' Cc: Keith Busch Cc: Vishal Verma Signed-off-by: Dan Williams --- Changes since v2: * report whether ndctl_cmd_submit() suceeded (vishal) Documentation/ndctl/Makefile.am | 1 + Documentation/ndctl/ndctl-dirty-dimm.txt | 29 +++++++++++++++++++++++++++ builtin.h | 1 + ndctl/dimm.c | 32 ++++++++++++++++++++++++++++++ ndctl/ndctl.c | 1 + 5 files changed, 64 insertions(+) create mode 100644 Documentation/ndctl/ndctl-dirty-dimm.txt diff --git a/Documentation/ndctl/Makefile.am b/Documentation/ndctl/Makefile.am index a30b139ba3a3..1a826bb001be 100644 --- a/Documentation/ndctl/Makefile.am +++ b/Documentation/ndctl/Makefile.am @@ -38,6 +38,7 @@ man1_MANS = \ ndctl-disable-region.1 \ ndctl-enable-dimm.1 \ ndctl-disable-dimm.1 \ + ndctl-dirty-dimm.1 \ ndctl-enable-namespace.1 \ ndctl-disable-namespace.1 \ ndctl-create-namespace.1 \ diff --git a/Documentation/ndctl/ndctl-dirty-dimm.txt b/Documentation/ndctl/ndctl-dirty-dimm.txt new file mode 100644 index 000000000000..02a30fe85f53 --- /dev/null +++ b/Documentation/ndctl/ndctl-dirty-dimm.txt @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0 + +ndctl-dirty-dimm(1) +=================== + +NAME +---- +ndctl-dirty-dimm - set dimm to record the next dirty shutdown event + +SYNOPSIS +-------- +[verse] +'ndctl dirty-dimm [..]' + +Some NVDIMMs have the capability to detect 'flush failed' events whereby +data that is pending in buffers at the time of system power loss fail to +be flushed out to media. Some DIMMs go further to count how many times +such fatal events occur, but only roll the count in response to a latch +being set. The 'dirty-dimm' command sets this latch on those devices and +is meant to be called in advance to any writes to media. + +OPTIONS +------- +:: +include::xable-dimm-options.txt[] + +SEE ALSO +-------- +http://pmem.io/documents/NVDIMM_DSM_Interface-V1.7.pdf[NVDIMM DSM Inteface] diff --git a/builtin.h b/builtin.h index 675a6ce79b9c..1157243cdf60 100644 --- a/builtin.h +++ b/builtin.h @@ -48,4 +48,5 @@ int cmd_bat(int argc, const char **argv, void *ctx); #endif int cmd_update_firmware(int argc, const char **argv, void *ctx); int cmd_inject_smart(int argc, const char **argv, void *ctx); +int cmd_dirty_dimm(int argc, const char **argv, void *ctx); #endif /* _NDCTL_BUILTIN_H_ */ diff --git a/ndctl/dimm.c b/ndctl/dimm.c index a4203f354000..2d658dab34a5 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -61,6 +61,23 @@ static int action_zero(struct ndctl_dimm *dimm, struct action_context *actx) return ndctl_dimm_zero_labels(dimm); } +static int action_dirty(struct ndctl_dimm *dimm, struct action_context *actx) +{ + struct ndctl_cmd *cmd; + int rc; + + cmd = ndctl_dimm_cmd_new_ack_shutdown_count(dimm); + if (!cmd) { + fprintf(stderr, "%s: 'dirty-dimm' not supported\n", + ndctl_dimm_get_devname(dimm)); + return -EOPNOTSUPP; + } + + rc = ndctl_cmd_submit(cmd); + ndctl_cmd_unref(cmd); + return rc; +} + static struct json_object *dump_label_json(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd_read, ssize_t size) { @@ -943,6 +960,11 @@ static const struct option update_options[] = { OPT_END(), }; +static const struct option dirty_options[] = { + BASE_OPTIONS(), + OPT_END(), +}; + static const struct option base_options[] = { BASE_OPTIONS(), OPT_END(), @@ -1181,3 +1203,13 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_dirty_dimm(int argc, const char **argv, void *ctx) +{ + int count = dimm_action(argc, argv, ctx, action_dirty, dirty_options, + "ndctl dirty-dimm [..] []"); + + fprintf(stderr, "dirtied %d nmem%s.\n", count >= 0 ? count : 0, + count > 1 ? "s" : ""); + return count >= 0 ? 0 : EXIT_FAILURE; +} diff --git a/ndctl/ndctl.c b/ndctl/ndctl.c index 73dabfac3908..93d0d88a274c 100644 --- a/ndctl/ndctl.c +++ b/ndctl/ndctl.c @@ -83,6 +83,7 @@ static struct cmd_struct commands[] = { { "write-labels", cmd_write_labels }, { "init-labels", cmd_init_labels }, { "check-labels", cmd_check_labels }, + { "dirty-dimm", cmd_dirty_dimm }, { "inject-error", cmd_inject_error }, { "update-firmware", cmd_update_firmware }, { "inject-smart", cmd_inject_smart },