From patchwork Wed Dec 28 08:53:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coly Li X-Patchwork-Id: 9490107 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 2887A60488 for ; Wed, 28 Dec 2016 08:53:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A6A1FF1E for ; Wed, 28 Dec 2016 08:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04389205AF; Wed, 28 Dec 2016 08:53:40 +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=-6.9 required=2.0 tests=BAYES_00,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 70B581FF1E for ; Wed, 28 Dec 2016 08:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751138AbcL1Ixi (ORCPT ); Wed, 28 Dec 2016 03:53:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:44688 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751105AbcL1Ixh (ORCPT ); Wed, 28 Dec 2016 03:53:37 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6D1C3ABA3; Wed, 28 Dec 2016 08:53:36 +0000 (UTC) From: Coly Li To: linux-fsdevel@vger.kernel.org Cc: nongli1031@gmail.com, Coly Li , Andrew Morton Subject: [PATCH v2] romfs: use different way to generate fsid for BLOCK or MTD Date: Wed, 28 Dec 2016 16:53:27 +0800 Message-Id: <1482915207-109005-1-git-send-email-colyli@suse.de> X-Mailer: git-send-email 2.6.6 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 'Commit 8a59f5d25265 ("fs/romfs: return f_fsid for statfs(2)")' generates a 64bit id from sb->s_bdev->bd_dev. This is only correct when romfs is defined with CONFIG_ROMFS_ON_BLOCK. If romfs is defined with CONFIG_ROMFS_ON_MTD, sb->s_bdev is NULL, referencing sb->s_bdev->bd_dev will triger an oops. If romfs is built on top of a MTD abstracted block device, this MTD block device has a device ID generated by MTD_BLOCK_MAJOR and mtd index. This patch uses the same ID to generate fsid for the romfs on top of the MTD block device. Generally only one romfs can be built on single MTD block device, this method is enough to identify multiple romfs instances in a computer. If romfs is built on top of a common block device, sb->s_bdev->bd_dev is used to generate the 64bit id, as previous commit did. Signed-off-by: Coly Li Reported-by: Nong Li Tested-by: Nong Li Cc: Andrew Morton Cc: linux-fsdevel@vger.kernel.org --- fs/romfs/super.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/romfs/super.c b/fs/romfs/super.c index d0f8a38..a38c07f 100644 --- a/fs/romfs/super.c +++ b/fs/romfs/super.c @@ -74,6 +74,7 @@ #include #include #include +#include #include "internal.h" static struct kmem_cache *romfs_inode_cachep; @@ -416,8 +417,14 @@ static void romfs_destroy_inode(struct inode *inode) static int romfs_statfs(struct dentry *dentry, struct kstatfs *buf) { struct super_block *sb = dentry->d_sb; - u64 id = huge_encode_dev(sb->s_bdev->bd_dev); + u64 id = 0; +#ifdef CONFIG_ROMFS_ON_BLOCK + id = huge_encode_dev(sb->s_bdev->bd_dev); +#endif +#ifdef CONFIG_ROMFS_ON_MTD + id = huge_encode_dev(sb->s_dev); +#endif buf->f_type = ROMFS_MAGIC; buf->f_namelen = ROMFS_MAXFN; buf->f_bsize = ROMBSIZE; @@ -489,6 +496,13 @@ static int romfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_flags |= MS_RDONLY | MS_NOATIME; sb->s_op = &romfs_super_ops; +#ifdef CONFIG_ROMFS_ON_MTD + /* Use same dev ID from the underlying mtdblock device */ + if (sb->s_mtd) + sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, sb->s_mtd->index); + else + sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, 0); +#endif /* read the image superblock and check it */ rsb = kmalloc(512, GFP_KERNEL); if (!rsb)