From patchwork Thu Jul 19 21:23:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 10535363 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 602BC600F4 for ; Thu, 19 Jul 2018 21:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D6A429D45 for ; Thu, 19 Jul 2018 21:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FA9729D55; Thu, 19 Jul 2018 21:23:27 +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 D1C1929D45 for ; Thu, 19 Jul 2018 21:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727721AbeGSWIV (ORCPT ); Thu, 19 Jul 2018 18:08:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:48540 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727615AbeGSWIV (ORCPT ); Thu, 19 Jul 2018 18:08:21 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B680CAE1E; Thu, 19 Jul 2018 21:23:24 +0000 (UTC) To: "linux-xfs@vger.kernel.org" , Eric Sandeen , Dave Chinner From: Jeff Mahoney Subject: [PATCH] mkfs: avoid divide-by-zero when hardware reports optimal i/o size as 0 Openpgp: preference=signencrypt Message-ID: <6f62dbc6-f516-e8b5-1f08-6be227a61219@suse.com> Date: Thu, 19 Jul 2018 17:23:22 -0400 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 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 Commit 051b4e37f5e (mkfs: factor AG alignment) factored out the AG alignment code into a separate function. It got rid of redundant checks for dswidth != 0 since calc_stripe_factors was supposed to guarantee that if dsunit is non-zero dswidth will be as well. Unfortunately, there's hardware out there that reports its optimal i/o size as larger than the maximum i/o size, which the kernel treats as broken and zeros out the optimal i/o size. We'll accept the multi-sector dsunit but have a zero dswidth and hit a divide-by-zero in align_ag_geometry. To resolve this we can check the topology before consuming it, default to using the stripe unit as the stripe width, and warn the user about it. Fixes: 051b4e37f5e (mkfs: factor AG alignment) Signed-off-by: Jeff Mahoney --- mkfs/xfs_mkfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index a135e06e..35542e57 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2295,6 +2295,12 @@ _("data stripe width (%d) must be a multiple of the data stripe unit (%d)\n"), if (!dsunit) { dsunit = ft->dsunit; dswidth = ft->dswidth; + if (dsunit && dswidth == 0) { + fprintf(stderr, +_("%s: Volume reports stripe unit of %d bytes but stripe width of 0. Using stripe width of %d bytes, which may not be optimal.\n"), + progname, dsunit << 9, dsunit << 9); + dswidth = dsunit; + } use_dev = true; } else { /* check and warn is alignment is sub-optimal */