Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/smbfs make smbfs_lookup() look more like nfs_lookup()...



details:   https://anonhg.NetBSD.org/src/rev/2e28bd5c12b8
branches:  trunk
changeset: 543181:2e28bd5c12b8
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Tue Feb 18 20:07:50 2003 +0000

description:
make smbfs_lookup() look more like nfs_lookup(), particularily account
for different cache_lookup() semantics
fix smbfs_pathcheck() to not assume zero-ended component name
remove the bogus code in smbfs_close(), it's not needed on NetBSD
fix couple other vnop routines to do vput()/vrele()/PNBUF_PUT() as appropriate
KNF

diffstat:

 sys/fs/smbfs/smbfs_vnops.c |  672 ++++++++++++++++++++++++--------------------
 1 files changed, 367 insertions(+), 305 deletions(-)

diffs (truncated from 1026 to 300 lines):

diff -r 3d7ba68dc678 -r 2e28bd5c12b8 sys/fs/smbfs/smbfs_vnops.c
--- a/sys/fs/smbfs/smbfs_vnops.c        Tue Feb 18 20:00:35 2003 +0000
+++ b/sys/fs/smbfs/smbfs_vnops.c        Tue Feb 18 20:07:50 2003 +0000
@@ -1,4 +1,40 @@
-/*     $NetBSD: smbfs_vnops.c,v 1.2 2002/01/09 17:43:29 deberg Exp $   */
+/*     $NetBSD: smbfs_vnops.c,v 1.3 2003/02/18 20:07:50 jdolecek Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jaromir Dolecek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 
 /*
  * Copyright (c) 2000-2001 Boris Popov
@@ -64,7 +100,6 @@
  * Prototypes for SMBFS vnode operations
  */
 int smbfs_create(void *);
-int smbfs_mknod(void *);
 int smbfs_open(void *);
 int smbfs_close(void *);
 int smbfs_access(void *);
@@ -145,13 +180,13 @@
        { &vop_getattr_desc,            smbfs_getattr },
        { &vop_getpages_desc,           genfs_getpages },
        { &vop_inactive_desc,           smbfs_inactive },
-       { &vop_ioctl_desc,              smbfs_ioctl },
+       { &vop_ioctl_desc,              genfs_enoioctl },
        { &vop_islocked_desc,           genfs_noislocked },
        { &vop_link_desc,               smbfs_link },
        { &vop_lock_desc,               genfs_nolock },
        { &vop_lookup_desc,             smbfs_lookup },
        { &vop_mkdir_desc,              smbfs_mkdir },
-       { &vop_mknod_desc,              smbfs_mknod },
+       { &vop_mknod_desc,              genfs_eopnotsupp },
        { &vop_open_desc,               smbfs_open },
        { &vop_pathconf_desc,           smbfs_pathconf },
        { &vop_print_desc,              smbfs_print },
@@ -171,9 +206,6 @@
 };
 const struct vnodeopv_desc smbfs_vnodeop_opv_desc =
        { &smbfs_vnodeop_p, smbfs_vnodeop_entries };
-
-#define VI_LOCK(vp) simple_lock(&(vp)->v_interlock)
-#define VI_UNLOCK(vp) simple_unlock(&(vp)->v_interlock)
 #endif /* __NetBSD__ */
 
 int
@@ -192,15 +224,17 @@
        struct smbmount *smp = VTOSMBFS(vp);
        int error = 0;
 
-       SMBVDEBUG("\n");
        if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
                switch (vp->v_type) {
-                   case VREG: case VDIR: case VLNK:
+               case VREG:
+               case VDIR:
+               case VLNK:
                        return EROFS;
-                   default:
+               default:
                        break;
                }
        }
+
        if (cred->cr_uid == 0)
                return 0;
        if (cred->cr_uid != smp->sm_args.uid) {
@@ -209,6 +243,7 @@
                        mode >>= 3;
        }
        error = (((vp->v_type == VREG) ? smp->sm_args.file_mode : smp->sm_args.dir_mode) & mode) == mode ? 0 : EACCES;
+
        return error;
 }
 
@@ -270,8 +305,7 @@
        if (error) {
                if (mode & FWRITE)
                        return EACCES;
-               accmode = SMB_AM_OPENREAD;
-               error = smbfs_smb_open(np, accmode, &scred);
+               error = smbfs_smb_open(np, SMB_AM_OPENREAD, &scred);
        }
        if (!error) {
                np->n_opencount++;
@@ -321,8 +355,7 @@
 }
 
 /*
- * XXX: VOP_CLOSE() usually called without lock held which is suck. Here we
- * do some heruistic to determine if vnode should be locked.
+ * Close called.
  */
 int
 smbfs_close(v)
@@ -336,17 +369,12 @@
                struct proc *p;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-       int error, dolock;
+       int error;
 
-       VI_LOCK(vp);
-       dolock = (vp->v_flag & VXLOCK) == 0;
-       if (dolock)
-               vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK);
-       else
-               VI_UNLOCK(vp);
+       simple_lock(&(vp)->v_interlock);
        error = smbfs_closel(ap);
