From patchwork Tue Mar 19 05:10:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Rajendra X-Patchwork-Id: 10858819 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 DD637139A for ; Tue, 19 Mar 2019 05:09:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B492F294F5 for ; Tue, 19 Mar 2019 05:09:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3FD2294FA; Tue, 19 Mar 2019 05:09:52 +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 49E36294F5 for ; Tue, 19 Mar 2019 05:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726067AbfCSFJv (ORCPT ); Tue, 19 Mar 2019 01:09:51 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33054 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfCSFJv (ORCPT ); Tue, 19 Mar 2019 01:09:51 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2J552GX089052 for ; Tue, 19 Mar 2019 01:09:50 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rasu5rcj2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 19 Mar 2019 01:09:50 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 19 Mar 2019 05:09:47 -0000 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 19 Mar 2019 05:09:44 -0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2J59jTJ24510554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Mar 2019 05:09:45 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 03BDBAE05F; Tue, 19 Mar 2019 05:09:45 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B8802AE071; Tue, 19 Mar 2019 05:09:43 +0000 (GMT) Received: from localhost.in.ibm.com (unknown [9.124.35.75]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 19 Mar 2019 05:09:43 +0000 (GMT) From: Chandan Rajendra To: linux-xfs@vger.kernel.org Cc: Chandan Rajendra , darrick.wong@oracle.com, sandeen@sandeen.net Subject: [PATCH V2] mkfs: Round down log device size if aligned value is larger than device size Date: Tue, 19 Mar 2019 10:40:27 +0530 X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190318155757.GM4929@magnolia> References: <20190318155757.GM4929@magnolia> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 19031905-0064-0000-0000-000003BC32F1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010783; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01176449; UDB=6.00615343; IPR=6.00957135; MB=3.00026045; MTD=3.00000008; XFM=3.00000015; UTC=2019-03-19 05:09:46 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031905-0065-0000-0000-00003CC444EE Message-Id: <20190319051027.27897-1-chandan@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-19_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=877 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903190038 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 When using a disk of size 798903808 bytes as the log device and when having a log stripe unit size of 32768, align_log_size() rounds up log device size to 195048 4k blocks i.e. 798916608. This value is larger than the device size. Hence the last call to write(2) inside libxfs_device_zero() would end up returning an error. To fix this bug, we now round down the log device size if the newly computed size is larger than the actual log device size. Signed-off-by: Chandan Rajendra Reviewed-by: Darrick J. Wong --- Changelog: v1 -> v2: 1. Remove extraneous parenthesis around conditions. mkfs/xfs_mkfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index d1387ddf..c9e22560 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2937,8 +2937,9 @@ _("log size %lld is not a multiple of the log stripe unit %d\n"), tmp_logblocks = ((cfg->logblocks + (sunit - 1)) / sunit) * sunit; /* If the log is too large, round down instead of round up */ - if ((tmp_logblocks > XFS_MAX_LOG_BLOCKS) || - ((tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)) { + if (tmp_logblocks > XFS_MAX_LOG_BLOCKS || + tmp_logblocks > cfg->logblocks || + (tmp_logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES) { tmp_logblocks = (cfg->logblocks / sunit) * sunit; } cfg->logblocks = tmp_logblocks;