Deleted Added
full compact
vfs_mount.c (182371) vfs_mount.c (182542)
1/*-
2 * Copyright (c) 1999-2004 Poul-Henning Kamp
3 * Copyright (c) 1999 Michael Smith
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

--- 21 unchanged lines hidden (view full) ---

30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1999-2004 Poul-Henning Kamp
3 * Copyright (c) 1999 Michael Smith
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph

--- 21 unchanged lines hidden (view full) ---

30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/kern/vfs_mount.c 182371 2008-08-28 15:23:18Z attilio $");
38__FBSDID("$FreeBSD: head/sys/kern/vfs_mount.c 182542 2008-08-31 14:26:08Z attilio $");
39
40#include <sys/param.h>
41#include <sys/conf.h>
42#include <sys/fcntl.h>
43#include <sys/jail.h>
44#include <sys/kernel.h>
45#include <sys/libkern.h>
46#include <sys/malloc.h>

--- 420 unchanged lines hidden (view full) ---

467 lockdestroy(&mp->mnt_lock);
468 mtx_destroy(&mp->mnt_mtx);
469}
470
471/*
472 * Allocate and initialize the mount point struct.
473 */
474struct mount *
39
40#include <sys/param.h>
41#include <sys/conf.h>
42#include <sys/fcntl.h>
43#include <sys/jail.h>
44#include <sys/kernel.h>
45#include <sys/libkern.h>
46#include <sys/malloc.h>

--- 420 unchanged lines hidden (view full) ---

467 lockdestroy(&mp->mnt_lock);
468 mtx_destroy(&mp->mnt_mtx);
469}
470
471/*
472 * Allocate and initialize the mount point struct.
473 */
474struct mount *
475vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp,
476 const char *fspath, struct thread *td)
475vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp, const char *fspath,
476 struct ucred *cred)
477{
478 struct mount *mp;
479
480 mp = uma_zalloc(mount_zone, M_WAITOK);
481 bzero(&mp->mnt_startzero,
482 __rangeof(struct mount, mnt_startzero, mnt_endzero));
483 TAILQ_INIT(&mp->mnt_nvnodelist);
484 mp->mnt_nvnodelistsize = 0;
485 mp->mnt_ref = 0;
477{
478 struct mount *mp;
479
480 mp = uma_zalloc(mount_zone, M_WAITOK);
481 bzero(&mp->mnt_startzero,
482 __rangeof(struct mount, mnt_startzero, mnt_endzero));
483 TAILQ_INIT(&mp->mnt_nvnodelist);
484 mp->mnt_nvnodelistsize = 0;
485 mp->mnt_ref = 0;
486 (void) vfs_busy(mp, LK_NOWAIT, 0, td);
486 (void) vfs_busy(mp, LK_NOWAIT, 0);
487 mp->mnt_op = vfsp->vfc_vfsops;
488 mp->mnt_vfc = vfsp;
489 vfsp->vfc_refcount++; /* XXX Unlocked */
490 mp->mnt_stat.f_type = vfsp->vfc_typenum;
491 mp->mnt_gen++;
492 strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
493 mp->mnt_vnodecovered = vp;
487 mp->mnt_op = vfsp->vfc_vfsops;
488 mp->mnt_vfc = vfsp;
489 vfsp->vfc_refcount++; /* XXX Unlocked */
490 mp->mnt_stat.f_type = vfsp->vfc_typenum;
491 mp->mnt_gen++;
492 strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
493 mp->mnt_vnodecovered = vp;
494 mp->mnt_cred = crdup(td->td_ucred);
495 mp->mnt_stat.f_owner = td->td_ucred->cr_uid;
494 mp->mnt_cred = crdup(cred);
495 mp->mnt_stat.f_owner = cred->cr_uid;
496 strlcpy(mp->mnt_stat.f_mntonname, fspath, MNAMELEN);
497 mp->mnt_iosize_max = DFLTPHYS;
498#ifdef MAC
499 mac_mount_init(mp);
496 strlcpy(mp->mnt_stat.f_mntonname, fspath, MNAMELEN);
497 mp->mnt_iosize_max = DFLTPHYS;
498#ifdef MAC
499 mac_mount_init(mp);
500 mac_mount_create(td->td_ucred, mp);
500 mac_mount_create(cred, mp);
501#endif
502 arc4rand(&mp->mnt_hashseed, sizeof mp->mnt_hashseed, 0);
503 return (mp);
504}
505
506/*
507 * Destroy the mount struct previously allocated by vfs_mount_alloc().
508 */

--- 418 unchanged lines hidden (view full) ---

927 * Only privileged root, or (if MNT_USER is set) the user that
928 * did the original mount is permitted to update it.
929 */
930 error = vfs_suser(mp, td);
931 if (error) {
932 vput(vp);
933 return (error);
934 }
501#endif
502 arc4rand(&mp->mnt_hashseed, sizeof mp->mnt_hashseed, 0);
503 return (mp);
504}
505
506/*
507 * Destroy the mount struct previously allocated by vfs_mount_alloc().
508 */