-       if (dolock)
-               VOP_UNLOCK(vp, 0);
+       simple_unlock(&(vp)->v_interlock);
+
        return error;
 }
 
@@ -372,9 +400,9 @@
        int error;
 
        SMBVDEBUG("%lx: '%s' %d\n", (long)vp, np->n_name, (vp->v_flag & VROOT) != 0);
-       error = smbfs_attr_cachelookup(vp, va);
-       if (!error)
-               return 0;
+       if ((error = smbfs_attr_cachelookup(vp, va)) == 0)
+               return (0);
+
        SMBVDEBUG("not in the cache\n");
        smb_makescred(&scred, ap->a_p, ap->a_cred);
        oldsize = np->n_size;
@@ -424,11 +452,11 @@
        smb_makescred(&scred, ap->a_p, ap->a_cred);
        if (vap->va_size != VNOVAL) {
                switch (vp->v_type) {
-                   case VDIR:
+               case VDIR:
                        return EISDIR;
-                   case VREG:
+               case VREG:
                        break;
-                   default:
+               default:
                        return EINVAL;
                };
                if (isreadonly)
@@ -548,7 +576,7 @@
        SMBVDEBUG("%d,ofs=%d,sz=%d\n",vp->v_type, (int)uio->uio_offset, uio->uio_resid);
        if (vp->v_type != VREG)
                return (EPERM);
-       return smbfs_writevnode(vp, uio, ap->a_cred,ap->a_ioflag);
+       return smbfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
 }
 /*
  * smbfs_create call
@@ -569,39 +597,40 @@
        } */ *ap = v;
        struct vnode *dvp = ap->a_dvp;
        struct vattr *vap = ap->a_vap;
-       struct vnode **vpp=ap->a_vpp;
        struct componentname *cnp = ap->a_cnp;
        struct smbnode *dnp = VTOSMB(dvp);
-       struct vnode *vp;
-       struct vattr vattr;
        struct smbfattr fattr;
        struct smb_cred scred;
-       char *name = (char *)cnp->cn_nameptr;
+       const char *name = cnp->cn_nameptr;
        int nmlen = cnp->cn_namelen;
        int error;
        
 
-       SMBVDEBUG("\n");
-       *vpp = NULL;
        if (vap->va_type != VREG)
-               return EOPNOTSUPP;
-       if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_proc)))
-               return error;
+               goto out;
+
        smb_makescred(&scred, cnp->cn_proc, cnp->cn_cred);
-       
        error = smbfs_smb_create(dnp, name, nmlen, &scred);
        if (error)
-               return error;
+               goto out;
+
        error = smbfs_smb_lookup(dnp, name, nmlen, &fattr, &scred);
        if (error)
-               return error;
-       error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, &vp);
+               goto out;
+       error = smbfs_nget(VTOVFS(dvp), dvp, name, nmlen, &fattr, ap->a_vpp);
        if (error)
-               return error;
-       *vpp = vp;
+               goto out;
+
+       /* No error */
        if (cnp->cn_flags & MAKEENTRY)
-               cache_enter(dvp, vp, cnp);
-       return error;
+               cache_enter(dvp, *ap->a_vpp, cnp);
+
+  out:
+       PNBUF_PUT(cnp->cn_pnbuf);
+       vput(dvp);
+       return (error);
+
+
 }
 
 int
@@ -615,18 +644,26 @@
                struct componentname * a_cnp;
        } */ *ap = v;
        struct vnode *vp = ap->a_vp;
-/*     struct vnode *dvp = ap->a_dvp;*/
+       struct vnode *dvp = ap->a_dvp;
        struct componentname *cnp = ap->a_cnp;
        struct smbnode *np = VTOSMB(vp);
        struct smb_cred scred;
        int error;
 
-       if (vp->v_type == VDIR || np->n_opencount || vp->v_usecount != 1)
-               return EPERM;
-       smb_makescred(&scred, cnp->cn_proc, cnp->cn_cred);
-       error = smbfs_smb_delete(np, &scred);
-       cache_purge(vp);
-       return error;
+       if (vp->v_type != VDIR && np->n_opencount == 0 && vp->v_usecount == 1)
+               error = EPERM;
+       else {
+               smb_makescred(&scred, cnp->cn_proc, cnp->cn_cred);
+               error = smbfs_smb_delete(np, &scred);
+       }
+
+       PNBUF_PUT(cnp->cn_pnbuf);
+       if (dvp == vp)
+               vrele(vp);
+       else
+               vput(vp);
+       vput(dvp);
+       return (error);
 }
 
 /*
@@ -700,23 +737,22 @@
                        cache_purge(tdvp);
                cache_purge(fdvp);
        }
+
 out:
+       smbfs_attr_cacheremove(fdvp);
+       smbfs_attr_cacheremove(tdvp);
+
        if (tdvp == tvp)
                vrele(tdvp);
        else
                vput(tdvp);
        if (tvp)
                vput(tvp);
+
        vrele(fdvp);
        vrele(fvp);
-       smbfs_attr_cacheremove(fdvp);
-       smbfs_attr_cacheremove(tdvp);
-#ifdef possible_mistake



Home | Main Index | Thread Index | Old Index