From patchwork Thu Jan 3 23:44:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10747859 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 F0D1617D2 for ; Thu, 3 Jan 2019 23:44:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFF7824603 for ; Thu, 3 Jan 2019 23:44:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D43FD2621B; Thu, 3 Jan 2019 23:44:13 +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 75A3024603 for ; Thu, 3 Jan 2019 23:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728937AbfACXoM (ORCPT ); Thu, 3 Jan 2019 18:44:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45852 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728829AbfACXoL (ORCPT ); Thu, 3 Jan 2019 18:44:11 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D214583F3C; Thu, 3 Jan 2019 23:44:10 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-244.rdu2.redhat.com [10.10.120.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id E575D600C9; Thu, 3 Jan 2019 23:44:09 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 2/5] kernfs: Provide a fill_super hook for the subclass filesystem From: David Howells To: viro@zeniv.linux.org.uk Cc: avagin@gmail.com, dhowells@redhat.com, linux-fsdevel@vger.kernel.org Date: Thu, 03 Jan 2019 23:44:09 +0000 Message-ID: <154655904912.3032.14601659851271963173.stgit@warthog.procyon.org.uk> In-Reply-To: <154655904205.3032.4248425887082198759.stgit@warthog.procyon.org.uk> References: <154655904205.3032.4248425887082198759.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 03 Jan 2019 23:44:10 +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 Provide a fill_super hook for a subclass filesystem to use to get a reference on the resource it attaches to struct kernfs_super_info::root. Without this, error handling becomes tricky in the event that, say, kernfs_get_inode() fails in kernfs_fill_super() as the superblock destructor will be invoked before kernfs_get_tree() returns. Fixes: b3678086951a ("kernfs, sysfs, cgroup, intel_rdt: Support fs_context") Signed-off-by: David Howells --- fs/kernfs/mount.c | 13 +++++++++++-- include/linux/kernfs.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index 3b61a4bb02c4..f04173d29845 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -217,11 +217,13 @@ struct dentry *kernfs_node_dentry(struct kernfs_node *kn, } while (true); } -static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *kfc) +static int kernfs_fill_super(struct super_block *sb, struct fs_context *fc) { + struct kernfs_fs_context *kfc = fc->fs_private; struct kernfs_super_info *info = kernfs_info(sb); struct inode *inode; struct dentry *root; + int ret; info->sb = sb; /* Userspace would break if executables or devices appear on sysfs */ @@ -238,6 +240,12 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k /* sysfs dentries and inodes don't require IO to create */ sb->s_shrink.seeks = 0; + if (kfc->fill_super) { + ret = kfc->fill_super(sb, fc); + if (ret < 0) + return ret; + } + /* get root inode, initialize and unlock it */ mutex_lock(&kernfs_mutex); inode = kernfs_get_inode(sb, info->root->kn); @@ -290,6 +298,7 @@ const void *kernfs_super_ns(struct super_block *sb) /** * kernfs_get_tree - kernfs filesystem access/retrieval helper * @fc: The filesystem context. + * @fill_super: The subclass's superblock initialiser function * * This is to be called from each kernfs user's fs_context->ops->get_tree() * implementation, which should set the specified ->@fs_type and ->@flags, and @@ -321,7 +330,7 @@ int kernfs_get_tree(struct fs_context *fc) kfc->new_sb_created = true; - error = kernfs_fill_super(sb, kfc); + error = kernfs_fill_super(sb, fc); if (error) { deactivate_locked_super(sb); return error; diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h index 60ae0f862a79..a68e3fdd428c 100644 --- a/include/linux/kernfs.h +++ b/include/linux/kernfs.h @@ -277,6 +277,7 @@ struct kernfs_fs_context { struct kernfs_root *root; /* Root of the hierarchy being mounted */ void *ns_tag; /* Namespace tag of the mount (or NULL) */ unsigned long magic; /* File system specific magic number */ + int (*fill_super)(struct super_block *sb, struct fs_context *fc); /* The following are set/used by kernfs_mount() */ bool new_sb_created; /* Set to T if we allocated a new sb */