Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Whoops -- move the location of the VOP_OPEN()/VOP_CLOSE(...



details:   https://anonhg.NetBSD.org/src/rev/09dead486c6f
branches:  trunk
changeset: 572619:09dead486c6f
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Sun Jan 09 09:27:17 2005 +0000

description:
Whoops -- move the location of the VOP_OPEN()/VOP_CLOSE(), et al, from
foo_mountfs() to foo_mount(), to match the new mountroot API.
Also, for ext2fs and lfs, copy some restructuring from ffs to allow changing
file system parameters without specifying the device name.
(ntfs could use some more work.)

diffstat:

 sys/fs/ntfs/ntfs_vfsops.c      |  140 ++++++++++----------------
 sys/ufs/ext2fs/ext2fs_vfsops.c |  212 ++++++++++++++++++++++++----------------
 sys/ufs/lfs/lfs_vfsops.c       |  194 +++++++++++++++++++++++--------------
 3 files changed, 301 insertions(+), 245 deletions(-)

diffs (truncated from 856 to 300 lines):

diff -r 7ea1d3be9792 -r 09dead486c6f sys/fs/ntfs/ntfs_vfsops.c
--- a/sys/fs/ntfs/ntfs_vfsops.c Sun Jan 09 07:31:31 2005 +0000
+++ b/sys/fs/ntfs/ntfs_vfsops.c Sun Jan 09 09:27:17 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntfs_vfsops.c,v 1.27 2005/01/09 03:11:48 mycroft Exp $ */
+/*     $NetBSD: ntfs_vfsops.c,v 1.28 2005/01/09 09:27:17 mycroft Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999 Semen Ustimenko
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.27 2005/01/09 03:11:48 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.28 2005/01/09 09:27:17 mycroft Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -266,43 +266,10 @@
        struct nameidata *ndp,
        struct proc *p )
 {
-       int             err = 0;
+       int             err = 0, flags;
        struct vnode    *devvp;
        struct ntfs_args args;
 
-#ifdef __FreeBSD__
-       /*
-        * Use NULL path to flag a root mount
-        */
-       if( path == NULL) {
-               /*
-                ***
-                * Mounting root file system
-                ***
-                */
-       
-               /* Get vnode for root device*/
-               if( bdevvp( rootdev, &rootvp))
-                       panic("ffs_mountroot: can't setup bdevvp for root");
-
-               /*
-                * FS specific handling
-                */
-               mp->mnt_flag |= MNT_RDONLY;     /* XXX globally applicable?*/
-
-               /*
-                * Attempt mount
-                */
-               if( ( err = ntfs_mountfs(rootvp, mp, &args, p)) != 0) {
-                       /* fs specific cleanup (if any)*/
-                       goto error_1;
-               }
-
-               goto dostatvfs;         /* success*/
-
-       }
-#endif /* FreeBSD */
-
        if (mp->mnt_flag & MNT_GETARGS) {
                struct ntfsmount *ntmp = VFSTONTFS(mp);
                if (ntmp == NULL)
@@ -324,7 +291,7 @@
        /* copy in user arguments*/
        err = copyin(data, &args, sizeof (struct ntfs_args));
        if (err)
-               goto error_1;           /* can't get arguments*/
+               return (err);           /* can't get arguments*/
 
        /*
         * If updating, check whether changing from read-only to
@@ -338,13 +305,11 @@
                         * will return the vfs_export() error code.
                         */
                        struct ntfsmount *ntm = VFSTONTFS(mp);
-                       err = vfs_export(mp, &ntm->ntm_export, &args.export);
-                       goto success;
+                       return (vfs_export(mp, &ntm->ntm_export, &args.export));
                }
 
                printf("ntfs_mount(): MNT_UPDATE not supported\n");
-               err = EINVAL;
-               goto error_1;
+               return (EINVAL);
        }
 
        /*
@@ -355,14 +320,14 @@
        err = namei(ndp);
        if (err) {
                /* can't get devvp!*/
