From patchwork Wed Mar 6 01:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10840309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2B5A180E for ; Wed, 6 Mar 2019 01:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE2BA2D07F for ; Wed, 6 Mar 2019 01:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2CD32D09F; Wed, 6 Mar 2019 01:47:00 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 84CE42D07F for ; Wed, 6 Mar 2019 01:47:00 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7C21B211D56AE; Tue, 5 Mar 2019 17:47:00 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 282B521A134A1 for ; Tue, 5 Mar 2019 17:46:59 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2019 17:46:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,446,1544515200"; d="scan'208";a="324576531" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga006.fm.intel.com with ESMTP; 05 Mar 2019 17:46:58 -0800 Subject: [ndctl PATCH 4/5] ndctl/dimm: Limit read-labels with --index option From: Dan Williams To: linux-nvdimm@lists.01.org Date: Tue, 05 Mar 2019 17:34:20 -0800 Message-ID: <155183606035.191625.14877180930823274559.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <155183603979.191625.11689546261255336448.stgit@dwillia2-desk3.amr.corp.intel.com> References: <155183603979.191625.11689546261255336448.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 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 Provide a capability to limit the read-labels payload to just the index-block data space. Signed-off-by: Dan Williams --- ndctl/dimm.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 478e0fea3afc..a4b9999d9c67 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -54,6 +54,7 @@ static struct parameters { bool master_pass; bool human; bool force; + bool index; bool json; bool verbose; } param = { @@ -275,27 +276,26 @@ static struct json_object *dump_json(struct ndctl_dimm *dimm, if (!jdimm) return NULL; - jindex = dump_index_json(cmd_read, size); - if (!jindex) - goto err_jindex; - jlabel = dump_label_json(dimm, cmd_read, size, flags); - if (!jlabel) - goto err_jlabel; jobj = json_object_new_string(ndctl_dimm_get_devname(dimm)); if (!jobj) - goto err_jobj; - + goto err; json_object_object_add(jdimm, "dev", jobj); + + jindex = dump_index_json(cmd_read, size); + if (!jindex) + goto err; json_object_object_add(jdimm, "index", jindex); + if (param.index) + return jdimm; + + jlabel = dump_label_json(dimm, cmd_read, size, flags); + if (!jlabel) + goto err; json_object_object_add(jdimm, "label", jlabel); - return jdimm; - err_jobj: - json_object_put(jlabel); - err_jlabel: - json_object_put(jindex); - err_jindex: + return jdimm; +err: json_object_put(jdimm); return NULL; } @@ -384,7 +384,11 @@ static int action_read(struct ndctl_dimm *dimm, struct action_context *actx) ssize_t size; int rc = 0; - cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, param.offset); + if (param.index) + cmd_read = ndctl_dimm_read_label_index(dimm); + else + cmd_read = ndctl_dimm_read_label_extent(dimm, param.len, + param.offset); if (!cmd_read) return -EINVAL; @@ -1046,7 +1050,8 @@ OPT_BOOLEAN('v',"verbose", ¶m.verbose, "turn on debug") OPT_STRING('o', "output", ¶m.outfile, "output-file", \ "filename to write label area contents"), \ OPT_BOOLEAN('j', "json", ¶m.json, "parse label data into json"), \ -OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats ") +OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats "), \ +OPT_BOOLEAN('I', "index", ¶m.index, "limit read to the index block area") #define WRITE_OPTIONS() \ OPT_STRING('i', "input", ¶m.infile, "input-file", \ @@ -1173,6 +1178,12 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, return -EINVAL; } + if (param.index && param.len) { + fprintf(stderr, "pick either --size, or --index, not both\n"); + usage_with_options(u, options); + return -EINVAL; + } + if (param.json) { actx.jdimms = json_object_new_array(); if (!actx.jdimms)