On Mon, Jun 08, 2009 at 09:23:54PM +0000, Paul Saab wrote:
> Author: ps
> Date: Mon Jun  8 21:23:54 2009
> New Revision: 193762
> URL: http://svn.freebsd.org/changeset/base/193762
> 
> Log:
>   Simply shared vnode locking and extend it to also include fsync.
>   Also, in vop_write, no longer assert for exclusive locks on the
>   vnode.
>   
>   Reviewed by:        jhb, kmacy, jeffr
> 
> Modified:
>   head/sys/kern/vfs_syscalls.c
>   head/sys/kern/vfs_vnops.c
>   head/sys/kern/vnode_if.src
>   head/sys/sys/mount.h
> 
> Modified: head/sys/kern/vfs_syscalls.c
> ==============================================================================
> --- head/sys/kern/vfs_syscalls.c      Mon Jun  8 21:16:06 2009        
> (r193761)
> +++ head/sys/kern/vfs_syscalls.c      Mon Jun  8 21:23:54 2009        
> (r193762)
> @@ -3476,7 +3476,7 @@ fsync(td, uap)
>       struct mount *mp;
>       struct file *fp;
>       int vfslocked;
> -     int error;
> +     int error, lock_flags;
>  
>       AUDIT_ARG(fd, uap->fd);
>       if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
> @@ -3485,7 +3485,13 @@ fsync(td, uap)
>       vfslocked = VFS_LOCK_GIANT(vp->v_mount);
>       if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
>               goto drop;
> -     vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
> +     if (MNT_SHARED_WRITES(mp) ||
> +         ((mp == NULL) && MNT_SHARED_WRITES(vp->v_mount))) {
> +             lock_flags = LK_SHARED;
> +     } else {
> +             lock_flags = LK_EXCLUSIVE;
> +     }
> +     vn_lock(vp, lock_flags | LK_RETRY);
>       AUDIT_ARG(vnode, vp, ARG_VNODE1);
>       if (vp->v_object != NULL) {
>               VM_OBJECT_LOCK(vp->v_object);
> 


vnode_if.src needs to be changed:

diff --git a/sys/kern/vnode_if.src b/sys/kern/vnode_if.src
index f54d046..49cc782 100644
--- a/sys/kern/vnode_if.src
+++ b/sys/kern/vnode_if.src
@@ -247,7 +247,7 @@ vop_revoke {
 };


-%% fsync       vp      E E E
+%% fsync       vp      L L L

 vop_fsync {
        IN struct vnode *vp;






> Modified: head/sys/kern/vfs_vnops.c
> ==============================================================================
> --- head/sys/kern/vfs_vnops.c Mon Jun  8 21:16:06 2009        (r193761)
> +++ head/sys/kern/vfs_vnops.c Mon Jun  8 21:23:54 2009        (r193762)
> @@ -376,8 +376,8 @@ vn_rdwr(rw, vp, base, len, offset, segfl
>                           (error = vn_start_write(vp, &mp, V_WAIT | PCATCH))
>                           != 0)
>                               return (error);
> -                     if (mp != NULL &&
> -                         (mp->mnt_kern_flag & MNTK_SHARED_WRITES)) {
> +                     if (MNT_SHARED_WRITES(mp) ||
> +                         ((mp == NULL) && MNT_SHARED_WRITES(vp->v_mount))) {
>                               lock_flags = LK_SHARED;
>                       } else {
>                               lock_flags = LK_EXCLUSIVE;
> @@ -592,7 +592,8 @@ vn_write(fp, uio, active_cred, flags, td
>           (error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
>               goto unlock;
>   
> -     if (mp != NULL && (mp->mnt_kern_flag & MNTK_SHARED_WRITES) &&
> +     if ((MNT_SHARED_WRITES(mp) ||
> +         ((mp == NULL) && MNT_SHARED_WRITES(vp->v_mount))) &&
>           (flags & FOF_OFFSET) != 0) {
>               lock_flags = LK_SHARED;
>       } else {
> 
> Modified: head/sys/kern/vnode_if.src
> ==============================================================================
> --- head/sys/kern/vnode_if.src        Mon Jun  8 21:16:06 2009        
> (r193761)
> +++ head/sys/kern/vnode_if.src        Mon Jun  8 21:23:54 2009        
> (r193762)
> @@ -197,7 +197,7 @@ vop_read {
>  };
>  
>  
> -%% write     vp      E E E
> +%% write     vp      L L L
>  %! write     pre     VOP_WRITE_PRE
>  %! write     post    VOP_WRITE_POST
>  
> 
> Modified: head/sys/sys/mount.h
> ==============================================================================
> --- head/sys/sys/mount.h      Mon Jun  8 21:16:06 2009        (r193761)
> +++ head/sys/sys/mount.h      Mon Jun  8 21:23:54 2009        (r193762)
> @@ -336,6 +336,9 @@ void          __mnt_vnode_markerfree(str
>  #define MNTK_LOOKUP_SHARED   0x40000000 /* FS supports shared lock lookups */
>  #define      MNTK_NOKNOTE    0x80000000      /* Don't send KNOTEs from VOP 
> hooks */
>  
> +#define      MNT_SHARED_WRITES(mp) (((mp) != NULL) &&        \
> +                             ((mp)->mnt_kern_flag & MNTK_SHARED_WRITES))
> +
>  /*
>   * Sysctl CTL_VFS definitions.
>   *

-- 
Have fun!
chd

Attachment: pgpN1rF2ykPMV.pgp
Description: PGP signature

Reply via email to