-               goto error_1;
+               return (err);
        }
 
        devvp = ndp->ni_vp;
 
        if (devvp->v_type != VBLK) {
                err = ENOTBLK;
-               goto error_2;
+               goto fail;
        }
 #ifdef __FreeBSD__
        if (bdevsw(devvp->v_rdev) == NULL) {
@@ -370,7 +335,7 @@
        if (bdevsw_lookup(devvp->v_rdev) == NULL) {
 #endif
                err = ENXIO;
-               goto error_2;
+               goto fail;
        }
        if (mp->mnt_flag & MNT_UPDATE) {
 #if 0
@@ -380,17 +345,20 @@
                 ********************
                 */
 
-               if (devvp != ntmp->um_devvp)
+               if (devvp != ntmp->um_devvp) {
                        err = EINVAL;   /* needs translation */
-               else
-                       vrele(devvp);
+                       goto fail;
+               }
+
                /*
                 * Update device name only on success
                 */
-               if( !err) {
-                       err = set_statvfs_info(NULL, UIO_USERSPACE, args.fspec,
-                           UIO_USERSPACE, mp, p);
-               }
+               err = set_statvfs_info(NULL, UIO_USERSPACE, args.fspec,
+                   UIO_USERSPACE, mp, p);
+               if (err)
+                       goto fail;
+
+               vrele(devvp);
 #endif
        } else {
                /*
@@ -405,15 +373,40 @@
                 * error occurs,  the mountpoint is discarded by the
                 * upper level code.
                 */
+
                /* Save "last mounted on" info for mount point (NULL pad)*/
                err = set_statvfs_info(path, UIO_USERSPACE, args.fspec,
                    UIO_USERSPACE, mp, p);
-               if ( !err) {
-                       err = ntfs_mountfs(devvp, mp, &args, p);
+               if (err)
+                       goto fail;
+
+               /*
+                * Disallow multiple mounts of the same device.
+                * Disallow mounting of a device that is currently in use
+                * (except for root, which might share swap device for
+                * miniroot).
+                */
+               err = vfs_mountedon(devvp);
+               if (err)
+                       goto fail;
+               if (vcount(devvp) > 1 && devvp != rootvp) {
+                       err = EBUSY;
+                       goto fail;
                }
-       }
-       if (err) {
-               goto error_2;
+               if (mp->mnt_flag & MNT_RDONLY)
+                       flags = FREAD;
+               else
+                       flags = FREAD|FWRITE;
+               err = VOP_OPEN(devvp, flags, FSCRED, p);
+               if (err)
+                       goto fail;
+               err = ntfs_mountfs(devvp, mp, &args, p);
+               if (err) {
+                       vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
+                       (void)VOP_CLOSE(devvp, flags, NOCRED, p);
+                       VOP_UNLOCK(devvp, 0);
+                       goto fail;
+               }
        }
 
 #ifdef __FreeBSD__
@@ -426,19 +419,11 @@
         * This code is common to root and non-root mounts
         */
        (void)VFS_STATVFS(mp, &mp->mnt_stat, p);
-
-       goto success;
-
-
-error_2:       /* error with devvp held*/
+       return (err);
 
-       /* release devvp before failing*/
+fail:
        vrele(devvp);
-
-error_1:       /* no state to back out*/
-
-success:
-       return(err);
+       return (err);
 }
 
 /*
@@ -454,29 +439,19 @@
        struct buf *bp;
        struct ntfsmount *ntmp;
        dev_t dev = devvp->v_rdev;
-       int error, ronly, ncount, i;
+       int error, ronly, i;
        struct vnode *vp;
 
        /*
-        * Disallow multiple mounts of the same device.
-        * Disallow mounting of a device that is currently in use
-        * (except for root, which might share swap device for miniroot).
         * Flush out any old buffers remaining from a previous use.
         */
-       error = vfs_mountedon(devvp);
-       if (error)
-               return (error);
-       ncount = vcount(devvp);
-       if (ncount > 1 && devvp != rootvp)
-               return (EBUSY);
+       vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
        error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0);
+       VOP_UNLOCK(devvp, 0);
        if (error)
                return (error);
 
        ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
-       error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
-       if (error)
-               return (error);
 
        bp = NULL;
 
@@ -631,11 +606,6 @@
        if (bp)
                brelse(bp);
 
-       /* lock the device vnode before calling VOP_CLOSE() */
-       vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
-       (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
-       VOP_UNLOCK(devvp, 0);
-       
        return (error);
 }
 
diff -r 7ea1d3be9792 -r 09dead486c6f sys/ufs/ext2fs/ext2fs_vfsops.c
--- a/sys/ufs/ext2fs/ext2fs_vfsops.c    Sun Jan 09 07:31:31 2005 +0000
+++ b/sys/ufs/ext2fs/ext2fs_vfsops.c    Sun Jan 09 09:27:17 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ext2fs_vfsops.c,v 1.79 2005/01/09 03:11:48 mycroft Exp $       */
+/*     $NetBSD: ext2fs_vfsops.c,v 1.80 2005/01/09 09:27:17 mycroft Exp $       */
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1994
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.79 2005/01/09 03:11:48 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.80 2005/01/09 09:27:17 mycroft Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -254,7 +254,7 @@
        struct ufsmount *ump = NULL;
        struct m_ext2fs *fs;
        size_t size;
-       int error, flags;
+       int error, flags, update;
        mode_t accessmode;
 
        if (mp->mnt_flag & MNT_GETARGS) {
@@ -265,25 +265,132 @@
                vfs_showexport(mp, &args.export, &ump->um_export);
                return copyout(&args, data, sizeof(args));
        }
-
        error = copyin(data, &args, sizeof (struct ufs_args));
        if (error)
                return (error);
+
+       update = mp->mnt_flag & MNT_UPDATE;
+
        /*
         * If updating, check whether changing from read-only to
         * read/write; if there is no device name, that's all we do.
         */
-       if (mp->mnt_flag & MNT_UPDATE) {
+       if (update) {



Home | Main Index | Thread Index | Old Index