From patchwork Wed Jul 19 18:33:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9852981 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 B0840602C8 for ; Wed, 19 Jul 2017 18:39:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 969222863B for ; Wed, 19 Jul 2017 18:39:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B63928672; Wed, 19 Jul 2017 18:39:34 +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 437292863B for ; Wed, 19 Jul 2017 18:39:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E863D21D147CF; Wed, 19 Jul 2017 11:37:38 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: 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 8E43121D0B67E for ; Wed, 19 Jul 2017 11:37:37 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jul 2017 11:39:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,381,1496127600"; d="scan'208";a="129400108" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga006.fm.intel.com with ESMTP; 19 Jul 2017 11:39:32 -0700 Subject: [ndctl PATCH 2/6] daxctl: stop carrying 'dax_region' in the daxctl_region region_path From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 19 Jul 2017 11:33:07 -0700 Message-ID: <150048918710.12895.9803911483651783630.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150048917662.12895.15953645444185664230.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150048917662.12895.15953645444185664230.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 Clean up region_path to carry the region device path directly. This aligns libdaxctl with libndctl internal path names, and is a preparation for carrying absolute path names that are needed for multi-device-dax per region support. Signed-off-by: Dan Williams --- daxctl/lib/libdaxctl.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 019f31b5067c..41af6ee92300 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -27,6 +27,8 @@ #include #include "libdaxctl-private.h" +static const char *attrs = "dax_region"; + /** * struct daxctl_ctx - library user context to find "nd" instances * @@ -219,14 +221,16 @@ DAXCTL_EXPORT void daxctl_region_ref(struct daxctl_region *region) region->refcount++; } -static void *add_dax_region(void *parent, int id, const char *base) +static struct daxctl_region *add_dax_region(void *parent, int id, + const char *base) { struct daxctl_region *region, *region_dup; - const char *attrs = "dax_region"; struct daxctl_ctx *ctx = parent; char buf[SYSFS_ATTR_SIZE]; char *path; + dbg(ctx, "%s: \'%s\'\n", __func__, base); + daxctl_region_foreach(ctx, region_dup) if (region_dup->id == id) return region_dup; @@ -255,12 +259,12 @@ static void *add_dax_region(void *parent, int id, const char *base) if (sysfs_read_attr(ctx, path, buf) == 0) region->align = strtoul(buf, NULL, 0); - sprintf(path, "%s/%s", base, attrs); - region->region_path = strdup(path); + region->region_path = strdup(base); if (!region->region_path) goto err_read; - region->region_buf = calloc(1, strlen(path) + REGION_BUF_SIZE); + region->region_buf = calloc(1, strlen(path) + strlen(attrs) + + REGION_BUF_SIZE); if (!region->region_buf) goto err_read; region->buf_len = strlen(path) + REGION_BUF_SIZE; @@ -306,6 +310,7 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base) if (!path) return NULL; + dbg(ctx, "%s: base: \'%s\'\n", __func__, daxdev_base); dev = calloc(1, sizeof(*dev)); if (!dev) @@ -382,8 +387,8 @@ DAXCTL_EXPORT unsigned long long daxctl_region_get_available_size( int len = region->buf_len; unsigned long long avail; - if (snprintf(path, len, "%s/available_size", - region->region_path) >= len) { + if (snprintf(path, len, "%s/%s/available_size", + region->region_path, attrs) >= len) { err(ctx, "%s: buffer too small!\n", daxctl_region_get_devname(region)); return 0; @@ -407,7 +412,7 @@ DAXCTL_EXPORT struct daxctl_dev *daxctl_region_get_dev_seed( char buf[SYSFS_ATTR_SIZE]; struct daxctl_dev *dev; - if (snprintf(path, len, "%s/seed", region->region_path) >= len) { + if (snprintf(path, len, "%s/%s/seed", region->region_path, attrs) >= len) { err(ctx, "%s: buffer too small!\n", daxctl_region_get_devname(region)); return NULL;