From patchwork Thu Mar 21 17:26:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Price X-Patchwork-Id: 10864153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB9C0139A for ; Thu, 21 Mar 2019 17:26:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7FCA29E65 for ; Thu, 21 Mar 2019 17:26:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBC902A306; Thu, 21 Mar 2019 17:26:52 +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=ham 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 4FE922A169 for ; Thu, 21 Mar 2019 17:26:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727987AbfCUR0v (ORCPT ); Thu, 21 Mar 2019 13:26:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33694 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727829AbfCUR0v (ORCPT ); Thu, 21 Mar 2019 13:26:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A2F3859FB for ; Thu, 21 Mar 2019 17:26:51 +0000 (UTC) Received: from cicero.redhat.com (unknown [10.33.36.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B240E4A5; Thu, 21 Mar 2019 17:26:47 +0000 (UTC) From: Andrew Price To: cluster-devel@redhat.com, dhowells@redhat.com Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH] vfs: Allow selection of fs root independent of sb Date: Thu, 21 Mar 2019 17:26:44 +0000 Message-Id: <20190321172644.17218-1-anprice@redhat.com> In-Reply-To: <27020.1553188118@warthog.procyon.org.uk> References: <27020.1553188118@warthog.procyon.org.uk> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 21 Mar 2019 17:26:51 +0000 (UTC) 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 Take a function pointer 'select_root' in vfs_get_block_super() to allow callers to select the root dentry based on the context. This is intended for gfs2 to select between the normal root and the 'meta' root, which must be done whether a root already exists for a superblock or not, i.e. it cannot be decided in fill_super(). This will allow gfs2 to avoid duplicating a function from the vfs just to special-case the root dentry selection. Signed-off-by: Andrew Price --- Depends on "vfs: Create fs_context-aware mount_bdev() replacement" fs/super.c | 11 ++++++++--- include/linux/fs_context.h | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/super.c b/fs/super.c index 6d8dbf309241..0cdeaf28126f 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1232,11 +1232,12 @@ static int test_bdev_super_fc(struct super_block *s, struct fs_context *fc) * @fill_super: Helper to initialise a new superblock */ int vfs_get_block_super(struct fs_context *fc, - int (*fill_super)(struct super_block *, - struct fs_context *)) + int (*fill_super)(struct super_block *, struct fs_context *), + struct dentry* (*select_root)(struct fs_context *, struct super_block *)) { struct block_device *bdev; struct super_block *s; + struct dentry *root; int error = 0; fc->bdev_mode = FMODE_READ | FMODE_EXCL; @@ -1302,7 +1303,11 @@ int vfs_get_block_super(struct fs_context *fc, } BUG_ON(fc->root); - fc->root = dget(s->s_root); + if (select_root) + root = select_root(fc, s); + else + root = s->s_root; + fc->root = dget(root); return 0; error_sb: diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h index 8233c873af73..c2e9dc5826ce 100644 --- a/include/linux/fs_context.h +++ b/include/linux/fs_context.h @@ -145,8 +145,8 @@ extern int vfs_get_super(struct fs_context *fc, struct fs_context *fc)); extern int vfs_get_block_super(struct fs_context *fc, - int (*fill_super)(struct super_block *sb, - struct fs_context *fc)); + int (*fill_super)(struct super_block *, struct fs_context *), + struct dentry* (*select_root)(struct fs_context *, struct super_block *)); extern const struct file_operations fscontext_fops;