From patchwork Thu Apr 4 15:35:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 2393411 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 1B09B3FD1A for ; Thu, 4 Apr 2013 15:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760014Ab3DDPgA (ORCPT ); Thu, 4 Apr 2013 11:36:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755785Ab3DDPf7 (ORCPT ); Thu, 4 Apr 2013 11:35:59 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r34FZxcN022591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Apr 2013 11:35:59 -0400 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r34FZwpG031569 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 4 Apr 2013 11:35:59 -0400 Message-ID: <515D9DDE.5040306@redhat.com> Date: Thu, 04 Apr 2013 10:35:58 -0500 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: linux-btrfs , Jan Safranek Subject: [PATCH] btrfs: close any open devices if btrfs_mount fails X-Enigmail-Version: 1.5.1 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This: # mkfs.btrfs /dev/sdb{1,2} ; wipefs -a /dev/sdb1; mount /dev/sdb2 /mnt/test would lead to a blkdev open/close mismatch when the mount fails, and a permanently busy (opened O_EXCL) sdb2: # wipefs -a /dev/sdb2 wipefs: error: /dev/sdb2: probing initialization failed: Device or resource busy It's because btrfs_open_devices() may open some devices, and still return failure. So the error unwinding needs to close any open devices in fs_devices before returning. Reported-by: Jan Safranek Signed-off-by: Eric Sandeen --- Note, __btrfs_open_devices is weird; it seems to return success or failure based on the outcome of the result of the last call to btrfs_get_bdev_and_sb(). But that's a different bug... -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" 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/fs/btrfs/super.c b/fs/btrfs/super.c index f6b8859..60c67fa 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1125,7 +1125,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, error = btrfs_open_devices(fs_devices, mode, fs_type); if (error) - goto error_fs_info; + goto error_close_devices; if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) { error = -EACCES; @@ -1161,7 +1161,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, return root; error_close_devices: - btrfs_close_devices(fs_devices); + if (fs_devices->opened) + btrfs_close_devices(fs_devices); error_fs_info: free_fs_info(fs_info); return ERR_PTR(error);