From patchwork Thu Jul 16 18:47:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A6B913B6 for ; Thu, 16 Jul 2020 18:47:45 +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 7512D207FB for ; Thu, 16 Jul 2020 18:47:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jaRTKL52" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7512D207FB 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 86DBA11571BEB; Thu, 16 Jul 2020 11:47:44 -0700 (PDT) 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 1D04B11078320 for ; Thu, 16 Jul 2020 11:47:40 -0700 (PDT) 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 06GIb28v145415; Thu, 16 Jul 2020 18:47:38 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=GHorhZpluozLUMVAc2bOZLOZIfO5aEfQ1y342YF9NEE=; b=jaRTKL52zzj7wXFKTOGkElyWhuSe8fB+ovrEDmB6734rK+UWAN4fJPkKs/9TgUL0s+kR C+LKF/UcZxzJNC3O6pcEYdYon3lPDROmn//9xY0bVgh2YbzxNd1ocuEPHr/E37SChlv9 WYne4fq5kVaisDhjuQvlY2CNod2CxQuW2A5Q1VHFLQcpDNF4uiSkG6VvSUOFA8bLzKst CG/lvKTjeWs0AwyzI4kaMyL60shpsiUAUwAPNabUPVVlin2SCj32XUlhTQuildDhTXJT IoEG0lKLx/QfGP2Ws993igrW+3CQhgcQhCz7rj6BJbo47bOHbsE2/WftWvDkhfg3Z0Hk 4A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 3275cmk6jq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:38 +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 06GIbh09163631; Thu, 16 Jul 2020 18:47:37 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 327qbc77w0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:37 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06GIlaTi011674; Thu, 16 Jul 2020 18:47:36 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:36 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 1/8] daxctl: add daxctl_dev_{get,set}_align() Date: Thu, 16 Jul 2020 19:47:00 +0100 Message-Id: <20200716184707.23018-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 priorityscore=1501 bulkscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: 43ND2MGT7N37HM4ZIHC5QRQY4IEBXMAW X-Message-ID-Hash: 43ND2MGT7N37HM4ZIHC5QRQY4IEBXMAW 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 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 support for changing devices alignment. Signed-off-by: Joao Martins --- daxctl/lib/libdaxctl-private.h | 1 + daxctl/lib/libdaxctl.c | 34 ++++++++++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 2 ++ daxctl/libdaxctl.h | 2 ++ 4 files changed, 39 insertions(+) diff --git a/daxctl/lib/libdaxctl-private.h b/daxctl/lib/libdaxctl-private.h index 9f9c70d6024f..b307a8bc9438 100644 --- a/daxctl/lib/libdaxctl-private.h +++ b/daxctl/lib/libdaxctl-private.h @@ -99,6 +99,7 @@ struct daxctl_dev { struct list_node list; unsigned long long resource; unsigned long long size; + unsigned long align; struct kmod_module *module; struct daxctl_region *region; struct daxctl_memory *mem; diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 9b43b68facfe..c62e04bcdfd1 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -498,6 +498,11 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base) goto err_read; dev->size = strtoull(buf, NULL, 0); + sprintf(path, "%s/align", daxdev_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto err_read; + dev->align = strtoull(buf, NULL, 0); + dev->dev_path = strdup(daxdev_base); if (!dev->dev_path) goto err_read; @@ -1086,6 +1091,35 @@ DAXCTL_EXPORT int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long return 0; } +DAXCTL_EXPORT unsigned long daxctl_dev_get_align(struct daxctl_dev *dev) +{ + return dev->align; +} + +DAXCTL_EXPORT int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align) +{ + struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev); + char buf[SYSFS_ATTR_SIZE]; + char *path = dev->dev_buf; + int len = dev->buf_len; + + if (snprintf(path, len, "%s/align", dev->dev_path) >= len) { + err(ctx, "%s: buffer too small!\n", + daxctl_dev_get_devname(dev)); + return -ENXIO; + } + + sprintf(buf, "%#lx\n", align); + if (sysfs_write_attr(ctx, path, buf) < 0) { + err(ctx, "%s: failed to set align\n", + daxctl_dev_get_devname(dev)); + return -ENXIO; + } + + dev->align = align; + 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 33c926411037..c3d08179c9fd 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -81,4 +81,6 @@ global: daxctl_dev_set_size; daxctl_region_create_dev; daxctl_region_destroy_dev; + daxctl_dev_get_align; + daxctl_dev_set_align; } LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index 2b14faad1895..b0bb5d78d357 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -71,6 +71,8 @@ int daxctl_dev_get_minor(struct daxctl_dev *dev); unsigned long long daxctl_dev_get_resource(struct daxctl_dev *dev); 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); 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 Thu Jul 16 18:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668317 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA2751392 for ; Thu, 16 Jul 2020 18:47:46 +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 C5CCF207FB for ; Thu, 16 Jul 2020 18:47:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="JCXfRDTv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5CCF207FB 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 9FB6F11571BEF; Thu, 16 Jul 2020 11:47:44 -0700 (PDT) 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 CF6FE11078320 for ; Thu, 16 Jul 2020 11:47:41 -0700 (PDT) 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 06GIb2mj145391; Thu, 16 Jul 2020 18:47:40 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=BsagXx+EkIVuvdKfzPULeXePpGdW9sRMAiW64NoPUjw=; b=JCXfRDTvgoxYpZgN7CEZxBYwItO/BnFYzAMzP0dB7zHO/UWle4zPmvlb5DKQeonYtEBz jmKVkXhfWf3EuFHvp+f6G/80HqTj9mFdxZAgqwCWeykCUbRwKggjeo+rvK2B7ySkh/uC CgjUs3gbi9jozJAPzvjk8Uj1qESxP+RxXMIQ37FowyXA/E//NrvAmft46M33qh1ap8Xx sxVaYpna1gRD/hcTmXqFWoChMJFbxFUp8k7SDasLEsafov11ESsvxF5Oq/Rt1USTHAV+ dOGI8A5KvOrzJpefkJRHcPVcTlLDn/S9MTyt3OVSVD/UlflRw4KpZgaUZHOaacWfSw35 Vg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 3275cmk6k2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:40 +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 06GIbiOg163822; Thu, 16 Jul 2020 18:47:39 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 327qbc7818-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:39 +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 06GIldJn025612; Thu, 16 Jul 2020 18:47:39 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:38 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 3/8] daxctl: add align support in reconfigure-device Date: Thu, 16 Jul 2020 19:47:02 +0100 Message-Id: <20200716184707.23018-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 priorityscore=1501 bulkscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: 7UPGFWF4SNBEIYNGGJRE634GZXKYV2QN X-Message-ID-Hash: 7UPGFWF4SNBEIYNGGJRE634GZXKYV2QN 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 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 alignment option to reconfigure-device and use the newly added libdaxctl API to set the alignment of the device prior to setting size. Signed-off-by: Joao Martins --- daxctl/device.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/daxctl/device.c b/daxctl/device.c index 05293d6c38ee..9d82ea12aca2 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -22,6 +22,7 @@ static struct { const char *mode; const char *region; const char *size; + const char *align; bool no_online; bool no_movable; bool force; @@ -36,6 +37,7 @@ enum dev_mode { }; static enum dev_mode reconfig_mode = DAXCTL_DEV_MODE_UNKNOWN; +static long long align = -1; static long long size = -1; static unsigned long flags; @@ -68,7 +70,8 @@ OPT_BOOLEAN('f', "force", ¶m.force, \ "attempt to offline memory sections before reconfiguration") #define CREATE_OPTIONS() \ -OPT_STRING('s', "size", ¶m.size, "size", "size to switch the device to") +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") #define DESTROY_OPTIONS() \ OPT_BOOLEAN('f', "force", ¶m.force, \ @@ -185,8 +188,10 @@ static const char *parse_device_options(int argc, const char **argv, /* Handle action-specific options */ switch (action) { case ACTION_RECONFIG: - if (!param.size && !param.mode) { - fprintf(stderr, "error: a 'mode' or 'size' option is required\n"); + if (!param.size && + !param.align && + !param.mode) { + fprintf(stderr, "error: a 'align', 'mode' or 'size' option is required\n"); usage_with_options(u, reconfig_options); rc = -EINVAL; } @@ -204,6 +209,8 @@ static const char *parse_device_options(int argc, const char **argv, rc = -EINVAL; } } + if (param.align) + align = __parse_size64(param.align, &units); break; case ACTION_CREATE: if (param.size) @@ -558,6 +565,12 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode, struct json_object *jdev; int rc = 0; + if (align > 0) { + rc = daxctl_dev_set_align(dev, align); + if (rc < 0) + return rc; + } + if (size >= 0) { rc = dev_resize(dev, size); return rc; From patchwork Thu Jul 16 18:47:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668319 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 473A91392 for ; Thu, 16 Jul 2020 18:47:48 +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 2236A207FB for ; Thu, 16 Jul 2020 18:47:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NmBRkEnf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2236A207FB 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 B6B2C11571BF0; Thu, 16 Jul 2020 11:47:46 -0700 (PDT) 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 2654011078321 for ; Thu, 16 Jul 2020 11:47:43 -0700 (PDT) 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 06GIcDXu059674; Thu, 16 Jul 2020 18:47:41 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=aBSi1lpzBMIY87jld3MWKzOCHTPvU/b8jx1r4Uu5aNQ=; b=NmBRkEnfFyUOud7vqUO+AyxcwW4MXodOtixCuexmM5/VUwamJSfHKOcDWHFnCSFgs4bh OrkP9NNYE0Np4515aRJ7vY5YeeKMmy2MDnCVhhCAQwv43ZwyhVXtFbCpp5E1Np0+jbo9 jM7xxsbsnCN4mJ4Tlj4iEX8ncFpKBb76KPdxxWclY77RLpgwhsLANwBilCYMRELHJsuV hoP/aYChd8us6oaiIq0DM6F1UyP5gtgxYomTrcshlpUPUqtmv+BCSSYBw751yLn1dy/5 /PjG5oBsqIqGRqlGfz3J2IhwFoKzXY5q4jXaJjNUi/6JLhZxg5TewiAFDrfMDZL6t1qG Mg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 3274urk8mx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:41 +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 06GIbmZ4167687; Thu, 16 Jul 2020 18:47:41 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 32akr3vv3n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:41 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06GIlefO011692; Thu, 16 Jul 2020 18:47:40 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:40 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 4/8] daxctl: add align support in create-device Date: Thu, 16 Jul 2020 19:47:03 +0100 Message-Id: <20200716184707.23018-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 suspectscore=1 mlxlogscore=999 spamscore=0 mlxscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=1 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 priorityscore=1501 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: UN4PZ4WUZ6H4XRM42B6HVZ3WWIYSZ5BU X-Message-ID-Hash: UN4PZ4WUZ6H4XRM42B6HVZ3WWIYSZ5BU 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 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 And thus allow changing devices alignment when creating a new child device. Signed-off-by: Joao Martins --- daxctl/device.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/daxctl/device.c b/daxctl/device.c index 9d82ea12aca2..3a844462829b 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -215,6 +215,8 @@ static const char *parse_device_options(int argc, const char **argv, case ACTION_CREATE: if (param.size) size = __parse_size64(param.size, &units); + if (param.align) + align = __parse_size64(param.align, &units); /* fall through */ case ACTION_ONLINE: if (param.no_movable) @@ -537,6 +539,12 @@ static int do_create(struct daxctl_region *region, long long val, if (val <= 0) return -ENOSPC; + if (align > 0) { + rc = daxctl_dev_set_align(dev, align); + if (rc < 0) + return rc; + } + rc = daxctl_dev_set_size(dev, val); if (rc < 0) return rc; From patchwork Thu Jul 16 18:47:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D982813B6 for ; Thu, 16 Jul 2020 18:49:47 +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 B460D207FB for ; Thu, 16 Jul 2020 18:49:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DjpCF+U4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B460D207FB 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 7763C11571BEC; Thu, 16 Jul 2020 11:49:47 -0700 (PDT) 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 13DC611571BE9 for ; Thu, 16 Jul 2020 11:49:45 -0700 (PDT) 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 06GIcGTo059705; Thu, 16 Jul 2020 18:49:43 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=UK336btG/X7IpIfPfmuRoEp+2U5ISMmotevSo3n2BzQ=; b=DjpCF+U4boUR60iXlZfqG3jETSuf4TghocF8Jef2I25dFgMSGg29/rlgtT5ciE3sF2LS whBUzNhfg9e0hU7J37okp04TkPLlA2ipZOZxzXJr4sE7nf+1Q3+vXUG7SpVxnvZpMx2E oSogiiZB+Vbml0wEWcNFP1pK9t/WyN99pChPnuAEYUqlLEVwoe1Tb3Z10WTuqjJaFCvO uJJVgWnve2r3Qo0iGyOHYCCpJfWvINubWgkZNPCmW1RObKvom6RXTJQDe+9ZXJcXuFqQ 93rfkpaAXhehm0J5XFIGB3bmL5x2M04HCXKwENINnW/88T5lGwxuTQJWVUqF+PmtX4BK 4A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 3274urk8yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:49:43 +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 06GIbjfF095910; Thu, 16 Jul 2020 18:47:42 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 327q0u0bqd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:42 +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 06GIlgaV000520; Thu, 16 Jul 2020 18:47:42 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:41 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 5/8] libdaxctl: add mapping iterator APIs Date: Thu, 16 Jul 2020 19:47:04 +0100 Message-Id: <20200716184707.23018-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=3 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 priorityscore=1501 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: POW3S6VOEDGKTT3EAWJIKEECK7NAXN7W X-Message-ID-Hash: POW3S6VOEDGKTT3EAWJIKEECK7NAXN7W 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 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 c62e04bcdfd1..506cf4b93236 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -524,7 +524,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; @@ -1148,6 +1149,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 Thu Jul 16 18:47:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBB371392 for ; Thu, 16 Jul 2020 18:47:49 +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 A700E20809 for ; Thu, 16 Jul 2020 18:47:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="r3jAv9It" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A700E20809 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 DCAD611571BF7; Thu, 16 Jul 2020 11:47:48 -0700 (PDT) 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 16CC411571BF3 for ; Thu, 16 Jul 2020 11:47:47 -0700 (PDT) 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 06GIcg3I059855; Thu, 16 Jul 2020 18:47:44 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=t2P2AIAk4ZNLW6HyD2mHfc2ay8bdG1XLlb49iW8oaZ8=; b=r3jAv9ItRPFqgvu53i0ldUZufjWhcwuq+paCnfnHIUFFmxkvextHGsrG0aFyf94/pCMy 1Fg+sByylSmOgtxr/mWBVopJ2ucomQk/Q6c4nIZyHi1SBPm0C1PRrlNAeXLqiG9qibYB WJDCdCW6LmMAbb0KsI9az9pTjhybZ5ZXVCmljh9zckyskXUESSgIVV6jS0ecfSpUxlh7 Qak9lZFpd4YVHOu7U+65yw/1kQvZzmWMY2nua0MRARyhQD54HkNbTyPM6tTSPzeL4H/i 8bUSBfvVInTVRfK4fsfhibpaRtjtS1SkQ0xSX2I8xRKhwBd73squeVIYVSNY5J14WOIq Ew== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 3274urk8n9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:44 +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 06GIbisM163891; Thu, 16 Jul 2020 18:47:44 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 327qbc787e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:43 +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 06GIlhva000567; Thu, 16 Jul 2020 18:47:43 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:43 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 6/8] daxctl: include mappings when listing Date: Thu, 16 Jul 2020 19:47:05 +0100 Message-Id: <20200716184707.23018-7-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 suspectscore=1 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=1 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 priorityscore=1501 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: 6J2LKZTNW3BYXJHNEJRNF5PJ2UKQJOZJ X-Message-ID-Hash: 6J2LKZTNW3BYXJHNEJRNF5PJ2UKQJOZJ 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 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. Signed-off-by: Joao Martins --- Perhaps hiding it behind a -v|--verbose? --- util/json.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- util/json.h | 3 +++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/util/json.c b/util/json.c index 4d9787381d6b..c814298ad0dc 100644 --- a/util/json.c +++ b/util/json.c @@ -277,7 +277,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(); @@ -331,6 +332,22 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev, json_object_object_add(jdev, "state", jobj); } + 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; } @@ -1180,6 +1197,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 6d39d3aa4693..c32074939068 100644 --- a/util/json.h +++ b/util/json.h @@ -15,6 +15,7 @@ #include #include #include +#include #include enum util_json_flags { @@ -36,6 +37,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 Thu Jul 16 18:47:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668323 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DC1D161F for ; Thu, 16 Jul 2020 18:47:51 +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 082DF207E8 for ; Thu, 16 Jul 2020 18:47:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FPTP54iI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 082DF207E8 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 0236311078326; Thu, 16 Jul 2020 11:47:51 -0700 (PDT) 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 815F011571BF7 for ; Thu, 16 Jul 2020 11:47:48 -0700 (PDT) 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 06GIb2sO145393; Thu, 16 Jul 2020 18:47:46 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=WpfOXvX7LXsNP4LILznAi2fO63aacseY0ywwvmou1xI=; b=FPTP54iIJtsrTVwzTBYipn+QxZEQQj37OfFEV4FKIJ0jjrt6BYXDxf/mxzmWtTVISpnb T/2A+Z9h5X5z93poZ8UuxHYYOd3jCpP8k9F0bi9D4jYTHlmTNV3PFDZjpUdi08DfKg+w OwI8JobweB4fyzmqiNRtMrNmyaTrR5eV4SKovclLXcGfCQqdoBGk3PjMi57Q4mXL1mS8 cgbN4GuoKe8ah3YNvRc8CSw0Zwsz1bT/GwIlwuoO8+CMMAwDA2/WXaY6geftzx7gajQI v2w6Ld5VQmkRf4yVProJvEwdOjSi+mX/1sonZrmNfXha3Nw15JQZjARATaDWnRjW+YXZ 3Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 3275cmk6kt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:46 +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 06GIclST189117; Thu, 16 Jul 2020 18:47:45 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 327qc3yawp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:45 +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 06GIlirE007494; Thu, 16 Jul 2020 18:47:45 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:44 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v1 7/8] libdaxctl: add daxctl_dev_set_mapping() Date: Thu, 16 Jul 2020 19:47:06 +0100 Message-Id: <20200716184707.23018-8-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 spamscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 priorityscore=1501 bulkscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: 6OB2557GSKZRRU7A5CBP3YSTL3ZEKZQU X-Message-ID-Hash: 6OB2557GSKZRRU7A5CBP3YSTL3ZEKZQU 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 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 506cf4b93236..3992ae733b16 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -1121,6 +1121,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 Thu Jul 16 18:47:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11668325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABE961392 for ; Thu, 16 Jul 2020 18:47:52 +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 863D62082E for ; Thu, 16 Jul 2020 18:47:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="vH1RMHlr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 863D62082E 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 32D3D11571BEF; Thu, 16 Jul 2020 11:47:52 -0700 (PDT) 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 5D2C11108EF26 for ; Thu, 16 Jul 2020 11:47:50 -0700 (PDT) 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 06GIcC5e059656; Thu, 16 Jul 2020 18:47:48 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=Y2Bv2dxeFkdqyYlI+JrtzhTtExT1WznUOd8+/Xsn90Q=; b=vH1RMHlr86to8+vO4ovikBux16WRz/+oVgyaKhiU4UUhEm8aZjU6VGgilLdSjmZntybd NQXXnLmlNkSOavzZxJyhyYrYrYRu9Omr6O3tcFjBAkM8HPuuSeDGgU0rHE8Kivs4EKTc o1xjvNANE+jjA5l1Q/YWBNhN6mi5fi43SBlZvojMJBfmyS5UR8H3TvpBwPZr2/ETSIz/ sFZmyAcrJqcAg43vFNS1MyqEp825IoRByZeLEbKNyRcNa/tROn439rLoSd3XfRyo3w+/ 3Ex8nyzouSfpUySWYvjp9ih5EBnVb3uuPMPM+NIGGdLogcuw9VcGBjUp89g6pTLuHQ2v eg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 3274urk8nw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Jul 2020 18:47:48 +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 06GIbjRM096023; Thu, 16 Jul 2020 18:47:48 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 327q0u0bu7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jul 2020 18:47:47 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06GIlkFW011728; Thu, 16 Jul 2020 18:47:46 GMT Received: from paddy.uk.oracle.com (/10.175.173.87) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Jul 2020 11:47:46 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Subject: [PATCH ndctl v1 8/8] daxctl: Allow restore devices from JSON metadata Date: Thu, 16 Jul 2020 19:47:07 +0100 Message-Id: <20200716184707.23018-9-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200716184707.23018-1-joao.m.martins@oracle.com> References: <20200716184707.23018-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9684 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=3 phishscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 priorityscore=1501 adultscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007160131 Message-ID-Hash: 2465OSDYIIQZVXSKIYLMNFIFEZJ76BHQ X-Message-ID-Hash: 2465OSDYIIQZVXSKIYLMNFIFEZJ76BHQ 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: Jason Zeng 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 --restore which passes a parameter which is a JSON file path. The JSON file contains the data usually returned by: $ 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 } ] } For purposes of RFC, the input values in the mapping json are decimal for now. A device can then be created by specifying this same data to restore it e.g. daxctl create-device -u --restore device.json { "chardev":"dax0.1", "size":"32.00 GiB (34.36 GB)", "target_node":0, "align":"1024.00 MiB (1073.74 MB)", "mode":"devdax", "mappings":[ { "page_offset":"0x400000", "start":"0x600000000", "end":"0x9ffffffff", "size":"16.00 GiB (17.18 GB)" }, { "page_offset":"0", "start":"0x200000000", "end":"0x5ffffffff", "size":"16.00 GiB (17.18 GB)" } ] } created 1 device This is handy as we are able to kexec and restore previously mappings that we had established. Signed-off-by: Joao Martins --- daxctl/device.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 5 deletions(-) diff --git a/daxctl/device.c b/daxctl/device.c index 3a844462829b..fe34f0e44569 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 *restore; 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,9 @@ 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', "restore", ¶m.restore, "restore", \ + "restore the device from device JSON") #define DESTROY_OPTIONS() \ OPT_BOOLEAN('f', "force", ¶m.force, \ @@ -124,6 +134,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) @@ -213,6 +311,13 @@ static const char *parse_device_options(int argc, const char **argv, align = __parse_size64(param.align, &units); break; case ACTION_CREATE: + if (param.restore && + (rc = parse_device_file(param.restore)) != 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) @@ -524,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; @@ -545,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) {