From patchwork Thu Jun 16 16:38:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Rajendra X-Patchwork-Id: 9181337 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 C56E260776 for ; Thu, 16 Jun 2016 16:39:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B64AE2835E for ; Thu, 16 Jun 2016 16:39:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB43028365; Thu, 16 Jun 2016 16:39:00 +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=-6.9 required=2.0 tests=BAYES_00,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 57F432835E for ; Thu, 16 Jun 2016 16:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754694AbcFPQis (ORCPT ); Thu, 16 Jun 2016 12:38:48 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40479 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753962AbcFPQir (ORCPT ); Thu, 16 Jun 2016 12:38:47 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5GGYNtw002534 for ; Thu, 16 Jun 2016 12:38:46 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 23kw2pqkuc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Jun 2016 12:38:46 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Jun 2016 10:38:45 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Jun 2016 10:38:43 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: chandan@linux.vnet.ibm.com X-IBM-RcptTo: bo.li.liu@oracle.com; dsterba@suse.com; linux-btrfs@vger.kernel.org Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id F198C3E40030; Thu, 16 Jun 2016 10:38:34 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5GGcYr241484308; Thu, 16 Jun 2016 09:38:34 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98D69BE03A; Thu, 16 Jun 2016 10:38:34 -0600 (MDT) Received: from localhost.in.ibm.com (unknown [9.84.226.14]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id EB732BE039; Thu, 16 Jun 2016 10:38:32 -0600 (MDT) From: Chandan Rajendra To: linux-btrfs@vger.kernel.org Cc: Chandan Rajendra , dsterba@suse.com, bo.li.liu@oracle.com Subject: [PATCH] Btrfs-progs: Initialize stripesize to the value of sectorsize Date: Thu, 16 Jun 2016 22:08:29 +0530 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16061616-0004-0000-0000-00000FB393E8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16061616-0005-0000-0000-00007639D87F Message-Id: <1466095109-26044-1-git-send-email-chandan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-16_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606160181 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP stripesize should ideally be set to the value of sectorsize. However previous versions of btrfs-progs/mkfs.btrfs had set stripesize to a value of 4096. On machines with PAGE_SIZE other than 4096, This could lead to the following scenario, - /dev/loop0, /dev/loop1 and /dev/loop2 are mounted as a single filesystem. The filesystem was created by an older version of mkfs.btrfs which set stripesize to 4k. - losetup -a /dev/loop0: [0030]:19477 (/root/disk-imgs/file-0.img) /dev/loop1: [0030]:16577 (/root/disk-imgs/file-1.img) /dev/loop2: [64770]:3423229 (/root/disk-imgs/file-2.img) - /etc/mtab lists only /dev/loop0 - losetup /dev/loop4 /root/disk-imgs/file-1.img The new mkfs.btrfs invoked as 'mkfs.btrfs -f /dev/loop4' succeeds even though /dev/loop1 has already been mounted and has /root/disk-imgs/file-1.img as its backing file. The above behaviour occurs because check_super() function returns an error code (due to stripesize not being set to 4096) and hence check_mounted_where() function treats /dev/loop1 as a disk containing a filesystem other than Btrfs. Hence as a workaround this commit allows 4096 as a valid stripesize. Signed-off-by: Chandan Rajendra --- disk-io.c | 4 +++- mkfs.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/disk-io.c b/disk-io.c index 77eb0a6..1ac7631 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1476,7 +1476,9 @@ static int check_super(struct btrfs_super_block *sb) error("invalid bytes_used %llu", btrfs_super_bytes_used(sb)); goto error_out; } - if (btrfs_super_stripesize(sb) != 4096) { + + if ((btrfs_super_stripesize(sb) != 4096) + && (btrfs_super_stripesize(sb) != btrfs_super_sectorsize(sb))) { error("invalid stripesize %u", btrfs_super_stripesize(sb)); goto error_out; } diff --git a/mkfs.c b/mkfs.c index a3a3c14..697bdc2 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1482,6 +1482,7 @@ int main(int argc, char **argv) } sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE)); + stripesize = sectorsize; saved_optind = optind; dev_cnt = argc - optind; if (dev_cnt == 0)