From: visa Date: Mon, 17 Sep 2018 14:56:37 +0000 (+0000) Subject: Simplify VFS initialization. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2a8e6c51f70d8aea8ab0b5351f5054af434ce93b;p=openbsd Simplify VFS initialization. Because loadable kernel modules are no longer, there is no need to register or unregister filesystem implementations at runtime. Remove vfs_register() and vfs_unregister(), and make vfsinit() call vfs_init routines directly. Replace the linked list of vfsconf structs with the vfsconflist[] array. OK mpi@ bluhm@ --- diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index 2448e1f6ad2..78301377e97 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_init.c,v 1.40 2018/09/16 11:41:44 visa Exp $ */ +/* $OpenBSD: vfs_init.c,v 1.41 2018/09/17 14:56:37 visa Exp $ */ /* $NetBSD: vfs_init.c,v 1.6 1996/02/09 19:00:58 christos Exp $ */ /* @@ -93,52 +93,52 @@ extern const struct vfsops tmpfs_vfsops; /* Set up the filesystem operations for vnodes. */ static struct vfsconf vfsconflist[] = { #ifdef FFS - { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, NULL, + { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, sizeof(struct ufs_args) }, #endif #ifdef MFS - { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, NULL, + { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, sizeof(struct mfs_args) }, #endif #ifdef EXT2FS - { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, NULL, + { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, sizeof(struct ufs_args) }, #endif #ifdef CD9660 - { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, NULL, + { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, sizeof(struct iso_args) }, #endif #ifdef MSDOSFS - { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL, + { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, sizeof(struct msdosfs_args) }, #endif #ifdef NFSCLIENT - { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, NULL, + { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, sizeof(struct nfs_args) }, #endif #ifdef NTFS - { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL, + { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, sizeof(struct ntfs_args) }, #endif #ifdef UDF - { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL, + { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, sizeof(struct iso_args) }, #endif #ifdef FUSE - { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, NULL, + { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, sizeof(struct fusefs_args) }, #endif #ifdef TMPFS - { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, NULL, + { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, sizeof(struct tmpfs_args) }, #endif }; @@ -149,15 +149,13 @@ static struct vfsconf vfsconflist[] = { * to the highest defined type number. */ int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf); -struct vfsconf *vfsconf = vfsconflist; /* Initialize the vnode structures and initialize each file system type. */ void vfsinit(void) { + struct vfsconf *vfsp; int i; - struct vfsconf *vfsconflist; - int vfsconflistlen; pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei", NULL); @@ -168,39 +166,36 @@ vfsinit(void) /* Initialize the vnode name cache. */ nchinit(); - /* - * Stop using vfsconf and maxvfsconf as a temporary storage, - * set them to their correct values now. - */ - vfsconflist = vfsconf; - vfsconflistlen = maxvfsconf; - vfsconf = NULL; maxvfsconf = 0; - - for (i = 0; i < vfsconflistlen; i++) - vfs_register(&vfsconflist[i]); + for (i = 0; i < nitems(vfsconflist); i++) { + vfsp = &vfsconflist[i]; + if (vfsp->vfc_typenum > maxvfsconf) + maxvfsconf = vfsp->vfc_typenum; + if (vfsp->vfc_vfsops->vfs_init != NULL) + (*vfsp->vfc_vfsops->vfs_init)(vfsp); + } } struct vfsconf * vfs_byname(const char *name) { - struct vfsconf *vfsp; + int i; - for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) { - if (strcmp(vfsp->vfc_name, name) == 0) - break; + for (i = 0; i < nitems(vfsconflist); i++) { + if (strcmp(vfsconflist[i].vfc_name, name) == 0) + return &vfsconflist[i]; } - return vfsp; + return NULL; } struct vfsconf * vfs_bytypenum(int typenum) { - struct vfsconf *vfsp; + int i; - for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) { - if (vfsp->vfc_typenum == typenum) - break; + for (i = 0; i < nitems(vfsconflist); i++) { + if (vfsconflist[i].vfc_typenum == typenum) + return &vfsconflist[i]; } - return vfsp; + return NULL; } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 997b636d009..1e1ed6e6ace 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.278 2018/09/16 11:41:44 visa Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.279 2018/09/17 14:56:37 visa Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -1329,7 +1329,6 @@ vfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, tmpvfsp = malloc(sizeof(*tmpvfsp), M_TEMP, M_WAITOK|M_ZERO); memcpy(tmpvfsp, vfsp, sizeof(*tmpvfsp)); tmpvfsp->vfc_vfsops = NULL; - tmpvfsp->vfc_next = NULL; ret = sysctl_rdstruct(oldp, oldlenp, newp, tmpvfsp, sizeof(struct vfsconf)); @@ -2112,72 +2111,6 @@ reassignbuf(struct buf *bp) bufinsvn(bp, listheadp); } -int -vfs_register(struct vfsconf *vfs) -{ - struct vfsconf *vfsp; - struct vfsconf **vfspp; - -#ifdef DIAGNOSTIC - /* Paranoia? */ - if (vfs->vfc_refcount != 0) - printf("vfs_register called with vfc_refcount > 0\n"); -#endif - - /* Check if filesystem already known */ - for (vfspp = &vfsconf, vfsp = vfsconf; vfsp; - vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next) - if (strcmp(vfsp->vfc_name, vfs->vfc_name) == 0) - return (EEXIST); - - if (vfs->vfc_typenum > maxvfsconf) - maxvfsconf = vfs->vfc_typenum; - - vfs->vfc_next = NULL; - - /* Add to the end of the list */ - *vfspp = vfs; - - /* Call vfs_init() */ - if (vfs->vfc_vfsops->vfs_init) - (*(vfs->vfc_vfsops->vfs_init))(vfs); - - return 0; -} - -int -vfs_unregister(struct vfsconf *vfs) -{ - struct vfsconf *vfsp; - struct vfsconf **vfspp; - int maxtypenum; - - /* Find our vfsconf struct */ - for (vfspp = &vfsconf, vfsp = vfsconf; vfsp; - vfspp = &vfsp->vfc_next, vfsp = vfsp->vfc_next) { - if (strcmp(vfsp->vfc_name, vfs->vfc_name) == 0) - break; - } - - if (!vfsp) /* Not found */ - return (ENOENT); - - if (vfsp->vfc_refcount) /* In use */ - return (EBUSY); - - /* Remove from list and free */ - *vfspp = vfsp->vfc_next; - - maxtypenum = 0; - - for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) - if (vfsp->vfc_typenum > maxtypenum) - maxtypenum = vfsp->vfc_typenum; - - maxvfsconf = maxtypenum; - return 0; -} - /* * Check if vnode represents a disk device */ diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 05b5243c8ef..4c54936cd04 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.h,v 1.139 2018/09/16 11:41:44 visa Exp $ */ +/* $OpenBSD: mount.h,v 1.140 2018/09/17 14:56:37 visa Exp $ */ /* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ /* @@ -456,7 +456,6 @@ struct vfsconf { int vfc_typenum; /* historic filesystem type number */ int vfc_refcount; /* number mounted of this type */ int vfc_flags; /* permanent flags */ - struct vfsconf *vfc_next; /* next in list */ size_t vfc_datasize; /* size of data args */ }; @@ -500,7 +499,6 @@ struct nameidata; struct mbuf; extern int maxvfsconf; /* highest defined filesystem type */ -extern struct vfsconf *vfsconf; /* head of list of filesystem types */ struct vfsops { int (*vfs_mount)(struct mount *mp, const char *path, @@ -600,8 +598,6 @@ int vfs_syncwait(struct proc *, int); /* sync and wait for complete */ void vfs_shutdown(struct proc *); /* unmount and sync file systems */ int dounmount(struct mount *, int, struct proc *); void vfsinit(void); -int vfs_register(struct vfsconf *); -int vfs_unregister(struct vfsconf *); struct vfsconf *vfs_byname(const char *); struct vfsconf *vfs_bytypenum(int); #else /* _KERNEL */