From patchwork Mon Sep 11 02:39:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?R290b3UsIFlhc3Vub3JpL+S6lOWztiDlurfmloc=?= X-Patchwork-Id: 9946505 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 969C9602C9 for ; Mon, 11 Sep 2017 02:39:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 880EA28A84 for ; Mon, 11 Sep 2017 02:39:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CA0228A89; Mon, 11 Sep 2017 02:39:55 +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 0C9E428A84 for ; Mon, 11 Sep 2017 02:39:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 554082095BB74; Sun, 10 Sep 2017 19:36:30 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mgwkm03.jp.fujitsu.com (mgwkm03.jp.fujitsu.com [202.219.69.170]) (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 B4DD120958BCF for ; Sun, 10 Sep 2017 19:36:28 -0700 (PDT) Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [192.168.231.132]) by mgwkm03.jp.fujitsu.com with smtp id 6c10_6e59_b30f12dd_7161_4816_b8c6_3b33d1d36abc; Mon, 11 Sep 2017 11:39:18 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id 581CCAC00B2 for ; Mon, 11 Sep 2017 11:39:17 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 60bf408847e0455b8506f40bca48595e Date: Mon, 11 Sep 2017 11:39:03 +0900 From: Yasunori Goto To: Subject: [PATCH ndctl] ndctl: sort by dimm's number when bad dimms are shown. In-Reply-To: <20170911112149.17E3.E1E9C6FF@jp.fujitsu.com> References: <150490956040.8621.9918102309170733621.stgit@dwillia2-desk3.amr.corp.intel.com> <20170911112149.17E3.E1E9C6FF@jp.fujitsu.com> Message-Id: <20170911113900.17E6.E1E9C6FF@jp.fujitsu.com> MIME-Version: 1.0 X-Mailer: Becky! ver. 2.73 [ja] X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 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 > > + > > + if (!found) > > + goto err_found; > > + > > + for (i = 0; i < found; i++) { > > + const char *devname = ndctl_dimm_get_devname(dimms[i]); > > + > > + jobj = json_object_new_string(devname); > > + if (!jobj) > > + break; > > + json_object_array_add(jdimms, jobj); > > + } > > I have one comment. > > If output is sorted by device number here, > it may be friendly for users. > (Especially, # of interleave way becomes huge in future...) > > Other things are looks good for me. I made a patch to make sorting. I hope it will help.... ------- To make user friendly, it is desirable that ndctl sorts by dimm's number, when output dimms which have badblocks. Signed-off-by: Yasunori Goto --- util/json.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/util/json.c b/util/json.c index 9b7773e..dac8692 100644 --- a/util/json.c +++ b/util/json.c @@ -366,6 +366,21 @@ struct json_object *util_daxctl_region_to_json(struct daxctl_region *region, return NULL; } +static int compare_dimm_number(const void *p1, const void *p2) +{ + struct ndctl_dimm *dimm1 = *(struct ndctl_dimm **)p1; + struct ndctl_dimm *dimm2 = *(struct ndctl_dimm **)p2; + const char *dimm1_name = ndctl_dimm_get_devname(dimm1); + const char *dimm2_name = ndctl_dimm_get_devname(dimm2); + int num1, num2; + + sscanf(dimm1_name, "nmem%d", &num1); + sscanf(dimm2_name, "nmem%d", &num2); + + return num1 - num2; + +} + static struct json_object *badblocks_to_jdimms(struct ndctl_region *region, unsigned long long addr, unsigned long len) { @@ -399,6 +414,8 @@ static struct json_object *badblocks_to_jdimms(struct ndctl_region *region, if (!found) goto err_found; + qsort(dimms, found, sizeof(dimm), compare_dimm_number); + for (i = 0; i < found; i++) { const char *devname = ndctl_dimm_get_devname(dimms[i]);