From patchwork Tue Mar 8 23:36:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8538331 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A0D3BC0553 for ; Tue, 8 Mar 2016 23:37:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A86D0201FA for ; Tue, 8 Mar 2016 23:37:06 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id AA4D3201EF for ; Tue, 8 Mar 2016 23:37:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3BC6D1A1F3E; Tue, 8 Mar 2016 15:37:19 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id B4C611A1F3E for ; Tue, 8 Mar 2016 15:37:18 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP; 08 Mar 2016 15:37:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,558,1449561600"; d="scan'208";a="62455204" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by fmsmga004.fm.intel.com with ESMTP; 08 Mar 2016 15:37:04 -0800 Subject: [ndctl PATCH 2/8] ndctl: ndctl_{namespace|pfn}_get_resource From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 08 Mar 2016 15:36:38 -0800 Message-ID: <20160308233638.18628.9488.stgit@dwillia2-desk3.jf.intel.com> In-Reply-To: <20160308233628.18628.13786.stgit@dwillia2-desk3.jf.intel.com> References: <20160308233628.18628.13786.stgit@dwillia2-desk3.jf.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.17 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Retrieve the physical address corresponding to sector-0 of a pmem device. Note that ndctl_pfn_get_resource() is only valid while the given pfn instance is enabled. Reported-by: Haozhong Zhang Signed-off-by: Dan Williams --- lib/libndctl.c | 36 +++++++++++++++++++++++++++++++++++- lib/libndctl.sym | 3 +++ lib/ndctl/libndctl.h | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/libndctl.c b/lib/libndctl.c index 56838c8a2a92..91e855bf525a 100644 --- a/lib/libndctl.c +++ b/lib/libndctl.c @@ -246,7 +246,7 @@ struct ndctl_namespace { char *bdev; int type, id, buf_len, raw_mode; int generation; - unsigned long long size; + unsigned long long resource, size; char *alt_name; uuid_t uuid; struct ndctl_lbasize lbasize; @@ -297,6 +297,7 @@ struct ndctl_pfn { struct list_node list; enum ndctl_pfn_loc loc; unsigned long align; + unsigned long long resource, size; char *pfn_path; char *pfn_buf; char *bdev; @@ -2669,6 +2670,12 @@ static int add_namespace(void *parent, int id, const char *ndns_base) goto err_read; ndns->size = strtoull(buf, NULL, 0); + sprintf(path, "%s/resource", ndns_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + ndns->resource = ULLONG_MAX; + else + ndns->resource = strtoull(buf, NULL, 0); + sprintf(path, "%s/force_raw", ndns_base); if (sysfs_read_attr(ctx, path, buf) < 0) goto err_read; @@ -3312,6 +3319,11 @@ NDCTL_EXPORT unsigned long long ndctl_namespace_get_size(struct ndctl_namespace return ndns->size; } +NDCTL_EXPORT unsigned long long ndctl_namespace_get_resource(struct ndctl_namespace *ndns) +{ + return ndns->resource; +} + static int namespace_set_size(struct ndctl_namespace *ndns, unsigned long long size) { @@ -3853,6 +3865,18 @@ static int add_pfn(void *parent, int id, const char *pfn_base) else pfn->align = strtoul(buf, NULL, 0); + sprintf(path, "%s/resource", pfn_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + pfn->resource = ULLONG_MAX; + else + pfn->resource = strtoull(buf, NULL, 0); + + sprintf(path, "%s/size", pfn_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + pfn->size = ULLONG_MAX; + else + pfn->size = strtoull(buf, NULL, 0); + free(path); ndctl_pfn_foreach(region, pfn_dup) if (pfn->id == pfn_dup->id) { @@ -3924,6 +3948,16 @@ NDCTL_EXPORT void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu) memcpy(uu, pfn->uuid, sizeof(uuid_t)); } +NDCTL_EXPORT unsigned long long ndctl_pfn_get_size(struct ndctl_pfn *pfn) +{ + return pfn->size; +} + +NDCTL_EXPORT unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn) +{ + return pfn->resource; +} + NDCTL_EXPORT int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu) { struct ndctl_ctx *ctx = ndctl_pfn_get_ctx(pfn); diff --git a/lib/libndctl.sym b/lib/libndctl.sym index 38c588cb8864..6c74e73189f6 100644 --- a/lib/libndctl.sym +++ b/lib/libndctl.sym @@ -149,6 +149,7 @@ global: ndctl_namespace_set_alt_name; ndctl_namespace_get_size; ndctl_namespace_set_size; + ndctl_namespace_get_resource; ndctl_namespace_get_supported_sector_size; ndctl_namespace_get_sector_size; ndctl_namespace_get_num_sector_sizes; @@ -197,6 +198,8 @@ global: ndctl_pfn_get_location; ndctl_pfn_set_location; ndctl_pfn_get_align; + ndctl_pfn_get_size; + ndctl_pfn_get_resource; ndctl_pfn_set_align; ndctl_pfn_set_namespace; ndctl_pfn_get_bus; diff --git a/lib/ndctl/libndctl.h b/lib/ndctl/libndctl.h index 17770f78ce01..dbe98b0f159b 100644 --- a/lib/ndctl/libndctl.h +++ b/lib/ndctl/libndctl.h @@ -353,6 +353,7 @@ const char *ndctl_namespace_get_alt_name(struct ndctl_namespace *ndns); int ndctl_namespace_set_alt_name(struct ndctl_namespace *ndns, const char *alt_name); unsigned long long ndctl_namespace_get_size(struct ndctl_namespace *ndns); +unsigned long long ndctl_namespace_get_resource(struct ndctl_namespace *ndns); int ndctl_namespace_set_size(struct ndctl_namespace *ndns, unsigned long long size); unsigned int ndctl_namespace_get_supported_sector_size( @@ -430,6 +431,8 @@ int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu); void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu); int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align); unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn); +unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn); +unsigned long long ndctl_pfn_get_size(struct ndctl_pfn *pfn); int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns); struct ndctl_namespace *ndctl_pfn_get_namespace(struct ndctl_pfn *pfn); int ndctl_pfn_enable(struct ndctl_pfn *pfn);