From patchwork Tue Jul 21 08:37:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Dongsheng X-Patchwork-Id: 6833261 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 69AD9C05AC for ; Tue, 21 Jul 2015 08:43:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C9D120690 for ; Tue, 21 Jul 2015 08:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A74A820678 for ; Tue, 21 Jul 2015 08:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754164AbbGUInp (ORCPT ); Tue, 21 Jul 2015 04:43:45 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7296 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753858AbbGUInh (ORCPT ); Tue, 21 Jul 2015 04:43:37 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="98671196" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Jul 2015 16:47:13 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6L8fhJA004996; Tue, 21 Jul 2015 16:41:43 +0800 Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 21 Jul 2015 16:43:30 +0800 From: Dongsheng Yang To: , , CC: , , Dongsheng Yang Subject: [PATCH 04/25] fs: super: introduce the functions to get super by cdev reference Date: Tue, 21 Jul 2015 16:37:35 +0800 Message-ID: <1437467876-22106-5-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1437467876-22106-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 As we have cdev in super block now, we can provide get_super_cdev to get super_block by a cdev reference, similar with get_super which is working only for block_device. Signed-off-by: Dongsheng Yang --- fs/super.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/fs/super.c b/fs/super.c index 928c20f..4a9031a 100644 --- a/fs/super.c +++ b/fs/super.c @@ -605,6 +605,37 @@ rescan: EXPORT_SYMBOL(get_super); +struct super_block *get_super_cdev(struct cdev *cdev) +{ + struct super_block *sb; + + if (!cdev) + return NULL; + + spin_lock(&sb_lock); +rescan: + list_for_each_entry(sb, &super_blocks, s_list) { + if (hlist_unhashed(&sb->s_instances)) + continue; + if (sb->s_cdev == cdev) { + sb->s_count++; + spin_unlock(&sb_lock); + down_read(&sb->s_umount); + /* still alive? */ + if (sb->s_root && (sb->s_flags & MS_BORN)) + return sb; + up_read(&sb->s_umount); + /* nope, got unmounted */ + spin_lock(&sb_lock); + __put_super(sb); + goto rescan; + } + } + spin_unlock(&sb_lock); + return NULL; +} +EXPORT_SYMBOL(get_super_cdev); + /** * get_super_thawed - get thawed superblock of a device * @bdev: device to get the superblock for @@ -628,6 +659,20 @@ struct super_block *get_super_thawed(struct block_device *bdev) } EXPORT_SYMBOL(get_super_thawed); +struct super_block *get_super_cdev_thawed(struct cdev *cdev) +{ + while (1) { + struct super_block *s = get_super_cdev(cdev); + if (!s || s->s_writers.frozen == SB_UNFROZEN) + return s; + up_read(&s->s_umount); + wait_event(s->s_writers.wait_unfrozen, + s->s_writers.frozen == SB_UNFROZEN); + put_super(s); + } +} +EXPORT_SYMBOL(get_super_cdev_thawed); + /** * get_active_super - get an active reference to the superblock of a device * @bdev: device to get the superblock for diff --git a/include/linux/fs.h b/include/linux/fs.h index 2f1d9499..5c7d789 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2744,7 +2744,9 @@ extern void get_filesystem(struct file_system_type *fs); extern void put_filesystem(struct file_system_type *fs); extern struct file_system_type *get_fs_type(const char *name); extern struct super_block *get_super(struct block_device *); +extern struct super_block *get_super_cdev(struct cdev *); extern struct super_block *get_super_thawed(struct block_device *); +extern struct super_block *get_super_cdev_thawed(struct cdev *); extern struct super_block *get_active_super(struct block_device *bdev); extern void drop_super(struct super_block *sb); extern void iterate_supers(void (*)(struct super_block *, void *), void *);