From patchwork Fri Dec 18 02:14:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11981063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AD49C4361B for ; Fri, 18 Dec 2020 02:15:02 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 34B4123A59 for ; Fri, 18 Dec 2020 02:15:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34B4123A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C7AF7100EB322; Thu, 17 Dec 2020 18:15:01 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=141.146.126.79; helo=aserp2130.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) (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 409E3100EB855 for ; Thu, 17 Dec 2020 18:14:58 -0800 (PST) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI2DoW7069588; Fri, 18 Dec 2020 02:14:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=6MBEvjCkL2aXmE5D8EqV1A4XQpQVwnU2JNtG0eD/Qg4=; b=DTrayLGzmWtMpj1yFXNQOUj/Vd9kCY+D9VyMeiOhWSn9FAdHRE80IhYaGkVIOq8Yhqal 3C94m40C3+rER7Dhg+26Krioo0Jd4K85gcxDii1QJiovMgUvDMWq3PcVEJtcxGNG1nlq RDbVLXe8MbMHwJcHZpHI793KTq3jWl4+AEn8Dtd8uvy4iPF7g2aocVSFh9feSFcvI46B X6ivqA8IR2FrOJ2wU4G4q68Bv6RpJ02qIRqNHfO+FiWz4L04NDxzHbMSEl6RDMyD5ZYd OUdCZj2KXA4eLJhyUtG1rY/fXwzhYqJQTmA4+qcCLqmx4kYx5o5zO5yQBonE/hiVSeK5 vA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 35ckcbrfx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 02:14:56 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI25Ipf077684; Fri, 18 Dec 2020 02:14:55 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 35g3rfgvc5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 02:14:55 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BI2Es81014216; Fri, 18 Dec 2020 02:14:54 GMT Received: from paddy.uk.oracle.com (/10.175.180.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 18:14:54 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH daxctl v2 1/5] libdaxctl: add mapping iterator APIs Date: Fri, 18 Dec 2020 02:14:34 +0000 Message-Id: <20201218021438.8926-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com> References: <20201218021438.8926-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 suspectscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180012 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180013 Message-ID-Hash: 7G6BRAOOIGOAJRV5MZEAILV7QW6DA3DG X-Message-ID-Hash: 7G6BRAOOIGOAJRV5MZEAILV7QW6DA3DG X-MailFrom: joao.m.martins@oracle.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Joao Martins X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add the following APIs to be able to iterate over a dynamic device-dax mapping list, as well as fetching each of the mapping attributes. Signed-off-by: Joao Martins --- daxctl/lib/libdaxctl-private.h | 8 ++++ daxctl/lib/libdaxctl.c | 91 +++++++++++++++++++++++++++++++++++++++++- daxctl/lib/libdaxctl.sym | 6 +++ daxctl/libdaxctl.h | 12 ++++++ 4 files changed, 116 insertions(+), 1 deletion(-) diff --git a/daxctl/lib/libdaxctl-private.h b/daxctl/lib/libdaxctl-private.h index b307a8bc9438..6d05aefbeda0 100644 --- a/daxctl/lib/libdaxctl-private.h +++ b/daxctl/lib/libdaxctl-private.h @@ -91,6 +91,12 @@ struct daxctl_region { struct list_head devices; }; +struct daxctl_mapping { + struct daxctl_dev *dev; + unsigned long long pgoff, start, end; + struct list_node list; +}; + struct daxctl_dev { int id, major, minor; void *dev_buf; @@ -104,6 +110,8 @@ struct daxctl_dev { struct daxctl_region *region; struct daxctl_memory *mem; int target_node; + int num_mappings; + struct list_head mappings; }; struct daxctl_memory { diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 39871427c799..3781e9ed27d5 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -526,7 +526,8 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base) free(path); return dev_dup; } - + dev->num_mappings = -1; + list_head_init(&dev->mappings); list_add(®ion->devices, &dev->list); free(path); return dev; @@ -1150,6 +1151,94 @@ DAXCTL_EXPORT unsigned long daxctl_memory_get_block_size(struct daxctl_memory *m return mem->block_size; } +static void mappings_init(struct daxctl_dev *dev) +{ + struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev); + char buf[SYSFS_ATTR_SIZE]; + char *path = dev->dev_buf; + int i; + + if (dev->num_mappings != -1) + return; + + dev->num_mappings = 0; + for (;;) { + struct daxctl_mapping *mapping; + unsigned long long pgoff, start, end; + + i = dev->num_mappings; + mapping = calloc(1, sizeof(*mapping)); + if (!mapping) { + err(ctx, "%s: mapping%u allocation failure\n", + daxctl_dev_get_devname(dev), i); + continue; + } + + sprintf(path, "%s/mapping%d/start", dev->dev_path, i); + if (sysfs_read_attr(ctx, path, buf) < 0) { + free(mapping); + break; + } + start = strtoull(buf, NULL, 0); + + sprintf(path, "%s/mapping%d/end", dev->dev_path, i); + if (sysfs_read_attr(ctx, path, buf) < 0) { + free(mapping); + break; + } + end = strtoull(buf, NULL, 0); + + sprintf(path, "%s/mapping%d/page_offset", dev->dev_path, i); + if (sysfs_read_attr(ctx, path, buf) < 0) { + free(mapping); + break; + } + pgoff = strtoull(buf, NULL, 0); + + mapping->dev = dev; + mapping->start = start; + mapping->end = end; + mapping->pgoff = pgoff; + + dev->num_mappings++; + list_add(&dev->mappings, &mapping->list); + } +} + +DAXCTL_EXPORT struct daxctl_mapping *daxctl_mapping_get_first(struct daxctl_dev *dev) +{ + mappings_init(dev); + + return list_top(&dev->mappings, struct daxctl_mapping, list); +} + +DAXCTL_EXPORT struct daxctl_mapping *daxctl_mapping_get_next(struct daxctl_mapping *mapping) +{ + struct daxctl_dev *dev = mapping->dev; + + return list_next(&dev->mappings, mapping, list); +} + +DAXCTL_EXPORT unsigned long long daxctl_mapping_get_start(struct daxctl_mapping *mapping) +{ + return mapping->start; +} + +DAXCTL_EXPORT unsigned long long daxctl_mapping_get_end(struct daxctl_mapping *mapping) +{ + return mapping->end; +} + +DAXCTL_EXPORT unsigned long long daxctl_mapping_get_offset(struct daxctl_mapping *mapping) +{ + return mapping->pgoff; +} + +DAXCTL_EXPORT unsigned long long daxctl_mapping_get_size(struct daxctl_mapping *mapping) +{ + return mapping->end - mapping->start + 1; +} + static int memblock_is_online(struct daxctl_memory *mem, char *memblock) { struct daxctl_dev *dev = daxctl_memory_get_dev(mem); diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym index c3d08179c9fd..08362b683678 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -83,4 +83,10 @@ global: daxctl_region_destroy_dev; daxctl_dev_get_align; daxctl_dev_set_align; + daxctl_mapping_get_first; + daxctl_mapping_get_next; + daxctl_mapping_get_start; + daxctl_mapping_get_end; + daxctl_mapping_get_offset; + daxctl_mapping_get_size; } LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index b0bb5d78d357..f94a72fed85b 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -103,6 +103,18 @@ int daxctl_memory_online_no_movable(struct daxctl_memory *mem); region != NULL; \ region = daxctl_region_get_next(region)) +struct daxctl_mapping; +struct daxctl_mapping *daxctl_mapping_get_first(struct daxctl_dev *dev); +struct daxctl_mapping *daxctl_mapping_get_next(struct daxctl_mapping *mapping); +#define daxctl_mapping_foreach(dev, mapping) \ + for (mapping = daxctl_mapping_get_first(dev); \ + mapping != NULL; \ + mapping = daxctl_mapping_get_next(mapping)) +unsigned long long daxctl_mapping_get_start(struct daxctl_mapping *mapping); +unsigned long long daxctl_mapping_get_end(struct daxctl_mapping *mapping); +unsigned long long daxctl_mapping_get_offset(struct daxctl_mapping *mapping); +unsigned long long daxctl_mapping_get_size(struct daxctl_mapping *mapping); + #ifdef __cplusplus } /* extern "C" */ #endif From patchwork Fri Dec 18 02:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11981065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9B4AC2BBCF for ; Fri, 18 Dec 2020 02:15:03 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EF2723A5C for ; Fri, 18 Dec 2020 02:15:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF2723A5C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EA575100EB325; Thu, 17 Dec 2020 18:15:02 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=141.146.126.79; helo=aserp2130.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from aserp2130.oracle.com (aserp2130.oracle.com [141.146.126.79]) (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 9DAD5100EB85D for ; Thu, 17 Dec 2020 18:15:00 -0800 (PST) Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI2E5j2070189; Fri, 18 Dec 2020 02:14:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=i9+hp0ynoCYWyuzNCYHjrATZU9rsLmvfD0HKd2ID5/0=; b=XXxY/52VNsr9TY8jNbOraEpY3IS0tvN/eeaqutNAXaZzyCUBcF0wRyPCyDjrBMEiiZks Mzfa8iGaXF/fCcnkSz8L4n1JsZZMdooVXCDPQCHb2SAPx59s1VY2lxyi//ut4i3eDHzq hGK9H7AR4UIPT9xtVwJ9Ue4n0o1aMWexpxduaBU1y976BUZJ34niz6OKsrGUhR8sPd3W p6lWZQc+Krl/8FJxLR/d5ZgcMR52FVJD09EGmWjsQ0lPrHQZoWrXyvOTFUZ1kNEMFQer wWVkYZx/y0l/dLwaKg/DhPjbsjohfUYOLwipvBhBPz6vGTNBQ8izVxfeL76jK5jEI5bZ gQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 35ckcbrfx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 02:14:59 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI25KSV013798; Fri, 18 Dec 2020 02:14:58 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 35d7erq72t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 02:14:58 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BI2EwBg021959; Fri, 18 Dec 2020 02:14:58 GMT Received: from paddy.uk.oracle.com (/10.175.180.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 18:14:57 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH daxctl v2 2/5] daxctl: include mappings when listing Date: Fri, 18 Dec 2020 02:14:35 +0000 Message-Id: <20201218021438.8926-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com> References: <20201218021438.8926-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180012 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180013 Message-ID-Hash: 6GATPF4BI4UUO3P7RD3FDBJJXWW6KGLN X-Message-ID-Hash: 6GATPF4BI4UUO3P7RD3FDBJJXWW6KGLN X-MailFrom: joao.m.martins@oracle.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Joao Martins X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Iterate over the device mappings and print @page_offset, @start, @end and a computed size, but only if user passes -M|--mappings to daxctl list as the output can get verbose with a lot of mapping entries. Signed-off-by: Joao Martins --- Documentation/daxctl/daxctl-list.txt | 4 +++ daxctl/list.c | 4 +++ util/json.c | 57 +++++++++++++++++++++++++++++++++++- util/json.h | 4 +++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Documentation/daxctl/daxctl-list.txt b/Documentation/daxctl/daxctl-list.txt index cb82c3cc6fb2..5a6a98e73849 100644 --- a/Documentation/daxctl/daxctl-list.txt +++ b/Documentation/daxctl/daxctl-list.txt @@ -67,6 +67,10 @@ OPTIONS --devices:: Include device-dax instance info in the listing (default) +-M:: +--mappings:: + Include device-dax instance mappings info in the listing + -R:: --regions:: Include region info in the listing diff --git a/daxctl/list.c b/daxctl/list.c index 6c6251b4de37..6860a460e4c0 100644 --- a/daxctl/list.c +++ b/daxctl/list.c @@ -25,6 +25,7 @@ static struct { bool devs; bool regions; + bool mappings; bool idle; bool human; } list; @@ -35,6 +36,8 @@ static unsigned long listopts_to_flags(void) if (list.devs) flags |= UTIL_JSON_DAX_DEVS; + if (list.mappings) + flags |= UTIL_JSON_DAX_MAPPINGS; if (list.idle) flags |= UTIL_JSON_IDLE; if (list.human) @@ -70,6 +73,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx) "filter by dax device instance name"), OPT_BOOLEAN('D', "devices", &list.devs, "include dax device info"), OPT_BOOLEAN('R', "regions", &list.regions, "include dax region info"), + OPT_BOOLEAN('M', "mappings", &list.mappings, "include dax mappings info"), OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"), OPT_BOOLEAN('u', "human", &list.human, "use human friendly number formats "), diff --git a/util/json.c b/util/json.c index 357dff20d6be..dcc927294e4f 100644 --- a/util/json.c +++ b/util/json.c @@ -454,7 +454,8 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, { struct daxctl_memory *mem = daxctl_dev_get_memory(dev); const char *devname = daxctl_dev_get_devname(dev); - struct json_object *jdev, *jobj; + struct json_object *jdev, *jobj, *jmappings = NULL; + struct daxctl_mapping *mapping = NULL; int node, movable, align; jdev = json_object_new_object(); @@ -508,6 +509,25 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, json_object_object_add(jdev, "state", jobj); } + if (!(flags & UTIL_JSON_DAX_MAPPINGS)) + return jdev; + + daxctl_mapping_foreach(dev, mapping) { + struct json_object *jmapping; + + if (!jmappings) { + jmappings = json_object_new_array(); + if (!jmappings) + continue; + + json_object_object_add(jdev, "mappings", jmappings); + } + + jmapping = util_daxctl_mapping_to_json(mapping, flags); + if (!jmapping) + continue; + json_object_array_add(jmappings, jmapping); + } return jdev; } @@ -1357,6 +1377,41 @@ struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping, return NULL; } +struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping, + unsigned long flags) +{ + struct json_object *jmapping = json_object_new_object(); + struct json_object *jobj; + + if (!jmapping) + return NULL; + + jobj = util_json_object_hex(daxctl_mapping_get_offset(mapping), flags); + if (!jobj) + goto err; + json_object_object_add(jmapping, "page_offset", jobj); + + jobj = util_json_object_hex(daxctl_mapping_get_start(mapping), flags); + if (!jobj) + goto err; + json_object_object_add(jmapping, "start", jobj); + + jobj = util_json_object_hex(daxctl_mapping_get_end(mapping), flags); + if (!jobj) + goto err; + json_object_object_add(jmapping, "end", jobj); + + jobj = util_json_object_size(daxctl_mapping_get_size(mapping), flags); + if (!jobj) + goto err; + json_object_object_add(jmapping, "size", jobj); + + return jmapping; + err: + json_object_put(jmapping); + return NULL; +} + struct json_object *util_badblock_rec_to_json(u64 block, u64 count, unsigned long flags) { diff --git a/util/json.h b/util/json.h index 39a33789bac9..e26875a5ecd8 100644 --- a/util/json.h +++ b/util/json.h @@ -15,6 +15,7 @@ #include #include #include +#include #include enum util_json_flags { @@ -27,6 +28,7 @@ enum util_json_flags { UTIL_JSON_CAPABILITIES = (1 << 6), UTIL_JSON_CONFIGURED = (1 << 7), UTIL_JSON_FIRMWARE = (1 << 8), + UTIL_JSON_DAX_MAPPINGS = (1 << 9), }; struct json_object; @@ -38,6 +40,8 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm, unsigned long flags); struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping, unsigned long flags); +struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping, + unsigned long flags); struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, unsigned long flags); struct json_object *util_badblock_rec_to_json(u64 block, u64 count, From patchwork Fri Dec 18 02:14:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11981071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BEC4C4361B for ; Fri, 18 Dec 2020 02:17:07 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AFF0D23A5D for ; Fri, 18 Dec 2020 02:17:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFF0D23A5D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7E482100EB321; Thu, 17 Dec 2020 18:17:06 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=141.146.126.78; helo=aserp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (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 A3710100EB84D for ; Thu, 17 Dec 2020 18:17:03 -0800 (PST) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI2G5JC014056; Fri, 18 Dec 2020 02:17:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=sYgGLcTcsQaq4OWP+USSdocYF/Hqfy6hUH9SkjvBDzs=; b=Q5TMI+fo/HWdVuWSbH/5b4arfA2zFRGDHXJWsQFKeV3A+ddWVwUhzw3S77fF+GbOiJjj eIGC7FXPZEG5TKpyJ1csOvodvYj/4DJ7c+c9e+BYvxawDTetwLDon/W1lqdzBf+o7PpN GBzIsgAiwnueaGkTaD9h4Nk/yRexmOrsY8yMz7UgHFsm/M9ORfWpw3ro7Gq5WUAPIHHN 89ucd9dcishlnKgSYk+68WDrgszAGEt6rhQHROwVfhP2qLsfwYPjQzZlXBZmY6bSJyC/ E338vYt2H/wQURCYLeyQDdg29dNMq+fQkUiTChPcz8Qu3fo+8DDUXA5FBGrQMEZGqJHU 5w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 35cntmg9bq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 02:17:01 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI25Iwa101402; Fri, 18 Dec 2020 02:15:01 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 35e6eu4aw6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 02:15:01 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BI2F0JT026939; Fri, 18 Dec 2020 02:15:00 GMT Received: from paddy.uk.oracle.com (/10.175.180.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 18:15:00 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH daxctl v2 3/5] libdaxctl: add daxctl_dev_set_mapping() Date: Fri, 18 Dec 2020 02:14:36 +0000 Message-Id: <20201218021438.8926-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com> References: <20201218021438.8926-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180012 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180013 Message-ID-Hash: MUG6NKKW6T2KOUI3FNL5WBBGOWT4KQNM X-Message-ID-Hash: MUG6NKKW6T2KOUI3FNL5WBBGOWT4KQNM X-MailFrom: joao.m.martins@oracle.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Joao Martins X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This API adds the ability to manually pick a range within the region device. Such routine allows for a admin to restore the mappings of a device after kexec. This is specially useful for hmem dynamic devdax which do not persistent ranges allocation through say a e.g. namespace label storage area. It also allows an userspace application to pick it's own ranges, should it want to avoid relying on kernel's policy. Signed-off-by: Joao Martins --- daxctl/lib/libdaxctl.c | 27 +++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 1 + daxctl/libdaxctl.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 3781e9ed27d5..59fe84fee409 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -1123,6 +1123,33 @@ DAXCTL_EXPORT int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long ali return 0; } +DAXCTL_EXPORT int daxctl_dev_set_mapping(struct daxctl_dev *dev, + unsigned long long start, + unsigned long long end) +{ + struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev); + unsigned long long size = end - start + 1; + char buf[SYSFS_ATTR_SIZE]; + char *path = dev->dev_buf; + int len = dev->buf_len; + + if (snprintf(path, len, "%s/mapping", dev->dev_path) >= len) { + err(ctx, "%s: buffer too small!\n", + daxctl_dev_get_devname(dev)); + return -ENXIO; + } + + sprintf(buf, "%#llx-%#llx\n", start, end); + if (sysfs_write_attr(ctx, path, buf) < 0) { + err(ctx, "%s: failed to set mapping\n", + daxctl_dev_get_devname(dev)); + return -ENXIO; + } + dev->size += size; + + return 0; +} + DAXCTL_EXPORT int daxctl_dev_get_target_node(struct daxctl_dev *dev) { return dev->target_node; diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym index 08362b683678..a4e16848494b 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -89,4 +89,5 @@ global: daxctl_mapping_get_end; daxctl_mapping_get_offset; daxctl_mapping_get_size; + daxctl_dev_set_mapping; } LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index f94a72fed85b..09439c16d6df 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -73,6 +73,8 @@ unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev); int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long size); unsigned long daxctl_dev_get_align(struct daxctl_dev *dev); int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align); +int daxctl_dev_set_mapping(struct daxctl_dev *dev, unsigned long long start, + unsigned long long end); struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev); int daxctl_dev_is_enabled(struct daxctl_dev *dev); int daxctl_dev_disable(struct daxctl_dev *dev); From patchwork Fri Dec 18 02:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11981067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AE6DC4361B for ; Fri, 18 Dec 2020 02:15:10 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C2BB23A5D for ; Fri, 18 Dec 2020 02:15:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C2BB23A5D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0F88A100EB325; Thu, 17 Dec 2020 18:15:10 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=141.146.126.78; helo=aserp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (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 F1EC6100EB85C for ; Thu, 17 Dec 2020 18:15:07 -0800 (PST) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI2DuUk012449; Fri, 18 Dec 2020 02:15:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=568+5jShrNbw5FxMAj7MkwEXhKoo+U/+eWhVE4kNsWw=; b=RX2dX9NwyeDkjBWgTiGyz2BHW6/RHAgzb+ScWOd5kJ3+dNwBiYW6w8PqE+gAEdHN2GA4 8NiJvMAofTiEMxg4mbeKvBVQs9resTnrGFzw1RO4J1qZH138RG/3L/x2sv6szpeXB8w1 nwsMVXs0eg7HNJ+x426BYe6UdPiLB0jJX6fa8UzcdKUOxhYvMdicsi8g/nLEZlMJxLG5 +ebjwMyR+rMKO42/MydJeN1A0lajwsj3r2kZj2Nkt6Pr5Z142SnKsC8oLLvYfoVyHXj4 xoyj6sTm1+lwA1A3sA8bkPIE9HhxoEb2R8gpkRkmpC6GT/kFhOBnOroJLOeLiNpOn+1I eA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 35cntmg95t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 02:15:04 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI26ICA194854; Fri, 18 Dec 2020 02:15:04 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 35d7t180sf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 02:15:03 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BI2F2rF021988; Fri, 18 Dec 2020 02:15:02 GMT Received: from paddy.uk.oracle.com (/10.175.180.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 18:15:02 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH daxctl v2 4/5] daxctl: allow creating devices from input json Date: Fri, 18 Dec 2020 02:14:37 +0000 Message-Id: <20201218021438.8926-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com> References: <20201218021438.8926-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180012 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180013 Message-ID-Hash: 5OBZJMW244UHL625643D3FX2JCV7W3FH X-Message-ID-Hash: 5OBZJMW244UHL625643D3FX2JCV7W3FH X-MailFrom: joao.m.martins@oracle.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Joao Martins X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add an option namely --input which passes a parameter which is a JSON file path. The JSON file contains the data usually returned by: $ daxctl list -d dax0.1 | jq -er '.[]' > device.json { "chardev":"dax0.1", "size":34359738368, "target_node":0, "align":1073741824, "mode":"devdax", "mappings":[ { "page_offset":4194304, "start":25769803776, "end":42949672959, "size":17179869184 }, { "page_offset":0, "start":8589934592, "end":25769803775, "size":17179869184 } ] } The input values in the mapping json are decimal for now. A device can then be created by specifying this same data to re-create it e.g. $ daxctl create-device -u --input device.json { "chardev":"dax0.1", "size":"32.00 GiB (34.36 GB)", "target_node":0, "align":"1024.00 MiB (1073.74 MB)", "mode":"devdax", } $ daxctl list -d dax0.1 { "chardev":"dax0.1", "size":34359738368, "target_node":0, "align":1073741824, "mode":"devdax", "mappings":[ { "page_offset":4194304, "start":25769803776, "end":42949672959, "size":17179869184 }, { "page_offset":0, "start":8589934592, "end":25769803775, "size":17179869184 } ] } created 1 device This means we can restore/recreate previously established mappings. Signed-off-by: Joao Martins --- Documentation/daxctl/daxctl-create-device.txt | 13 +++ daxctl/device.c | 128 +++++++++++++++++++++++++- 2 files changed, 136 insertions(+), 5 deletions(-) diff --git a/Documentation/daxctl/daxctl-create-device.txt b/Documentation/daxctl/daxctl-create-device.txt index 7f64719d16f2..05f4dbd9d61c 100644 --- a/Documentation/daxctl/daxctl-create-device.txt +++ b/Documentation/daxctl/daxctl-create-device.txt @@ -90,6 +90,19 @@ include::region-option.txt[] to 2M. Note that "devdax" mode enforces all mappings to be aligned to this value, i.e. it fails unaligned mapping attempts. +--input:: + Applications that want to select ranges assigned to a device-dax + instance, or wanting to establish previously created devices, can + pass an input JSON file. The file option lets a user pass a JSON + object similar to the one listed with "daxctl list". + + The device name is not re-created, but if a "chardev" is passed in + the JSON file, it will use that to get the region id. + + Note that the JSON content in the file cannot be an array of + JSON objects but rather a single JSON object i.e. without the + array enclosing brackets. + include::human-option.txt[] include::verbose-option.txt[] diff --git a/daxctl/device.c b/daxctl/device.c index 3c2d4e3d8b48..fe4291199312 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ static struct { const char *region; const char *size; const char *align; + const char *input; bool no_online; bool no_movable; bool force; @@ -36,10 +38,16 @@ enum dev_mode { DAXCTL_DEV_MODE_RAM, }; +struct mapping { + unsigned long long start, end, pgoff; +}; + static enum dev_mode reconfig_mode = DAXCTL_DEV_MODE_UNKNOWN; static long long align = -1; static long long size = -1; static unsigned long flags; +static struct mapping *maps = NULL; +static long long nmaps = -1; enum memory_zone { MEM_ZONE_MOVABLE, @@ -71,7 +79,8 @@ OPT_BOOLEAN('f', "force", ¶m.force, \ #define CREATE_OPTIONS() \ OPT_STRING('s', "size", ¶m.size, "size", "size to switch the device to"), \ -OPT_STRING('a', "align", ¶m.align, "align", "alignment to switch the device to") +OPT_STRING('a', "align", ¶m.align, "align", "alignment to switch the device to"), \ +OPT_STRING('\0', "input", ¶m.input, "input", "input device JSON file") #define DESTROY_OPTIONS() \ OPT_BOOLEAN('f', "force", ¶m.force, \ @@ -124,6 +133,94 @@ static const struct option destroy_options[] = { OPT_END(), }; +static int sort_mappings(const void *a, const void *b) +{ + json_object **jsoa, **jsob; + struct json_object *va, *vb; + unsigned long long pga, pgb; + + jsoa = (json_object **)a; + jsob = (json_object **)b; + if (!*jsoa && !*jsob) + return 0; + + if (!json_object_object_get_ex(*jsoa, "page_offset", &va) || + !json_object_object_get_ex(*jsob, "page_offset", &vb)) + return 0; + + pga = json_object_get_int64(va); + pgb = json_object_get_int64(vb); + + return pga > pgb; +} + +static int parse_device_file(const char *filename) +{ + struct json_object *jobj, *jval = NULL, *jmappings = NULL; + int i, len, rc = -EINVAL, region_id, id; + const char *chardev; + char *region = NULL; + struct mapping *m; + + jobj = json_object_from_file(filename); + if (!jobj) + return rc; + + if (!json_object_object_get_ex(jobj, "align", &jval)) + return rc; + param.align = json_object_get_string(jval); + + if (!json_object_object_get_ex(jobj, "size", &jval)) + return rc; + param.size = json_object_get_string(jval); + + if (!json_object_object_get_ex(jobj, "chardev", &jval)) + return rc; + chardev = json_object_get_string(jval); + if (sscanf(chardev, "dax%u.%u", ®ion_id, &id) != 2) + return rc; + if (asprintf(®ion, "%u", region_id) < 0) + return rc; + param.region = region; + + if (!json_object_object_get_ex(jobj, "mappings", &jmappings)) + return rc; + json_object_array_sort(jmappings, sort_mappings); + + len = json_object_array_length(jmappings); + m = calloc(len, sizeof(*m)); + if (!m) + return -ENOMEM; + + for (i = 0; i < len; i++) { + struct json_object *j, *val; + + j = json_object_array_get_idx(jmappings, i); + if (!j) + goto err; + + if (!json_object_object_get_ex(j, "start", &val)) + goto err; + m[i].start = json_object_get_int64(val); + + if (!json_object_object_get_ex(j, "end", &val)) + goto err; + m[i].end = json_object_get_int64(val); + + if (!json_object_object_get_ex(j, "page_offset", &val)) + goto err; + m[i].pgoff = json_object_get_int64(val); + } + maps = m; + nmaps = len; + rc = 0; + +err: + if (!maps) + free(m); + return rc; +} + static const char *parse_device_options(int argc, const char **argv, enum device_action action, const struct option *options, const char *usage, struct daxctl_ctx *ctx) @@ -214,6 +311,13 @@ static const char *parse_device_options(int argc, const char **argv, } break; case ACTION_CREATE: + if (param.input && + (rc = parse_device_file(param.input)) != 0) { + fprintf(stderr, + "error: failed to parse device file: %s\n", + strerror(-rc)); + break; + } if (param.size) size = __parse_size64(param.size, &units); if (param.align) @@ -525,7 +629,8 @@ static int do_create(struct daxctl_region *region, long long val, { struct json_object *jdev; struct daxctl_dev *dev; - int rc = 0; + int i, rc = 0; + long long alloc = 0; if (daxctl_region_create_dev(region)) return -ENOSPC; @@ -546,9 +651,22 @@ static int do_create(struct daxctl_region *region, long long val, return rc; } - rc = daxctl_dev_set_size(dev, val); - if (rc < 0) - return rc; + /* @maps is ordered by page_offset */ + for (i = 0; i < nmaps; i++) { + rc = daxctl_dev_set_mapping(dev, maps[i].start, maps[i].end); + if (rc < 0) + return rc; + alloc += (maps[i].end - maps[i].start + 1); + } + + if (nmaps > 0 && val > 0 && alloc != val) { + fprintf(stderr, "%s: allocated %lld but specified size %lld\n", + daxctl_dev_get_devname(dev), alloc, val); + } else { + rc = daxctl_dev_set_size(dev, val); + if (rc < 0) + return rc; + } rc = daxctl_dev_enable_devdax(dev); if (rc) { From patchwork Fri Dec 18 02:14:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11981069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9E83C2BBCD for ; Fri, 18 Dec 2020 02:15:11 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DBE823A5D for ; Fri, 18 Dec 2020 02:15:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DBE823A5D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2A205100EB85F; Thu, 17 Dec 2020 18:15:11 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.86; helo=userp2130.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) (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 594F3100EB85D for ; Thu, 17 Dec 2020 18:15:08 -0800 (PST) Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI2EeT3110085; Fri, 18 Dec 2020 02:15:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=QSAlX6peOVryBnEhb24N/QLanHIAnoP2De/C9296E54=; b=iQNDy0v7ghwJkxFRbNaZtHBfFBVC3a/MzJ22NHrtmkOASC6amIMBK6yBwIxTymTMy0/m oLF8Z6bE/pkqyPsT3b5B7gO5HInKZivz5S4+9umXsDpUo+x7LK9H0wW1ltXqhjZelVGo 27vLg9yH6kcKE0KLRWhROlpVy2GT+Lcuu0LZzSC2cgoL+HVuFMy2eZD20y276r2oDxq9 KY8NZ2SZ4dLzsxATGhiyyDEjOzwW7kExnkiNis+gu3P0mMVcerYD1HTAdQt9f/E2u2ON WD0HfeQXIUcwNI2qJrGX3JDv2hmTbCuAkg0cQCIv1JiVcDLMvrNFAZTX58uCwdOjb4Pj TQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 35cn9rrb04-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 18 Dec 2020 02:15:07 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI25Jg4101608; Fri, 18 Dec 2020 02:15:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 35e6eu4b2j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Dec 2020 02:15:06 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BI2F5VK014367; Fri, 18 Dec 2020 02:15:05 GMT Received: from paddy.uk.oracle.com (/10.175.180.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 18:15:04 -0800 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH daxctl v2 5/5] daxctl/test: add a test for daxctl-create with input file Date: Fri, 18 Dec 2020 02:14:38 +0000 Message-Id: <20201218021438.8926-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201218021438.8926-1-joao.m.martins@oracle.com> References: <20201218021438.8926-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180012 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 malwarescore=0 priorityscore=1501 phishscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180013 Message-ID-Hash: LJMZU6D5YYIIAVJQ2ZRPJFBNB3AH7XDI X-Message-ID-Hash: LJMZU6D5YYIIAVJQ2ZRPJFBNB3AH7XDI X-MailFrom: joao.m.martins@oracle.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Joao Martins X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The test creates a multi-range device (4 mappings) using the same setup as one of the tests. Afterwards we validate that the size/nr-mappings are the same as the original test. Signed-off-by: Joao Martins --- test/daxctl-create.sh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/daxctl-create.sh b/test/daxctl-create.sh index 41d5ba5888f7..e1d733916851 100755 --- a/test/daxctl-create.sh +++ b/test/daxctl-create.sh @@ -199,6 +199,7 @@ daxctl_test_multi() daxctl_test_multi_reconfig() { local ncfgs=$1 + local dump=$2 local daxdev size=$((available / ncfgs)) @@ -226,6 +227,10 @@ daxctl_test_multi_reconfig() test "$(daxctl_get_nr_mappings "$testdev")" -eq $((ncfgs / 2)) test "$(daxctl_get_nr_mappings "$daxdev_1")" -eq $((ncfgs / 2)) + if [[ $dump ]]; then + "$DAXCTL" list -M -d "$daxdev_1" | jq -er '.[]' > $dump + fi + fail_if_available "$DAXCTL" disable-device "$daxdev_1" && "$DAXCTL" destroy-device "$daxdev_1" @@ -328,7 +333,7 @@ daxctl_test3() # pick at the end of the region daxctl_test4() { - daxctl_test_multi_reconfig 8 + daxctl_test_multi_reconfig 8 "" clear_dev test_pass } @@ -371,6 +376,29 @@ daxctl_test6() test_pass } +# Test 7: input device +# Successfully creates a device with an input file from the multi-range +# device test, and checking that we have the same number of mappings/size. +daxctl_test7() +{ + daxctl_test_multi_reconfig 8 "input.json" + + # The parameter should parse the region_id from the chardev entry + # therefore using the same region_id as test4 + daxdev_1=$("$DAXCTL" create-device --input input.json | jq -er '.[].chardev') + + # Validate if it's the same mappings as done by test4 + # It also validates the size computed from the mappings + # A zero value means it failed, and four mappings is what's + # created by daxctl_test4 + test "$(daxctl_get_nr_mappings "$daxdev_1")" -eq 4 + + "$DAXCTL" disable-device "$daxdev_1" && "$DAXCTL" destroy-device "$daxdev_1" + + clear_dev + test_pass +} + find_testdev rc=1 setup_dev @@ -381,5 +409,6 @@ daxctl_test3 daxctl_test4 daxctl_test5 daxctl_test6 +daxctl_test7 reset_dev exit 0