From patchwork Wed Aug 30 02:11:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9928649 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 353AF602B9 for ; Wed, 30 Aug 2017 02:17:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F9E026E97 for ; Wed, 30 Aug 2017 02:17:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1440827853; Wed, 30 Aug 2017 02:17:56 +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.9 required=2.0 tests=BAYES_00, 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 C645926E97 for ; Wed, 30 Aug 2017 02:17:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8CFE421E49BD1; Tue, 29 Aug 2017 19:15:14 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: 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 B6F4721E2BE4E for ; Tue, 29 Aug 2017 19:15:13 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 29 Aug 2017 19:17:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,446,1498546800"; d="scan'208"; a="1212287774" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga002.fm.intel.com with ESMTP; 29 Aug 2017 19:17:54 -0700 Subject: [ndctl PATCH v2 06/10] ndctl: refactor region type setting From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 29 Aug 2017 19:11:30 -0700 Message-ID: <150405909062.22171.14671734486415875234.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150405905872.22171.7217183939530397385.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150405905872.22171.7217183939530397385.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 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 When a region is updated after initializing labels it may potentially change types. For now factor out type setting into a helper so that it can later be triggered by a new ndctl_dimm_init_labels(). Signed-off-by: Dan Williams --- ndctl/lib/libndctl.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 86abeb6cc577..3d37ded69c26 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1552,6 +1552,32 @@ static struct ndctl_dimm *ndctl_dimm_get_by_id(struct ndctl_bus *bus, unsigned i return NULL; } +static int region_set_type(struct ndctl_region *region, char *path) +{ + struct ndctl_ctx *ctx = ndctl_region_get_ctx(region); + char buf[SYSFS_ATTR_SIZE]; + int rc; + + sprintf(path, "%s/nstype", region->region_path); + rc = sysfs_read_attr(ctx, path, buf); + if (rc < 0) + return rc; + region->nstype = strtoul(buf, NULL, 0); + + sprintf(path, "%s/set_cookie", region->region_path); + if (region->nstype == ND_DEVICE_NAMESPACE_PMEM) { + rc = sysfs_read_attr(ctx, path, buf); + if (rc < 0) + return rc; + region->iset.cookie = strtoull(buf, NULL, 0); + dbg(ctx, "%s: iset-%#.16llx added\n", + ndctl_region_get_devname(region), + region->iset.cookie); + } + + return 0; +} + static void *add_region(void *parent, int id, const char *region_base) { char buf[SYSFS_ATTR_SIZE]; @@ -1575,6 +1601,7 @@ static void *add_region(void *parent, int id, const char *region_base) list_head_init(®ion->mappings); list_head_init(®ion->namespaces); list_head_init(®ion->stale_namespaces); + region->region_path = (char *) region_base; region->bus = bus; region->id = id; @@ -1588,11 +1615,6 @@ static void *add_region(void *parent, int id, const char *region_base) goto err_read; region->num_mappings = strtoul(buf, NULL, 0); - sprintf(path, "%s/nstype", region_base); - if (sysfs_read_attr(ctx, path, buf) < 0) - goto err_read; - region->nstype = strtoul(buf, NULL, 0); - sprintf(path, "%s/nfit/range_index", region_base); if (ndctl_bus_has_nfit(bus)) { if (sysfs_read_attr(ctx, path, buf) < 0) @@ -1601,15 +1623,6 @@ static void *add_region(void *parent, int id, const char *region_base) } else region->range_index = -1; - sprintf(path, "%s/set_cookie", region_base); - if (region->nstype == ND_DEVICE_NAMESPACE_PMEM) { - if (sysfs_read_attr(ctx, path, buf) < 0) - goto err_read; - region->iset.cookie = strtoull(buf, NULL, 0); - dbg(ctx, "region%d: iset-%#.16llx added\n", id, - region->iset.cookie); - } - sprintf(path, "%s/read_only", region_base); if (sysfs_read_attr(ctx, path, buf) < 0) goto err_read; @@ -1620,6 +1633,9 @@ static void *add_region(void *parent, int id, const char *region_base) goto err_read; region->module = to_module(ctx, buf); + if (region_set_type(region, path) < 0) + goto err_read; + region->region_buf = calloc(1, strlen(region_base) + 50); if (!region->region_buf) goto err_read;