From patchwork Mon Jul 13 16:08:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660171 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 AB872722 for ; Mon, 13 Jul 2020 16:09: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 7B2692076D for ; Mon, 13 Jul 2020 16:09:02 +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="Hi2uKJpg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B2692076D 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 3DB89118128FC; Mon, 13 Jul 2020 09:09:02 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.85; helo=userp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (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 6BC3A118128FA for ; Mon, 13 Jul 2020 09:08:59 -0700 (PDT) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06DG2oGV153718; Mon, 13 Jul 2020 16:08:57 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=lpVMQgHXWEwziqNXeWi4pHdjy+sddg5bwh4bUJlXqI0=; b=Hi2uKJpgJ/H+RdEBXP78eHFnDchCgSFJ/eGAxtPjzYTDNqMPnDPb8azXpZCvXMoZokqB YuYq6ffGO8MxesuUS9olZYLJEg+uVmoSXEq9P0ymTTF2XmjXxS+TK71LCRGdkhwJkE9d /P1Wob6fB1oXPw5d2Q2KEEhow6y/d8JAMy25Zgwph00Ii/4wRiw0DX0CDj4s/XaYqIOq oTuoCnT98WVyt+CU902dRwcsdD/QbcM5lREPjm7QaC4H+s7GcsFxEthz/GlJoJ9RYX5G KJq6KVC+IV0eeTdiWLB2bM8fvnL/302pQp5EzbCv9sX4plADB2EpTWABRMYQ3LkIww9u TQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 32762n7v1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:08:57 +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 06DG3XUk138226; Mon, 13 Jul 2020 16:08:56 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 327q0mhxb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:08:56 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG8tlq027581; Mon, 13 Jul 2020 16:08:55 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:08:54 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 01/10] daxctl: Cleanup whitespace Date: Mon, 13 Jul 2020 17:08:28 +0100 Message-Id: <20200713160837.13774-2-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=1 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 Message-ID-Hash: 3C2OPXCRKSYRRMGDTVOZGGASKOQN6MJK X-Message-ID-Hash: 3C2OPXCRKSYRRMGDTVOZGGASKOQN6MJK 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 From: Dan Williams Re-indent util_daxctl_region_filter() to match expectations. Signed-off-by: Dan Williams --- util/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/filter.c b/util/filter.c index af72793929e2..7d0159f8cef6 100644 --- a/util/filter.c +++ b/util/filter.c @@ -344,7 +344,7 @@ struct daxctl_region *util_daxctl_region_filter(struct daxctl_region *region, return region; if ((sscanf(ident, "%d", ®ion_id) == 1 - || sscanf(ident, "region%d", ®ion_id) == 1) + || sscanf(ident, "region%d", ®ion_id) == 1) && daxctl_region_get_id(region) == region_id) return region; From patchwork Mon Jul 13 16:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660173 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 975F3722 for ; Mon, 13 Jul 2020 16:09:04 +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 757F92076D for ; Mon, 13 Jul 2020 16:09:04 +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="lWM+ixZj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 757F92076D 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 51FA2118128FF; Mon, 13 Jul 2020 09:09:04 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.85; helo=userp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (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 57BFD118128FA for ; Mon, 13 Jul 2020 09:09:01 -0700 (PDT) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06DG2sr8153766; Mon, 13 Jul 2020 16:08: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=WKwprZiq492CwV4bVGMZKAghzGepHyPSRuyoU/cWs9I=; b=lWM+ixZjBzWkSSKXctoQaZJpipmkO9BnIHhmJsrop5mbTZe6mG2mRTVdr9ZSXoLkadhO 170LPMrEVmq4QP8m2DiBE5ktcNPGpwOW3XhuIJVumUgTurNDc4F6VP8Ic3M6B3lMGZGs 5noiCu3wyv7LOsIa5wKFmnxqG8TE7xBFcaMYad1stQ++9gXZaX1eoFtsE0lfSZkuKLI2 60/JXmoR1OaIePhOXR9bI/muwAMMnyhcG2OJtxaRZ9ssCn5MrEFxWh7VjItJ3kP+GxjO N5E63uFNt2DxR5CQ8EYJ4Mjocv9T8FlJucsLs2J34kAUoheSdpWYoaL246/uue5WVTHb XQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 32762n7v2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:08: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 06DG3Wrg138095; Mon, 13 Jul 2020 16:08:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 327q0mhxgb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:08:58 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG8vI3011393; Mon, 13 Jul 2020 16:08:57 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:08:57 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 02/10] libdaxctl: add daxctl_dev_set_size() Date: Mon, 13 Jul 2020 17:08:29 +0100 Message-Id: <20200713160837.13774-3-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=1 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 Message-ID-Hash: NJXOYN7EFJ6QSDI2XXE5DZUIXYYH3ZRC X-Message-ID-Hash: NJXOYN7EFJ6QSDI2XXE5DZUIXYYH3ZRC 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 API for setting the size of a dax device. This sysfs attribute is only writeable for a dynamic dax device such as the one exported by hmem. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- daxctl/lib/libdaxctl.c | 24 ++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 5 +++++ daxctl/libdaxctl.h | 1 + 3 files changed, 30 insertions(+) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index ee4a069eb463..00d5f7fe61ad 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -1019,6 +1019,30 @@ DAXCTL_EXPORT unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev) return dev->size; } +DAXCTL_EXPORT int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long size) +{ + 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/size", dev->dev_path) >= len) { + err(ctx, "%s: buffer too small!\n", + daxctl_dev_get_devname(dev)); + return -ENXIO; + } + + sprintf(buf, "%#llx\n", size); + if (sysfs_write_attr(ctx, path, buf) < 0) { + err(ctx, "%s: failed to set size\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 87d02366a917..d8b4137c76b7 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -75,3 +75,8 @@ global: daxctl_memory_is_movable; daxctl_memory_online_no_movable; } LIBDAXCTL_6; + +LIBDAXCTL_8 { +global: + daxctl_dev_set_size; +} LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index 6c545e1f3055..e3d482743cc6 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -68,6 +68,7 @@ int daxctl_dev_get_major(struct daxctl_dev *dev); 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); 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 Mon Jul 13 16:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660187 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 98200618 for ; Mon, 13 Jul 2020 16:11:04 +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 75A92206F5 for ; Mon, 13 Jul 2020 16:11:04 +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="xZQkL92c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75A92206F5 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 61E6B11812912; Mon, 13 Jul 2020 09:11:04 -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 3D237118128FA for ; Mon, 13 Jul 2020 09:11:02 -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 06DG21Cx124931; Mon, 13 Jul 2020 16:11: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=NRrv/MewWLA7Zo9aIabo5WeLfhrLsA2v49PBPELlUqQ=; b=xZQkL92cHIZ/ZX2KFLNygKdkIYJjH+B59r9iuUOcwWcbKzP4g7Hp78vqPBQtV1l3QD8X 0SA8N6iHxge83Hwz0Zoanw0U8qVO9PG7nQHnhwEAewEw65DagD8lfddzhVa/WunHXGDO X1xCfQLTEpI5EWMzMI4XcBJRdLJJwR/KECLxwo3ZuGcC12Zycs6mg3YrQcSk4czPbPu4 JYQ3PemOzy+l7/zNfhYBct/PUgHfKwnWmsVQkxBpRuqYc//kVD6R53IaSbios+Qorx0W Pu4X4V/ZBZtwS5VJKZ5B7PlaSb59yX6ZVcwXf5H3ac0ZAooCoYLfOcJ61T+xRK7qnzxP 4w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 3274ur01ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:11: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 06DG3WmX127445; Mon, 13 Jul 2020 16:09:00 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 327qb11j9f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:00 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG8wcV011403; Mon, 13 Jul 2020 16:08:59 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:08:58 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 03/10] daxctl: add resize support in reconfigure-device Date: Mon, 13 Jul 2020 17:08:30 +0100 Message-Id: <20200713160837.13774-4-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 Message-ID-Hash: 3RNTK42HY2UJHZA6TXFHFFC553N6U5I4 X-Message-ID-Hash: 3RNTK42HY2UJHZA6TXFHFFC553N6U5I4 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 ability to change the size of an inactive dax device. Uses of this includes adjusting existing devices or enterily freeing the region device to make the space available. $ daxctl disable-device dax0.0 disabled 1 device $ daxctl reconfigure-device -s 0 dax0.0 reconfigured 1 device $ daxctl reconfigure-device -s 4G dax0.0 reconfigured 1 device @size (-s) and @mode (-m) are mutually exclusive as the latter relates to assigning memory to System-RAM through kmem as opposed to reconfiguring dynamic dax devices. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- Documentation/daxctl/daxctl-reconfigure-device.txt | 16 +++++++++++ daxctl/device.c | 32 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Documentation/daxctl/daxctl-reconfigure-device.txt b/Documentation/daxctl/daxctl-reconfigure-device.txt index cb28fed24e52..8caae436faae 100644 --- a/Documentation/daxctl/daxctl-reconfigure-device.txt +++ b/Documentation/daxctl/daxctl-reconfigure-device.txt @@ -75,6 +75,14 @@ daxctl_dev_get_target_node() or 'daxctl list') # numactl --cpunodebind=0-1 --membind=2 -- some-service --opt1 --opt2 ---- +* Change the size of a dax device +---- +# daxctl reconfigure-device dax0.1 -s 16G +reconfigured 1 device +# daxctl reconfigure-device dax0.1 -s 0 +reconfigured 1 device +---- + DESCRIPTION ----------- @@ -120,6 +128,14 @@ OPTIONS more /dev/daxX.Y devices, where X is the region id and Y is the device instance id. +-s:: +--size=:: + For regions that support dax device creation, change the device size + in bytes. This option supports the suffixes "k" or "K" for KiB, "m" or + "M" for MiB, "g" or "G" for GiB and "t" or "T" for TiB. + + The size must be a multiple of the region alignment. + -m:: --mode=:: Specify the mode to which the dax device(s) should be reconfigured. diff --git a/daxctl/device.c b/daxctl/device.c index 705f1f8ff7f6..033e098eafe0 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ static struct { const char *dev; const char *mode; const char *region; + const char *size; bool no_online; bool no_movable; bool force; @@ -34,6 +36,7 @@ enum dev_mode { }; static enum dev_mode reconfig_mode = DAXCTL_DEV_MODE_UNKNOWN; +static long long size = -1; static unsigned long flags; enum memory_zone { @@ -60,12 +63,16 @@ OPT_BOOLEAN('N', "no-online", ¶m.no_online, \ 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") + #define ZONE_OPTIONS() \ OPT_BOOLEAN('\0', "no-movable", ¶m.no_movable, \ "online memory in ZONE_NORMAL") static const struct option reconfig_options[] = { BASE_OPTIONS(), + CREATE_OPTIONS(), RECONFIG_OPTIONS(), ZONE_OPTIONS(), OPT_END(), @@ -90,6 +97,7 @@ static const char *parse_device_options(int argc, const char **argv, usage, NULL }; + unsigned long long units = 1; int i, rc = 0; argc = parse_options(argc, argv, options, u, 0); @@ -135,12 +143,14 @@ static const char *parse_device_options(int argc, const char **argv, /* Handle action-specific options */ switch (action) { case ACTION_RECONFIG: - if (!param.mode) { - fprintf(stderr, "error: a 'mode' option is required\n"); + if (!param.size && !param.mode) { + fprintf(stderr, "error: a 'mode' or 'size' option is required\n"); usage_with_options(u, reconfig_options); rc = -EINVAL; } - if (strcmp(param.mode, "system-ram") == 0) { + if (param.size) { + size = __parse_size64(param.size, &units); + } else if (strcmp(param.mode, "system-ram") == 0) { reconfig_mode = DAXCTL_DEV_MODE_RAM; if (param.no_movable) mem_zone = MEM_ZONE_NORMAL; @@ -309,6 +319,17 @@ static int dev_offline_memory(struct daxctl_dev *dev) return 0; } +static int dev_resize(struct daxctl_dev *dev, unsigned long long val) +{ + int rc; + + rc = daxctl_dev_set_size(dev, val); + if (rc < 0) + return rc; + + return 0; +} + static int disable_devdax_device(struct daxctl_dev *dev) { struct daxctl_memory *mem = daxctl_dev_get_memory(dev); @@ -418,6 +439,11 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode, struct json_object *jdev; int rc = 0; + if (size >= 0) { + rc = dev_resize(dev, size); + return rc; + } + switch (mode) { case DAXCTL_DEV_MODE_RAM: rc = reconfig_mode_system_ram(dev); From patchwork Mon Jul 13 16:08:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660189 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 A378C618 for ; Mon, 13 Jul 2020 16:11:05 +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 815CD206F5 for ; Mon, 13 Jul 2020 16:11:05 +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="JzyFwS9W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 815CD206F5 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 78CFE11812917; Mon, 13 Jul 2020 09:11:05 -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 11991118128FF for ; Mon, 13 Jul 2020 09:11:03 -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 06DG2B9D125089; Mon, 13 Jul 2020 16:11: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=/5cJdvZqwicZ2ywaLEdgmv/rSktSHf+hONT2vIXxwk8=; b=JzyFwS9WHQzpC69szgQXZJy+kjcfLD7yUYk6CRRLNMQUpwkSV7kXK9VO6KTDh7l8twD6 L6yV9kaki9KqrciPe2neeJg17u/NY1o6VDpG+cJ56zCyu33XpGAPNOocfwPsiP0B+kO7 sxO0YE/rizLe2Qkqqk6iM4e8LlVAxXN8SD+RVtajTHWYBgAs2XFRhxXvC38FMolOWpLD BfVh+mTzHPYf7+bWxkIQdgPJBO6BouQ4sJDPxTU4oAmi+dJy1elNPQ3YgmtWyQmLfGCq oixr/dUFTF8ktzftkT+Uaz9+D7FcDWNtykyw7wyhF5bcUrA7xqG/rD3axi1q2Q+AyVUc hg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 3274ur01eg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:11:01 +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 06DG4a06008077; Mon, 13 Jul 2020 16:09:01 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 327qbvu1w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:01 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG90Z7011414; Mon, 13 Jul 2020 16:09:00 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:00 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 04/10] daxctl: add command to disable devdax device Date: Mon, 13 Jul 2020 17:08:31 +0100 Message-Id: <20200713160837.13774-5-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 Message-ID-Hash: 4QTNJNVLGUP3GZC7EKM53XKFQ6YZM55I X-Message-ID-Hash: 4QTNJNVLGUP3GZC7EKM53XKFQ6YZM55I 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 a 'disable-device' command, required prior to reconfiguration or destruction of the dax device. Mimmics the same functionality as seen in ndctl-disable-namespace. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- Documentation/daxctl/Makefile.am | 3 +- Documentation/daxctl/daxctl-disable-device.txt | 58 ++++++++++++++++++++++++ daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 61 ++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 Documentation/daxctl/daxctl-disable-device.txt diff --git a/Documentation/daxctl/Makefile.am b/Documentation/daxctl/Makefile.am index 7696e23cc9c0..1f070771cd95 100644 --- a/Documentation/daxctl/Makefile.am +++ b/Documentation/daxctl/Makefile.am @@ -31,7 +31,8 @@ man1_MANS = \ daxctl-migrate-device-model.1 \ daxctl-reconfigure-device.1 \ daxctl-online-memory.1 \ - daxctl-offline-memory.1 + daxctl-offline-memory.1 \ + daxctl-disable-device.1 EXTRA_DIST = $(man1_MANS) diff --git a/Documentation/daxctl/daxctl-disable-device.txt b/Documentation/daxctl/daxctl-disable-device.txt new file mode 100644 index 000000000000..383aeeb58150 --- /dev/null +++ b/Documentation/daxctl/daxctl-disable-device.txt @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 + +daxctl-disable-device(1) +======================== + +NAME +---- +daxctl-disable-device - Disables a devdax device + +SYNOPSIS +-------- +[verse] +'daxctl disable-device' [] + +EXAMPLES +-------- + +* Disables dax0.1 +---- +# daxctl disable-device dax0.1 +---- + +* Disables all devices in region id 0 +---- +# daxctl disable-device -r 0 all +disabled 3 devices +---- + +DESCRIPTION +----------- + +Disables a dax device in 'devdax' mode. + +OPTIONS +------- +-r:: +--region=:: + Restrict the operation to devices belonging to the specified region(s). + A device-dax region is a contiguous range of memory that hosts one or + more /dev/daxX.Y devices, where X is the region id and Y is the device + instance id. + +-u:: +--human:: + By default the command will output machine-friendly raw-integer + data. Instead, with this flag, numbers representing storage size + will be formatted as human readable strings with units, other + fields are converted to hexadecimal strings. + +-v:: +--verbose:: + Emit more debug messages + +include::../copyright.txt[] + +SEE ALSO +-------- +linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] diff --git a/daxctl/builtin.h b/daxctl/builtin.h index f5a0147f0e11..c9848953bbd8 100644 --- a/daxctl/builtin.h +++ b/daxctl/builtin.h @@ -7,6 +7,7 @@ struct daxctl_ctx; int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx); +int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_online_memory(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_offline_memory(int argc, const char **argv, struct daxctl_ctx *ctx); #endif /* _DAXCTL_BUILTIN_H_ */ diff --git a/daxctl/daxctl.c b/daxctl/daxctl.c index 1ab073200313..1707a9ff0791 100644 --- a/daxctl/daxctl.c +++ b/daxctl/daxctl.c @@ -74,6 +74,7 @@ static struct cmd_struct commands[] = { { "reconfigure-device", .d_fn = cmd_reconfig_device }, { "online-memory", .d_fn = cmd_online_memory }, { "offline-memory", .d_fn = cmd_offline_memory }, + { "disable-device", .d_fn = cmd_disable_device }, }; int main(int argc, const char **argv) diff --git a/daxctl/device.c b/daxctl/device.c index 033e098eafe0..20df2b844774 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -49,6 +49,7 @@ enum device_action { ACTION_RECONFIG, ACTION_ONLINE, ACTION_OFFLINE, + ACTION_DISABLE, }; #define BASE_OPTIONS() \ @@ -89,6 +90,11 @@ static const struct option offline_options[] = { OPT_END(), }; +static const struct option disable_options[] = { + BASE_OPTIONS(), + OPT_END(), +}; + 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) @@ -116,6 +122,9 @@ static const char *parse_device_options(int argc, const char **argv, case ACTION_OFFLINE: action_string = "offline memory for"; break; + case ACTION_DISABLE: + action_string = "disable"; + break; default: action_string = "<>"; break; @@ -168,6 +177,7 @@ static const char *parse_device_options(int argc, const char **argv, mem_zone = MEM_ZONE_NORMAL; /* fall through */ case ACTION_OFFLINE: + case ACTION_DISABLE: /* nothing special */ break; } @@ -497,6 +507,35 @@ static int do_xline(struct daxctl_dev *dev, enum device_action action) return rc; } +static int do_xble(struct daxctl_dev *dev, enum device_action action) +{ + struct daxctl_memory *mem = daxctl_dev_get_memory(dev); + const char *devname = daxctl_dev_get_devname(dev); + int rc; + + if (mem) { + fprintf(stderr, + "%s: status operations are only applicable in devdax mode\n", + devname); + return -ENXIO; + } + + switch (action) { + case ACTION_DISABLE: + rc = daxctl_dev_disable(dev); + if (rc) { + fprintf(stderr, "%s: disable failed: %s\n", + daxctl_dev_get_devname(dev), strerror(-rc)); + return rc; + } + break; + default: + fprintf(stderr, "%s: invalid action: %d\n", devname, action); + rc = -EINVAL; + } + return rc; +} + static int do_xaction_device(const char *device, enum device_action action, struct daxctl_ctx *ctx, int *processed) { @@ -531,6 +570,11 @@ static int do_xaction_device(const char *device, enum device_action action, if (rc == 0) (*processed)++; break; + case ACTION_DISABLE: + rc = do_xble(dev, action); + if (rc == 0) + (*processed)++; + break; default: rc = -EINVAL; break; @@ -566,6 +610,23 @@ int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx) return rc; } +int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx) +{ + char *usage = "daxctl disable-device "; + const char *device = parse_device_options(argc, argv, ACTION_DISABLE, + disable_options, usage, ctx); + int processed, rc; + + rc = do_xaction_device(device, ACTION_DISABLE, ctx, &processed); + if (rc < 0) + fprintf(stderr, "error disabling device: %s\n", + strerror(-rc)); + + fprintf(stderr, "disabled %d device%s\n", processed, + processed == 1 ? "" : "s"); + return rc; +} + int cmd_online_memory(int argc, const char **argv, struct daxctl_ctx *ctx) { char *usage = "daxctl online-memory []"; From patchwork Mon Jul 13 16:08:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660191 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 CCAD6722 for ; Mon, 13 Jul 2020 16:11: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 A995D206F0 for ; Mon, 13 Jul 2020 16:11:07 +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="okm4H/II" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A995D206F0 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 A380511812919; Mon, 13 Jul 2020 09:11:07 -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 A3223118128FA for ; Mon, 13 Jul 2020 09:11:05 -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 06DG36Lt173950; Mon, 13 Jul 2020 16:11: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=v/GishVAFqCGPBy48bYcG//2iv3yh4KG4mjfMhq6f0U=; b=okm4H/IIO+X1OvGQwRaAQUT5O2+CGiZfOLfZ3uxTZZr3A4/ltW9vkx/DAfW4OvYqYEia UVFPNWnLiuLQs+NjH0fBmehLGuQk1te0ERHsKeQZJM9HEIM0pedXiTikjHmNFbMk37pA C0mWeop6riM5zwArxCktcJbec9q8yryvZMi7H5l4xqqYAxo7ELzEsGl+amu1md+dCqd8 9TDb5iVKL5HGR4HXBD4tmUPTnGzoV5f8eADYhhb9XQ5VtEjWRX2YUJ3Z8A+koqhGm6dD V8XaKm6hD73aoziEnQnuCW/wquWeYiRci8qGVrR2aDHliSBIiczCY8TdalXoHBMzAHsJ wA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 3275ckyydy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:11:03 +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 06DG3Xgd138168; Mon, 13 Jul 2020 16:09:03 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 327q0mhxq6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:02 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG91pi011424; Mon, 13 Jul 2020 16:09:01 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:01 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 05/10] daxctl: add command to enable devdax device Date: Mon, 13 Jul 2020 17:08:32 +0100 Message-Id: <20200713160837.13774-6-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 Message-ID-Hash: 3S7XVAAOSG2YJI3NVZUXJFNG3U22OCVB X-Message-ID-Hash: 3S7XVAAOSG2YJI3NVZUXJFNG3U22OCVB 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 a 'enable-device' command, required prior to reconfiguration of the dax device. Mimics the same functionality as seen in ndctl-enable-namespace. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- Documentation/daxctl/Makefile.am | 3 +- Documentation/daxctl/daxctl-enable-device.txt | 59 +++++++++++++++++++++++++++ daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 40 ++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 Documentation/daxctl/daxctl-enable-device.txt diff --git a/Documentation/daxctl/Makefile.am b/Documentation/daxctl/Makefile.am index 1f070771cd95..e43d34183142 100644 --- a/Documentation/daxctl/Makefile.am +++ b/Documentation/daxctl/Makefile.am @@ -32,7 +32,8 @@ man1_MANS = \ daxctl-reconfigure-device.1 \ daxctl-online-memory.1 \ daxctl-offline-memory.1 \ - daxctl-disable-device.1 + daxctl-disable-device.1 \ + daxctl-enable-device.1 EXTRA_DIST = $(man1_MANS) diff --git a/Documentation/daxctl/daxctl-enable-device.txt b/Documentation/daxctl/daxctl-enable-device.txt new file mode 100644 index 000000000000..6410d92cafe9 --- /dev/null +++ b/Documentation/daxctl/daxctl-enable-device.txt @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 + +daxctl-enable-device(1) +======================= + +NAME +---- +daxctl-enable-device - Enable a devdax device + +SYNOPSIS +-------- +[verse] +'daxctl enable-device' [...] [] + +EXAMPLES +-------- + +* Enables dax0.1 +---- +# daxctl enable-device dax0.1 +enabled 1 device +---- + +* Enables all devices in region id 0 +---- +# daxctl enable-device -r 0 all +enabled 3 devices +---- + +DESCRIPTION +----------- + +Enables a dax device in 'devdax' mode. + +OPTIONS +------- +-r:: +--region=:: + Restrict the operation to devices belonging to the specified region(s). + A device-dax region is a contiguous range of memory that hosts one or + more /dev/daxX.Y devices, where X is the region id and Y is the device + instance id. + +-u:: +--human:: + By default the command will output machine-friendly raw-integer + data. Instead, with this flag, numbers representing storage size + will be formatted as human readable strings with units, other + fields are converted to hexadecimal strings. + +-v:: +--verbose:: + Emit more debug messages + +include::../copyright.txt[] + +SEE ALSO +-------- +linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] diff --git a/daxctl/builtin.h b/daxctl/builtin.h index c9848953bbd8..8f344f86ad20 100644 --- a/daxctl/builtin.h +++ b/daxctl/builtin.h @@ -8,6 +8,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx); +int cmd_enable_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_online_memory(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_offline_memory(int argc, const char **argv, struct daxctl_ctx *ctx); #endif /* _DAXCTL_BUILTIN_H_ */ diff --git a/daxctl/daxctl.c b/daxctl/daxctl.c index 1707a9ff0791..a4699b3780bd 100644 --- a/daxctl/daxctl.c +++ b/daxctl/daxctl.c @@ -75,6 +75,7 @@ static struct cmd_struct commands[] = { { "online-memory", .d_fn = cmd_online_memory }, { "offline-memory", .d_fn = cmd_offline_memory }, { "disable-device", .d_fn = cmd_disable_device }, + { "enable-device", .d_fn = cmd_enable_device }, }; int main(int argc, const char **argv) diff --git a/daxctl/device.c b/daxctl/device.c index 20df2b844774..05a9247ecfde 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -50,6 +50,7 @@ enum device_action { ACTION_ONLINE, ACTION_OFFLINE, ACTION_DISABLE, + ACTION_ENABLE, }; #define BASE_OPTIONS() \ @@ -95,6 +96,11 @@ static const struct option disable_options[] = { OPT_END(), }; +static const struct option enable_options[] = { + BASE_OPTIONS(), + OPT_END(), +}; + 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) @@ -125,6 +131,9 @@ static const char *parse_device_options(int argc, const char **argv, case ACTION_DISABLE: action_string = "disable"; break; + case ACTION_ENABLE: + action_string = "enable"; + break; default: action_string = "<>"; break; @@ -178,6 +187,7 @@ static const char *parse_device_options(int argc, const char **argv, /* fall through */ case ACTION_OFFLINE: case ACTION_DISABLE: + case ACTION_ENABLE: /* nothing special */ break; } @@ -521,6 +531,14 @@ static int do_xble(struct daxctl_dev *dev, enum device_action action) } switch (action) { + case ACTION_ENABLE: + rc = daxctl_dev_enable_devdax(dev); + if (rc) { + fprintf(stderr, "%s: enable failed: %s\n", + daxctl_dev_get_devname(dev), strerror(-rc)); + return rc; + } + break; case ACTION_DISABLE: rc = daxctl_dev_disable(dev); if (rc) { @@ -570,6 +588,11 @@ static int do_xaction_device(const char *device, enum device_action action, if (rc == 0) (*processed)++; break; + case ACTION_ENABLE: + rc = do_xble(dev, action); + if (rc == 0) + (*processed)++; + break; case ACTION_DISABLE: rc = do_xble(dev, action); if (rc == 0) @@ -627,6 +650,23 @@ int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx) return rc; } +int cmd_enable_device(int argc, const char **argv, struct daxctl_ctx *ctx) +{ + char *usage = "daxctl enable-device "; + const char *device = parse_device_options(argc, argv, ACTION_DISABLE, + enable_options, usage, ctx); + int processed, rc; + + rc = do_xaction_device(device, ACTION_ENABLE, ctx, &processed); + if (rc < 0) + fprintf(stderr, "error enabling device: %s\n", + strerror(-rc)); + + fprintf(stderr, "enabled %d device%s\n", processed, + processed == 1 ? "" : "s"); + return rc; +} + int cmd_online_memory(int argc, const char **argv, struct daxctl_ctx *ctx) { char *usage = "daxctl online-memory []"; From patchwork Mon Jul 13 16:08:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 11660175 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 B3E97618 for ; Mon, 13 Jul 2020 16:09: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 9208D2076D for ; Mon, 13 Jul 2020 16:09:07 +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="reK1eDdc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9208D2076D 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 7B734118128FF; Mon, 13 Jul 2020 09:09:07 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.85; helo=userp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (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 E8AFB118128FC for ; Mon, 13 Jul 2020 09:09:05 -0700 (PDT) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06DG2rT5153758; Mon, 13 Jul 2020 16:09: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=DSaZ5xiy1IGYoySsmTYVslGcVar1nxmLVGY9gmsigYk=; b=reK1eDdctPNpqtMbzm6fU1OTnNxuetsuEjudV3Cy/NfEg8RGGssRHXpp9gFcDKrmu1DM 2myo0iDM2+62PER7Gjj8CRjfrsFnSm5J88T/zDmMtQr/j0eTO8l+RcyyPLRcXQ8ADIZZ 5IVmkv7LoFW4zy9vwaY6yFrSnZ/JlC9zjtZX+n6F71aSRK0dLCSkCMYKzuzFGxkT27n5 SaKScyvMqnVjE2K8rab0UJ1XzdQvd1iIibT/DMx/GkeZS4ohVArP1osy7iRNpizfolav nsoGTM733I4Tey/k8IJICYAEnGypg1ZizXVOV3Esv9HoPoSjFlMTQFIV/JbWEpgHfzdU Bg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 32762n7v31-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:09: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 06DG4b1c008161; Mon, 13 Jul 2020 16:09:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 327qbvu20k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:03 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06DG93xa012084; Mon, 13 Jul 2020 16:09:03 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:02 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 06/10] libdaxctl: add daxctl_region_create_dev() Date: Mon, 13 Jul 2020 17:08:33 +0100 Message-Id: <20200713160837.13774-7-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=1 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 Message-ID-Hash: OQKKRLE5MZHDCECNWCDGEW3OXXGWY5IT X-Message-ID-Hash: OQKKRLE5MZHDCECNWCDGEW3OXXGWY5IT 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 API to create an empty seed device. This sysfs attribute is only writeable for a dynamic dax device such as the one exported by hmem. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- daxctl/lib/libdaxctl.c | 26 ++++++++++++++++++++++++++ daxctl/lib/libdaxctl.sym | 1 + daxctl/libdaxctl.h | 1 + 3 files changed, 28 insertions(+) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index 00d5f7fe61ad..d17ff7a02bad 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -583,6 +583,32 @@ DAXCTL_EXPORT unsigned long long daxctl_region_get_available_size( return 0; } +DAXCTL_EXPORT int daxctl_region_create_dev(struct daxctl_region *region) +{ + struct daxctl_ctx *ctx = daxctl_region_get_ctx(region); + char *path = region->region_buf; + int rc, len = region->buf_len; + char *num_devices; + + if (snprintf(path, len, "%s/%s/create", region->region_path, attrs) >= len) { + err(ctx, "%s: buffer too small!\n", + daxctl_region_get_devname(region)); + return -EFAULT; + } + + if (asprintf(&num_devices, "%d", 1) < 0) { + err(ctx, "%s: buffer too small!\n", + daxctl_region_get_devname(region)); + return -EFAULT; + } + + rc = sysfs_write_attr(ctx, path, num_devices); + if (rc) + return rc; + + return 0; +} + DAXCTL_EXPORT struct daxctl_dev *daxctl_region_get_dev_seed( struct daxctl_region *region) { diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym index d8b4137c76b7..26987ba021ab 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -79,4 +79,5 @@ global: LIBDAXCTL_8 { global: daxctl_dev_set_size; + daxctl_region_create_dev; } LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index e3d482743cc6..a579ddd1d43c 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -56,6 +56,7 @@ unsigned long daxctl_region_get_align(struct daxctl_region *region); const char *daxctl_region_get_devname(struct daxctl_region *region); const char *daxctl_region_get_path(struct daxctl_region *region); +int daxctl_region_create_dev(struct daxctl_region *region); struct daxctl_dev *daxctl_region_get_dev_seed(struct daxctl_region *region); struct daxctl_dev; From patchwork Mon Jul 13 16:08: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: 11660177 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 BDC69722 for ; Mon, 13 Jul 2020 16:09: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 9A703206F0 for ; Mon, 13 Jul 2020 16:09:10 +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="QV+0I335" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A703206F0 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 924C911812903; Mon, 13 Jul 2020 09:09:10 -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 8723011812902 for ; Mon, 13 Jul 2020 09:09:07 -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 06DG21Kk124923; Mon, 13 Jul 2020 16:09:06 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=g0G2pLw+bxiW8GfO9Bf7h0+3e5MxnPE9tC51iqbaTYk=; b=QV+0I335Q0mRdS0zf/1Tfvyo0WK+jtCCno1h32jw9Q0sxLNLPTy4/iFjHmPz5l1Xwnch a26OpHBEdqCFdWhKil3vwYJMUKFFlLDocsc3mb+ze3heEW2AFI4VN2reA6EcYZXMZvwx zkSMQtf6sjpui7zMOsuR1MX6dcJnlp1HgmJOOyDU7kbhjJoYM5W3R1q1bD38GGJF27CP mK9Z8R7MDNPpYc0KFakkofMyj2WK3dFeUx50zJvCGciGZRtFCpYzbXpXPIsJHEgaCcPZ DdUIoFzBM/El9oV3pRBKAq2lI3sW4kiRuPrrXMkVdvpbmkqh2WswVbDtPAfioNdTzDf+ mQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 3274ur013p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:09:06 +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 06DG3YZv062734; Mon, 13 Jul 2020 16:09:05 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 327q6qgsty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:05 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG94ra027627; Mon, 13 Jul 2020 16:09:04 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:04 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 07/10] daxctl: add command to create device Date: Mon, 13 Jul 2020 17:08:34 +0100 Message-Id: <20200713160837.13774-8-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 Message-ID-Hash: H4NHX5RGJW566K7R7IID4RSPSASK5QYS X-Message-ID-Hash: H4NHX5RGJW566K7R7IID4RSPSASK5QYS 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 a 'create-device' command which creates a devdax region. So far the only new option is size, which when omitted uses the entire available space. Example usage: $ daxctl reconfigure-device -s 0 dax0.0 reconfigured 1 device $ daxctl create-device -s 4G -r 0 [ { "chardev":"dax0.1", "size":4294967296, "target_node":0, "mode":"devdax" } ] created 1 device Or using the whole available space like default behaviour or ndctl-create-namespace: $ daxctl create-device [ { "chardev":"dax0.1", "size":120259084288, "target_node":0, "mode":"devdax" } ] created 1 device Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- Documentation/daxctl/Makefile.am | 3 +- Documentation/daxctl/daxctl-create-device.txt | 105 ++++++++++++++++++++++++ daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 111 +++++++++++++++++++++++++- 5 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 Documentation/daxctl/daxctl-create-device.txt diff --git a/Documentation/daxctl/Makefile.am b/Documentation/daxctl/Makefile.am index e43d34183142..27e201dfc254 100644 --- a/Documentation/daxctl/Makefile.am +++ b/Documentation/daxctl/Makefile.am @@ -33,7 +33,8 @@ man1_MANS = \ daxctl-online-memory.1 \ daxctl-offline-memory.1 \ daxctl-disable-device.1 \ - daxctl-enable-device.1 + daxctl-enable-device.1 \ + daxctl-create-device.1 EXTRA_DIST = $(man1_MANS) diff --git a/Documentation/daxctl/daxctl-create-device.txt b/Documentation/daxctl/daxctl-create-device.txt new file mode 100644 index 000000000000..648d2541f833 --- /dev/null +++ b/Documentation/daxctl/daxctl-create-device.txt @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 + +daxctl-create-device(1) +======================= + +NAME +---- +daxctl-create-device - Create a devdax device + +SYNOPSIS +-------- +[verse] +'daxctl create-device' [] + +EXAMPLES +-------- + +* Creates dax0.1 with 4G of size +---- +# daxctl create-device -s 4G +[ + { + "chardev":"dax0.1", + "size":4294967296, + "target_node":0, + "mode":"devdax" + } +] +---- + +* Creates devices with fully available size on all regions +---- +# daxctl create-device -u +[ + { + "chardev":"dax0.1", + "size":"15.63 GiB (16.78 GB)", + "target_node":0, + "mode":"devdax" + }, + { + "chardev":"dax1.1", + "size":"15.63 GiB (16.78 GB)", + "target_node":1, + "mode":"devdax" + } +] +---- + +* Creates dax0.1 with fully available size on region id 0 +---- +# daxctl create-device -r 0 -u +{ + "chardev":"dax0.1", + "size":"15.63 GiB (16.78 GB)", + "target_node":0, + "mode":"devdax" +} +---- + +DESCRIPTION +----------- + +Creates dax device in 'devdax' mode in dynamic regions. The resultant can also +be convereted to the 'system-ram' mode which arranges for the dax range to be +hot-plugged into the system as regular memory. + +'daxctl create-device' expects that the BIOS or kernel defines a range in the +EFI memory map with EFI_MEMORY_SP. The resultant ranges mean that it's +100% capacity is reserved for applications. + +OPTIONS +------- +-r:: +--region=:: + Restrict the operation to devices belonging to the specified region(s). + A device-dax region is a contiguous range of memory that hosts one or + more /dev/daxX.Y devices, where X is the region id and Y is the device + instance id. + +-s:: +--size=:: + For regions that support dax device cretion, set the device size + in bytes. Otherwise it defaults to the maximum size specified by + region. This option supports the suffixes "k" or "K" for KiB, "m" or + "M" for MiB, "g" or "G" for GiB and "t" or "T" for TiB. + + The size must be a multiple of the region alignment. + +-u:: +--human:: + By default the command will output machine-friendly raw-integer + data. Instead, with this flag, numbers representing storage size + will be formatted as human readable strings with units, other + fields are converted to hexadecimal strings. + +-v:: +--verbose:: + Emit more debug messages + +include::../copyright.txt[] + +SEE ALSO +-------- +linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-destroy-device[1] diff --git a/daxctl/builtin.h b/daxctl/builtin.h index 8f344f86ad20..19b33933b91b 100644 --- a/daxctl/builtin.h +++ b/daxctl/builtin.h @@ -6,6 +6,7 @@ struct daxctl_ctx; int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx); +int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_enable_device(int argc, const char **argv, struct daxctl_ctx *ctx); diff --git a/daxctl/daxctl.c b/daxctl/daxctl.c index a4699b3780bd..1f315168c513 100644 --- a/daxctl/daxctl.c +++ b/daxctl/daxctl.c @@ -71,6 +71,7 @@ static struct cmd_struct commands[] = { { "list", .d_fn = cmd_list }, { "help", .d_fn = cmd_help }, { "migrate-device-model", .d_fn = cmd_migrate }, + { "create-device", .d_fn = cmd_create_device }, { "reconfigure-device", .d_fn = cmd_reconfig_device }, { "online-memory", .d_fn = cmd_online_memory }, { "offline-memory", .d_fn = cmd_offline_memory }, diff --git a/daxctl/device.c b/daxctl/device.c index 05a9247ecfde..c038abba8063 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -49,6 +49,7 @@ enum device_action { ACTION_RECONFIG, ACTION_ONLINE, ACTION_OFFLINE, + ACTION_CREATE, ACTION_DISABLE, ACTION_ENABLE, }; @@ -72,6 +73,14 @@ OPT_STRING('s', "size", ¶m.size, "size", "size to switch the device to") OPT_BOOLEAN('\0', "no-movable", ¶m.no_movable, \ "online memory in ZONE_NORMAL") +static const struct option create_options[] = { + BASE_OPTIONS(), + CREATE_OPTIONS(), + RECONFIG_OPTIONS(), + ZONE_OPTIONS(), + OPT_END(), +}; + static const struct option reconfig_options[] = { BASE_OPTIONS(), CREATE_OPTIONS(), @@ -115,7 +124,8 @@ static const char *parse_device_options(int argc, const char **argv, argc = parse_options(argc, argv, options, u, 0); /* Handle action-agnostic non-option arguments */ - if (argc == 0) { + if (argc == 0 && + action != ACTION_CREATE) { char *action_string; switch (action) { @@ -181,6 +191,10 @@ static const char *parse_device_options(int argc, const char **argv, } } break; + case ACTION_CREATE: + if (param.size) + size = __parse_size64(param.size, &units); + /* fall through */ case ACTION_ONLINE: if (param.no_movable) mem_zone = MEM_ZONE_NORMAL; @@ -452,6 +466,47 @@ static int reconfig_mode_devdax(struct daxctl_dev *dev) return 0; } +static int do_create(struct daxctl_region *region, long long val, + struct json_object **jdevs) +{ + struct json_object *jdev; + struct daxctl_dev *dev; + int rc = 0; + + if (daxctl_region_create_dev(region)) + return -ENOSPC; + + dev = daxctl_region_get_dev_seed(region); + if (!dev) + return -ENOSPC; + + if (val == -1) + val = daxctl_region_get_available_size(region); + + if (val <= 0) + return -ENOSPC; + + rc = daxctl_dev_set_size(dev, val); + if (rc < 0) + return rc; + + rc = daxctl_dev_enable_devdax(dev); + if (rc) { + fprintf(stderr, "%s: enable failed: %s\n", + daxctl_dev_get_devname(dev), strerror(-rc)); + return rc; + } + + *jdevs = json_object_new_array(); + if (*jdevs) { + jdev = util_daxctl_dev_to_json(dev, flags); + if (jdev) + json_object_array_add(*jdevs, jdev); + } + + return 0; +} + static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode, struct json_object **jdevs) { @@ -554,6 +609,42 @@ static int do_xble(struct daxctl_dev *dev, enum device_action action) return rc; } +static int do_xaction_region(enum device_action action, + struct daxctl_ctx *ctx, int *processed) +{ + struct json_object *jdevs = NULL; + struct daxctl_region *region; + int rc = -ENXIO; + + *processed = 0; + + daxctl_region_foreach(ctx, region) { + if (!util_daxctl_region_filter(region, param.region)) + continue; + + switch (action) { + case ACTION_CREATE: + rc = do_create(region, size, &jdevs); + if (rc == 0) + (*processed)++; + break; + default: + rc = -EINVAL; + break; + } + } + + /* + * jdevs is the containing json array for all devices we are reporting + * on. It therefore needs to be outside the region/device iterators, + * and passed in to the do_ functions to add their objects to + */ + if (jdevs) + util_display_json_array(stdout, jdevs, flags); + + return rc; +} + static int do_xaction_device(const char *device, enum device_action action, struct daxctl_ctx *ctx, int *processed) { @@ -616,6 +707,24 @@ static int do_xaction_device(const char *device, enum device_action action, return rc; } +int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx) +{ + char *usage = "daxctl create-device []"; + int processed, rc; + + parse_device_options(argc, argv, ACTION_CREATE, + create_options, usage, ctx); + + rc = do_xaction_region(ACTION_CREATE, ctx, &processed); + if (rc < 0) + fprintf(stderr, "error creating devices: %s\n", + strerror(-rc)); + + fprintf(stderr, "created %d device%s\n", processed, + processed == 1 ? "" : "s"); + return rc; +} + int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx) { char *usage = "daxctl reconfigure-device []"; From patchwork Mon Jul 13 16:08: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: 11660179 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 DA98A618 for ; Mon, 13 Jul 2020 16:09: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 B8D552076D for ; Mon, 13 Jul 2020 16:09:11 +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="gXyJmWWI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8D552076D 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 A6CA411812906; Mon, 13 Jul 2020 09:09:11 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.85; helo=userp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (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 F1F7911812903 for ; Mon, 13 Jul 2020 09:09:09 -0700 (PDT) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06DG2odv153693; Mon, 13 Jul 2020 16:09:08 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=WGLplW2NpfAwk85W5JfJubuEaQCeJRBR89eeTZsInvA=; b=gXyJmWWIE31Hjuvlr7942xDnOFxGKMIDYCZhKEwuvxcQdBAR99vqHJIPknAF1xxe9kwS hNI0DZl6SzT2z0qtsoFV1M8RyJ8vsDMpTCJbISp+uo31wKOaGtwRNM+RbBYXreR92BUn Li8qYDOmmm0GZibCIEULpi7Iv8jcex4tuKVoDfazcWgUF3O5aVhvA95mgbkux/Wk7saf sj9Yh0f0tynSrEhc2AUHCw8PMCIMu5ReEAGgUWCkZHqly9GJ+scI/iXnZO71pLsdhs6g pM2LV7O9x8yGTZdqFYvqlovvGxrMAdgrpIhfgXkbPuwo6mizfWbykXhPMePB4GL3iw0/ jQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 32762n7v3g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:09:08 +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 06DG3XU3138108; Mon, 13 Jul 2020 16:09:07 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 327q0mhxwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:07 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG961G011456; Mon, 13 Jul 2020 16:09:06 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:05 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 08/10] libdaxctl: add daxctl_region_destroy_dev() Date: Mon, 13 Jul 2020 17:08:35 +0100 Message-Id: <20200713160837.13774-9-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=1 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 Message-ID-Hash: WSXGPV32FRHKHHONGPLVOMPVKMJFARTP X-Message-ID-Hash: WSXGPV32FRHKHHONGPLVOMPVKMJFARTP 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 API to destroy an empty device. This 'delete' sysfs attribute is only writeable for a dynamic dax device such as the one exported by hmem. Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- daxctl/lib/libdaxctl.c | 17 +++++++++++++++++ daxctl/lib/libdaxctl.sym | 1 + daxctl/libdaxctl.h | 1 + 3 files changed, 19 insertions(+) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index d17ff7a02bad..9b43b68facfe 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -609,6 +609,23 @@ DAXCTL_EXPORT int daxctl_region_create_dev(struct daxctl_region *region) return 0; } +DAXCTL_EXPORT int daxctl_region_destroy_dev(struct daxctl_region *region, + struct daxctl_dev *dev) +{ + struct daxctl_ctx *ctx = daxctl_region_get_ctx(region); + char *path = region->region_buf; + int rc, len = region->buf_len; + + if (snprintf(path, len, "%s/%s/delete", region->region_path, attrs) >= len) { + err(ctx, "%s: buffer too small!\n", + daxctl_region_get_devname(region)); + return -EFAULT; + } + + rc = sysfs_write_attr(ctx, path, daxctl_dev_get_devname(dev)); + return rc; +} + DAXCTL_EXPORT struct daxctl_dev *daxctl_region_get_dev_seed( struct daxctl_region *region) { diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym index 26987ba021ab..33c926411037 100644 --- a/daxctl/lib/libdaxctl.sym +++ b/daxctl/lib/libdaxctl.sym @@ -80,4 +80,5 @@ LIBDAXCTL_8 { global: daxctl_dev_set_size; daxctl_region_create_dev; + daxctl_region_destroy_dev; } LIBDAXCTL_7; diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h index a579ddd1d43c..2b14faad1895 100644 --- a/daxctl/libdaxctl.h +++ b/daxctl/libdaxctl.h @@ -61,6 +61,7 @@ struct daxctl_dev *daxctl_region_get_dev_seed(struct daxctl_region *region); struct daxctl_dev; struct daxctl_dev *daxctl_dev_get_first(struct daxctl_region *region); +int daxctl_region_destroy_dev(struct daxctl_region *region, struct daxctl_dev *dev); struct daxctl_dev *daxctl_dev_get_next(struct daxctl_dev *dev); struct daxctl_region *daxctl_dev_get_region(struct daxctl_dev *dev); int daxctl_dev_get_id(struct daxctl_dev *dev); From patchwork Mon Jul 13 16:08: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: 11660181 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 F3833722 for ; Mon, 13 Jul 2020 16:09:12 +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 D18A3206F0 for ; Mon, 13 Jul 2020 16:09:12 +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="NWUiI7bb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D18A3206F0 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 C197411812904; Mon, 13 Jul 2020 09:09:12 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=156.151.31.85; helo=userp2120.oracle.com; envelope-from=joao.m.martins@oracle.com; receiver= Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (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 A543A11812905 for ; Mon, 13 Jul 2020 09:09:10 -0700 (PDT) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 06DG2oG9153678; Mon, 13 Jul 2020 16:09:09 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=4s2mSg9kYaDxi57G6K467sUZRbv15wkylcd6Wz2Kx7Y=; b=NWUiI7bbBftlpuDLSqEVtpn5uK1/aqODF8O1xVrD1hn9AcCA4mfcC+8iWY//FrzbuwYY aM+kFRhDHRZf6qvZah5yJz+aQdXgwoXVLouHnzWfW2ORQu4S+EFtqDGfXkUUpK+iFw85 tChaeZP1g4HrLuTiCNQlos+fWs/g/IK9LOAFn2Aj+Ai+1prX4Y7KTwebYScXX3wSMoY2 EMxoUF46Q5aCq/GdKFGAWHEiNHxNOJNaj1ezckGw3QBwq6+Yp1t7arCmg8w0PZJwcQnF 3aLc8rtoIMRhWCcBgHFxnMp60ed06w4Di9rlgKBi3AWwHM778ciIwehfz5R4GcHveR2O 3Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 32762n7v3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:09:09 +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 06DG3VBM127198; Mon, 13 Jul 2020 16:09:08 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 327qb11jqh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:08 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 06DG97qS010835; Mon, 13 Jul 2020 16:09:07 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:07 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 09/10] daxctl: add command to destroy device Date: Mon, 13 Jul 2020 17:08:36 +0100 Message-Id: <20200713160837.13774-10-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 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-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 suspectscore=1 phishscore=0 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 Message-ID-Hash: LCLSLAV7MSCXESM2SIP5Q54VLPYFNVTA X-Message-ID-Hash: LCLSLAV7MSCXESM2SIP5Q54VLPYFNVTA 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 a 'destroy-device' command which destroys a dax device. Like namespaces, the device needs to be disabled in order to be destroyed. Example usage: $ daxctl disable-device dax0.1 disabled 1 device $ daxctl destroy-device dax0.1 destroyed 1 device Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- Documentation/daxctl/Makefile.am | 3 +- Documentation/daxctl/daxctl-destroy-device.txt | 63 ++++++++++++++++++++++++ daxctl/builtin.h | 1 + daxctl/daxctl.c | 1 + daxctl/device.c | 66 ++++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 Documentation/daxctl/daxctl-destroy-device.txt diff --git a/Documentation/daxctl/Makefile.am b/Documentation/daxctl/Makefile.am index 27e201dfc254..2b3f92ca5b96 100644 --- a/Documentation/daxctl/Makefile.am +++ b/Documentation/daxctl/Makefile.am @@ -34,7 +34,8 @@ man1_MANS = \ daxctl-offline-memory.1 \ daxctl-disable-device.1 \ daxctl-enable-device.1 \ - daxctl-create-device.1 + daxctl-create-device.1 \ + daxctl-destroy-device.1 EXTRA_DIST = $(man1_MANS) diff --git a/Documentation/daxctl/daxctl-destroy-device.txt b/Documentation/daxctl/daxctl-destroy-device.txt new file mode 100644 index 000000000000..1c91cb2fab75 --- /dev/null +++ b/Documentation/daxctl/daxctl-destroy-device.txt @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 + +daxctl-destroy-device(1) +======================== + +NAME +---- +daxctl-destroy-device - Destroy a devdax device + +SYNOPSIS +-------- +[verse] +'daxctl destroy-device' [...] [] + +EXAMPLES +-------- + +* Destroys dax0.1 +---- +# daxctl disable-device dax0.1 +disabled 1 device +# daxctl destroy-device dax0.1 +destroyed 1 device +---- + +* Destroys all devices in region id 0 +---- +# daxctl disable-device -r 0 all +disabled 3 devices +# daxctl destroy-device -r 0 all +destroyed 2 devices +---- + +DESCRIPTION +----------- + +Destroys a dax device in 'devdax' mode. + +OPTIONS +------- +-r:: +--region=:: + Restrict the operation to devices belonging to the specified region(s). + A device-dax region is a contiguous range of memory that hosts one or + more /dev/daxX.Y devices, where X is the region id and Y is the device + instance id. + +-u:: +--human:: + By default the command will output machine-friendly raw-integer + data. Instead, with this flag, numbers representing storage size + will be formatted as human readable strings with units, other + fields are converted to hexadecimal strings. + +-v:: +--verbose:: + Emit more debug messages + +include::../copyright.txt[] + +SEE ALSO +-------- +linkdaxctl:daxctl-list[1],daxctl-reconfigure-device[1],daxctl-create-device[1] diff --git a/daxctl/builtin.h b/daxctl/builtin.h index 19b33933b91b..29ba63ca17aa 100644 --- a/daxctl/builtin.h +++ b/daxctl/builtin.h @@ -7,6 +7,7 @@ struct daxctl_ctx; int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_migrate(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx); +int cmd_destroy_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_disable_device(int argc, const char **argv, struct daxctl_ctx *ctx); int cmd_enable_device(int argc, const char **argv, struct daxctl_ctx *ctx); diff --git a/daxctl/daxctl.c b/daxctl/daxctl.c index 1f315168c513..bd5539900391 100644 --- a/daxctl/daxctl.c +++ b/daxctl/daxctl.c @@ -72,6 +72,7 @@ static struct cmd_struct commands[] = { { "help", .d_fn = cmd_help }, { "migrate-device-model", .d_fn = cmd_migrate }, { "create-device", .d_fn = cmd_create_device }, + { "destroy-device", .d_fn = cmd_destroy_device }, { "reconfigure-device", .d_fn = cmd_reconfig_device }, { "online-memory", .d_fn = cmd_online_memory }, { "offline-memory", .d_fn = cmd_offline_memory }, diff --git a/daxctl/device.c b/daxctl/device.c index c038abba8063..05293d6c38ee 100644 --- a/daxctl/device.c +++ b/daxctl/device.c @@ -52,6 +52,7 @@ enum device_action { ACTION_CREATE, ACTION_DISABLE, ACTION_ENABLE, + ACTION_DESTROY, }; #define BASE_OPTIONS() \ @@ -69,6 +70,10 @@ OPT_BOOLEAN('f', "force", ¶m.force, \ #define CREATE_OPTIONS() \ OPT_STRING('s', "size", ¶m.size, "size", "size to switch the device to") +#define DESTROY_OPTIONS() \ +OPT_BOOLEAN('f', "force", ¶m.force, \ + "attempt to disable before destroying device") + #define ZONE_OPTIONS() \ OPT_BOOLEAN('\0', "no-movable", ¶m.no_movable, \ "online memory in ZONE_NORMAL") @@ -110,6 +115,12 @@ static const struct option enable_options[] = { OPT_END(), }; +static const struct option destroy_options[] = { + BASE_OPTIONS(), + DESTROY_OPTIONS(), + OPT_END(), +}; + 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) @@ -144,6 +155,9 @@ static const char *parse_device_options(int argc, const char **argv, case ACTION_ENABLE: action_string = "enable"; break; + case ACTION_DESTROY: + action_string = "destroy"; + break; default: action_string = "<>"; break; @@ -199,6 +213,7 @@ static const char *parse_device_options(int argc, const char **argv, if (param.no_movable) mem_zone = MEM_ZONE_NORMAL; /* fall through */ + case ACTION_DESTROY: case ACTION_OFFLINE: case ACTION_DISABLE: case ACTION_ENABLE: @@ -364,6 +379,35 @@ static int dev_resize(struct daxctl_dev *dev, unsigned long long val) return 0; } +static int dev_destroy(struct daxctl_dev *dev) +{ + const char *devname = daxctl_dev_get_devname(dev); + int rc; + + if (daxctl_dev_is_enabled(dev) && !param.force) { + fprintf(stderr, "%s is active, specify --force for deletion\n", + devname); + return -ENXIO; + } else { + rc = daxctl_dev_disable(dev); + if (rc) { + fprintf(stderr, "%s: disable failed: %s\n", + daxctl_dev_get_devname(dev), strerror(-rc)); + return rc; + } + } + + rc = daxctl_dev_set_size(dev, 0); + if (rc < 0) + return rc; + + rc = daxctl_region_destroy_dev(daxctl_dev_get_region(dev), dev); + if (rc < 0) + return rc; + + return 0; +} + static int disable_devdax_device(struct daxctl_dev *dev) { struct daxctl_memory *mem = daxctl_dev_get_memory(dev); @@ -689,6 +733,11 @@ static int do_xaction_device(const char *device, enum device_action action, if (rc == 0) (*processed)++; break; + case ACTION_DESTROY: + rc = dev_destroy(dev); + if (rc == 0) + (*processed)++; + break; default: rc = -EINVAL; break; @@ -725,6 +774,23 @@ int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx) return rc; } +int cmd_destroy_device(int argc, const char **argv, struct daxctl_ctx *ctx) +{ + char *usage = "daxctl destroy-device []"; + const char *device = parse_device_options(argc, argv, ACTION_DESTROY, + destroy_options, usage, ctx); + int processed, rc; + + rc = do_xaction_device(device, ACTION_DESTROY, ctx, &processed); + if (rc < 0) + fprintf(stderr, "error destroying devices: %s\n", + strerror(-rc)); + + fprintf(stderr, "destroyed %d device%s\n", processed, + processed == 1 ? "" : "s"); + return rc; +} + int cmd_reconfig_device(int argc, const char **argv, struct daxctl_ctx *ctx) { char *usage = "daxctl reconfigure-device []"; From patchwork Mon Jul 13 16:08: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: 11660183 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 4E95F618 for ; Mon, 13 Jul 2020 16:09:15 +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 2C9DA20771 for ; Mon, 13 Jul 2020 16:09:15 +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="TMDiQe6T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C9DA20771 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 E88C01181290D; Mon, 13 Jul 2020 09:09:14 -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 E489C11812904 for ; Mon, 13 Jul 2020 09:09:11 -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 06DG23DU125041; Mon, 13 Jul 2020 16:09:10 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=3wo52LLAfM7RoNMtM2VCMPzkZlYfWPmm6hiLrvJWFDE=; b=TMDiQe6T0gw64CsraXrQnjkhjA1W1kVACm90wH69o9pfKjLZUgyz2uWo9b+qV6rj/VZD CGU87ba1IA14TGIXmVm/f9dsw6LY+S7gwER4J9EQw+ybyJkD/pVrIGKa4GqqFzeCwCR/ BbaWoRThGr5ARMW2iV5B6wl0aKwaI77+6RKdwY8rLkBQXfbsow606QHVecHn4+o+tDKf HAdhCMQUZh1CRjxxjOd9e9fP+WDFHZldpoFTr9g6PiDKNAIRcGZpUVlWPRbQMWR6MJ6l 9IxOPFGWHVxNEYCyXczmQx88b8MkUc7TPcJxj5zfA7vBFbapsFI7p1heep3T7b6pJ5v6 9Q== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 3274ur0145-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 13 Jul 2020 16:09:10 +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 06DG3YCl062768; Mon, 13 Jul 2020 16:09:10 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 327q6qgsyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jul 2020 16:09:09 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 06DG99I6011472; Mon, 13 Jul 2020 16:09:09 GMT Received: from paddy.uk.oracle.com (/10.175.167.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 13 Jul 2020 09:09:08 -0700 From: Joao Martins To: linux-nvdimm@lists.01.org Cc: Dan Williams , Vishal Verma Subject: [PATCH ndctl v2 10/10] daxctl/test: Add tests for dynamic dax regions Date: Mon, 13 Jul 2020 17:08:37 +0100 Message-Id: <20200713160837.13774-11-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200713160837.13774-1-joao.m.martins@oracle.com> References: <20200713160837.13774-1-joao.m.martins@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 phishscore=0 malwarescore=0 mlxlogscore=841 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007130119 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9681 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 impostorscore=0 suspectscore=1 phishscore=0 spamscore=0 mlxlogscore=835 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-2007130119 Message-ID-Hash: IPVDINCS2B724HDBMP6SSFB4GEMEY5QM X-Message-ID-Hash: IPVDINCS2B724HDBMP6SSFB4GEMEY5QM 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 a couple tests which exercise the new sysfs based interface for Soft-Reserved regions (by EFI/HMAT, or efi_fake_mem). The tests exercise the daxctl orchestration surrounding for creating/disabling/destroying/reconfiguring devices. Furthermore it exercises dax region space allocation code paths particularly: 1) zeroing out and reconfiguring a dax device from its current size to be max available and back to initial size 2) creates devices from holes in the beginning, middle of the region. 3) reconfigures devices in a interleaving fashion 4) test adjust of the region towards beginning and end The tests assume you pass a valid efi_fake_mem parameter marked as EFI_MEMORY_SP e.g. efi_fake_mem=112G@16G:0x40000 Naturally it bails out from the test if hmem device driver isn't loaded or builtin. If hmem regions are found, only region 0 is used, and the others remain untouched. Signed-off-by: Joao Martins --- test/Makefile.am | 1 + test/daxctl-create.sh | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100755 test/daxctl-create.sh diff --git a/test/Makefile.am b/test/Makefile.am index 1d24a65ded8b..6b7c82f9a4e2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -58,6 +58,7 @@ TESTS +=\ device-dax \ device-dax-fio.sh \ daxctl-devices.sh \ + daxctl-create.sh \ dm.sh \ mmap.sh diff --git a/test/daxctl-create.sh b/test/daxctl-create.sh new file mode 100755 index 000000000000..0d35112b4119 --- /dev/null +++ b/test/daxctl-create.sh @@ -0,0 +1,294 @@ +#!/bin/bash -Ex +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Oracle Corporation. + +rc=77 +. $(dirname $0)/common + +trap 'cleanup $LINENO' ERR + +cleanup() +{ + printf "Error at line %d\n" "$1" + [[ $testdev ]] && reset + exit $rc +} + +find_testdev() +{ + local rc=77 + + # The hmem driver is needed to change the device mode, only + # kernels >= v5.6 might have it available. Skip if not. + if ! modinfo hmem; then + # check if hmem is builtin + if [ ! -d "/sys/module/device_hmem" ]; then + printf "Unable to find hmem module\n" + exit $rc + fi + fi + + # find a victim region provided by dax_hmem + testpath=$("$DAXCTL" list -r 0 | jq -er '.[0].path | .//""') + if [[ ! "$testpath" == *"hmem"* ]]; then + printf "Unable to find a victim region\n" + exit "$rc" + fi + + # find a victim device + testdev=$("$DAXCTL" list -D -r 0 | jq -er '.[0].chardev | .//""') + if [[ ! $testdev ]]; then + printf "Unable to find a victim device\n" + exit "$rc" + fi + printf "Found victim dev: %s on region id 0\n" "$testdev" +} + +setup_dev() +{ + test -n "$testdev" + + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s 0 "$testdev" + available=$("$DAXCTL" list -r 0 | jq -er '.[0].available_size | .//""') +} + +reset_dev() +{ + test -n "$testdev" + + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s $available "$testdev" + "$DAXCTL" enable-device "$testdev" +} + +reset() +{ + test -n "$testdev" + + "$DAXCTL" disable-device -r 0 all + "$DAXCTL" destroy-device -r 0 all + "$DAXCTL" reconfigure-device -s $available "$testdev" +} + +clear_dev() +{ + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s 0 "$testdev" +} + +test_pass() +{ + local rc=1 + + # Available size + _available_size=$("$DAXCTL" list -r 0 | jq -er '.[0].available_size | .//""') + if [[ ! $_available_size == $available ]]; then + printf "Unexpected available size $_available_size != $available\n" + exit "$rc" + fi +} + +fail_if_available() +{ + local rc=1 + + _size=$("$DAXCTL" list -r 0 | jq -er '.[0].available_size | .//""') + if [[ $_size ]]; then + printf "Unexpected available size $_size\n" + exit "$rc" + fi +} + +daxctl_get_dev() +{ + "$DAXCTL" list -d "$1" | jq -er '.[].chardev' +} + +daxctl_get_mode() +{ + "$DAXCTL" list -d "$1" | jq -er '.[].mode' +} + +daxctl_test_multi() +{ + local daxdev + + size=$(expr $available / 4) + + if [[ $2 ]]; then + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s $size "$testdev" + fi + + daxdev_1=$("$DAXCTL" create-device -r 0 -s $size | jq -er '.[].chardev') + test -n $daxdev_1 + + daxdev_2=$("$DAXCTL" create-device -r 0 -s $size | jq -er '.[].chardev') + test -n $daxdev_2 + + if [[ ! $2 ]]; then + daxdev_3=$("$DAXCTL" create-device -r 0 -s $size | jq -er '.[].chardev') + test -n $daxdev_3 + fi + + # Hole + "$DAXCTL" disable-device $1 && "$DAXCTL" destroy-device $1 + + # Pick space in the created hole and at the end + new_size=$(expr $size \* 2) + daxdev_4=$("$DAXCTL" create-device -r 0 -s $new_size | jq -er '.[].chardev') + test -n $daxdev_4 + + fail_if_available + + "$DAXCTL" disable-device -r 0 all + "$DAXCTL" destroy-device -r 0 all +} + +daxctl_test_multi_reconfig() +{ + local ncfgs=$1 + local daxdev + + size=$(expr $available / $ncfgs) + + test -n "$testdev" + + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s $size "$testdev" + "$DAXCTL" disable-device "$testdev" + + daxdev_1=$("$DAXCTL" create-device -r 0 -s $size | jq -er '.[].chardev') + "$DAXCTL" disable-device "$daxdev_1" + + start=$(expr $size + $size) + max=$(expr $ncfgs / 2 \* $size) + for i in $(seq $start $size $max) + do + "$DAXCTL" disable-device "$testdev" + "$DAXCTL" reconfigure-device -s $i "$testdev" + + "$DAXCTL" disable-device "$daxdev_1" + "$DAXCTL" reconfigure-device -s $i "$daxdev_1" + done + + fail_if_available + + "$DAXCTL" disable-device "$daxdev_1" && "$DAXCTL" destroy-device "$daxdev_1" +} + +daxctl_test_adjust() +{ + local rc=1 + local ncfgs=4 + local daxdev + + size=$(expr $available / $ncfgs) + + test -n "$testdev" + + start=$(expr $size + $size) + for i in $(seq 1 1 $ncfgs) + do + daxdev=$("$DAXCTL" create-device -r 0 -s $size) + done + + daxdev=$(daxctl_get_dev "dax0.1") + "$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev" + daxdev=$(daxctl_get_dev "dax0.4") + "$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev" + + daxdev=$(daxctl_get_dev "dax0.2") + "$DAXCTL" disable-device "$daxdev" + "$DAXCTL" reconfigure-device -s $(expr $size \* 2) "$daxdev" + + daxdev=$(daxctl_get_dev "dax0.3") + "$DAXCTL" disable-device "$daxdev" + "$DAXCTL" reconfigure-device -s $(expr $size \* 2) "$daxdev" + + fail_if_available + + daxdev=$(daxctl_get_dev "dax0.3") + "$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev" + daxdev=$(daxctl_get_dev "dax0.2") + "$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev" +} + +# Test 0: +# Sucessfully zero out the region device and allocate the whole space again. +daxctl_test0() +{ + clear_dev + test_pass +} + +# Test 1: +# Sucessfully creates and destroys a device with the whole available space +daxctl_test1() +{ + local daxdev + + daxdev=$("$DAXCTL" create-device -r 0 | jq -er '.[].chardev') + + test -n "$daxdev" + fail_if_available + + "$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev" + + clear_dev + test_pass +} + +# Test 2: space at the middle and at the end +# Successfully pick space in the middle and space at the end, by +# having the region device reconfigured with some of the memory. +daxctl_test2() +{ + daxctl_test_multi "dax0.1" 1 + clear_dev + test_pass +} + +# Test 3: space at the beginning and at the end +# Successfully pick space in the beginning and space at the end, by +# having the region device emptied (so region beginning starts with dax0.1). +daxctl_test3() +{ + daxctl_test_multi "dax0.1" + clear_dev + test_pass +} + +# Test 4: space at the end +# Successfully reconfigure two devices in increasingly bigger allocations. +# The difference is that it reuses an existing resource, and only needs to +# pick at the end of the region +daxctl_test4() +{ + daxctl_test_multi_reconfig 8 + clear_dev + test_pass +} + +# Test 5: space adjust +# Successfully adjusts two resources to fill the whole region +# First adjusts towards the beginning of region, the second towards the end. +daxctl_test5() +{ + daxctl_test_adjust + clear_dev + test_pass +} + +find_testdev +rc=1 +setup_dev +daxctl_test0 +daxctl_test1 +daxctl_test2 +daxctl_test3 +daxctl_test4 +daxctl_test5 +reset_dev +exit 0