From patchwork Tue Mar 8 23:36:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 8538351 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 8F6B9C0553 for ; Tue, 8 Mar 2016 23:37:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBD5920211 for ; Tue, 8 Mar 2016 23:37:17 +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 CFEA6201FA for ; Tue, 8 Mar 2016 23:37:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 62D0D1A1F36; Tue, 8 Mar 2016 15:37:30 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ml01.01.org (Postfix) with ESMTP id 23BE81A1F36 for ; Tue, 8 Mar 2016 15:37:29 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 08 Mar 2016 15:37:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,558,1449561600"; d="scan'208";a="919748232" Received: from dwillia2-desk3.jf.intel.com ([10.54.39.14]) by fmsmga001.fm.intel.com with ESMTP; 08 Mar 2016 15:37:15 -0800 Subject: [ndctl PATCH 4/8] ndctl: use the pfn trimmed size for memory mode namespaces From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 08 Mar 2016 15:36:49 -0800 Message-ID: <20160308233649.18628.96818.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 If the kernel reports the size of the namespace after the memmap allocation is removed use that value, otherwise don't emit raw namespace size since it is not accurate. For the btt case, the effective size is further constrained by the sector geometry, so userspace should just use the block device size. Otherwise, the size and base address of the namespace is useful for hypervisors that want to establish their own host-physical-address mappings for a guest to consume. Signed-off-by: Dan Williams --- util/json.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/util/json.c b/util/json.c index b9a5e75164d8..288efee723ff 100644 --- a/util/json.c +++ b/util/json.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -76,6 +77,8 @@ bool util_namespace_active(struct ndctl_namespace *ndns) struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) { struct json_object *jndns = json_object_new_object(); + unsigned long long size = ULLONG_MAX; + enum ndctl_namespace_mode mode; struct json_object *jobj; const char *bdev = NULL; struct ndctl_btt *btt; @@ -91,14 +94,22 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) goto err; json_object_object_add(jndns, "dev", jobj); - switch (ndctl_namespace_get_mode(ndns)) { + btt = ndctl_namespace_get_btt(ndns); + pfn = ndctl_namespace_get_pfn(ndns); + mode = ndctl_namespace_get_mode(ndns); + switch (mode) { case NDCTL_NS_MODE_MEMORY: + if (pfn) /* dynamic memory mode */ + size = ndctl_pfn_get_size(pfn); + else /* native/static memory mode */ + size = ndctl_namespace_get_size(ndns); jobj = json_object_new_string("memory"); break; case NDCTL_NS_MODE_SAFE: jobj = json_object_new_string("sector"); break; case NDCTL_NS_MODE_RAW: + size = ndctl_namespace_get_size(ndns); jobj = json_object_new_string("raw"); break; default: @@ -107,13 +118,12 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns) if (jobj) json_object_object_add(jndns, "mode", jobj); - jobj = json_object_new_int64(ndctl_namespace_get_size(ndns)); - if (!jobj) - goto err; - json_object_object_add(jndns, "size", jobj); + if (size < ULLONG_MAX) { + jobj = json_object_new_int64(size); + if (jobj) + json_object_object_add(jndns, "size", jobj); + } - btt = ndctl_namespace_get_btt(ndns); - pfn = ndctl_namespace_get_pfn(ndns); if (btt) { ndctl_btt_get_uuid(btt, uuid); uuid_unparse(uuid, buf);