From patchwork Wed Jan 30 10:59:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 413FF91E for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 283B42E3BB for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C1F2E3E3; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 935D02E3BB for ; Wed, 30 Jan 2019 10:59:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 386DD211BFCC7; Wed, 30 Jan 2019 02:59:42 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 56809211BFCC4 for ; Wed, 30 Jan 2019 02:59:41 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id u6so11225565pfh.11 for ; Wed, 30 Jan 2019 02:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gpcJC925Dzn4L84tSMBOywJz1xpyjGw7bG2diEjC9BE=; b=qX0qzRn3+7JY5yopwYqNP0felpK1v4A3sLZdWvDBjnZhOmssqD1L/ioF4VBNbDxtbR tvWdQ4+nELD447ZYF5i+nFV3gDZcq1GCeK30F62f3hWjEWdSlgeob+PdqBJ7Un4lQEiM 6BhnMAL9kCQFMeur4jLHz9a6vSYTTJqIJKdBraN0gvamb8/BuDCOOYxu2zeop0s1/Q5h otZqyh7etesH2/Or0ExVv+LM5ztfW/saf8e36N0OAtmVaWKAePKUmumM53xs3LiXZeMY +3VYmHWNd+IkQbkd5kfmUlwBhNQqK5gMxgEInYVsujzRQ30pfvzWGmd/h7jgoD14cyAH lSig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gpcJC925Dzn4L84tSMBOywJz1xpyjGw7bG2diEjC9BE=; b=Yj2y/0IvNnBRmEDgf6RVNFcFkGk/ca5iq791fPdtD9tDXZDpOT5whGNcqQWqn+VuZC NYcEhj2P5xyYiBpqzK5R9ACEiKRlVwdFHOqwFbjpMYSmGabuw0Vqem6Ail+RpmWlLba1 zHHtvsQeFGpKshrsFrni9HXXnklO6//V/3z0aI4+GI6WINbHS6AyxIlgp+J1HiHSjfoX WlQ3OdH/n8tq2/dFXYyUhnLvpz3XdoNtuTxfmCfUlPHPjNLcsg9uKLgWTcooQO5phxMm 7Hr01AKODrmtESsQx2Q331fuaiv/xb6PN1a8mDWRzN0qif/yfhgN6M98jQEftNermtIG 0v/Q== X-Gm-Message-State: AJcUukf/YiUFEfOdKft+itrt0UhW4zlXLvNgKBfq5PqZsLKBFRJ/TgIB 8cc5NIxpoKFl3ekh6znTYao9+D6y X-Google-Smtp-Source: ALg8bN45wf+t5l8C6ru1UrdTSmJNbxVlgqVRk/L257R6una77PpvRyOjw9+jOEyZYnSdAAQhlSA8jQ== X-Received: by 2002:a62:16d6:: with SMTP id 205mr29865402pfw.256.1548845980004; Wed, 30 Jan 2019 02:59:40 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:39 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 1/7] libndctl: Use the supported_alignment attribute Date: Wed, 30 Jan 2019 21:59:21 +1100 Message-Id: <20190130105927.31901-1-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Newer kernels provide the "supported_alignments" sysfs attribute that indicates what alignments can be used with a PFN or DAX namespace. This patch adds the plumbing inside of libndctl to allow users to query this information through using: ndctl_{dax|pfn}_get_supported_alignment(), and ndctl_{dax|pfn}_get_num_alignments() Signed-off-by: Oliver O'Halloran --- v5: Fixed comment wording v4: Changed return code of ndctl_pfn_get_supported_alignment from -1 to -1 to -EINVAL. Reworded comment about why we default to 4K and 2M alignments when the sysfs attribute is missing. Shuffled around prototypes in ndctl.h. 80 char compliance fixes. rebased onto pending branch v3: Changed the return type of the *_get_supported_alignment() functions to unsigned long to match the existing *_get_alignment() functions. --- ndctl/lib/libndctl.c | 43 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 4 ++++ ndctl/libndctl.h | 4 ++++ 3 files changed, 51 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 830b791339d2..06f835d76117 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -237,6 +238,7 @@ struct ndctl_pfn { int buf_len; uuid_t uuid; int id, generation; + struct ndctl_lbasize alignments; }; struct ndctl_dax { @@ -4814,6 +4816,19 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base) else pfn->size = strtoull(buf, NULL, 0); + /* + * The supported_alignments attribute was added before arches other + * than x86 had pmem support. If the kernel doesn't provide the + * attribute then it's safe to assume that we running on x86 where + * 4KiB and 2MiB have always been supported. + */ + sprintf(path, "%s/supported_alignments", pfn_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + sprintf(buf, "%d %d", SZ_4K, SZ_2M); + + if (parse_lbasize_supported(ctx, pfn_base, buf, &pfn->alignments) < 0) + goto err_read; + free(path); return pfn; @@ -5048,6 +5063,23 @@ NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align) return 0; } +NDCTL_EXPORT int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn) +{ + return pfn->alignments.num; +} + +NDCTL_EXPORT unsigned long ndctl_pfn_get_supported_alignment( + struct ndctl_pfn *pfn, int i) +{ + if (pfn->alignments.num == 0) + return 0; + + if (i < 0 || i > pfn->alignments.num) + return -EINVAL; + else + return pfn->alignments.supported[i]; +} + NDCTL_EXPORT int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns) { @@ -5270,6 +5302,17 @@ NDCTL_EXPORT unsigned long ndctl_dax_get_align(struct ndctl_dax *dax) return ndctl_pfn_get_align(&dax->pfn); } +NDCTL_EXPORT int ndctl_dax_get_num_alignments(struct ndctl_dax *dax) +{ + return ndctl_pfn_get_num_alignments(&dax->pfn); +} + +NDCTL_EXPORT unsigned long ndctl_dax_get_supported_alignment( + struct ndctl_dax *dax, int i) +{ + return ndctl_pfn_get_supported_alignment(&dax->pfn, i); +} + NDCTL_EXPORT int ndctl_dax_has_align(struct ndctl_dax *dax) { return ndctl_pfn_has_align(&dax->pfn); diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 275db92ee103..a30a93e3c012 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -390,4 +390,8 @@ LIBNDCTL_19 { global: ndctl_cmd_xlat_firmware_status; ndctl_cmd_submit_xlat; + ndctl_pfn_get_supported_alignment; + ndctl_pfn_get_num_alignments; + ndctl_dax_get_supported_alignment; + ndctl_dax_get_num_alignments; } LIBNDCTL_18; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index e55a5932781d..ac639b7d9142 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -597,7 +597,9 @@ int ndctl_pfn_set_uuid(struct ndctl_pfn *pfn, uuid_t uu); void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu); int ndctl_pfn_has_align(struct ndctl_pfn *pfn); int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align); +int ndctl_pfn_get_num_alignments(struct ndctl_pfn *pfn); unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn); +unsigned long ndctl_pfn_get_supported_alignment(struct ndctl_pfn *pfn, int i); unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn); unsigned long long ndctl_pfn_get_size(struct ndctl_pfn *pfn); int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns); @@ -628,7 +630,9 @@ unsigned long long ndctl_dax_get_resource(struct ndctl_dax *dax); int ndctl_dax_set_uuid(struct ndctl_dax *dax, uuid_t uu); enum ndctl_pfn_loc ndctl_dax_get_location(struct ndctl_dax *dax); int ndctl_dax_set_location(struct ndctl_dax *dax, enum ndctl_pfn_loc loc); +int ndctl_dax_get_num_alignments(struct ndctl_dax *dax); unsigned long ndctl_dax_get_align(struct ndctl_dax *dax); +unsigned long ndctl_dax_get_supported_alignment(struct ndctl_dax *dax, int i); int ndctl_dax_has_align(struct ndctl_dax *dax); int ndctl_dax_set_align(struct ndctl_dax *dax, unsigned long align); int ndctl_dax_set_namespace(struct ndctl_dax *dax, From patchwork Wed Jan 30 10:59:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8C561874 for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1A442E395 for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B433C2E3EF; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5C6F02E3BB for ; Wed, 30 Jan 2019 10:59:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 526FC211BFCD0; Wed, 30 Jan 2019 02:59:43 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 95681211BFCC4 for ; Wed, 30 Jan 2019 02:59:42 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id z23so10905039plo.0 for ; Wed, 30 Jan 2019 02:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9CZe6/mPyds7N/cI342d0fhejbMy5coCz60V5tgIoz0=; b=PaW1+WdbU1RRFdw7IyOK2Nl+27lOYMrTEaMsCjdcbrg7teN0ztZ8J/qInCehM82wQu jc4nOipbXCPbvHXdE4P+kVV0GA5jlr+Zg3Xu5gNs8aq2lJs10BTUM62jEMlJ8lfUk0A3 DUfHO0wmgVpO/MkipimHP4rz2j0Qc+g/0wC1DTk8Q1pHcxTwp32p9/CTMKD1PWGN5Smk rfdEFljXa8YdHsKxJ99VATH0PbbNTz5oH8jR4abTfrYPQmg5M7mNk8+uSp5zL4A8oFKV BWFNcS4Hy2D6jV5f5Cb6BiU123Q8OVujvnRIyESEIhq9vBnIVSgbSXKmo05AYg4EoYeG oyRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9CZe6/mPyds7N/cI342d0fhejbMy5coCz60V5tgIoz0=; b=fvCBVxHHQcBLY5fmLrNWh9JFiZtzNSCjZWXWFmlQhjfQkjpWUHmoS0VKgCNTkbc7I6 DDA/DGGVfcselTHlKs9uV36ewl5N5LrIQB+cLxL5w5J4YU9Fta2YruDs08kX55o1Dj+Y KEcqjdnKnPtAtESqK6wfxz6eJ7yOAw2/XNgGo76gw45sHmUn1iHWBFNVrGvlAxFi44Xw ydHUeOr6OH188Xigia881/t4OUPHr6v60GIOatFh6AXuS+nG7NEXYMk3WsntmSe4Osrg bLmhBys+Hg1RtvfHpmMtNy/xXPWVlpHU1K+oEvM1K1YlGJ2nFbkR87M/IUF5yPG/AewW 0I2A== X-Gm-Message-State: AJcUukfj1JZAFDpdhAGMslHSvId6H87dJ0CafHcP4HjGaYLNfrROGr2l KoO1QSdIv+/7YA0lvVmpN+ZSbxHY X-Google-Smtp-Source: ALg8bN7xXmjtjgCfVJtUrZ1SeSaB3Y4EKalh5mudV4SidBt7zq+C5u1CCocwb8Rr6vvoEmN4KVHpgA== X-Received: by 2002:a17:902:32c3:: with SMTP id z61mr29811449plb.114.1548845981977; Wed, 30 Jan 2019 02:59:41 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:41 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 2/7] ndctl/namespace: Check for seed namespaces earlier Date: Wed, 30 Jan 2019 21:59:22 +1100 Message-Id: <20190130105927.31901-2-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When creating an fsdax or devdax namespace we need to verify that the seed namespaces exist. This patch reworks the validation so that it's done earlier to simplify the subsequent patches in the series. Signed-off-by: Oliver O'Halloran --- No functional changes, I hope. v3: Don't fail early if the user specifies fsdax mode without pfn support. Instead, if we try to validate a feature that requires pfn support, fail the validation at that point. --- ndctl/namespace.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index b35812bd17a9..12253a96e095 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -469,6 +469,8 @@ static int validate_namespace_options(struct ndctl_region *region, { const char *region_name = ndctl_region_get_devname(region); unsigned long long size_align = SZ_4K, units = 1, resource; + struct ndctl_pfn *pfn = NULL; + struct ndctl_dax *dax = NULL; unsigned int ways; int rc = 0; @@ -525,10 +527,24 @@ static int validate_namespace_options(struct ndctl_region *region, } else if (ndns) p->mode = ndctl_namespace_get_mode(ndns); - if (param.align) { - struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); - struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); + if (p->mode == NDCTL_NS_MODE_MEMORY) { + pfn = ndctl_region_get_pfn_seed(region); + if (!pfn && param.mode_default) { + debug("%s fsdax mode not available\n", region_name); + p->mode = NDCTL_NS_MODE_RAW; + } + /* + * NB: We only fail validation if a pfn-specific option is used + */ + } else if (p->mode == NDCTL_NS_MODE_DAX) { + dax = ndctl_region_get_dax_seed(region); + if (!dax) { + error("Kernel does not support devdax mode\n"); + return -ENODEV; + } + } + if (param.align) { p->align = parse_size64(param.align); if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M @@ -709,30 +725,12 @@ static int validate_namespace_options(struct ndctl_region *region, || p->mode == NDCTL_NS_MODE_DAX) p->loc = NDCTL_PFN_LOC_PMEM; - /* check if we need, and whether the kernel supports, pfn devices */ - if (do_setup_pfn(ndns, p)) { - struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); - - if (!pfn && param.mode_default) { - debug("%s fsdax mode not available\n", region_name); - p->mode = NDCTL_NS_MODE_RAW; - } else if (!pfn) { - error("operation failed, %s fsdax mode not available\n", - region_name); - return -EINVAL; - } + if (!pfn && do_setup_pfn(ndns, p)) { + error("operation failed, %s cannot support requested mode\n", + region_name); + return -EINVAL; } - /* check if we need, and whether the kernel supports, dax devices */ - if (p->mode == NDCTL_NS_MODE_DAX) { - struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); - - if (!dax) { - error("operation failed, %s devdax mode not available\n", - region_name); - return -EINVAL; - } - } p->autolabel = param.autolabel; From patchwork Wed Jan 30 10:59:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B78091E for ; Wed, 30 Jan 2019 10:59:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 079B52E3BB for ; Wed, 30 Jan 2019 10:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFCB82E3C3; Wed, 30 Jan 2019 10:59:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DFC42E3E2 for ; Wed, 30 Jan 2019 10:59:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 67EF5211BFCD4; Wed, 30 Jan 2019 02:59:45 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::641; helo=mail-pl1-x641.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8E795211BFCC4 for ; Wed, 30 Jan 2019 02:59:44 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id z23so10905109plo.0 for ; Wed, 30 Jan 2019 02:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uUaBuQNjN+mwEK3nGm85GwqwVxv+e1kYXkYn5D57eJ4=; b=MLhPckB8y8Ol1HHYEWxJUXzzycK3HO0u7hyAbDMmgQ2zIfRcko4wro5xnpTor7wEwl GObNrnvOuTBaaUXfhmCMMOESCriqf3JzBN44y6y02j+W8v8V55TRmQulLr1CZBPyr1SZ UYgLw4JFtrdMji6HgyC0r6TTUqlPeTGXdx1kS85Ky4y/3ppFgaxEL1xP+/CZKHjmIGtY R2umXqSNIfZfRc23CEzZAl8Qk0Uvbap3N0wN6PyAWWtrknOW7MdyURQztUilvYEoGtkn lWYEGovVO1nt1CXlr5QkjTDg1RQs0Y+H5k1OwbUWkRGpVaAj234jKzf2wtNlJ0OpamIR RylQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uUaBuQNjN+mwEK3nGm85GwqwVxv+e1kYXkYn5D57eJ4=; b=PXtAeJRopIvrWieHfhbsUgrHq/Ou/C2CoOCcGIxZqjp/0vmERq25+J3eqUJ/Xvmo94 Csia/skvQrbV9uVOuO067Ier2n7KkD56ABIAtfIB3reiJIh2YGVya97oPGuY8ztnL+mx wXEJ35GH4mPY8eZg5LTe0Q4j4vdw3YqHpau35DtLAnmWuFjs3V1BtDYx/Pn4Rx0AUTOe JAJgW872mCGiG7CJ7xPRmeJfBlBlOea6JKH8dt7BG1xJM8rGaGYqESv9jcFyfxJgAba3 h2miKzYD/+QOAPucDDELT+c0dfopZI3jxEhK20AGdEWebenxWGGqEwyXExVx+rp3lOI/ gsVQ== X-Gm-Message-State: AHQUAuZFODOWs3gI4zKGCqDJa2LMcue7VPDhPojTlQpg7OurKvhwRQPz rpKNZl2MtIPQrikYEfH50FCWz6Tu X-Google-Smtp-Source: AHgI3IbnAxGc+yM8mw7RWCLbxvGz7lLgKrVd1p/Es2LRMfc2h0XHvi+axnx1hSU1K6qM8dhtRnTo0g== X-Received: by 2002:a17:902:9687:: with SMTP id n7mr8189612plp.94.1548845984015; Wed, 30 Jan 2019 02:59:44 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:43 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 3/7] ndctl/namespace: Use seed alignment as the default Date: Wed, 30 Jan 2019 21:59:23 +1100 Message-Id: <20190130105927.31901-3-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When creating a pfn or dax namespace ndctl uses a default alignment of 2MB when the user does not explicitly supply one. This works on most systems (x86, ARM, PPC64 with radix MMU), but it fails when the kernel does not support a 2MB page size (PPC64 with hash MMU). This patch makes ndctl use the alignment of the relevant seed namespace as the default instead. The kernel will always pick a valid default alignment so this should be a bit more portable. Signed-off-by: Oliver O'Halloran --- v3: Only use the pfn seed for the default alignment if there is a pfn seed. --- ndctl/namespace.c | 96 +++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 12253a96e095..5d672810a712 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -39,7 +39,6 @@ static bool logfix; static struct parameters { bool do_scan; bool mode_default; - bool align_default; bool autolabel; const char *bus; const char *map; @@ -226,9 +225,6 @@ static int set_defaults(enum device_action mode) error("failed to parse namespace alignment '%s'\n", param.align); rc = -EINVAL; - } else if (!param.align) { - param.align = "2M"; - param.align_default = true; } if (param.uuid) { @@ -468,7 +464,7 @@ static int validate_namespace_options(struct ndctl_region *region, struct ndctl_namespace *ndns, struct parsed_parameters *p) { const char *region_name = ndctl_region_get_devname(region); - unsigned long long size_align = SZ_4K, units = 1, resource; + unsigned long long size_align, units = 1, resource; struct ndctl_pfn *pfn = NULL; struct ndctl_dax *dax = NULL; unsigned int ways; @@ -545,53 +541,15 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.align) { - p->align = parse_size64(param.align); - - if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M - && (!pfn || !ndctl_pfn_has_align(pfn))) { - /* - * Initial pfn device support in the kernel - * supported a 2M default alignment when - * ndctl_pfn_has_align() returns false. - */ - debug("%s not support 'align' for fsdax mode\n", - region_name); - return -EAGAIN; - } else if (p->mode == NDCTL_NS_MODE_DAX - && (!dax || !ndctl_dax_has_align(dax))) { - /* - * Unlike the pfn case, we require the kernel to - * have 'align' support for device-dax. - */ - debug("%s not support 'align' for devdax mode\n", - region_name); - return -EAGAIN; - } else if (!param.align_default - && (p->mode == NDCTL_NS_MODE_SAFE - || p->mode == NDCTL_NS_MODE_RAW)) { - /* - * Specifying an alignment has no effect for - * raw, or btt mode namespaces. - */ + if (p->mode != NDCTL_NS_MODE_MEMORY && + p->mode != NDCTL_NS_MODE_DAX) { error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); return -ENXIO; } - /* - * Fallback to a 4K default alignment if the region is - * not 2MB (typical default) aligned. This mainly helps - * the nfit_test use case where it is backed by vmalloc - * memory. - */ - resource = ndctl_region_get_resource(region); - if (param.align_default && resource < ULLONG_MAX - && (resource & (SZ_2M - 1))) { - debug("%s: falling back to a 4K alignment\n", - region_name); - p->align = SZ_4K; - } + p->align = parse_size64(param.align); switch (p->align) { case SZ_4K: @@ -602,16 +560,48 @@ static int validate_namespace_options(struct ndctl_region *region, error("unsupported align: %s\n", param.align); return -ENXIO; } + } else { + /* + * Use the seed namespace alignment as the default if we need + * one. If we don't then use PAGE_SIZE so the size_align + * checking works. + */ + if (p->mode == NDCTL_NS_MODE_MEMORY) { + /* + * The initial pfn device support in the kernel didn't + * have the 'align' sysfs attribute and assumed a 2MB + * alignment. Fall back to that if we don't have the + * attribute. + */ + if (pfn && ndctl_pfn_has_align(pfn)) + p->align = ndctl_pfn_get_align(pfn); + else + p->align = SZ_2M; + } else if (p->mode == NDCTL_NS_MODE_DAX) { + /* + * device dax mode was added after the align attribute + * so checking for it is unnecessary. + */ + p->align = ndctl_dax_get_align(dax); + } else { + p->align = sysconf(_SC_PAGE_SIZE); + } /* - * 'raw' and 'sector' mode namespaces don't support an - * alignment attribute. + * Fallback to a page alignment if the region is not aligned + * to the default. This is mainly useful for the nfit_test + * use case where it is backed by vmalloc memory. */ - if (p->mode == NDCTL_NS_MODE_MEMORY - || p->mode == NDCTL_NS_MODE_DAX) - size_align = p->align; + resource = ndctl_region_get_resource(region); + if (resource < ULLONG_MAX && (resource & (p->align - 1))) { + debug("%s: falling back to a page alignment\n", + region_name); + p->align = sysconf(_SC_PAGE_SIZE); + } } + size_align = p->align; + /* (re-)validate that the size satisfies the alignment */ ways = ndctl_region_get_interleave_ways(region); if (p->size % (size_align * ways)) { @@ -637,8 +627,8 @@ static int validate_namespace_options(struct ndctl_region *region, p->size *= size_align; p->size /= units; error("'--size=' must align to interleave-width: %d and alignment: %ld\n" - " did you intend --size=%lld%s?\n", ways, param.align - ? p->align : SZ_4K, p->size, suffix); + "did you intend --size=%lld%s?\n", + ways, p->align, p->size, suffix); return -EINVAL; } From patchwork Wed Jan 30 10:59:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F40D591E for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0E282E3BB for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C942E3E2; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F9022E3BB for ; Wed, 30 Jan 2019 10:59:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 88F26211BFCC5; Wed, 30 Jan 2019 02:59:47 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::642; helo=mail-pl1-x642.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7B614211BFCCE for ; Wed, 30 Jan 2019 02:59:46 -0800 (PST) Received: by mail-pl1-x642.google.com with SMTP id b5so10883253plr.4 for ; Wed, 30 Jan 2019 02:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PGMLKYyWN6m+7zcPu8D+Qb9UkgrHqlfU5cdS5j2X1o0=; b=OWaBGkvuKLqE8TKWtlp6/ilIwAaUPch89sFjZydtQXwN/Ia+TIQe9nW4dWx4Hip8CW xVMQKL+E9p4chn9CE+pbPmLJIVYRpe2E3EBQok9LytQTj9hPYqNlrs4dMlQiyJVkaKm/ LVpAHlPZ0ce7qA5L8mq9aBvK9LpWVAAEeUx8l0RlhNQVgNkBz4bhgPNGqvQ1Sp6uHIgq T+40NL3s7hwrPmKI9U1h82rYsNakkuw6QD2aEo13IFE6huimjmRaFgLxlDktqCvcCRLU CbjvUOkJ7L2VHNHILxMeFTSLg3EjsjDZp+hR3oo7ue+7Rq/UqcBntpHewSs+cuHrB93/ c77w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PGMLKYyWN6m+7zcPu8D+Qb9UkgrHqlfU5cdS5j2X1o0=; b=bB5hhrobGCSoCnLnpsvZBn1suSnbufHm6DgHrVAyLksAlRWFqDnIpunTM6qVW/0dGS ev137ShaBq3R3pwDsbkHEkT5uIllffqn2vooUQtc4j/NpPYvB+YPKlcsDaR5+JAGF8hU NajVECd+yccNPoCgaX2fcUWeOAa/vTDzJFdl0ScLgvgDdV5vgkumwacAnOVia0fIA+W2 YRjDFiA3i0wbDxjVeBNc3A1dABXiHVPdhceWJxDKPDTdDgPrpE4OEcATLUXmfcZptHjw yNZt/TuerdmgDIE3/h9CRGJ4CStVZSAThpaWFzGm+ZquKhuyQE6gwuP9xI+McPsBZaOY s5tw== X-Gm-Message-State: AJcUukfLmEcwpU/UDF0Nmw8qYdIk1sC6zcLGdrt6sCDR6Gbi+CcgTJVG I1eAufS72kjeg7hHyf/y0Bsy9GTd X-Google-Smtp-Source: ALg8bN4+AheVv5kRGbM8wvr7qAFhhsDeNKeSj9JDPAVrnH6MLNgGo+jLxJ0WCAhRWejcfMQTOTmk6A== X-Received: by 2002:a17:902:280b:: with SMTP id e11mr29919204plb.269.1548845985938; Wed, 30 Jan 2019 02:59:45 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:45 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 4/7] ndctl/namespace: Validate alignment from the {pfn|dax} seed Date: Wed, 30 Jan 2019 21:59:24 +1100 Message-Id: <20190130105927.31901-4-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support to the ndctl tool for validating that the namespace alignment is valid. Signed-off-by: Oliver O'Halloran --- v3: Fail validation if an alignment is specified, but pfn mode is not supported. --- ndctl/namespace.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 5d672810a712..25e0a87676e4 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -541,8 +541,23 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.align) { - if (p->mode != NDCTL_NS_MODE_MEMORY && - p->mode != NDCTL_NS_MODE_DAX) { + int i, alignments; + + switch (p->mode) { + case NDCTL_NS_MODE_MEMORY: + if (!pfn) { + error("Kernel does not support setting an alignment in fsdax mode\n"); + return -EINVAL; + } + + alignments = ndctl_pfn_get_num_alignments(pfn); + break; + + case NDCTL_NS_MODE_DAX: + alignments = ndctl_dax_get_num_alignments(dax); + break; + + default: error("%s mode does not support setting an alignment\n", p->mode == NDCTL_NS_MODE_SAFE ? "sector" : "raw"); @@ -550,13 +565,19 @@ static int validate_namespace_options(struct ndctl_region *region, } p->align = parse_size64(param.align); + for (i = 0; i < alignments; i++) { + uint64_t a; - switch (p->align) { - case SZ_4K: - case SZ_2M: - case SZ_1G: - break; - default: + if (p->mode == NDCTL_NS_MODE_MEMORY) + a = ndctl_pfn_get_supported_alignment(pfn, i); + else + a = ndctl_dax_get_supported_alignment(dax, i); + + if (p->align == a) + break; + } + + if (i >= alignments) { error("unsupported align: %s\n", param.align); return -ENXIO; } From patchwork Wed Jan 30 10:59:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12B911390 for ; Wed, 30 Jan 2019 10:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2EA72E3BB for ; Wed, 30 Jan 2019 10:59:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E76422E3E2; Wed, 30 Jan 2019 10:59:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A63B92E3BB for ; Wed, 30 Jan 2019 10:59:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9DFB5211BFCCE; Wed, 30 Jan 2019 02:59:49 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6F87A211BFCDB for ; Wed, 30 Jan 2019 02:59:48 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id w7so10165256pgp.13 for ; Wed, 30 Jan 2019 02:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lRsftHXqbcA8HYVYnpE+da6pldgpNEpRW/GWwqlthA4=; b=QLL3zLrBGVui20yStz2pUosX2LkCNQGOGiyot84L0wdIszRxndjbNiVLGeED6nSivq wp/eisj68s0Mhl6Mtrs0+uE+kIU26ykoyLOPeoIBjFxEXmRGsChHL1hQ9PAz5N1BuR2i CNS3FIpNCGZ9bwWGUKfCJEI8JtFbtlXwV0wApY3L8BHyDjcJoISG3imXYXUsKPJGbjMZ M09I4MQuDeZs2UEmrv5g5/7jcohSOOIlkg0ULads5NPA9l3t6yRjV4119FqAht61g4mN zKVxQ9Fs4tJrFMkt9g2cKQ9AaYvHpvuQxXQsDDSwClNtTu3nzLZkRiS9bind/BJqa5Oy 1HAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lRsftHXqbcA8HYVYnpE+da6pldgpNEpRW/GWwqlthA4=; b=gqPzO6x5cfvoluysjKrRre1gluD9HQ0JisvtJX6iF5gx/cFV1n7rpfrF3pEy+7mJsF bSAsZnPqO4HXW70bJOaXN+Yqv+NDeF5ldmaHgAGixYHYoPdn9y+i/06uB4X5Dx3PH+Qr NaAaqYYaxMeT4gm6yZDBfo8c89sfaLXz/6tueCXL75mCzgIUscEN0WengL5WpfJ3SDf9 vd8bugEY2tmkJxvaPxlwWvTfGceYCfMCQvaVUEVXynWhsEzPUVoPBAMGnAOi5EnTJpo7 ZJlYKPX6eVF/Nl8Ps2qxIhIN/WfKkt73P2F6Hw4T+Cm+bx3N97Dn4UztUy2js8LAmdMY +6hg== X-Gm-Message-State: AJcUukdlNTaRTFC3dDzmhbI5QfH2UHD2Pz4MHsFGgqQn1+LMqGB5K64/ X4Bimfk5AMfisCFPDJGQ+p5X9Ur0 X-Google-Smtp-Source: ALg8bN5SXQFV9uOkt8Qzif4m49pd0K7CX0EgFWF/9i73aAJuaRJX5jko1GIrosPc+Su3kdU/lw/Qzg== X-Received: by 2002:a63:a16:: with SMTP id 22mr27111621pgk.318.1548845987877; Wed, 30 Jan 2019 02:59:47 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:47 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 5/7] ndctl: Add alignment to the namespace JSON output Date: Wed, 30 Jan 2019 21:59:25 +1100 Message-Id: <20190130105927.31901-5-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Automated tooling probably wants to know this and it's helpful output for command line users for ndctl. Signed-off-by: Oliver O'Halloran --- util/json.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/json.c b/util/json.c index 5c3424e2a707..77c96fb53c27 100644 --- a/util/json.c +++ b/util/json.c @@ -753,6 +753,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, struct ndctl_btt *btt; struct ndctl_pfn *pfn; struct ndctl_dax *dax; + unsigned long align = 0; char buf[40]; uuid_t uuid; int numa; @@ -825,6 +826,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, util_raw_uuid_to_json(ndns, flags, jndns); bdev = ndctl_btt_get_block_device(btt); } else if (pfn) { + align = ndctl_pfn_get_align(pfn); ndctl_pfn_get_uuid(pfn, uuid); uuid_unparse(uuid, buf); jobj = json_object_new_string(buf); @@ -837,6 +839,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, struct daxctl_region *dax_region; dax_region = ndctl_dax_get_daxctl_region(dax); + align = ndctl_dax_get_align(dax); ndctl_dax_get_uuid(dax, uuid); uuid_unparse(uuid, buf); jobj = json_object_new_string(buf); @@ -897,6 +900,13 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "sector_size", jobj); } + if (align) { + jobj = json_object_new_int64(align); + if (!jobj) + goto err; + json_object_object_add(jndns, "align", jobj); + } + if (bdev && bdev[0]) { jobj = json_object_new_string(bdev); if (!jobj) From patchwork Wed Jan 30 10:59:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D43B1390 for ; Wed, 30 Jan 2019 10:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18E3C2E3BB for ; Wed, 30 Jan 2019 10:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D46E2E3E2; Wed, 30 Jan 2019 10:59:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA93B2E3BB for ; Wed, 30 Jan 2019 10:59:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B379C211BFCDE; Wed, 30 Jan 2019 02:59:51 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 35FB9211BFCC4 for ; Wed, 30 Jan 2019 02:59:50 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id q1so11247781pfi.5 for ; Wed, 30 Jan 2019 02:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K92h6Rlu4j6Xqm8dLWaxY/7XfcGWwmbRzOpyf3BlgyI=; b=MXi9Y9MrRyglpOTCDznqtjzU4N01u98BvRuBagblqUCFTHHY9WQqeWdiLytl/7Yp0M ZESxn9OcdPoDMXVyw9NcYfJSvGkeKLsHcnn+TnPQJ+DK1J67EzMnWqdfNRMTf0dgvR4A V8VVbdJWckEbEGaTrjplg7S5ZgjmfJH3qClrqRwPAHzJ2EF541YPSywYs3K8rRcVS9d8 +tXdgrlJaKqnw13uKjf3O3ofAWxldNuCXljQQ3H/QvUtbzSe6K3knYJolN4HMD8dC9wA 6qEblup7XdGeO+vTGhPy2G4emh6mrDCp5Cct+YHaKMz5SW5UmdnE1v25q+1xji0Ym/cQ 7gYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K92h6Rlu4j6Xqm8dLWaxY/7XfcGWwmbRzOpyf3BlgyI=; b=ERxYePHxCbQlvHy6aKw/oJLbj8GYEJTHTXL8i2iUrES/kSBqWYEnhj+oaiJ6wBGr4e /pXLLqN/EFJ1yHEzDb2bKh8E/tVChAn+abtbxOaQvP8RdpDaHxvEzQJY9tEtomiaj0fu Xa2hjF+IFAVJYk5z1acHnp0hK+VhtcdSZt4MzkGvrNdLl55UX+AFm85tZh2mQUwVsNF6 1iPD9U/2pFo1vDNODHKT//0lePctKU26RqHrjA9kpGxwSCdR4pUHXO3R9rYM86dtszj0 iC0AIXbVayaovohqXZO1XCaW/628WyB+4ki6ydXh39nhP5ygTnjBD6TNWXMn6wKGlqG7 SymQ== X-Gm-Message-State: AJcUukeDKn+wpNUtTieD5yWo3aiAbU2sn8eiuVe7LfQ3kOcRTx0JL3/k XiTp6+J1jie+UULoSrUJBx2voCDC X-Google-Smtp-Source: ALg8bN43yQznWXbIhUL6gZ3XTgDOwlH0hdIGtSZSlvpajFxSU/KlnZ47mdrSL5iR9Jmjhm900xpcXw== X-Received: by 2002:a62:61c3:: with SMTP id v186mr30302435pfb.55.1548845989775; Wed, 30 Jan 2019 02:59:49 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:49 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 6/7] ndctl/namespace: Make the create-region JSON output non-verbose Date: Wed, 30 Jan 2019 21:59:26 +1100 Message-Id: <20190130105927.31901-6-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The ndctl unit tests parse the output of the create-region commands using a pile of regexs which makes adding new fields to create-namespace output blob a somewhat fraught activity. By moving the existing "verbose" fields into the normal output we keep the unit tests happy and allow ourselves to add more fields in the future. This patch also makes the 'sector_size' field non-verbose since the BTT unit tests require it. Signed-off-by: Oliver O'Halloran --- Ccurrently `ndctl list` has the -v flag to make the output more verbose, however every other ndctl command uses -v as a switch to enable debug output. We probably don't want to change the CLI much, but considering debug output requires running configure with --enable-debug it might be a good idea to change it to -d or something and free up the switch for actual verbosity. --- --- ndctl/namespace.c | 2 +- util/json.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 25e0a87676e4..03d805a69ce4 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -424,7 +424,7 @@ static int setup_namespace(struct ndctl_region *region, error("%s: failed to enable\n", ndctl_namespace_get_devname(ndns)); } else { - unsigned long flags = UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS | UTIL_JSON_VERBOSE; + unsigned long flags = UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS; struct json_object *jndns; if (isatty(1)) diff --git a/util/json.c b/util/json.c index 77c96fb53c27..eee459aa453b 100644 --- a/util/json.c +++ b/util/json.c @@ -893,7 +893,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, * happens because they use pre-v1.2 labels or because they * don't have a label space (devtype=nd_namespace_io). */ - if (sector_size < UINT_MAX && flags & UTIL_JSON_VERBOSE) { + if (sector_size < UINT_MAX) { jobj = json_object_new_int(sector_size); if (!jobj) goto err; From patchwork Wed Jan 30 10:59:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 10788275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 571EF91E for ; Wed, 30 Jan 2019 10:59:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4367A2E3BB for ; Wed, 30 Jan 2019 10:59:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37C632E3E2; Wed, 30 Jan 2019 10:59:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D2CED2E3BB for ; Wed, 30 Jan 2019 10:59:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CC330211BFCD8; Wed, 30 Jan 2019 02:59:53 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=oohall@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 45B0F211BFCC4 for ; Wed, 30 Jan 2019 02:59:52 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id w4so10918850plz.1 for ; Wed, 30 Jan 2019 02:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hgYSp06gS3OYi4WkqbXzqBZa7pW4nqWkeso0oY1Vzns=; b=t72zsm/60qUhVCRzN4RQjYN5ZHRIhK1oxrcOrQaLcr6Dkn/hFID1sAbZXQXdDIe6uh kndUdekF0TbbuDggGC7EnOWbgOyR7zBKI/x/7It6buNlmOTsBrvytHrkIrJnKkepeZA/ BJMMxy8oDN0VdI9nrEPnv4EoYtG0l2jzUUgKYmiirONwF9xxt3/dKpXDtcA6d6FPMTwO eF23bcoV1bELX7OVaW9GXIHJj6k6NbUo80q0C6nHJelasFBMHzFTeEMQAzdMUp9yJSft 1/y52koXwGSXgvSMM18jXf4Ibx6yEfbPvHeyJjS0tJ1YarcGPCdqa6Ro4ZX45o7pDpAL orQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hgYSp06gS3OYi4WkqbXzqBZa7pW4nqWkeso0oY1Vzns=; b=txHOBGRLeQPWBtAhvGcvSDC4Ih7DRl695+8xVtxh3S/MBA92+05cighUOo3N9jlJOX qkp6NQ/F+rJxgBHJZJ86CxuKmbUaHvzaSoLZfK1OqtZlMmwDIw+EjAyA0FmQ1ibhcDnh sQ8zP9nk0oLkMEhZMKvzP0OG9VRBZ9z1DjZa6koQG/4NGDAwOyd1T5FZNjK5BkvexZZ4 ljFbcTLYwYWOehyhhDqJGrTr68H7zA/mp0eDXbTz0FB/D/bPgtDXSkeG3Bmh+8nNcT6w JKrSDHpOsfhp+HDe1/gnRVDo+6wAXZsn45tUxRxfLWtwU4h86SBhRTHLF+HRQ5t9bfUt Wbtg== X-Gm-Message-State: AJcUukcPCC8/4RJK6lamM9SeVnvvZsiI3qyHDt3bveW41s8RxAv2zmRs FllPRUKEGm9F9cXy1D4zdH/j26H6 X-Google-Smtp-Source: ALg8bN6PiYBhOMBXBlhEnnOB9kkVl8gJskzFPeGUtGq1HtH2tHTp482uLl2Cjg3jGMOx2vC2P8cM0Q== X-Received: by 2002:a17:902:59c8:: with SMTP id d8mr29936713plj.116.1548845991760; Wed, 30 Jan 2019 02:59:51 -0800 (PST) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id r1sm3547452pgo.17.2019.01.30.02.59.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Jan 2019 02:59:51 -0800 (PST) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH v5 7/7] ndctl: Add supported_alignments to the JSON output Date: Wed, 30 Jan 2019 21:59:27 +1100 Message-Id: <20190130105927.31901-7-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130105927.31901-1-oohall@gmail.com> References: <20190130105927.31901-1-oohall@gmail.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add the list of supported alignemnts to PFN and DAX namespaces. Also add the list of supported sector sizes to BTT namespaces. Signed-off-by: Oliver O'Halloran --- v5: Added again. The supported_size array is now only included in the verbose JSON output. This means it won't be included in the JSON output from setup_namespace() so to see the list of supported alignments you need to use `ndctl list -v`. v4: Dropped due to unit test breakage. v3: Added Not sure the namespace JSON blob are the best place to put these. The region might be better, but slightly less accessable to users. --- util/json.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/util/json.c b/util/json.c index eee459aa453b..dd77b41e114c 100644 --- a/util/json.c +++ b/util/json.c @@ -303,6 +303,38 @@ struct json_object *util_daxctl_devs_to_list(struct daxctl_region *region, return jdevs; } +#define _SZ(get_max, get_elem, type) \ +static struct json_object *type##_build_size_array(struct type *arg) \ +{ \ + struct json_object *arr = json_object_new_array(); \ + int i; \ + \ + if (!arr) \ + return NULL; \ + \ + for (i = 0; i < get_max(arg); i++) { \ + struct json_object *jobj; \ + int64_t align; \ + \ + align = get_elem(arg, i); \ + jobj = json_object_new_int64(align); \ + if (!jobj) \ + goto err; \ + json_object_array_add(arr, jobj); \ + } \ + \ + return arr; \ +err: \ + json_object_put(arr); \ + return NULL; \ +} +#define SZ(type, kind) _SZ(ndctl_##type##_get_num_##kind##s, \ + ndctl_##type##_get_supported_##kind, ndctl_##type) +SZ(pfn, alignment) +SZ(dax, alignment) +SZ(btt, sector_size) +//SZ(namespace, sector_size) + struct json_object *util_daxctl_region_to_json(struct daxctl_region *region, const char *ident, unsigned long flags) { @@ -739,7 +771,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, { struct json_object *jndns = json_object_new_object(); enum ndctl_pfn_loc loc = NDCTL_PFN_LOC_NONE; - struct json_object *jobj, *jbbs = NULL; + struct json_object *jobj, *jbbs = NULL, *size_array = NULL; const char *locations[] = { [NDCTL_PFN_LOC_NONE] = "none", [NDCTL_PFN_LOC_RAM] = "mem", @@ -749,6 +781,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, unsigned int sector_size = UINT_MAX; enum ndctl_namespace_mode mode; const char *bdev = NULL, *name; + const char *size_array_name; unsigned int bb_count = 0; struct ndctl_btt *btt; struct ndctl_pfn *pfn; @@ -936,6 +969,19 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns, json_object_object_add(jndns, "numa_node", jobj); } + if (pfn) { + size_array_name = "supported_alignments"; + size_array = ndctl_pfn_build_size_array(pfn); + } else if (dax) { + size_array_name = "supported_alignments"; + size_array = ndctl_dax_build_size_array(dax); + } else if (btt) { + size_array_name = "supported sector sizes"; + size_array = ndctl_btt_build_size_array(btt); + } + if (size_array && flags & UTIL_JSON_VERBOSE) + json_object_object_add(jndns, size_array_name, size_array); + if (pfn) jbbs = util_pfn_badblocks_to_json(pfn, &bb_count, flags); else if (dax)