--- 418 unchanged lines hidden (view full) ---

927 * Only privileged root, or (if MNT_USER is set) the user that
928 * did the original mount is permitted to update it.
929 */
930 error = vfs_suser(mp, td);
931 if (error) {
932 vput(vp);
933 return (error);
934 }
935 if (vfs_busy(mp, LK_NOWAIT, 0, td)) {
935 if (vfs_busy(mp, LK_NOWAIT, 0)) {
936 vput(vp);
937 return (EBUSY);
938 }
939 VI_LOCK(vp);
940 if ((vp->v_iflag & VI_MOUNT) != 0 ||
941 vp->v_mountedhere != NULL) {
942 VI_UNLOCK(vp);
936 vput(vp);
937 return (EBUSY);
938 }
939 VI_LOCK(vp);
940 if ((vp->v_iflag & VI_MOUNT) != 0 ||
941 vp->v_mountedhere != NULL) {
942 VI_UNLOCK(vp);
943 vfs_unbusy(mp, td);
943 vfs_unbusy(mp);
944 vput(vp);
945 return (EBUSY);
946 }
947 vp->v_iflag |= VI_MOUNT;
948 VI_UNLOCK(vp);
949 MNT_ILOCK(mp);
950 mp->mnt_flag |= fsflags &
951 (MNT_RELOAD | MNT_FORCE | MNT_UPDATE | MNT_SNAPSHOT | MNT_ROOTFS);

--- 36 unchanged lines hidden (view full) ---

988 return (EBUSY);
989 }
990 vp->v_iflag |= VI_MOUNT;
991 VI_UNLOCK(vp);
992
993 /*
994 * Allocate and initialize the filesystem.
995 */
944 vput(vp);
945 return (EBUSY);
946 }
947 vp->v_iflag |= VI_MOUNT;
948 VI_UNLOCK(vp);
949 MNT_ILOCK(mp);
950 mp->mnt_flag |= fsflags &
951 (MNT_RELOAD | MNT_FORCE | MNT_UPDATE | MNT_SNAPSHOT | MNT_ROOTFS);

--- 36 unchanged lines hidden (view full) ---

