From patchwork Wed Apr 11 00:07:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10334667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF86B602D8 for ; Wed, 11 Apr 2018 00:07:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A951520453 for ; Wed, 11 Apr 2018 00:07:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DB5727FB7; Wed, 11 Apr 2018 00:07:52 +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 23BA220453 for ; Wed, 11 Apr 2018 00:07:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CA2962267F11E; Tue, 10 Apr 2018 17:07:51 -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=dave.jiang@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 CAE9B22618176 for ; Tue, 10 Apr 2018 17:07:50 -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; 10 Apr 2018 17:07:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,434,1517904000"; d="scan'208";a="219406256" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga006.fm.intel.com with ESMTP; 10 Apr 2018 17:07:49 -0700 Subject: [PATCH v4] ndctl: add support in libndctl to provide deep flush From: Dave Jiang To: vishal.l.verma@intel.com, dan.j.williams@intel.com Date: Tue, 10 Apr 2018 17:07:49 -0700 Message-ID: <152340525564.49190.4043221054821728642.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Providing an API call in libndctl to support accessing the region deep_flush in sysfs. Signed-off-by: Dave Jiang --- v4: Make setup of deep_flush open not interfere with add_region. (Dan) v3: - Add "\n" to sysfs write. (Dan) - add O_CLOEXEC to open() call for sysfs. (Dan) v2: Cover case where deep_flush doesn't exist, i.e. memmap=nn!ss. (Dan) ndctl/lib/libndctl.c | 31 +++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 1 + 3 files changed, 33 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 580a450e..5d91d34e 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -181,6 +181,8 @@ struct ndctl_region { FILE *badblocks; struct badblock bb; enum ndctl_persistence_domain persistence_domain; + /* file descriptor for deep flush sysfs entry */ + int flush_fd; }; /** @@ -511,6 +513,8 @@ static void free_region(struct ndctl_region *region) free(region->region_path); if (region->badblocks) fclose(region->badblocks); + if (region->flush_fd > 0) + close(region->flush_fd); free(region); } @@ -1049,6 +1053,14 @@ NDCTL_EXPORT unsigned long long ndctl_region_get_resource(struct ndctl_region *r return strtoull(buf, NULL, 0); } +NDCTL_EXPORT int ndctl_region_deep_flush(struct ndctl_region *region) +{ + int rc = pwrite(region->flush_fd, "1\n", 1, 0); + + return (rc == -1) ? -errno : 0; +} + + NDCTL_EXPORT const char *ndctl_bus_get_cmd_name(struct ndctl_bus *bus, int cmd) { return nvdimm_bus_cmd_name(cmd); @@ -1791,6 +1803,7 @@ static void *add_region(void *parent, int id, const char *region_base) struct ndctl_bus *bus = parent; struct ndctl_ctx *ctx = bus->ctx; char *path = calloc(1, strlen(region_base) + 100); + int perm; if (!path) return NULL; @@ -1866,6 +1879,24 @@ static void *add_region(void *parent, int id, const char *region_base) else region->persistence_domain = region_get_pd_type(buf); + sprintf(path, "%s/deep_flush", region_base); + region->flush_fd = open(path, O_RDWR | O_CLOEXEC); + if (region->flush_fd == -1) + goto out; + + if (pread(region->flush_fd, buf, 1, 0) == -1) { + close(region->flush_fd); + region->flush_fd = -1; + goto out; + } + + perm = strtol(buf, NULL, 0); + if (perm == 0) { + region->flush_fd = -1; + close(region->flush_fd); + } + + out: free(path); return region; diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 3209aefe..38cc3b9a 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -352,4 +352,5 @@ global: ndctl_dimm_fw_update_supported; ndctl_region_get_persistence_domain; ndctl_bus_get_persistence_domain; + ndctl_region_deep_flush; } LIBNDCTL_14; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index cf6a77fd..1a622ae5 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -365,6 +365,7 @@ int ndctl_region_enable(struct ndctl_region *region); int ndctl_region_disable_invalidate(struct ndctl_region *region); int ndctl_region_disable_preserve(struct ndctl_region *region); void ndctl_region_cleanup(struct ndctl_region *region); +int ndctl_region_deep_flush(struct ndctl_region *region); struct ndctl_interleave_set; struct ndctl_interleave_set *ndctl_region_get_interleave_set(