From patchwork Fri Apr 21 07:12:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 9691967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B7C3460328 for ; Fri, 21 Apr 2017 07:12:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A79E528602 for ; Fri, 21 Apr 2017 07:12:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 993D428606; Fri, 21 Apr 2017 07:12:44 +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=-1.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=no 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 2106628602 for ; Fri, 21 Apr 2017 07:12:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 182E72195407E; Fri, 21 Apr 2017 00:12:44 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-oi0-x244.google.com (mail-oi0-x244.google.com [IPv6:2607:f8b0:4003:c06::244]) (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 645492195406F for ; Fri, 21 Apr 2017 00:12:43 -0700 (PDT) Received: by mail-oi0-x244.google.com with SMTP id m34so8478954oik.2 for ; Fri, 21 Apr 2017 00:12:43 -0700 (PDT) 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; bh=ACQQSSbdbRaKft/0HD1/+AEsvcyM3/nTuPje7ErA150=; b=cLqPCoMpUUYiEHS+6sIO1Pu61spE3FY8j4nBKUBwasd3dGdpZrcyJS3XuKqFh/IIOw 4oYfb5xlc4CjuvMwtbbihUnphMijakzHhldRRgQHej7RtwR97iN3GaKyYgidGUVCJ30R HMJBUoOuVkH28b7jL0Nij2ape8Enh2A1enIz3vzPXMIj0lnBks29AkXcf+eTThQ+j71n 1EREiPb/C3xrN0ELkOwNqE5YpEHibaKlDcTCrM3UspIBK607ZrqhAPJlDYJIAsVpSUv5 0LycWQIzQJv5+VxEmFX5UFgfcZPv8bCMugPWoBpWv8msGgSK/QaWb7nC+YgkXXaMiC7T M9bg== 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; bh=ACQQSSbdbRaKft/0HD1/+AEsvcyM3/nTuPje7ErA150=; b=QnOKChIXVpysvBBpi5J8sG8BJ7FM33TcY9LeikjqYem8/0gGQrNBXMvKYOH99KFZnm 2dOedCM7PImxz6qyqroZWcYc9G51FeuIAXKHYsRNzR20ayDH1+/cCCjqUMTRxOlYkX9b 1PKIbeaHF0qE6K1hXTTub8K0b/4tBwNY7FWf1x9IM2xe1/1z4gTFRRcT3hVnAdOOEAwh dROl7ii5M1P9RviJUOqd0rNUmA6bf08ogeMmJwGAxltvz5C5eevxhvbj1/ZbHZZDrsmN Y8f2qz+C7MlYB9rYvChKaxOf91oAFyBx9+5RbD3+vKehCSVwu2mYmhBRsGS8mUZ8n8/n 9smw== X-Gm-Message-State: AN3rC/75qpO02sgV/iftZsWjGR19adVUE6JrbbrdQh1LmjQGjV0TcV91 hEymL1Rrg1zC7Q== X-Received: by 10.84.222.140 with SMTP id x12mr14400598pls.36.1492758762368; Fri, 21 Apr 2017 00:12:42 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y78sm14082658pff.107.2017.04.21.00.12.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2017 00:12:41 -0700 (PDT) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 2/3] ndctl, create-namespace: read default alignment from sysfs Date: Fri, 21 Apr 2017 17:12:18 +1000 Message-Id: <20170421071219.18744-2-oohall@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170421071219.18744-1-oohall@gmail.com> References: <20170421071219.18744-1-oohall@gmail.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Read the default alignment from the hpage_pmd_size in sysfs. On PPC the PMD size depends on the MMU being used. When the traditional hash MMU is used (P9 and earlier) the PMD size is 16MB while the newer radix MMU uses a 2MB PMD size. The choice of MMU is done at runtime depending on what the hardware supports so we need to detect this at runtime rather than hardcoding it. Signed-off-by: Oliver O'Halloran --- ndctl/Makefile.am | 3 ++- ndctl/builtin-xaction-namespace.c | 41 +++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ndctl/Makefile.am b/ndctl/Makefile.am index c563e9411cc3..6d565c643efd 100644 --- a/ndctl/Makefile.am +++ b/ndctl/Makefile.am @@ -10,7 +10,8 @@ ndctl_SOURCES = ndctl.c \ ../util/log.c \ builtin-list.c \ builtin-test.c \ - ../util/json.c + ../util/json.c \ + ../util/sysfs.c if ENABLE_SMART ndctl_SOURCES += util/json-smart.c diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c index d6c38dc15984..713a95987d91 100644 --- a/ndctl/builtin-xaction-namespace.c +++ b/ndctl/builtin-xaction-namespace.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,8 @@ static struct parameters { const char *align; } param; +char default_align_buf[SYSFS_ATTR_SIZE]; + void builtin_xaction_namespace_reset(void) { /* @@ -137,7 +140,24 @@ enum namespace_action { ACTION_DESTROY, }; -static int set_defaults(enum namespace_action mode) +const char *sysfs_read_default_align(struct ndctl_ctx *ctx, const char *def, + const char *path) +{ + /* + * HACK: The command handlers aren't supposed to write into + * the ndctl command context, but we want the debug + * output to go somewhere sensible. + */ + if (__sysfs_read_attr((struct log_ctx *)ctx, path, default_align_buf)) + return strdup(def); + + if (!strlen(default_align_buf)) + return def; + + return default_align_buf; +} + +static int set_defaults(enum namespace_action mode, struct ndctl_ctx *ctx) { int rc = 0; @@ -213,7 +233,8 @@ static int set_defaults(enum namespace_action mode) param.align); rc = -EINVAL; } else if (!param.align) { - param.align = "2M"; + param.align = sysfs_read_default_align(ctx, "2M", + "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"); param.align_default = true; } @@ -254,7 +275,7 @@ static int set_defaults(enum namespace_action mode) */ static const char *parse_namespace_options(int argc, const char **argv, enum namespace_action mode, const struct option *options, - char *xable_usage) + char *xable_usage, struct ndctl_ctx *ctx) { const char * const u[] = { xable_usage, @@ -265,7 +286,7 @@ static const char *parse_namespace_options(int argc, const char **argv, param.do_scan = argc == 1; argc = parse_options(argc, argv, options, u, 0); - rc = set_defaults(mode); + rc = set_defaults(mode, ctx); if (argc == 0 && mode != ACTION_CREATE) { error("specify a namespace to %s, or \"all\"\n", @@ -397,7 +418,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, units = 1; + unsigned long long size_align = 1, units = 1; unsigned int ways; int rc = 0; @@ -900,7 +921,7 @@ int cmd_disable_namespace(int argc, const char **argv, void *ctx) { char *xable_usage = "ndctl disable-namespace []"; const char *namespace = parse_namespace_options(argc, argv, - ACTION_DISABLE, base_options, xable_usage); + ACTION_DISABLE, base_options, xable_usage, ctx); int disabled = do_xaction_namespace(namespace, ACTION_DISABLE, ctx); if (disabled < 0) { @@ -921,7 +942,7 @@ int cmd_enable_namespace(int argc, const char **argv, void *ctx) { char *xable_usage = "ndctl enable-namespace []"; const char *namespace = parse_namespace_options(argc, argv, - ACTION_ENABLE, base_options, xable_usage); + ACTION_ENABLE, base_options, xable_usage, ctx); int enabled = do_xaction_namespace(namespace, ACTION_ENABLE, ctx); if (enabled < 0) { @@ -942,7 +963,7 @@ int cmd_create_namespace(int argc, const char **argv, void *ctx) { char *xable_usage = "ndctl create-namespace []"; const char *namespace = parse_namespace_options(argc, argv, - ACTION_CREATE, create_options, xable_usage); + ACTION_CREATE, create_options, xable_usage, ctx); int created = do_xaction_namespace(namespace, ACTION_CREATE, ctx); if (created < 1 && param.do_scan) { @@ -952,7 +973,7 @@ int cmd_create_namespace(int argc, const char **argv, void *ctx) */ memset(¶m, 0, sizeof(param)); param.type = "blk"; - set_defaults(ACTION_CREATE); + set_defaults(ACTION_CREATE, ctx); created = do_xaction_namespace(NULL, ACTION_CREATE, ctx); } @@ -981,7 +1002,7 @@ int cmd_destroy_namespace(int argc , const char **argv, void *ctx) { char *xable_usage = "ndctl destroy-namespace []"; const char *namespace = parse_namespace_options(argc, argv, - ACTION_DESTROY, destroy_options, xable_usage); + ACTION_DESTROY, destroy_options, xable_usage, ctx); int destroyed = do_xaction_namespace(namespace, ACTION_DESTROY, ctx); if (destroyed < 0) {