From patchwork Tue Jun 27 08:15:30 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: 9811043 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 DB82960329 for ; Tue, 27 Jun 2017 08:15:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D206828515 for ; Tue, 27 Jun 2017 08:15:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6B49285B5; Tue, 27 Jun 2017 08:15:59 +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 6BEA328515 for ; Tue, 27 Jun 2017 08:15:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 101CF21C943E7; Tue, 27 Jun 2017 01:14:29 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (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 47D8121A143C1 for ; Tue, 27 Jun 2017 01:14:28 -0700 (PDT) Received: by mail-pf0-x242.google.com with SMTP id z6so3753068pfk.3 for ; Tue, 27 Jun 2017 01:15:58 -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=6LsQT258D5Upzz5BREaIRorQo0BM2+wuJRoW/k9Dg/E=; b=T4j2w48+mqTnPJgrxCj7srAYiFOnYpAxt4ocF4t2VzSZkAoW2g1Zc/GGfMquPL10vF MzQZt4XrwMBPhl950GEKj2dzpsCJ+P2C1yBo92uVWG3F1nxBTbNE1f86+YtUwopRUwZD xTiN/Lwqu4MrK753pCrc00pcn0MIb3mKulcErMNzEcqSQeDkBKuTquyJYwMuR/rbYZt1 PPk0DFpsXYXDyEzKxr3iZ4zpLx0TqvXV1WCt7hWxvL74nzRvb5dP3xflYB0LSzDVbLrF x3Lnq6wDFp0PlcnP2IiTlb/COX9TyHN/3LTNKRBfMwh0qZjyVkjEJx/PuVhbuCa0pS3a M1xQ== 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=6LsQT258D5Upzz5BREaIRorQo0BM2+wuJRoW/k9Dg/E=; b=gCbH8RRHN+96Pf0Z52Jc6q3x19GQC61kjIOnMQqepsTPMSOzMb1DRI94PAike0j8dK YWwwknyMrCXav/MCGCY1wsqoeKyDqw8Ah2eWcHoTiASdhEUckQqdgMVjqnhABpa6+/fs gdlN8mXBIe3PHmjc5dx7xBv7zb0BHcyoY0HDUAE0FbS1hlJllpQnkx3q3FT8LUUkEiv1 YSEbXoEAc4BIomSN6OHO+zzZsXnSWTsAjWU6OODRylKaBI0ZFhV0NS9QUD2idNWyxeuT qugx8BClmvf2gwdCelCDSc+lo+5qw1ZLRALygogTILJ+hPRLAGRZDMd7sV458mzViLqR OMZw== X-Gm-Message-State: AKS2vOxgC3VUB6SBiTuaGiA6YR1TGpyPaWjA3m/h12xhtK/C2tf3P+jl an5L2oYp9yaT7inu X-Received: by 10.84.224.11 with SMTP id r11mr4523853plj.267.1498551358146; Tue, 27 Jun 2017 01:15:58 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id k129sm4875850pfc.87.2017.06.27.01.15.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 01:15:57 -0700 (PDT) From: Oliver O'Halloran To: linux-nvdimm@lists.01.org Subject: [PATCH 3/4] libndctl: Add helpers to check supported sector sizes Date: Tue, 27 Jun 2017 18:15:30 +1000 Message-Id: <20170627081531.7389-3-oohall@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170627081531.7389-1-oohall@gmail.com> References: <20170627081531.7389-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 libndctl now has the ndctl_{dax|pfn}_supports_align() helper functions for checking if PFN and DAX regions support a given alignment. The sector size of a BTT region is similar to the region alignment so add an equivilent helper to maintain a consistent API across region types. Adds: ndctl_namespace_supports_sector_size() ndctl_btt_supports_sector_size() Signed-off-by: Oliver O'Halloran --- ndctl/lib/libndctl.c | 12 ++++++++++++ ndctl/lib/libndctl.sym | 2 ++ ndctl/libndctl.h.in | 3 +++ ndctl/namespace.c | 30 ++++++++++++------------------ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index d21d372891a4..9668d8c5d34e 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -3586,6 +3586,12 @@ NDCTL_EXPORT int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *nd return ndns->lbasize.num; } +NDCTL_EXPORT int ndctl_namespace_supports_sector_size( + struct ndctl_namespace *ndns, unsigned long size) +{ + return sizes_contains(&ndns->lbasize, size); +} + NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns, unsigned int sector_size) { @@ -3912,6 +3918,12 @@ NDCTL_EXPORT int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt) return btt->lbasize.num; } +NDCTL_EXPORT int ndctl_btt_supports_sector_size( + struct ndctl_btt *btt, unsigned long size) +{ + return sizes_contains(&btt->lbasize, size); +} + NDCTL_EXPORT struct ndctl_namespace *ndctl_btt_get_namespace(struct ndctl_btt *btt) { struct ndctl_ctx *ctx = ndctl_btt_get_ctx(btt); diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 547d1bf133c6..4039f7311222 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -192,6 +192,7 @@ global: ndctl_namespace_get_sector_size; ndctl_namespace_get_num_sector_sizes; ndctl_namespace_set_sector_size; + ndctl_namespace_supports_sector_size; ndctl_namespace_get_raw_mode; ndctl_namespace_set_raw_mode; ndctl_namespace_get_numa_node; @@ -204,6 +205,7 @@ global: ndctl_btt_get_supported_sector_size; ndctl_btt_get_sector_size; ndctl_btt_get_num_sector_sizes; + ndctl_btt_supports_sector_size; ndctl_btt_get_namespace; ndctl_btt_get_uuid; ndctl_btt_get_size; diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in index 1d0924999b03..feefb9653c88 100644 --- a/ndctl/libndctl.h.in +++ b/ndctl/libndctl.h.in @@ -513,6 +513,8 @@ int ndctl_namespace_set_size(struct ndctl_namespace *ndns, unsigned long long size); unsigned int ndctl_namespace_get_supported_sector_size( struct ndctl_namespace *ndns, int i); +int ndctl_namespace_supports_sector_size( + struct ndctl_namespace *ndns, unsigned long size); unsigned int ndctl_namespace_get_sector_size(struct ndctl_namespace *ndns); int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *ndns); int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns, @@ -538,6 +540,7 @@ struct ndctl_ctx *ndctl_btt_get_ctx(struct ndctl_btt *btt); struct ndctl_bus *ndctl_btt_get_bus(struct ndctl_btt *btt); struct ndctl_region *ndctl_btt_get_region(struct ndctl_btt *btt); unsigned int ndctl_btt_get_id(struct ndctl_btt *btt); +int ndctl_btt_supports_sector_size(struct ndctl_btt *btt, unsigned long size); unsigned int ndctl_btt_get_supported_sector_size(struct ndctl_btt *btt, int i); unsigned int ndctl_btt_get_sector_size(struct ndctl_btt *btt); int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt); diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 895e39bb8c7d..0f402e8790a6 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -570,25 +570,21 @@ static int validate_namespace_options(struct ndctl_region *region, } if (param.sector_size) { - struct ndctl_btt *btt; - int num, i; + unsigned long long size = parse_size64(param.sector_size); - p->sector_size = parse_size64(param.sector_size); - btt = ndctl_region_get_btt_seed(region); if (p->mode == NDCTL_NS_MODE_SAFE) { + struct ndctl_btt *btt = + ndctl_region_get_btt_seed(region); + if (!btt) { debug("%s: does not support 'sector' mode\n", region_name); return -EINVAL; } - num = ndctl_btt_get_num_sector_sizes(btt); - for (i = 0; i < num; i++) - if (ndctl_btt_get_supported_sector_size(btt, i) - == p->sector_size) - break; - if (i >= num) { + + if (!ndctl_btt_supports_sector_size(btt, size)) { debug("%s: does not support btt sector_size %lu\n", - region_name, p->sector_size); + region_name, size); return -EINVAL; } } else { @@ -596,17 +592,15 @@ static int validate_namespace_options(struct ndctl_region *region, if (!seed) seed = ndctl_region_get_namespace_seed(region); - num = ndctl_namespace_get_num_sector_sizes(seed); - for (i = 0; i < num; i++) - if (ndctl_namespace_get_supported_sector_size(seed, i) - == p->sector_size) - break; - if (i >= num) { + + if (!ndctl_namespace_supports_sector_size(seed, size)) { debug("%s: does not support namespace sector_size %lu\n", - region_name, p->sector_size); + region_name, size); return -EINVAL; } } + + p->sector_size = size; } else if (ndns) { struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);