From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D7BBC64E7A for ; Tue, 1 Dec 2020 17:18:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00E9720757 for ; Tue, 1 Dec 2020 17:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729721AbgLARSm (ORCPT ); Tue, 1 Dec 2020 12:18:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:53736 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgLARSl (ORCPT ); Tue, 1 Dec 2020 12:18:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AE518AF06; Tue, 1 Dec 2020 17:18:00 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id A511ADA6E1; Tue, 1 Dec 2020 18:16:28 +0100 (CET) Date: Tue, 1 Dec 2020 18:16:28 +0100 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH] btrfs-progs: mkfs: refactor how we handle sectorsize override Message-ID: <20201201171628.GN6430@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org References: <20201013010602.11605-1-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201013010602.11605-1-wqu@suse.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Tue, Oct 13, 2020 at 09:06:02AM +0800, Qu Wenruo wrote: > There are several problems for current sectorsize check: > - No check at all for sectorsize > This means you can even specify "-s 62k". > > - No way to specify sectorsize smaller than page size > > Fix all these problems by: > - Introduce btrfs_check_sectorsize() > To do: > * power of 2 check for sectorsize > * lower and upper boundary check for sectorsize > * warn about sectorsize mismatch with page size > > - Remove the max() between page size and sectorsize > This allows us to override the sectorsize for 64K page systems. > > - Make nodesize calculation based on sectorsize > No need to use page size any more. > Users who specify sectorsize manually really know what they are doing, > and we have warned them already. > > Signed-off-by: Qu Wenruo Added to devel, thanks. > +int btrfs_check_sectorsize(u32 sectorsize) > +{ > + u32 page_size = (u32)sysconf(_SC_PAGESIZE); > + > + if (!is_power_of_2(sectorsize)) { > + error("illegal sectorsize %u, expect value power of 2", > + sectorsize); > + return -EUCLEAN; This should be EINVAL, updated > + } > + if (sectorsize < SZ_4K || sectorsize > SZ_64K) { > + error("illegal sectorsize %u, expect range [4K, 64K]", > + sectorsize); > + return -EUCLEAN; > + } > + if (page_size != sectorsize) > + warning( > +"the fs may not be mountable, sectorsize %u doesn't match page size %u", > + sectorsize, page_size); > + return 0; > +}