Module Name: src Committed By: dyoung Date: Wed Apr 29 01:03:43 UTC 2009
Modified Files: src/sys/kern: vfs_subr.c vfs_syscalls.c Log Message: Extract common code from vfs_rootmountalloc(9) and mount_domount() into a new struct mount-allocation routine, vfs_mountalloc(9). Documentation updates will follow. Attention: Synchronization Oversight Committee! In mount_domount(), I postpone the call mutex_enter(&mp->mnt_updating) until right before the VFS_MOUNT(9) call because (1) that looks to me like the earliest possible opportunity for mp to become visible to any other LWP, because it was just kmem_zalloc(9)'d and (2) it made extracting the common code much easier. Tell me if my reasoning is faulty. To generate a diff of this commit: cvs rdiff -u -r1.375 -r1.376 src/sys/kern/vfs_subr.c cvs rdiff -u -r1.392 -r1.393 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_subr.c diff -u src/sys/kern/vfs_subr.c:1.375 src/sys/kern/vfs_subr.c:1.376 --- src/sys/kern/vfs_subr.c:1.375 Sat Apr 25 18:53:44 2009 +++ src/sys/kern/vfs_subr.c Wed Apr 29 01:03:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.375 2009/04/25 18:53:44 elad Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.376 2009/04/29 01:03:43 dyoung Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. @@ -81,7 +81,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.375 2009/04/25 18:53:44 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.376 2009/04/29 01:03:43 dyoung Exp $"); #include "opt_ddb.h" #include "opt_compat_netbsd.h" @@ -455,6 +455,30 @@ } } +struct mount * +vfs_mountalloc(struct vfsops *vfsops, struct vnode *vp) +{ + int error; + struct mount *mp; + + mp = kmem_zalloc(sizeof(*mp), KM_SLEEP); + if (mp == NULL) + return NULL; + + mp->mnt_op = vfsops; + mp->mnt_refcnt = 1; + TAILQ_INIT(&mp->mnt_vnodelist); + rw_init(&mp->mnt_unmounting); + mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE); + mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE); + error = vfs_busy(mp, NULL); + KASSERT(error == 0); + mp->mnt_vnodecovered = vp; + mount_initspecific(mp); + + return mp; +} + /* * Lookup a filesystem type, and if found allocate and initialize * a mount structure for it. @@ -480,18 +504,9 @@ vfsp->vfs_refcount++; mutex_exit(&vfs_list_lock); - mp = kmem_zalloc(sizeof(*mp), KM_SLEEP); - if (mp == NULL) + if ((mp = vfs_mountalloc(vfsp, NULL)) == NULL) return ENOMEM; - mp->mnt_refcnt = 1; - rw_init(&mp->mnt_unmounting); - mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE); - mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE); - (void)vfs_busy(mp, NULL); - TAILQ_INIT(&mp->mnt_vnodelist); - mp->mnt_op = vfsp; mp->mnt_flag = MNT_RDONLY; - mp->mnt_vnodecovered = NULL; (void)strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfs_name, sizeof(mp->mnt_stat.f_fstypename)); mp->mnt_stat.f_mntonname[0] = '/'; @@ -500,7 +515,6 @@ '\0'; (void)copystr(devname, mp->mnt_stat.f_mntfromname, sizeof(mp->mnt_stat.f_mntfromname) - 1, 0); - mount_initspecific(mp); *mpp = mp; return (0); } Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.392 src/sys/kern/vfs_syscalls.c:1.393 --- src/sys/kern/vfs_syscalls.c:1.392 Tue Apr 28 03:01:15 2009 +++ src/sys/kern/vfs_syscalls.c Wed Apr 29 01:03:43 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.392 2009/04/28 03:01:15 yamt Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.393 2009/04/29 01:03:43 dyoung Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.392 2009/04/28 03:01:15 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.393 2009/04/29 01:03:43 dyoung Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -332,24 +332,10 @@ if (vp->v_mountedhere != NULL) return EBUSY; - mp = kmem_zalloc(sizeof(*mp), KM_SLEEP); - if (mp == NULL) + if ((mp = vfs_mountalloc(vfsops, vp)) == NULL) return ENOMEM; - mp->mnt_op = vfsops; - mp->mnt_refcnt = 1; - - TAILQ_INIT(&mp->mnt_vnodelist); - rw_init(&mp->mnt_unmounting); - mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE); - mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE); - error = vfs_busy(mp, NULL); - KASSERT(error == 0); - mutex_enter(&mp->mnt_updating); - - mp->mnt_vnodecovered = vp; mp->mnt_stat.f_owner = kauth_cred_geteuid(l->l_cred); - mount_initspecific(mp); /* * The underlying file system may refuse the mount for @@ -363,6 +349,7 @@ MNT_NOATIME | MNT_NODEVMTIME | MNT_SYMPERM | MNT_SOFTDEP | MNT_LOG | MNT_IGNORE | MNT_RDONLY); + mutex_enter(&mp->mnt_updating); error = VFS_MOUNT(mp, path, data, data_len); mp->mnt_flag &= ~MNT_OP_FLAGS;