From patchwork Fri Oct 12 06:50:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fernando_Luis_V=C3=A1zquez_Cao?= X-Patchwork-Id: 1585501 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 DAE533FC1A for ; Fri, 12 Oct 2012 06:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755907Ab2JLGu5 (ORCPT ); Fri, 12 Oct 2012 02:50:57 -0400 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]:52488 "EHLO tama50.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755779Ab2JLGu4 (ORCPT ); Fri, 12 Oct 2012 02:50:56 -0400 Received: from mfs5.rdh.ecl.ntt.co.jp (mfs5.rdh.ecl.ntt.co.jp [129.60.39.144]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id q9C6oJ0F014382; Fri, 12 Oct 2012 15:50:19 +0900 Received: from mfs5.rdh.ecl.ntt.co.jp (localhost.localdomain [127.0.0.1]) by mfs5.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 872F6E010F; Fri, 12 Oct 2012 15:50:19 +0900 (JST) Received: from imail1.m.ecl.ntt.co.jp (imail1.m.ecl.ntt.co.jp [129.60.5.246]) by mfs5.rdh.ecl.ntt.co.jp (Postfix) with ESMTP id 7AD16E010A; Fri, 12 Oct 2012 15:50:19 +0900 (JST) Received: from [129.60.241.51] (nexus.sic.ecl.ntt.co.jp [129.60.241.51]) by imail1.m.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id q9C6oJ8Y010517; Fri, 12 Oct 2012 15:50:19 +0900 Message-ID: <1350024619.5357.3.camel@nexus.lab.ntt.co.jp> Subject: [PATCH 1/2] vfs: leverage bd_super in get_active_super From: Fernando Luis =?ISO-8859-1?Q?V=E1zquez?= Cao To: Chris Mason , Alexander Viro Cc: Jan Kara , Josef Bacik , Christoph Hellwig , Eric Sandeen , Dave Chinner , linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org Date: Fri, 12 Oct 2012 15:50:19 +0900 Organization: NTT Open Source Software Center X-Mailer: Evolution 3.4.3-1 Mime-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Subject: vfs: leverage bd_super in get_active_super Using get_active_super will not work properly if the fs (like btrfs) does not save its s_bdev with the device it is on. Also it does not provide the entire picture, since an filesystem can be contained on multiple disks (again like btrfs). Fortunately we now have a bd_super field in struct block_device were a pointer to the superblock sitting on top of the block device can be stored. Filesystems using the vfs helper mount_bdev (the ext filesystems, xfs, etc) and gfs2 already do this (for the former it is a freebie), so for these there is no need to iterate through the list of superblocks; we can get the superblock directly from ->bd_super which is more efficient and what this patch implements. A multi-device filesystem (once again lile btrfs) can use that field to store a pointer to the superblock for each block device in its storage pool. By doing so it would get_active_super and, by extension, thaw_bdev initiated freezes working. Thanks go to Josef Bacik and Christoph Hellwig for initiating this effort to fix btrfs and for suggesting the solution implemented here, respectively. Cc: Josef Bacik Cc: Christoph Hellwig Signed-off-by: Fernando Luis Vazquez Cao --- -- 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 -urNp linux-3.6-orig/fs/super.c linux-3.6/fs/super.c --- linux-3.6-orig/fs/super.c 2012-10-10 11:20:58.000122252 +0900 +++ linux-3.6/fs/super.c 2012-10-10 14:56:44.260186674 +0900 @@ -725,18 +725,22 @@ struct super_block *get_active_super(str restart: spin_lock(&sb_lock); + if ((sb = bdev->bd_super) != NULL) + goto out_grabsuper; list_for_each_entry(sb, &super_blocks, s_list) { if (hlist_unhashed(&sb->s_instances)) continue; - if (sb->s_bdev == bdev) { - if (grab_super(sb)) /* drops sb_lock */ - return sb; - else - goto restart; - } + if (sb->s_bdev == bdev) + goto out_grabsuper; } spin_unlock(&sb_lock); return NULL; + +out_grabsuper: + if (grab_super(sb)) /* drops sb_lock */ + return sb; + else + goto restart; } struct super_block *user_get_super(dev_t dev)