From patchwork Thu Jun 12 06:25:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 4339661 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 34191BEEAA for ; Thu, 12 Jun 2014 06:22:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64DA420254 for ; Thu, 12 Jun 2014 06:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7551F2025B for ; Thu, 12 Jun 2014 06:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932175AbaFLGWp (ORCPT ); Thu, 12 Jun 2014 02:22:45 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:43216 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754234AbaFLGWl (ORCPT ); Thu, 12 Jun 2014 02:22:41 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5C6MbhZ026064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 Jun 2014 06:22:37 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s5C6MaN9016858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 12 Jun 2014 06:22:37 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5C6MZwY018334; Thu, 12 Jun 2014 06:22:36 GMT Received: from localhost.localdomain.com (/10.186.101.107) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 11 Jun 2014 23:22:35 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: wangsl.fnst@cn.fujitsu.com, Anand Jain Subject: [PATCH 1/1] btrfs: looping 'mkfs.btrfs -f ' may fail with EBUSY Date: Thu, 12 Jun 2014 14:25:00 +0800 Message-Id: <1402554300-13931-1-git-send-email-Anand.Jain@oracle.com> X-Mailer: git-send-email 1.8.5.3 X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The thread holding the O_EXCL flag seems to be BTRFS_IOC_SCAN_DEV ioctl, which in turn calls btrfs_scan_one_device() to open dev with the O_EXCL flag. But btrfs_scan_one_device() does not write anything to the disk. and it is called by . An intermediary step (not the final open_ctree) in the mount thread to read the SB and . btrfs-control ioctls viz BTRFS_IOC_SCAN_DEV and BTRFS_IOC_DEVICES_READY they don't need the O_EXCL. test script: (run this in a loop) static int test_skip_this_disk(char *path) { int fd; char c; printf("%s ", path); fd = open(path, O_RDWR|O_EXCL); if (fd < 0) { printf("Open failed\n"); return 1; } /*fflush(stdout); printf("Open Fine press enter\n"); scanf("%c", &c);*/ close(fd); return 0; } main(int arg, char **argv) { int i; if (arg == 1) { printf("usage: %s .. \n", argv[0]); exit(1); } for (i = 1; i < arg; i++) test_skip_this_disk(argv[i]); } dump stack after the userland close(fd) dump_stack+0x9/0x60 btrfs_scan_one_device+0x18d/0x1f0 [btrfs] btrfs_control_ioctl+0xb9/0x210 [btrfs] do_vfs_ioctl+0x84/0x4c0 inode_has_perm+0x28/0x30 file_has_perm+0x8a/0xa0 SyS_ioctl+0x91/0xa0 system_call_fastpath+0x16/0x1b Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 636faa0..c186b5e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -914,7 +914,6 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, * later supers, using BTRFS_SUPER_MIRROR_MAX instead */ bytenr = btrfs_sb_offset(0); - flags |= FMODE_EXCL; mutex_lock(&uuid_mutex); bdev = blkdev_get_by_path(path, flags, holder);