From patchwork Tue May 8 18:03:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Fasheh X-Patchwork-Id: 10387413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 45449602C2 for ; Tue, 8 May 2018 18:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 560F22917F for ; Tue, 8 May 2018 18:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AA6429192; Tue, 8 May 2018 18:41:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2F252917F for ; Tue, 8 May 2018 18:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756491AbeEHSla (ORCPT ); Tue, 8 May 2018 14:41:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:53809 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754386AbeEHSEu (ORCPT ); Tue, 8 May 2018 14:04:50 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D8FCDAE08; Tue, 8 May 2018 18:04:48 +0000 (UTC) From: Mark Fasheh To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, Mark Fasheh Subject: [PATCH 01/76] vfs: Introduce struct fs_view Date: Tue, 8 May 2018 11:03:21 -0700 Message-Id: <20180508180436.716-2-mfasheh@suse.de> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180508180436.716-1-mfasheh@suse.de> References: <20180508180436.716-1-mfasheh@suse.de> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We want to de-couple some items from struct super_block, in particular those that provide a 'fiew' into an fs. Introduce a small struct, fs_view to contain these fields. This first patch has a mostly empty fs_view. We do however, link it into the VFS: Each super_block gets a default fs_view which is filled in via the usual superblock intialization methods. struct inode is updated to point to an fs_view structure via a new 'i_view' pointer, which replaces i_sb. A filesystem can now optionally provide their own fs_view to point i_view to. So we don't lose our link from inode to superblock, fs_view gets an embedded super_block pointer. A helper function, inode_sb() is introduced to make getting the superblock from an inode less clunky. Filesystems need no functional changes, and the only additional memory usage here is the added pointer on struct super_block. Signed-off-by: Mark Fasheh --- fs/inode.c | 2 +- fs/super.c | 1 + include/linux/fs.h | 21 ++++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index ef362364d396..4f08fdc2c60f 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -133,7 +133,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) static const struct file_operations no_open_fops = {.open = no_open}; struct address_space *const mapping = &inode->i_data; - inode->i_sb = sb; + inode->i_view = &sb->s_view; inode->i_blkbits = sb->s_blocksize_bits; inode->i_flags = 0; atomic_set(&inode->i_count, 1); diff --git a/fs/super.c b/fs/super.c index 672538ca9831..5258a57d410a 100644 --- a/fs/super.c +++ b/fs/super.c @@ -245,6 +245,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_op = &default_op; s->s_time_gran = 1000000000; s->cleancache_poolid = CLEANCACHE_NO_POOL; + s->s_view.v_sb = s; s->s_shrink.seeks = DEFAULT_SEEKS; s->s_shrink.scan_objects = super_cache_scan; diff --git a/include/linux/fs.h b/include/linux/fs.h index c6baf767619e..4561cb9156d4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -580,7 +580,7 @@ struct inode { #endif const struct inode_operations *i_op; - struct super_block *i_sb; + struct fs_view *i_view; struct address_space *i_mapping; #ifdef CONFIG_SECURITY @@ -1340,6 +1340,24 @@ struct sb_writers { struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS]; }; +/* + * "View" into a filesystem. Allows us to abstract out those + * superblock fields which change between the roots on a given + * filesystem. Most filesystems can ignore this - inodes are pointed + * to the default view 's_view' during initialization. + * + * A file system with multiple roots should allocate a view structure + * per root and point each inodes view pointer to it in iget. + */ +struct fs_view { + struct super_block *v_sb; +}; + +static inline struct super_block *inode_sb(const struct inode *inode) +{ + return inode->i_view->v_sb; +} + struct super_block { struct list_head s_list; /* Keep this first */ dev_t s_dev; /* search index; _not_ kdev_t */ @@ -1358,6 +1376,7 @@ struct super_block { struct rw_semaphore s_umount; int s_count; atomic_t s_active; + struct fs_view s_view; /* default view into the fs */ #ifdef CONFIG_SECURITY void *s_security; #endif