From patchwork Tue Jun 26 17:00:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10489583 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 DA7A1602D8 for ; Tue, 26 Jun 2018 17:00:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C0042871C for ; Tue, 26 Jun 2018 17:00:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A58B28717; Tue, 26 Jun 2018 17:00:09 +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.9 required=2.0 tests=BAYES_00, 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 1DDEE286F8 for ; Tue, 26 Jun 2018 17:00:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A6ECD211F889A; Tue, 26 Jun 2018 10:00:04 -0700 (PDT) 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=134.134.136.24; helo=mga09.intel.com; envelope-from=keith.busch@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 4ADCA211F8878 for ; Tue, 26 Jun 2018 10:00:02 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 09:59:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,275,1526367600"; d="scan'208";a="62359107" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.44]) by orsmga003.jf.intel.com with ESMTP; 26 Jun 2018 09:59:18 -0700 From: Keith Busch To: linux-nvdimm@lists.01.org, Dan Williams , Dave Jiang , Ross Zwisler , Vishal Verma Subject: [ndctl PATCHv2] ndctl: Use max_available_extent for namespaces Date: Tue, 26 Jun 2018 11:00:27 -0600 Message-Id: <20180626170027.6942-1-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yasunori Goto MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created. If this is used on a kernel that predates the new attribute, ndctl will fall back to the previous behavior using available_size. While that may still fail, it is more likely to succeed than returning a hard-coded value. Signed-off-by: Keith Busch --- v1 -> v2: Appropriate subject-prefex for ndctl. Added the fallback to the previous behavior if the attribute is not found, and noted this behavior in the changelog. ndctl/lib/libndctl.c | 31 +++++++++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 1 + ndctl/libndctl.h | 2 ++ ndctl/namespace.c | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 47e005e..8ff1fa6 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -2025,6 +2025,37 @@ NDCTL_EXPORT unsigned long long ndctl_region_get_available_size( return strtoull(buf, NULL, 0); } +NDCTL_EXPORT unsigned long long ndctl_region_get_max_available_extent( + struct ndctl_region *region) +{ + unsigned int nstype = ndctl_region_get_nstype(region); + struct ndctl_ctx *ctx = ndctl_region_get_ctx(region); + char *path = region->region_buf; + int len = region->buf_len; + char buf[SYSFS_ATTR_SIZE]; + + switch (nstype) { + case ND_DEVICE_NAMESPACE_PMEM: + case ND_DEVICE_NAMESPACE_BLK: + break; + default: + return 0; + } + + if (snprintf(path, len, + "%s/max_available_extent", region->region_path) >= len) { + err(ctx, "%s: buffer too small!\n", + ndctl_region_get_devname(region)); + return ULLONG_MAX; + } + + /* fall back to legacy behavior if max extents is not exported */ + if (sysfs_read_attr(ctx, path, buf) < 0) + return ndctl_region_get_available_size(region); + + return strtoull(buf, NULL, 0); +} + NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct ndctl_region *region) { return region->range_index; diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index c1228e5..22fd026 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -123,6 +123,7 @@ global: ndctl_region_get_mappings; ndctl_region_get_size; ndctl_region_get_available_size; + ndctl_region_get_max_available_extent; ndctl_region_get_type; ndctl_region_get_namespace_seed; ndctl_region_get_btt_seed; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index be997ac..624115d 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -338,6 +338,8 @@ unsigned int ndctl_region_get_interleave_ways(struct ndctl_region *region); unsigned int ndctl_region_get_mappings(struct ndctl_region *region); unsigned long long ndctl_region_get_size(struct ndctl_region *region); unsigned long long ndctl_region_get_available_size(struct ndctl_region *region); +unsigned long long ndctl_region_get_max_available_extent( + struct ndctl_region *region); unsigned int ndctl_region_get_range_index(struct ndctl_region *region); unsigned int ndctl_region_get_type(struct ndctl_region *region); struct ndctl_namespace *ndctl_region_get_namespace_seed( diff --git a/ndctl/namespace.c b/ndctl/namespace.c index fe86d82..4a562a2 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -764,7 +764,7 @@ static int namespace_create(struct ndctl_region *region) return -EAGAIN; } - available = ndctl_region_get_available_size(region); + available = ndctl_region_get_max_available_extent(region); if (!available || p.size > available) { debug("%s: insufficient capacity size: %llx avail: %llx\n", devname, p.size, available);