From patchwork Fri Jun 14 18:52:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10996387 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 2FE5313AF for ; Fri, 14 Jun 2019 18:52:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2103F286DF for ; Fri, 14 Jun 2019 18:52:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14A3C286E3; Fri, 14 Jun 2019 18:52:36 +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 AFE54286E2 for ; Fri, 14 Jun 2019 18:52:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 797F32129EBBA; Fri, 14 Jun 2019 11:52:35 -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=vishal.l.verma@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 1DA1F2129EBB8 for ; Fri, 14 Jun 2019 11:52:33 -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; 14 Jun 2019 11:52:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,373,1557212400"; d="scan'208";a="185051531" Received: from vverma7-desk1.lm.intel.com ([10.232.112.185]) by fmsmga002.fm.intel.com with ESMTP; 14 Jun 2019 11:52:32 -0700 From: Vishal Verma To: Subject: [ndctl PATCH] libndctl/inject: Refuse error injection for BTT namespaces Date: Fri, 14 Jun 2019 12:52:22 -0600 Message-Id: <20190614185222.30068-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.20.1 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: , Cc: Marek de Rosier Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Error injection on a BTT namespace would treat the namespace as 'raw' for the purposes of the injection. This can be useful for development, but to a user this can be surprising, as injecting with --block=1 would corrupt the BTT info block, and the BTT would be lost. The unit tests do not rely on injecting errors directly into a BTT namespace - they convert the namespace to 'raw' mode before performing such an injection. For development and testing purposes, we will still retain this ability by enforcing that the BTT namespace be explicitly forced into raw mode before injection. Reported-by: Marek de Rosier Reported-by: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams --- ndctl/lib/inject.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c index c35d0f3..815f254 100644 --- a/ndctl/lib/inject.c +++ b/ndctl/lib/inject.c @@ -34,28 +34,36 @@ NDCTL_EXPORT int ndctl_bus_has_error_injection(struct ndctl_bus *bus) return 0; } -static void ndctl_namespace_get_injection_bounds( +static int ndctl_namespace_get_injection_bounds( struct ndctl_namespace *ndns, unsigned long long *ns_offset, unsigned long long *ns_size) { 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); if (!ns_offset || !ns_size) - return; + return -ENXIO; if (pfn) { *ns_offset = ndctl_pfn_get_resource(pfn); *ns_size = ndctl_pfn_get_size(pfn); - return; - } else if (dax) { + return 0; + } + + if (dax) { *ns_offset = ndctl_dax_get_resource(dax); *ns_size = ndctl_dax_get_size(dax); - return; + return 0; } - /* raw or btt */ + + if (btt) + return -EOPNOTSUPP; + + /* raw */ *ns_offset = ndctl_namespace_get_resource(ndns); *ns_size = ndctl_namespace_get_size(ndns); + return 0; } static int block_to_spa_offset(struct ndctl_namespace *ndns, @@ -64,8 +72,11 @@ static int block_to_spa_offset(struct ndctl_namespace *ndns, { struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns); unsigned long long ns_offset, ns_size; + int rc; - ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size); + rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size); + if (rc) + return rc; *offset = ns_offset + block * 512; *length = count * 512; @@ -98,8 +109,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns) struct ndctl_cmd *cmd; int rc; - ndctl_namespace_get_injection_bounds(ndns, &ns_offset, + rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size); + if (rc) + return rc; cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size); rc = ndctl_cmd_submit(cmd); if (rc < 0) { @@ -438,8 +451,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns) return -EOPNOTSUPP; if (ndctl_bus_has_nfit(bus)) { - ndctl_namespace_get_injection_bounds(ndns, &ns_offset, + rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size); + if (rc) + return rc; cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size); rc = ndctl_cmd_submit(cmd);