988 return (EBUSY);
989 }
990 vp->v_iflag |= VI_MOUNT;
991 VI_UNLOCK(vp);
992
993 /*
994 * Allocate and initialize the filesystem.
995 */
996 mp = vfs_mount_alloc(vp, vfsp, fspath, td);
996 mp = vfs_mount_alloc(vp, vfsp, fspath, td->td_ucred);
997 VOP_UNLOCK(vp, 0);
998
999 /* XXXMAC: pass to vfs_mount_alloc? */
1000 mp->mnt_optnew = fsdata;
1001 }
1002
1003 /*
1004 * Set the mount level flags.

--- 49 unchanged lines hidden (view full) ---

1054 if ((mp->mnt_flag & MNT_RDONLY) == 0) {
1055 if (mp->mnt_syncer == NULL)
1056 error = vfs_allocate_syncvnode(mp);
1057 } else {
1058 if (mp->mnt_syncer != NULL)
1059 vrele(mp->mnt_syncer);
1060 mp->mnt_syncer = NULL;
1061 }
997 VOP_UNLOCK(vp, 0);
998
999 /* XXXMAC: pass to vfs_mount_alloc? */
1000 mp->mnt_optnew = fsdata;
1001 }
1002
1003 /*
1004 * Set the mount level flags.

--- 49 unchanged lines hidden (view full) ---

1054 if ((mp->mnt_flag & MNT_RDONLY) == 0) {
1055 if (mp->mnt_syncer == NULL)
1056 error = vfs_allocate_syncvnode(mp);
1057 } else {
1058 if (mp->mnt_syncer != NULL)
1059 vrele(mp->mnt_syncer);
1060 mp->mnt_syncer = NULL;
1061 }
1062 vfs_unbusy(mp, td);
1062 vfs_unbusy(mp);
1063 VI_LOCK(vp);
1064 vp->v_iflag &= ~VI_MOUNT;
1065 VI_UNLOCK(vp);
1066 vrele(vp);
1067 return (error);
1068 }
1069 MNT_ILOCK(mp);
1070 if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0)

--- 19 unchanged lines hidden (view full) ---

1090 vfs_event_signal(NULL, VQ_MOUNT, 0);
1091 if (VFS_ROOT(mp, LK_EXCLUSIVE, &newdp, td))
1092 panic("mount: lost mount");
1093 mountcheckdirs(vp, newdp);
1094 vput(newdp);
1095 VOP_UNLOCK(vp, 0);
1096 if ((mp->mnt_flag & MNT_RDONLY) == 0)
1097 error = vfs_allocate_syncvnode(mp);
1063 VI_LOCK(vp);
1064 vp->v_iflag &= ~VI_MOUNT;
1065 VI_UNLOCK(vp);
1066 vrele(vp);
1067 return (error);
1068 }
1069 MNT_ILOCK(mp);
1070 if ((mp->mnt_flag & MNT_ASYNC) != 0 && mp->mnt_noasync == 0)

--- 19 unchanged lines hidden (view full) ---

1090 vfs_event_signal(NULL, VQ_MOUNT, 0);
1091 if (VFS_ROOT(mp, LK_EXCLUSIVE, &newdp, td))
1092 panic("mount: lost mount");
1093 mountcheckdirs(vp, newdp);
1094 vput(newdp);
1095 VOP_UNLOCK(vp, 0);
1096 if ((mp->mnt_flag & MNT_RDONLY) == 0)
1097 error = vfs_allocate_syncvnode(mp);
1098 vfs_unbusy(mp, td);
1098 vfs_unbusy(mp);
1099 if (error)
1100 vrele(vp);
1101 } else {
1102 VI_LOCK(vp);
1103 vp->v_iflag &= ~VI_MOUNT;
1104 VI_UNLOCK(vp);
1099 if (error)
1100 vrele(vp);
1101 } else {
1102 VI_LOCK(vp);
1103 vp->v_iflag &= ~VI_MOUNT;
1104 VI_UNLOCK(vp);
1105 vfs_unbusy(mp, td);
1105 vfs_unbusy(mp);
1106 vfs_mount_destroy(mp);
1107 vput(vp);
1108 }
1109 return (error);
1110}
1111
1112/*
1113 * Unmount a filesystem.

--- 395 unchanged lines hidden (view full) ---

1509 struct mount *mp = NULL;
1510 int error;
1511
1512 vfsp = vfs_byname("devfs");
1513 KASSERT(vfsp != NULL, ("Could not find devfs by name"));
1514 if (vfsp == NULL)
1515 return;
1516
1106 vfs_mount_destroy(mp);
1107 vput(vp);
1108 }
1109 return (error);
1110}
1111
1112/*
1113 * Unmount a filesystem.

--- 395 unchanged lines hidden (view full) ---

1509 struct mount *mp = NULL;
1510 int error;
1511
1512 vfsp = vfs_byname("devfs");
1513 KASSERT(vfsp != NULL, ("Could not find devfs by name"));
1514 if (vfsp == NULL)
1515 return;
1516
1517 mp = vfs_mount_alloc(NULLVP, vfsp, "/dev", td);
1517 mp = vfs_mount_alloc(NULLVP, vfsp, "/dev", td->td_ucred);
1518
1519 error = VFS_MOUNT(mp, td);
1520 KASSERT(error == 0, ("VFS_MOUNT(devfs) failed %d", error));
1521 if (error)
1522 return;
1523
1524 opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK);
1525 TAILQ_INIT(opts);

--- 58 unchanged lines hidden (view full) ---

1584 cache_purge(vp);
1585 mp->mnt_vnodecovered = vp;
1586 vp->v_mountedhere = mp;
1587 mtx_lock(&mountlist_mtx);
1588 TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
1589 mtx_unlock(&mountlist_mtx);
1590 VOP_UNLOCK(vp, 0);
1591 vput(dvp);
1518
1519 error = VFS_MOUNT(mp, td);
1520 KASSERT(error == 0, ("VFS_MOUNT(devfs) failed %d", error));
1521 if (error)
1522 return;
1523
1524 opts = malloc(sizeof(struct vfsoptlist), M_MOUNT, M_WAITOK);
1525 TAILQ_INIT(opts);

--- 58 unchanged lines hidden (view full) ---

1584 cache_purge(vp);
1585 mp->mnt_vnodecovered = vp;
1586 vp->v_mountedhere = mp;
1587 mtx_lock(&mountlist_mtx);
1588 TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
1589 mtx_unlock(&mountlist_mtx);
1590 VOP_UNLOCK(vp, 0);
1591 vput(dvp);
1592 vfs_unbusy(mp, td);
1592 vfs_unbusy(mp);
1593
1594 /* Unlink the no longer needed /dev/dev -> / symlink */
1595 kern_unlink(td, "/dev/dev", UIO_SYSSPACE);
1596}
1597
1598/*
1599 * Report errors during filesystem mounting.
1600 */

--- 728 unchanged lines hidden ---
1593
1594 /* Unlink the no longer needed /dev/dev -> / symlink */
1595 kern_unlink(td, "/dev/dev", UIO_SYSSPACE);
1596}
1597
1598/*
1599 * Report errors during filesystem mounting.
1600 */

--- 728 unchanged lines hidden ---