From patchwork Mon Jan 29 21:48:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10190985 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 A4B5860375 for ; Mon, 29 Jan 2018 21:48:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 976D3288FC for ; Mon, 29 Jan 2018 21:48:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A627288FE; Mon, 29 Jan 2018 21:48:08 +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 1BABA288FC for ; Mon, 29 Jan 2018 21:48:08 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 80AA02222C233; Mon, 29 Jan 2018 13:42:33 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=ross.zwisler@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 012082215BD88 for ; Mon, 29 Jan 2018 13:42:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2018 13:48:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,432,1511856000"; d="scan'208";a="27268309" Received: from theros.lm.intel.com ([10.232.112.164]) by orsmga001.jf.intel.com with ESMTP; 29 Jan 2018 13:48:05 -0800 From: Ross Zwisler To: Dave Jiang , Dan Williams , linux-nvdimm@lists.01.org Subject: [ndctl PATCH v3 2/2] ndctl: add sector_size to 'ndctl list' output Date: Mon, 29 Jan 2018 14:48:00 -0700 Message-Id: <20180129214800.13750-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP It used to be that the only PMEM namespaces with a variable sector size were ones with a BTT, but that has changed. sector_size still doesn't make sense for device DAX since we don't have a block I/O path. If we don't have a specified sector size, as happens with namespaces of devtype nd_namespace_io and older v1.1 namespace labels, we will display the default sector size of 512. Signed-off-by: Ross Zwisler Reviewed-by: Dave Jiang Reviewed-by: Dan Williams --- util/json.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/util/json.c b/util/json.c index 95beaa2..17d8f13 100644 --- a/util/json.c +++ b/util/json.c @@ -718,11 +718,6 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, goto err; json_object_object_add(jndns, "uuid", jobj); - jobj = json_object_new_int(ndctl_btt_get_sector_size(btt)); - if (!jobj) - goto err; - json_object_object_add(jndns, "sector_size", jobj); - bdev = ndctl_btt_get_block_device(btt); } else if (pfn) { ndctl_pfn_get_uuid(pfn, uuid); @@ -774,6 +769,30 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, } else bdev = ndctl_namespace_get_block_device(ndns); + jobj = NULL; + if (btt) { + jobj = json_object_new_int(ndctl_btt_get_sector_size(btt)); + if (!jobj) + goto err; + } else if (!dax) { + unsigned int sector_size = ndctl_namespace_get_sector_size(ndns); + + /* + * The kernel will default to a 512 byte sector size on PMEM + * namespaces that don't explicitly have a sector size. This + * happens because they use pre-v1.2 labels or because they + * don't have a label space (devtype=nd_namespace_io). + */ + if (!sector_size) + sector_size = 512; + + jobj = json_object_new_int(sector_size); + if (!jobj) + goto err; + } + if (jobj) + json_object_object_add(jndns, "sector_size", jobj); + if (bdev && bdev[0]) { jobj = json_object_new_string(bdev); if (!jobj)