From 9600d3df3e1b75cff0e3ecd20ae3ca2fe393eb8b Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 21 Nov 2025 13:59:34 -0500 Subject: kern: vfs: Decouple mounting from initialization Upon bootup, all filesystems are to be enumerated and initialized before they are mounted. Some filesystems may decide to mount themselves right away. However, it is crucial to keep mounting and initialization seperate. Signed-off-by: Ian Moffett --- sys/fs/tmpfs.c | 18 ++++++++++++++++-- sys/inc/kern/mount.h | 6 +++--- sys/kern/vfs_init.c | 11 +++++------ sys/kern/vfs_mount.c | 8 +++++++- 4 files changed, 31 insertions(+), 12 deletions(-) (limited to 'sys') diff --git a/sys/fs/tmpfs.c b/sys/fs/tmpfs.c index cb18b6b..5ac69b1 100644 --- a/sys/fs/tmpfs.c +++ b/sys/fs/tmpfs.c @@ -34,7 +34,20 @@ * Mount a filesystem */ static int -tmpfs_mount(struct fs_info *fip, void *data) +tmpfs_mount(struct fs_info *fip, struct mount *mp) +{ + int error; + + error = vnode_init(&mp->vp, VDIR); + if (error < 0) { + return error; + } + + return 0; +} + +static int +tmpfs_init(struct fs_info *fip) { struct mount_args mountargs; int error; @@ -50,5 +63,6 @@ tmpfs_mount(struct fs_info *fip, void *data) } struct vfsops g_tmpfs_ops = { - .mount = tmpfs_mount + .mount = tmpfs_mount, + .init = tmpfs_init }; diff --git a/sys/inc/kern/mount.h b/sys/inc/kern/mount.h index 1c3dde6..747514c 100644 --- a/sys/inc/kern/mount.h +++ b/sys/inc/kern/mount.h @@ -37,6 +37,7 @@ /* Filesystem names */ #define MOUNT_TMPFS "tmpfs" +struct mount; struct fs_info; /* @@ -55,7 +56,8 @@ struct mount_args { * on filesystem objects */ struct vfsops { - int(*mount)(struct fs_info *fip, void *data); + int(*mount)(struct fs_info *fip, struct mount *mpoint); + int(*init)(struct fs_info *fip); }; /* @@ -63,12 +65,10 @@ struct vfsops { * * @name: Name of filesystem * @vfsops: Represents operations that can be performed - * @is_mounted: Set if filesystem is mounted */ struct fs_info { char *name; struct vfsops *vfsops; - uint8_t is_mounted : 1; }; /* diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index 6372f3d..08be17a 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -87,18 +87,17 @@ vfs_init(void) continue; } - /* Mount if we can */ - if (ops->mount != NULL) { - error = ops->mount(fip, NULL); + /* Initialize the filesystem */ + if (ops->init != NULL) { + error = ops->init(fip); } if (error != 0) { - dtrace("failed to mount %s\n", fip->name); + dtrace("failed to init %s\n", fip->name); continue; } - dtrace("mounted %s\n", fip->name); - fip->is_mounted = 1; + dtrace("initialized %s\n", fip->name); ++mount_count; } diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 51a464a..39f98d2 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -74,6 +74,7 @@ int mount(struct mount_args *margs) { struct fs_info *fip; + struct vfsops *vfsops; struct mount *mp; int error; @@ -95,13 +96,18 @@ mount(struct mount_args *margs) return error; } + vfsops = fip->vfsops; + if (vfsops->mount == NULL) { + return -ENOTSUP; + } + mp = kalloc(sizeof(*mp)); if (mp == NULL) { return -ENOMEM; } mp->fip = fip; - error = vnode_init(&mp->vp, VDIR); + error = vfsops->mount(fip, mp); if (error < 0) { kfree(mp); return error; -- cgit v1.2.3