From patchwork Wed Jan 16 09:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10765599 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 0073313A4 for ; Wed, 16 Jan 2019 09:49:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E063B2B987 for ; Wed, 16 Jan 2019 09:49:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4B932BACC; Wed, 16 Jan 2019 09:49:35 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 D55002B987 for ; Wed, 16 Jan 2019 09:49:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CDBE6211B8183; Wed, 16 Jan 2019 01:49:34 -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=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4C599211B7F66 for ; Wed, 16 Jan 2019 01:49:33 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id u6so2813629pfh.11 for ; Wed, 16 Jan 2019 01:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r2HF3WJiQ2JXy+3DKuth6Tjhit44q897NLF3yrZ+lYY=; b=qS/l+62vvRwl0wf6a9rYh7WTKMNXGthcWvQgFY2Cm9bu2CYSNlwFaRSjzhSLUQs6zX A3wfvEuDBzIBI54J5WVqa5nr0mIIf13tTOG6Xs6rsek/ut6ZBzTkTAPivbQebhFbYJyG sqlzejUiYIQlYw1pQrtsgJX7a3Kcf6rdKuERvhJLHnVR3WyvUaZH1PXhQhEfsp5KC9DE 6D/HDoasLgKaQSj2+lZpr/JqmN0yQ9YD++4KH2LJrhjT9YXn13jt4G02dZJ0QoIhgRv3 mH1fd2zBjr6R4JbKNkanmokPNYgIql/+o05RtfP9mfbrky2wBh61482O7jQoCOrgoea5 R37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r2HF3WJiQ2JXy+3DKuth6Tjhit44q897NLF3yrZ+lYY=; b=NwsojQOm81t131EoqZvhbyhVP/7op9E+/pt9VqFd6UwYVO64CzeFC8xPvA7yCkUWP6 bZTqPeLJSw1uXhPGht8XBvO6tE4oDt4QgC3mrzERxp6McKucDSdgx/cTs9W5gIFHnA26 D6spZ89oKuT7iJReGJTlrsUKG2spt62Nlh+9a1RVJ/4PzxsdM2X3T2SIjnLtP9P5wpxU 55va1eQdbnkO5A6v8wHk9BT8KLyuKFkfk2B9141WIS34eE//6K48T5oADfWO1iul32/j 7QAUIoHQ7DxbhppcwcD8FqSxt1k40hoC7HlcsUXGCXFU1IdDWqMhl7YUc7+ncqyhqpUD G6Jg== X-Gm-Message-State: AJcUukdFR6CjmOsy4OquxZN5FJDgpfPvLNUZ/2NhlNsMLXcyCgyiVmNE dbU51TfY4rZgE2zBuFECdAsr2BoS X-Google-Smtp-Source: ALg8bN4AdseZscQLEZa/btXZYX+HcPsp2arXcu/4qZP4S3SeuGnaoj4Q2LJX+jb8I+nT6+OMeWg8hQ== X-Received: by 2002:a63:62c4:: with SMTP id w187mr7511226pgb.230.1547632172676; Wed, 16 Jan 2019 01:49:32 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id f13sm8777331pfa.132.2019.01.16.01.49.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 01:49:32 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v3 6/6] ndctl: Add supported_alignments to the JSON output Date: Wed, 16 Jan 2019 20:49:09 +1100 Message-Id: <20190116094909.23112-6-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190116094909.23112-1-oohall@gmail.com> References: <20190116094909.23112-1-oohall@gmail.com> 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 Add the list of supported alignemnts to PFN and DAX namespaces. Also add the list of supported sector sizes to BTT namespaces. Signed-off-by: Oliver O'Halloran --- Not sure the namespace JSON blob are the best place to put these. The region might be better, but slightly less accessable to users. --- util/json.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/util/json.c b/util/json.c index 77c96fb53c27..6c66033bd312 100644 --- a/util/json.c +++ b/util/json.c @@ -303,6 +303,38 @@ struct json_object *util_daxctl_devs_to_list(struct daxctl_region *region, return jdevs; } +#define _SZ(get_max, get_elem, type) \ +static struct json_object *type##_build_size_array(struct type *arg) \ +{ \ + struct json_object *arr = json_object_new_array(); \ + int i; \ + \ + if (!arr) \ + return NULL; \ + \ + for (i = 0; i < get_max(arg); i++) { \ + struct json_object *jobj; \ + int64_t align; \ + \ + align = get_elem(arg, i); \ + jobj = json_object_new_int64(align); \ + if (!jobj) \ + goto err; \ + json_object_array_add(arr, jobj); \ + } \ + \ + return arr; \ +err: \ + json_object_put(arr); \ + return NULL; \ +} +#define SZ(type, kind) _SZ(ndctl_##type##_get_num_##kind##s, \ + ndctl_##type##_get_supported_##kind, ndctl_##type) +SZ(pfn, alignment) +SZ(dax, alignment) +SZ(btt, sector_size) +//SZ(namespace, sector_size) + struct json_object *util_daxctl_region_to_json(struct daxctl_region *region, const char *ident, unsigned long flags) { @@ -739,7 +771,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, { struct json_object *jndns = json_object_new_object(); enum ndctl_pfn_loc loc = NDCTL_PFN_LOC_NONE; - struct json_object *jobj, *jbbs = NULL; + struct json_object *jobj, *jbbs = NULL, *size_array = NULL; const char *locations[] = { [NDCTL_PFN_LOC_NONE] = "none", [NDCTL_PFN_LOC_RAM] = "mem", @@ -749,6 +781,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, unsigned int sector_size = UINT_MAX; enum ndctl_namespace_mode mode; const char *bdev = NULL, *name; + const char *size_array_name; unsigned int bb_count = 0; struct ndctl_btt *btt; struct ndctl_pfn *pfn; @@ -936,6 +969,19 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "numa_node", jobj); } + if (pfn) { + size_array_name = "supported_alignments"; + size_array = ndctl_pfn_build_size_array(pfn); + } else if (dax) { + size_array_name = "supported_alignments"; + size_array = ndctl_dax_build_size_array(dax); + } else if (btt) { + size_array_name = "supported sector sizes"; + size_array = ndctl_btt_build_size_array(btt); + } + if (size_array) + json_object_object_add(jndns, size_array_name, size_array); + if (pfn) jbbs = util_pfn_badblocks_to_json(pfn, &bb_count, flags); else if (dax)