From patchwork Tue Jul 15 23:07:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Luis R. Rodriguez" X-Patchwork-Id: 4561671 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 5D832C0515 for ; Tue, 15 Jul 2014 23:07:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 625C720108 for ; Tue, 15 Jul 2014 23:07:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 62B01201BB for ; Tue, 15 Jul 2014 23:07:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759351AbaGOXHV (ORCPT ); Tue, 15 Jul 2014 19:07:21 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:42433 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbaGOXHQ (ORCPT ); Tue, 15 Jul 2014 19:07:16 -0400 Received: by mail-pa0-f50.google.com with SMTP id et14so129027pad.9 for ; Tue, 15 Jul 2014 16:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZDqae6q8cGQZVOF43XpQSknApWffDd25mSgIQq+nNTo=; b=rIoMllH00Qv8cRmbpaXoV7l2saXcIVKMnXA8v2RS8I6TRwUi4g1OLEOPtvY8wz0MoQ U9Ay08+fu+ueaz0dmQ5uPd/u7WXQaX7oVUSG9ZiInNYVERjHpy7GPVDFVYskwn+8M4I4 1FVIgSk77GN/ITPcXsKBIhXVsKCU7cSfTZ/mQAX9A0iNW4QcbzHRtTUU3tzuf1r8KIXE ypy/TFn/znB+OX+bw3PK9bdicLF7AlcKcjzrlFrLdO7z9tPfRMP2NmnxSPL/4gIUsZIs 3EjwmzwET5Z58wDShZiadWvm8erN/V7d1WcPcIis1ubZmR/Ay70B10LJlp32AJaqxIpw yDmg== X-Received: by 10.70.128.140 with SMTP id no12mr5113986pdb.147.1405465635492; Tue, 15 Jul 2014 16:07:15 -0700 (PDT) Received: from mcgrof@gmail.com (c-98-234-145-61.hsd1.ca.comcast.net. [98.234.145.61]) by mx.google.com with ESMTPSA id a5sm20129895pdo.1.2014.07.15.16.07.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Jul 2014 16:07:14 -0700 (PDT) Received: by mcgrof@gmail.com (sSMTP sendmail emulation); Tue, 15 Jul 2014 16:07:11 -0700 From: "Luis R. Rodriguez" To: viro@zeniv.linux.org.uk, clm@fb.com, jbacik@fb.com Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, jeffm@suse.com, fdmanana@suse.com, "Luis R. Rodriguez" Subject: [RFC 1/2] fs/super.c: add new super block sub devices super_block_dev Date: Tue, 15 Jul 2014 16:07:04 -0700 Message-Id: <1405465625-1122-2-git-send-email-mcgrof@do-not-panic.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405465625-1122-1-git-send-email-mcgrof@do-not-panic.com> References: <1405465625-1122-1-git-send-email-mcgrof@do-not-panic.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 From: "Luis R. Rodriguez" Modern filesystems are using the get_anon_bdev() for internal notions of volumes, snapshots for a single super block but never exposing them directly to the VFS layer. While this works its leaves the VFS layer growing dumb over what filesystems are doing. This creates a new super block subdevice which we can use to start stuffing in information about the underlying bdev's and its associated super block to start off with. This at least now lets us implement proper support for ustat() once filesystems are modified to use this data structure and respective helpers. Signed-off-by: Luis R. Rodriguez --- fs/super.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/fs.h | 10 ++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/fs/super.c b/fs/super.c index d20d5b1..f96ad1c 100644 --- a/fs/super.c +++ b/fs/super.c @@ -133,6 +133,90 @@ static unsigned long super_cache_count(struct shrinker *shrink, return total_objects; } +static bool super_dev_match(struct super_block *sb, dev_t dev) +{ + struct super_block_dev *sbdev; + + if (sb->s_dev == dev) + return true; + + if (list_empty(&sb->s_sbdevs)) + return false; + + list_for_each_entry(sbdev, &sb->s_sbdevs, entry) + if (sbdev->anon_dev == dev) + return true; + + return false; +} + +struct super_block_dev *get_anon_sbdev(struct super_block *sb) +{ + struct super_block_dev *sbdev; + int ret; + + sbdev = kzalloc(sizeof(struct super_block_dev), GFP_USER); + if (!sbdev) + return NULL; + + ret = get_anon_bdev(&sbdev->anon_dev); + if (ret) { + kfree(sbdev); + return NULL; + } + + sbdev->sb = sb; + + spin_lock(&sb_lock); + list_add_tail(&sbdev->entry, &sb->s_sbdevs); + spin_unlock(&sb_lock); + + return sbdev; +} +EXPORT_SYMBOL_GPL(get_anon_sbdev); + +void free_anon_sbdev(struct super_block_dev *sbdev) +{ + struct super_block *sb; + struct super_block_dev *sbdev_i, *tmp; + + if (!sbdev) + return; + + sb = sbdev->sb; + + spin_lock(&sb_lock); + + WARN_ON(list_empty(&sb->s_sbdevs)); + + list_for_each_entry_safe(sbdev_i, tmp, &sb->s_sbdevs, entry) { + if (sbdev == sbdev_i) { + list_del_init(&sbdev_i->entry); + break; + } + } + + spin_unlock(&sb_lock); + + free_anon_bdev(sbdev->anon_dev); + kfree(sbdev); +} +EXPORT_SYMBOL_GPL(free_anon_sbdev); + +static void free_anon_sbdevs(struct super_block *sb) +{ + struct super_block_dev *sbdev, *tmp; + + if (list_empty(&sb->s_sbdevs)) + return; + + list_for_each_entry_safe(sbdev, tmp, &sb->s_sbdevs, entry) { + list_del_init(&sbdev->entry); + free_anon_bdev(sbdev->anon_dev); + kfree(sbdev); + } +} + /** * destroy_super - frees a superblock * @s: superblock to free @@ -150,6 +234,7 @@ static void destroy_super(struct super_block *s) WARN_ON(!list_empty(&s->s_mounts)); kfree(s->s_subtype); kfree(s->s_options); + free_anon_sbdevs(s); kfree_rcu(s, rcu); } @@ -188,6 +273,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags) INIT_HLIST_NODE(&s->s_instances); INIT_HLIST_BL_HEAD(&s->s_anon); INIT_LIST_HEAD(&s->s_inodes); + INIT_LIST_HEAD(&s->s_sbdevs); if (list_lru_init(&s->s_dentry_lru)) goto fail; @@ -652,7 +738,7 @@ restart: spin_unlock(&sb_lock); return NULL; } - + struct super_block *user_get_super(dev_t dev) { struct super_block *sb; @@ -662,7 +748,7 @@ rescan: list_for_each_entry(sb, &super_blocks, s_list) { if (hlist_unhashed(&sb->s_instances)) continue; - if (sb->s_dev == dev) { + if (super_dev_match(sb, dev)) { sb->s_count++; spin_unlock(&sb_lock); down_read(&sb->s_umount); diff --git a/include/linux/fs.h b/include/linux/fs.h index e11d60c..9de1128 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1172,6 +1172,13 @@ struct sb_writers { #endif }; +/* we can expand this to help the VFS layer with modern filesystems */ +struct super_block_dev { + struct super_block *sb; + struct list_head entry; /* For struct sb->s_sbdevs */ + dev_t anon_dev; +}; + struct super_block { struct list_head s_list; /* Keep this first */ dev_t s_dev; /* search index; _not_ kdev_t */ @@ -1196,6 +1203,7 @@ struct super_block { struct list_head s_inodes; /* all inodes */ struct hlist_bl_head s_anon; /* anonymous dentries for (nfs) exporting */ + struct list_head s_sbdevs; /* internal fs dev_t */ struct list_head s_mounts; /* list of mounts; _not_ for fs use */ struct block_device *s_bdev; struct backing_dev_info *s_bdi; @@ -1796,6 +1804,8 @@ void deactivate_locked_super(struct super_block *sb); int set_anon_super(struct super_block *s, void *data); int get_anon_bdev(dev_t *); void free_anon_bdev(dev_t); +struct super_block_dev *get_anon_sbdev(struct super_block *sb); +void free_anon_sbdev(struct super_block_dev *sbdev); struct super_block *sget(struct file_system_type *type, int (*test)(struct super_block *,void *), int (*set)(struct super_block *,void *),