From patchwork Fri Apr 6 21:24:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10327605 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 AD4D260541 for ; Fri, 6 Apr 2018 21:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CF6129698 for ; Fri, 6 Apr 2018 21:24:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 916222969B; Fri, 6 Apr 2018 21:24:30 +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=-1.5 required=2.0 tests=BAYES_05, 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 1D28029698 for ; Fri, 6 Apr 2018 21:24:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A8114226FAA6B; Fri, 6 Apr 2018 14:24:29 -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=vishal.l.verma@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 861C222620E7A for ; Fri, 6 Apr 2018 14:24:28 -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; 06 Apr 2018 14:24:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,416,1517904000"; d="scan'208";a="31652162" Received: from vverma7-mobl4.lm.intel.com ([10.252.140.48]) by orsmga008.jf.intel.com with ESMTP; 06 Apr 2018 14:24:28 -0700 From: Vishal Verma To: Subject: [ndctl PATCH 2/2] ndctl, test: add write_cache testing to libndctl Date: Fri, 6 Apr 2018 15:24:17 -0600 Message-Id: <20180406212417.16227-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180406212417.16227-1-vishal.l.verma@intel.com> References: <20180406212417.16227-1-vishal.l.verma@intel.com> 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: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP in check_namespaces(), add a step to validate the write_cache status and controls for the namespaces that support it. Also add a negative test for the namespaces that don't have a write_cache (blk, sector etc), making sure the APIs fail as expected. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Wiiliams --- test/libndctl.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/libndctl.c b/test/libndctl.c index a66bcb7..72271f4 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -1614,6 +1614,56 @@ static int validate_bdev(const char *devname, struct ndctl_btt *btt, return rc; } +static int validate_write_cache(struct ndctl_namespace *ndns) +{ + const char *devname = ndctl_namespace_get_devname(ndns); + int wc, mode, type, rc; + + type = ndctl_namespace_get_type(ndns); + mode = ndctl_namespace_get_mode(ndns); + wc = ndctl_namespace_write_cache_is_enabled(ndns); + + if ((type == ND_DEVICE_NAMESPACE_PMEM || type == ND_DEVICE_NAMESPACE_IO) && + (mode == NDCTL_NS_MODE_FSDAX || mode == NDCTL_NS_MODE_RAW)) { + if (wc != 1) { + fprintf(stderr, "%s: expected write_cache enabled\n", + devname); + return -ENXIO; + } + rc = ndctl_namespace_disable_write_cache(ndns); + if (rc) { + fprintf(stderr, "%s: failed to disable write_cache\n", + devname); + return rc; + } + rc = ndctl_namespace_write_cache_is_enabled(ndns); + if (rc != 0) { + fprintf(stderr, "%s: write_cache could not be disabled\n", + devname); + return rc; + } + rc = ndctl_namespace_enable_write_cache(ndns); + if (rc) { + fprintf(stderr, "%s: failed to re-enable write_cache\n", + devname); + return rc; + } + rc = ndctl_namespace_write_cache_is_enabled(ndns); + if (rc != 1) { + fprintf(stderr, "%s: write_cache could not be re-enabled\n", + devname); + return rc; + } + } else { + if (wc == 0 || wc == 1) { + fprintf(stderr, "%s: expected write_cache to be absent\n", + devname); + return -ENXIO; + } + } + return 0; +} + static int check_namespaces(struct ndctl_region *region, struct namespace **namespaces, enum ns_mode mode) { @@ -1787,6 +1837,13 @@ static int check_namespaces(struct ndctl_region *region, break; } + rc = validate_write_cache(ndns); + if (rc) { + fprintf(stderr, "%s: %s validate_write_cache failed\n", + __func__, devname); + break; + } + if (ndctl_namespace_disable_invalidate(ndns) < 0) { fprintf(stderr, "%s: failed to disable\n", devname); rc = -ENXIO;