[RFC 2/6] sysfs-mount.patch

From: Maneesh Soni
Date: Mon Oct 06 2003 - 04:02:35 EST




o This patch provides mount related changes for sysfs backing store. Now,
sysfs_init() just registers the sysfs filesystem and do not mount it.

o The global sysfs_mount indicates whether sysfs is mounted or not. For this
we initialize it in fs/super.c:do_kern_mount(). It looks like more of a hack.

o We also have new dir_operations and dir_inode_operations structs for sysfs
directories including the root directory.

o sysfs inode links are obtained from sysfs_get_link_count().


fs/super.c | 5 +++++
fs/sysfs/mount.c | 26 ++++++--------------------
init/do_mounts.c | 1 +
3 files changed, 12 insertions(+), 20 deletions(-)

diff -puN init/do_mounts.c~sysfs-mount init/do_mounts.c
--- linux-2.6.0-test6/init/do_mounts.c~sysfs-mount 2003-10-06 11:54:59.000000000 +0530
+++ linux-2.6.0-test6-maneesh/init/do_mounts.c 2003-10-06 11:55:14.000000000 +0530
@@ -189,6 +189,7 @@ done:
sys_umount("/sys", 0);
out:
sys_rmdir("/sys");
+ sysfs_mount = NULL;
return res;
fail:
res = 0;
diff -puN fs/super.c~sysfs-mount fs/super.c
--- linux-2.6.0-test6/fs/super.c~sysfs-mount 2003-10-06 11:55:03.000000000 +0530
+++ linux-2.6.0-test6-maneesh/fs/super.c 2003-10-06 11:55:14.000000000 +0530
@@ -32,6 +32,7 @@
#include <linux/security.h>
#include <linux/vfs.h>
#include <linux/writeback.h> /* for the emergency remount stuff */
+#include <linux/sysfs.h>
#include <asm/uaccess.h>


@@ -692,6 +693,10 @@ do_kern_mount(const char *fstype, int fl
mnt->mnt_mountpoint = sb->s_root;
mnt->mnt_parent = mnt;
up_write(&sb->s_umount);
+
+ if (!strcmp(fstype, "sysfs"))
+ sysfs_mount = mnt;
+
put_filesystem(type);
return mnt;
out_sb:
diff -puN fs/sysfs/mount.c~sysfs-mount fs/sysfs/mount.c
--- linux-2.6.0-test6/fs/sysfs/mount.c~sysfs-mount 2003-10-06 11:55:07.000000000 +0530
+++ linux-2.6.0-test6-maneesh/fs/sysfs/mount.c 2003-10-06 11:55:14.000000000 +0530
@@ -2,8 +2,6 @@
* mount.c - operations for initializing and mounting sysfs.
*/

-#define DEBUG
-
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/pagemap.h>
@@ -14,7 +12,7 @@
/* Random magic number */
#define SYSFS_MAGIC 0x62656572

-struct vfsmount *sysfs_mount;
+struct vfsmount *sysfs_mount = NULL;
struct super_block * sysfs_sb = NULL;

static struct super_operations sysfs_ops = {
@@ -35,10 +33,9 @@ static int sysfs_fill_super(struct super

inode = sysfs_new_inode(S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
if (inode) {
- inode->i_op = &simple_dir_inode_operations;
- inode->i_fop = &simple_dir_operations;
- /* directory inodes start off with i_nlink == 2 (for "." entry) */
- inode->i_nlink++;
+ inode->i_op = &sysfs_dir_inode_operations;
+ inode->i_fop = &sysfs_dir_operations;
+ inode->i_nlink += sysfs_get_link_count(NULL);
} else {
pr_debug("sysfs: could not get root inode\n");
return -ENOMEM;
@@ -63,21 +60,10 @@ static struct super_block *sysfs_get_sb(
static struct file_system_type sysfs_fs_type = {
.name = "sysfs",
.get_sb = sysfs_get_sb,
- .kill_sb = kill_litter_super,
+ .kill_sb = kill_anon_super,
};

int __init sysfs_init(void)
{
- int err;
-
- err = register_filesystem(&sysfs_fs_type);
- if (!err) {
- sysfs_mount = kern_mount(&sysfs_fs_type);
- if (IS_ERR(sysfs_mount)) {
- printk(KERN_ERR "sysfs: could not mount!\n");
- err = PTR_ERR(sysfs_mount);
- sysfs_mount = NULL;
- }
- }
- return err;
+ return register_filesystem(&sysfs_fs_type);
}

_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@xxxxxxxxxx
Phone: 91-80-5044999 Fax: 91-80-5268553
T/L : 9243696
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/