diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/include/sys/vfs.h | 4 | ||||
-rw-r--r-- | sys/kern/vfs_init.c | 7 | ||||
-rw-r--r-- | sys/kern/vfs_mount.c (renamed from sys/kern/vfs_cache.c) | 49 | ||||
-rw-r--r-- | sys/kern/vfs_subr.c | 36 |
4 files changed, 33 insertions, 63 deletions
diff --git a/sys/include/sys/vfs.h b/sys/include/sys/vfs.h index 2c056a1..40b27af 100644 --- a/sys/include/sys/vfs.h +++ b/sys/include/sys/vfs.h @@ -42,10 +42,6 @@ struct vnode *vfs_path_to_node(const char *path); char *vfs_get_fname_at(const char *path, size_t idx); bool vfs_is_valid_path(const char *path); size_t vfs_hash_path(const char *path); - -void vfs_init_cache(void); -int vfs_cache_mp(struct mount *mp, const char *path); -int vfs_cache_fetch_mp(const char *path, struct mount **mp); #endif /* defined(_KERNEL) */ #endif /* !_SYS_VFS_H_ */ diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index bcda0dd..8decace 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -61,7 +61,7 @@ vfs_init(void) struct fs_info *info; struct vfsops *vfsops; - vfs_init_cache(); + vfs_mount_init(); for (int i = 0; i < __ARRAY_COUNT(filesystems); ++i) { info = &filesystems[i]; @@ -69,10 +69,5 @@ vfs_init(void) __assert(vfsops->init != NULL); vfsops->init(info); - - if (strcmp(info->name, "initramfs") == 0) { - /* Initramfs must be mounted */ - vfs_mount(&info->mp_root, "/ramdisk", MNT_RDONLY); - } } } diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_mount.c index fe31c75..53df6a2 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_mount.c @@ -35,38 +35,58 @@ #include <vm/dynalloc.h> #include <assert.h> -/* For caching */ +/* TODO: Make this more flexible */ #define MOUNTLIST_SIZE 8 -/* Mountlist cache entry */ +/* Mountlist entry */ struct mountlist_entry { TAILQ_HEAD(, mount) buckets; }; static struct mountlist_entry *mountlist = NULL; +static int +vfs_create_mp(const char *path, int mntflags, struct mount **mp_out) +{ + struct mount *mp; + + mp = dynalloc(sizeof(struct mount)); + if (mp == NULL) { + return -ENOMEM; + } + + mp->flags = mntflags; + *mp_out = mp; + return 0; +} + /* - * Cache a mountpoint + * Mount a mountpoint * - * @mp: Mountpoint to cache + * @mp: Mountpoint to mount * @path: Path this mountpoint belongs to * - * If this cache entry already exists, -EEXIST + * If this mount entry already exists, -EEXIST * will be returned. */ int -vfs_cache_mp(struct mount *mp, const char *path) +vfs_mount(const char *path, int mntflags) { size_t hash = vfs_hash_path(path); + int status; struct mountlist_entry *entry; + struct mount *mp; + if ((status = vfs_create_mp(path, mntflags, &mp)) != 0) { + return status; + } if (hash == 0) { /* Something is wrong with the path */ return -EINVAL; } - if (vfs_cache_fetch_mp(path, NULL) == 0) { - /* Cache hit, do not duplicate this entry */ + if (vfs_get_mp(path, NULL) == 0) { + /* mount hit, do not duplicate this entry */ return -EEXIST; } @@ -77,17 +97,17 @@ vfs_cache_mp(struct mount *mp, const char *path) } /* - * Fetch mountpoint from cache + * Fetch mountpoint * * @path: Path of target mountpoint * @mp: Pointer of variable where mountpoint fetched will * be stored * - * Returns 0 upon a cache hit, on a cache miss this + * Returns 0 upon a mplist hit, on a mplist miss this * function returns -ENOENT. */ int -vfs_cache_fetch_mp(const char *path, struct mount **mp) +vfs_get_mp(const char *path, struct mount **mp) { size_t hash = vfs_hash_path(path); struct mountlist_entry *entry; @@ -101,21 +121,16 @@ vfs_cache_fetch_mp(const char *path, struct mount **mp) entry = &mountlist[hash % MOUNTLIST_SIZE]; TAILQ_FOREACH(mount_iter, &entry->buckets, link) { if (mount_iter->phash == hash) { - /* Cache hit */ if (mp != NULL) *mp = mount_iter; return 0; } } - /* Cache miss */ return -ENOENT; } -/* - * Init all caches - */ void -vfs_init_cache(void) +vfs_mount_init(void) { mountlist = dynalloc(sizeof(struct mountlist_entry) * MOUNTLIST_SIZE); __assert(mountlist != NULL); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 6646f79..ac8a16b 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -158,39 +158,3 @@ vfs_alloc_vnode(struct vnode **vnode, struct mount *mp, int type) *vnode = new_vnode; return 0; } - -/* - * This function mounts a `mount' structure - * at a specific path. - * - * @mp_out: Where to store copy of new mountpoint (NULL if none) - * @path: Path to mount on. - * @mnt_flags: Mount flags (MNT_* from sys/mount.h) - * - * Returns 0 upon success, otherwise a < 0 value. - * - * XXX: This function assumes the mountpoint has its mount - * routine set in its vfsops. - */ -int -vfs_mount(struct mount **mp_out, const char *path, int mnt_flags) -{ - struct mount *mp; - int cache_status; - - mp = dynalloc(sizeof(struct mount)); - if (mp == NULL) { - return -ENOMEM; - } - - mp->flags = mnt_flags; - cache_status = vfs_cache_mp(mp, path); - - if (cache_status != 0) { - dynfree(mp); - return cache_status; - } - - *mp_out = mp; - return 0; -} |