From patchwork Wed Jul 26 19:56:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9865765 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 DDEBF602B1 for ; Wed, 26 Jul 2017 20:02:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D00E1287AC for ; Wed, 26 Jul 2017 20:02:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4C78287BA; Wed, 26 Jul 2017 20:02:29 +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.9 required=2.0 tests=BAYES_00, 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 60F1F287AC for ; Wed, 26 Jul 2017 20:02:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B894B21D0FDEF; Wed, 26 Jul 2017 13:00:25 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 A2E1B21D09186 for ; Wed, 26 Jul 2017 13:00:24 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2017 13:02:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,416,1496127600"; d="scan'208"; a="1155718080" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga001.jf.intel.com with ESMTP; 26 Jul 2017 13:02:27 -0700 Subject: [ndctl PATCH] ndctl, create-namespace: fix size alignment validation From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 26 Jul 2017 12:56:02 -0700 Message-ID: <150109896285.13943.15686058156974485950.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 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: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Linda reports: I was creating a namespace on a 4-way interleave set and got an error I didn't expect: $ sudo ndctl create-namespace -m sector -s 10G -n number2 Error: '--size=' must align to interleave-width: 4 and alignment: 2097152 did you intend --size=12G? What's happening is that since I specified my size in units of G, the function wants the namespace to be 1G * 4 aligned rather than 2M * 4 aligned. Fix this by using the base "align * interleave_ways" for the alignment check, and later calculate a 'friendly' recommended size value that takes into account the units specified for --size. Reported-by: Linda Knippers Signed-off-by: Dan Williams --- ndctl/namespace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 73a422633a0f..c4d70c39c6c4 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -557,8 +557,7 @@ static int validate_namespace_options(struct ndctl_region *region, /* (re-)validate that the size satisfies the alignment */ ways = ndctl_region_get_interleave_ways(region); - size_align = max(units, size_align) * ways; - if (p->size % size_align) { + if (p->size % (size_align * ways)) { char *suffix = ""; if (units == SZ_1K) @@ -570,6 +569,12 @@ static int validate_namespace_options(struct ndctl_region *region, else if (units == SZ_1T) suffix = "T"; + /* + * Make the recommendation in the units of the '--size' + * option + */ + size_align = max(units, size_align) * ways; + p->size /= size_align; p->size++; p->size *= size_align;