From patchwork Wed May 25 23:26:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9136349 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 C4427607D7 for ; Wed, 25 May 2016 23:27:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF2B228255 for ; Wed, 25 May 2016 23:27:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3F8F282E8; Wed, 25 May 2016 23:27:51 +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.1 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RDNS_NONE autolearn=no version=3.3.1 Received: from ml01.01.org (unknown [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 EAB5C28255 for ; Wed, 25 May 2016 23:27:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E76A71A1E70; Wed, 25 May 2016 16:27:39 -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]) by ml01.01.org (Postfix) with ESMTP id 225741A1E70 for ; Wed, 25 May 2016 16:27:38 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP; 25 May 2016 16:27:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,365,1459839600"; d="scan'208";a="110581753" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by fmsmga004.fm.intel.com with ESMTP; 25 May 2016 16:27:26 -0700 Subject: [ndctl PATCH] ndctl, list: display named devices by default From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 25 May 2016 16:26:41 -0700 Message-ID: <146421880119.1718.16999953314573964681.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.21 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 Instead of being silent when no list options are specified, default to list the device if it is the only parameter specified. For example, before: # ndctl list -d nmem0 # ...after: # ndctl list -d nmem0 { "dev":"nmem0", "id":"cdab-ffffffff" } # ...in other words omit the need for --dimms to be specified for this case. Reported-by: Vishal Verma Signed-off-by: Dan Williams Reviewed-by: Vishal Verma --- ndctl/builtin-list.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ndctl/builtin-list.c b/ndctl/builtin-list.c index 2080337252c8..5c5dc5a5db5b 100644 --- a/ndctl/builtin-list.c +++ b/ndctl/builtin-list.c @@ -179,6 +179,11 @@ static struct json_object *region_to_json(struct ndctl_region *region) return NULL; } +static int num_list_flags(void) +{ + return list.buses + list.dimms + list.regions + list.namespaces; +} + int cmd_list(int argc, const char **argv) { const struct option options[] = { @@ -212,9 +217,6 @@ int cmd_list(int argc, const char **argv) unsigned int type = 0; int i, rc; - if (argc == 1) - list.namespaces = true; - argc = parse_options(argc, argv, options, u, 0); for (i = 0; i < argc; i++) error("unknown parameter \"%s\"\n", argv[i]); @@ -228,6 +230,15 @@ int cmd_list(int argc, const char **argv) if (argc) usage_with_options(u, options); + if (num_list_flags() == 0) { + list.buses = !!param.bus; + list.regions = !!param.region; + list.dimms = !!param.dimm; + } + + if (num_list_flags() == 0) + list.namespaces = true; + if (param.type) { if (strcmp(param.type, "pmem") == 0) type = ND_DEVICE_REGION_PMEM;