From patchwork Mon Sep 10 06:21:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10593581 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 1B12D14DB for ; Mon, 10 Sep 2018 06:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08D1328C91 for ; Mon, 10 Sep 2018 06:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0DC528E82; Mon, 10 Sep 2018 06:24: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.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 AD3D228C91 for ; Mon, 10 Sep 2018 06:24:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 93E7B21122927; Sun, 9 Sep 2018 23:24:06 -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=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8146221962301 for ; Sun, 9 Sep 2018 23:24:05 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id ba4-v6so9235890plb.11 for ; Sun, 09 Sep 2018 23:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fHMI+xukBON89nXvZYMkVDi6OYKOCbycFLQGiP1LgNU=; b=lGkWmsODnzacGztU7q5LQsZn9aKq550tNmkWbHvANLe/cPvSn9JsM+U0OsudZB3jgr dFJgZvfOtiWdG+qfQO9a0A73ZS5/MrhBIAZO5jbEN+wzHdZtU5M5vpIWkL4216SFgM9+ TgB9zJPwM59H7umPCG1Miv4gIcbk5QKm3BwWOQNjradVbXmT+AvPGA/13XxeEyvW8oCT 5jMHRJMjc6haZgZWXmC24yslELdcZi1Xveh/ixjFjjEE6gQeIYbZwNgS4KIyx8fWBNFA tkU+17DcXdpGKIcY54LPGkchRYlET0aUghZ2zkab6A3v4XIJIqM1v5HYzx8xC+nqqdWu A+YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fHMI+xukBON89nXvZYMkVDi6OYKOCbycFLQGiP1LgNU=; b=CfmjCcAEUB73YarUZq7woGQiLHlaNjJ/w9hTAUpia+ra5HvlPydgjVwOKSVSPuWQGB EyZ7fpbL6+ueG+oBaNbsVjkBeGTpdyR77AR0XC0J9Qw2slWPaqJDEzq0+oOyiIjtX+ci 8ZtduQXWox+XdPP0WHZuFHCgyTnyLSAjv3ZrPnOZo5mCSkvOb+623NPIiv0pkeD+F+Xu N9zE4V22Vt0SRPnVuuTARzgQm5T4JOX1w+vPH1yzn3htd0VcHK5cjd8juP74xZsLo8hD fPaEtu8d9GOsb+4IqAbfWHn8cepi+Bn/7pc04Vzct/chTesJZZ7ZExFe5YtJMLXzM1Yj 7WlA== X-Gm-Message-State: APzg51APrTzAoM/4qKjzA0LhYEkVbK1kRZspgGjlUBfQhXO1D86QhyD4 ee9rxpzPpMOFCSYgYe+xgVzJYdVc X-Google-Smtp-Source: ANB0Vdanr0ZwDB8k65v4PQhQy8gJsV9jqtnA3Sd3QYhkEBBGczdUB0dsPKlLfwWmhas7whwGT8Q2Pg== X-Received: by 2002:a17:902:561:: with SMTP id 88-v6mr20030244plf.320.1536560645127; Sun, 09 Sep 2018 23:24:05 -0700 (PDT) Received: from localhost.localdomain ([104.237.86.186]) by smtp.gmail.com with ESMTPSA id e190-v6sm29884955pfc.81.2018.09.09.23.24.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 23:24:04 -0700 (PDT) From: Ocean He To: dan.j.williams@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH 1/3] libnvdimm, claim: remove static attribute of nd_detach_and_reset Date: Mon, 10 Sep 2018 02:21:46 -0400 Message-Id: <1536560508-24564-2-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> References: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> 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: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He The function nd_detach_and_reset needs to be called externally, so remove the static attribute and declare it in nd-core.h. Signed-off-by: Ocean He --- drivers/nvdimm/claim.c | 2 +- drivers/nvdimm/nd-core.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c index fb667bf..46e56ecf 100644 --- a/drivers/nvdimm/claim.c +++ b/drivers/nvdimm/claim.c @@ -117,7 +117,7 @@ struct nd_pfn *to_nd_pfn_safe(struct device *dev) return NULL; } -static void nd_detach_and_reset(struct device *dev, +void nd_detach_and_reset(struct device *dev, struct nd_namespace_common **_ndns) { /* detach the namespace and destroy / reset the device */ diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index ac68072..7fd74d0 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -123,6 +123,7 @@ struct resource *nsblk_add_resource(struct nd_region *nd_region, resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns); void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns); void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns); +void nd_detach_and_reset(struct device *dev, struct nd_namespace_common **_ndns); bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, struct nd_namespace_common **_ndns); bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, From patchwork Mon Sep 10 06:21:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10593583 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 4830A14DB for ; Mon, 10 Sep 2018 06:24:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36AA328C91 for ; Mon, 10 Sep 2018 06:24:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B0CC28E82; Mon, 10 Sep 2018 06:24:10 +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.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 D4ACE28C91 for ; Mon, 10 Sep 2018 06:24:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AA2B22112292F; Sun, 9 Sep 2018 23:24: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=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 22D922112121C for ; Sun, 9 Sep 2018 23:24:08 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id s7-v6so9930423pgc.0 for ; Sun, 09 Sep 2018 23:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JF0O4zn/LEpQ/Of9oMm7Pjnzg7UngdrXOP4yvvJEbCU=; b=dVXao5jdrcbYa/pAvRMpR9vVDp8yWciCujeAPE1yKGh8aMh1fWJTTxhxxP18vY74jy /KptFiua34FHKvaO/V8mYUneU8xJQgkdpEESdxpGJH3QOAQ0n4sAAPKRFfHsxvqIIz+6 x8MizVHElTK4CA3j1HQ5uvWkxFWkJoyHHyTc30uaZGn0ptLFkWLu9QJnsBuFhXHxcH+e X55UEUgs+ucx3VB2QlOj02Miz2uycvnG6me8E0zKvgiReOr6v4Lgl6Hxto7/Z09afC3q w6/wC7fMeysjdGCPo/E5OXt29w5C/BwzqwG2x8xtsyOhJFV7qIWM0/4djlaJM3uKryIT 5zoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JF0O4zn/LEpQ/Of9oMm7Pjnzg7UngdrXOP4yvvJEbCU=; b=jWd3JSVPS2ojhwMNelopG7P2okhuIrpN6aWqROlSUiXxGTLoFH7V38evBbCSwwAeOD jFj3VNrEG1OppkXOIA8n+k/JW9ancDUlvSXgEvESDyfarwK7bRDfzphgusbxNTipWwLh 14ufmQG+zCJdRy/9Yz13c7hhb6HBWUcn8BBRWwHfiWJs2Oiu8IGeawr/UTohFzPgmEcH kEJ6igqSJ0XKFlbCQTxS76MdNkeEyVuWabM7UDomHBmqUWqeT9MiuRzMhx+jTkuZv0zJ yKTT/R8+65WxcODDgw02RoypJWvApGkO760XP8WNeVaU3UC8BnqLbS07Ro+AtVKpuLbX T/cA== X-Gm-Message-State: APzg51DNCNudar3r4TLTBfeZ3V6XMBu+iHBL6J1wEItSTdFgirDgrzHB SdETZ9T8I5/dfe6akq8dspw= X-Google-Smtp-Source: ANB0VdbASkaicKOnGL6+UsioZtXnGGwHO4TNxNlyJZ1xpvq56/L4LUy8drHngFwzGqkGWyt2AclF0Q== X-Received: by 2002:a62:9349:: with SMTP id b70-v6mr22010117pfe.193.1536560647863; Sun, 09 Sep 2018 23:24:07 -0700 (PDT) Received: from localhost.localdomain ([104.237.86.186]) by smtp.gmail.com with ESMTPSA id e190-v6sm29884955pfc.81.2018.09.09.23.24.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 23:24:07 -0700 (PDT) From: Ocean He To: dan.j.williams@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH 2/3] libnvdimm, namespace_devs: add function nd_region_reset_ns_seed for namespace seed reset Date: Mon, 10 Sep 2018 02:21:47 -0400 Message-Id: <1536560508-24564-3-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> References: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> 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: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He During runtime, if a namespace seed is used for new namespace creation but fail, then it needs to be reset for next namespace creation. Add function nd_region_reset_ns_seed for namespace seed reset and declare it in nd-core.h. Signed-off-by: Ocean He --- drivers/nvdimm/namespace_devs.c | 32 ++++++++++++++++++++++++++++++++ drivers/nvdimm/nd-core.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 4a42662..6678bbe 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -2129,6 +2129,38 @@ void nd_region_create_ns_seed(struct nd_region *nd_region) nd_device_register(nd_region->ns_seed); } +void nd_region_reset_ns_seed(struct nd_region *nd_region) +{ + struct device *dev = nd_region->ns_seed; + unsigned long long val = 0; + ssize_t rc; + u8 **uuid = NULL; + + rc = __holder_class_store(dev, ""); + dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail to reset claim_class " : "", rc); + + rc = __size_store(dev, val); + if (rc >= 0) + rc = nd_namespace_label_update(nd_region, dev); + dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail to reset size " : "", rc); + + if (is_namespace_pmem(dev)) { + struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); + + uuid = &nspm->uuid; + } else if (is_namespace_blk(dev)) { + struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); + + uuid = &nsblk->uuid; + } + + if (rc == 0 && val == 0 && uuid) { + /* setting size zero == 'delete namespace' */ + kfree(*uuid); + *uuid = NULL; + } +} + void nd_region_create_dax_seed(struct nd_region *nd_region) { WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index 7fd74d0..3ec6909 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -81,6 +81,7 @@ static inline bool is_memory(struct device *dev) void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev); struct nd_region; void nd_region_create_ns_seed(struct nd_region *nd_region); +void nd_region_reset_ns_seed(struct nd_region *nd_region); void nd_region_create_btt_seed(struct nd_region *nd_region); void nd_region_create_pfn_seed(struct nd_region *nd_region); void nd_region_create_dax_seed(struct nd_region *nd_region); From patchwork Mon Sep 10 06:21:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ocean He X-Patchwork-Id: 10593585 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 3BD4E14E0 for ; Mon, 10 Sep 2018 06:24:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29C0B28C91 for ; Mon, 10 Sep 2018 06:24:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E18328E82; Mon, 10 Sep 2018 06:24:12 +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.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID 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 C8B8728C91 for ; Mon, 10 Sep 2018 06:24:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C1EA821122932; Sun, 9 Sep 2018 23:24: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=2607:f8b0:4864:20::643; helo=mail-pl1-x643.google.com; envelope-from=oceanhehy@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C82FF2112292A for ; Sun, 9 Sep 2018 23:24:10 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id f6-v6so9254615plo.1 for ; Sun, 09 Sep 2018 23:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3MmFh5VYNhBbWAgBarErsEIFlbjZvJPeEdHR7yalks8=; b=jXSLJXlot2IR2g7En6xCzJouoS5MAIcvPjxxGHeNhNdxkewv0TeRiuJkK58S6mGHdv CnEfwzqUoPNVTh6snNhv1eUfc7WMDg5fcA1NH+x0binvxbJJ1r+RUGWH1+aoWblULpmM HO6sAjz+7dz1Cd1PKEaFKE0PU+ztrm4eWWF/nOQxa49FVsPEIqXGvr70HVep1A5NcOBx MZrAftjohhWoxPtwHpYzOnLY61y6huNIPdULZf/3WfDJs1s6A2+wzXxBsC2GwrmPU3KM lepmp6NQcphykNAK4Bo/dDmOTkiray0cV8rf879Q73zdoTFSipVcmsZpWTGXXLf786NB lXfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3MmFh5VYNhBbWAgBarErsEIFlbjZvJPeEdHR7yalks8=; b=LXaTXcP7OdEJa0JG/3RZsmJZteqHTT6U0k7hs5yGeS4AgD6iZfbUDe5au9lD3jdfyp KCjEM4Ytt7PQRV/pOU3UCENjokPiU/k7ALVtJAe0zSWSLw3el+GywplRovfbMqqB/sF4 BjWPwmjXt0J6cZYCfZ3XDF8jE1ZbNr0utHlcJlP4L5QHd1pKs9HJRFDbdQIRZXPow74W BMI5F1yoA6gciTB35iCMex2kFy1MM9qH+JGcJSLVBj8A/IZsDG77rx9p59x073zlX0Hf yxyU6vKx51ZguP7gJMRiC7O3jKj+AzwyKE/XwTgrrRBii9rZVcM7e1I7QG1UwzrV7/NH DWeQ== X-Gm-Message-State: APzg51B6rmfywOjpzoHOUoShKjLBiFIGTQND3cso5Im0XpEVtmh0HXzG X/X8t+Or/yoGiXNRPqHTEYQ= X-Google-Smtp-Source: ANB0VdYwY1BEVzHUSZwG2PauzFQWzUu+hfuHu+/oMhmB2V8nB8hDeIBDfWFERedxly7NycDgbhFr5w== X-Received: by 2002:a17:902:b089:: with SMTP id p9-v6mr20108057plr.254.1536560650554; Sun, 09 Sep 2018 23:24:10 -0700 (PDT) Received: from localhost.localdomain ([104.237.86.186]) by smtp.gmail.com with ESMTPSA id e190-v6sm29884955pfc.81.2018.09.09.23.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 23:24:10 -0700 (PDT) From: Ocean He To: dan.j.williams@intel.com, zwisler@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com Subject: [PATCH 3/3] libnvdimm, region_devs: reset related seeds when fail to create namespace Date: Mon, 10 Sep 2018 02:21:48 -0400 Message-Id: <1536560508-24564-4-git-send-email-oceanhehy@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> References: <1536560508-24564-1-git-send-email-oceanhehy@gmail.com> 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: Ocean He , linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Ocean He During runtime, namespace creation may fail if blocked by commit 15d36fecd0bdc7510b70 ("mm: disallow mappings that conflict for devm_memremap_pages()"). To ensure pfn_seed/dax_seed and namespace_seed are ready for next namespace creation, here to do detach and reset. Signed-off-by: Ocean He --- drivers/nvdimm/region_devs.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index fa37afc..4c46fb6 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -703,7 +703,27 @@ void nd_mapping_free_labels(struct nd_mapping *nd_mapping) kfree(label_ent); } } +/* + * To ensure pfn_seed/dax_seed and namespace_seed are ready for + * next namespace creation, here to do detach and reset. + */ +void nd_region_detach_and_reset(struct device *dev, + struct nd_region *nd_region) +{ + /* Only nd_pmem has been verified, fix me for other dev type. */ + if (!is_nd_pmem(&nd_region->dev)) + return; + if (is_nd_pfn(dev) || is_nd_dax(dev)) { + struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); + struct nd_namespace_common *ndns = to_ndns(nd_region->ns_seed); + + if (nd_pfn->ndns == ndns && ndns->claim == dev) { + nd_detach_and_reset(dev, &nd_pfn->ndns); + nd_region_reset_ns_seed(nd_region); + } + } +} /* * Upon successful probe/remove, take/release a reference on the * associated interleave set (if present), and plant new btt + namespace @@ -774,6 +794,20 @@ static void nd_region_notify_driver_action(struct nvdimm_bus *nvdimm_bus, nd_region_create_ns_seed(nd_region); nvdimm_bus_unlock(dev); } + if (is_nd_pfn(dev) && !probe) { + nd_region = to_nd_region(dev->parent); + nvdimm_bus_lock(dev); + if (nd_region->pfn_seed == dev) + nd_region_detach_and_reset(dev, nd_region); + nvdimm_bus_unlock(dev); + } + if (is_nd_dax(dev) && !probe) { + nd_region = to_nd_region(dev->parent); + nvdimm_bus_lock(dev); + if (nd_region->dax_seed == dev) + nd_region_detach_and_reset(dev, nd_region); + nvdimm_bus_unlock(dev); + } } void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev)