From patchwork Tue Jul 31 02:57:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 10549819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E16313B8 for ; Tue, 31 Jul 2018 02:57:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10F3A29CDD for ; Tue, 31 Jul 2018 02:57:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 023742A191; Tue, 31 Jul 2018 02:57:39 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 586D3298A5 for ; Tue, 31 Jul 2018 02:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725891AbeGaEfi (ORCPT ); Tue, 31 Jul 2018 00:35:38 -0400 Received: from sandeen.net ([63.231.237.45]:48988 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbeGaEfi (ORCPT ); Tue, 31 Jul 2018 00:35:38 -0400 Received: from [10.0.0.4] (liberator [10.0.0.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id EC37F98; Mon, 30 Jul 2018 21:57:36 -0500 (CDT) Subject: [PATCH 2/1] mkfs: factor stripe geom validator & use for cli + device To: Jeff Mahoney , "linux-xfs@vger.kernel.org" , Dave Chinner References: <6f62dbc6-f516-e8b5-1f08-6be227a61219@suse.com> From: Eric Sandeen Openpgp: preference=signencrypt Autocrypt: addr=sandeen@sandeen.net; prefer-encrypt=mutual; keydata= xsFNBE6x99QBEADMR+yNFBc1Y5avoUhzI/sdR9ANwznsNpiCtZlaO4pIWvqQJCjBzp96cpCs nQZV32nqJBYnDpBDITBqTa/EF+IrHx8gKq8TaSBLHUq2ju2gJJLfBoL7V3807PQcI18YzkF+ WL05ODFQ2cemDhx5uLghHEeOxuGj+1AI+kh/FCzMedHc6k87Yu2ZuaWF+Gh1W2ix6hikRJmQ vj5BEeAx7xKkyBhzdbNIbbjV/iGi9b26B/dNcyd5w2My2gxMtxaiP7q5b6GM2rsQklHP8FtW ZiYO7jsg/qIppR1C6Zr5jK1GQlMUIclYFeBbKggJ9mSwXJH7MIftilGQ8KDvNuV5AbkronGC sEEHj2khs7GfVv4pmUUHf1MRIvV0x3WJkpmhuZaYg8AdJlyGKgp+TQ7B+wCjNTdVqMI1vDk2 BS6Rg851ay7AypbCPx2w4d8jIkQEgNjACHVDU89PNKAjScK1aTnW+HNUqg9BliCvuX5g4z2j gJBs57loTWAGe2Ve3cMy3VoQ40Wt3yKK0Eno8jfgzgb48wyycINZgnseMRhxc2c8hd51tftK LKhPj4c7uqjnBjrgOVaVBupGUmvLiePlnW56zJZ51BR5igWnILeOJ1ZIcf7KsaHyE6B1mG+X dmYtjDhjf3NAcoBWJuj8euxMB6TcQN2MrSXy5wSKaw40evooGwARAQABzSVFcmljIFIuIFNh bmRlZW4gPHNhbmRlZW5Ac2FuZGVlbi5uZXQ+wsF7BBMBAgAlAhsDBgsJCAcDAgYVCAIJCgsE FgIDAQIeAQIXgAUCUzMzbAIZAQAKCRAgrhaS4T3e4Fr7D/wO+fenqVvHjq21SCjDCrt8HdVj aJ28B1SqSU2toxyg5I160GllAxEHpLFGdbFAhQfBtnmlY9eMjwmJb0sCIrkrB6XNPSPA/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HngeN5fPx ze8X5NE3hb+SSwyMSEqJxhVTXJVfQWWW0dQxP7HNwqmOWYF/6m+1gK/Y2gY3jAQnsWTru4RV TZGnKwEPmOCpSUvsTRXsVHgsWJ70qd0yOSjWuiv4b8vmD3+QFgyvCBxPMdP3xsxN5etheLMO gRwWpLn6yNFq/xtgs+ECgG+gR78yXQyA7iCs5tFs2OrMqV5juSMGmn0kxJUAEQEAAcLBXwQY AQIACQUCTrH31AIbDAAKCRAgrhaS4T3e4BKwD/0ZOOmUNOZCSOLAMjZx3mtYtjYgfUNKi0ki YPveGoRWTqbis8UitPtNrG4XxgzLOijSdOEzQwkdOIp/QnZhGNssMejCnsluK0GQd+RkFVWN mcQT78hBeGcnEMAXZKq7bkIKzvc06GFmkMbX/gAl6DiNGv0UNAX+5FYh+ucCJZSyAp3sA+9/ LKjxnTedX0aygXA6rkpX0Y0FvN/9dfm47+LGq7WAqBOyYTU3E6/+Z72bZoG/cG7ANLxcPool LOrU43oqFnD8QwcN56y4VfFj3/jDF2MX3xu4v2OjglVjMEYHTCxP3mpxesGHuqOit/FR+mF0 MP9JGfj6x+bj/9JMBtCW1bY/aPeMdPGTJvXjGtOVYblGZrSjXRn5++Uuy36CvkcrjuziSDG+ JEexGxczWwN4mrOQWhMT5Jyb+18CO+CWxJfHaYXiLEW7dI1AynL4jjn4W0MSiXpWDUw+fsBO Pk6ah10C4+R1Jc7dyUsKksMfvvhRX1hTIXhth85H16706bneTayZBhlZ/hK18uqTX+s0onG/ m1F3vYvdlE4p2ts1mmixMF7KajN9/E5RQtiSArvKTbfsB6Two4MthIuLuf+M0mI4gPl9SPlf fWCYVPhaU9o83y1KFbD/+lh1pjP7bEu/YudBvz7F2Myjh4/9GUAijrCTNeDTDAgvIJDjXuLX pA== Message-ID: Date: Mon, 30 Jul 2018 21:57:36 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <6f62dbc6-f516-e8b5-1f08-6be227a61219@suse.com> Content-Language: en-US Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factor the dsunit-vs-dwidth-vs-blocksize checks into a helper. If they fail on user-specified values, exit with usage(). If they fail on values from the device, warn about it and set them to zero so they'll be ignored. This also ensures that we won't complain if user-specified values don't match bogus device-provided geometry. Signed-off-by: Eric Sandeen --- NB: this does undo Jeff's "try to make the best of it" approach which set swidth=sunit, but I feel like we get burned whenever we try to second-guess broken hardware anyway. Thoughts? -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 8f0bd89..4f05354 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2196,6 +2196,37 @@ validate_rtextsize( ASSERT(cfg->rtextblocks); } +static bool +validate_stripe_factors( + int blocksize, + int dsunit, + int dswidth, + bool devicevals) +{ + /* Can't have one without the other, and dswidth must be multiple */ + if ((dsunit && !dswidth) || (!dsunit && dswidth) || + (dsunit && (dswidth % dsunit != 0))) { + if (devicevals) + fprintf(stderr, _("Validating device geometry:\n")); + fprintf(stderr, +_("Data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), + BBTOB(dswidth), BBTOB(dsunit)); + return false; + } + + /* Check that the stripe config is a multiple of block size */ + if ((BBTOB(dsunit) % blocksize) || + (BBTOB(dswidth) % blocksize)) { + if (devicevals) + fprintf(stderr, _("Validating device geometry:\n")); + fprintf(stderr, +_("Stripe unit(%d) or stripe width(%d) is not a multiple of the block size(%d)\n"), + BBTOB(dsunit), BBTOB(dswidth), blocksize); + return false; + } + return true; +} + /* * Validate the configured stripe geometry, or is none is specified, pull * the configuration from the underlying device. @@ -2215,7 +2246,6 @@ calc_stripe_factors( int dsu = 0; int dsw = 0; int lsu = 0; - bool use_dev = false; if (cli_opt_set(&dopts, D_SUNIT)) dsunit = cli->dsunit; @@ -2259,13 +2289,9 @@ _("data stripe width (%lld) is too large of a multiple of the data stripe unit ( dswidth = big_dswidth; } - if ((dsunit && !dswidth) || (!dsunit && dswidth) || - (dsunit && (dswidth % dsunit != 0))) { - fprintf(stderr, -_("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), - dswidth, dsunit); + /* Validate the user-supplied stripe geometry */ + if (!validate_stripe_factors(cfg->blocksize, dsunit, dswidth, false)) usage(); - } /* If sunit & swidth were manually specified as 0, same as noalign */ if ((cli_opt_set(&dopts, D_SUNIT) || cli_opt_set(&dopts, D_SU)) && @@ -2279,22 +2305,16 @@ _("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), goto check_lsunit; } - /* if no stripe config set, use the device default */ - if (!dsunit) { - /* Watch out for nonsense from device */ - if (ft->dsunit && ft->dswidth == 0) { - fprintf(stderr, -_("%s: Volume reports stripe unit of %d bytes but stripe width of 0.\n"), - progname, ft->dsunit << 9); - fprintf(stderr, -_("Using stripe width of %d bytes, which may not be optimal.\n"), - ft->dsunit << 9); - ft->dswidth = ft->dsunit; - } - dsunit = ft->dsunit; - dswidth = ft->dswidth; - use_dev = true; - } else { + /* Validate the device-reported stripe geometry */ + if (!validate_stripe_factors(cfg->blocksize, ft->dsunit, ft->dswidth, true)) { + fprintf(stderr, +_("Device-reported stripe geometry failed checks, ignoring\n")); + ft->dsunit = 0; + ft->dswidth = 0; + } + + /* If user specified geometry, check against device values */ + if (dsunit) { /* check and warn if user-specified alignment is sub-optimal */ if (ft->dsunit && ft->dsunit != dsunit) { fprintf(stderr, @@ -2306,28 +2326,10 @@ _("%s: Specified data stripe unit %d is not the same as the volume stripe unit % _("%s: Specified data stripe width %d is not the same as the volume stripe width %d\n"), progname, dswidth, ft->dswidth); } - } - - /* - * now we have our stripe config, check it's a multiple of block - * size. - */ - if ((BBTOB(dsunit) % cfg->blocksize) || - (BBTOB(dswidth) % cfg->blocksize)) { - /* - * If we are using device defaults, just clear them and we're - * good to go. Otherwise bail out with an error. - */ - if (!use_dev) { - fprintf(stderr, -_("%s: Stripe unit(%d) or stripe width(%d) is not a multiple of the block size(%d)\n"), - progname, BBTOB(dsunit), BBTOB(dswidth), - cfg->blocksize); - exit(1); - } - dsunit = 0; - dswidth = 0; - cfg->sb_feat.nodalign = true; + } else { + /* Use the device-reported geometry */ + dsunit = ft->dsunit; + dswidth = ft->dswidth; } /* convert from 512 byte blocks to fs blocksize */