Author: kib
Date: Wed Jul 20 14:40:56 2016
New Revision: 303090
URL: https://svnweb.freebsd.org/changeset/base/303090

Log:
  Ensure that the UFS directory vnode' vm_object is properly sized
  before UFS_BALLOC() is called.  I do not believe that this caused any
  real issue on FreeBSD because the exclusive vnode lock is held over
  the balloc/resize, the change is to make formally correct KPI use.
  
  Based on:     the Matthew Dillon' patch from DragonFly BSD
  PR:   93942
  Reviewed by:  mckusick
  Tested by:    pho
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week

Modified:
  head/sys/ufs/ufs/ufs_lookup.c
  head/sys/ufs/ufs/ufs_vnops.c

Modified: head/sys/ufs/ufs/ufs_lookup.c
==============================================================================
--- head/sys/ufs/ufs/ufs_lookup.c       Wed Jul 20 14:38:02 2016        
(r303089)
+++ head/sys/ufs/ufs/ufs_lookup.c       Wed Jul 20 14:40:56 2016        
(r303090)
@@ -881,6 +881,7 @@ ufs_direnter(dvp, tvp, dirp, cnp, newdir
        struct buf *bp;
        u_int dsize;
        struct direct *ep, *nep;
+       u_int64_t old_isize;
        int error, ret, blkoff, loc, spacefree, flags, namlen;
        char *dirbuf;
 
@@ -909,16 +910,18 @@ ufs_direnter(dvp, tvp, dirp, cnp, newdir
                        return (error);
                }
 #endif
+               old_isize = dp->i_size;
+               vnode_pager_setsize(dvp, (u_long)dp->i_offset + DIRBLKSIZ);
                if ((error = UFS_BALLOC(dvp, (off_t)dp->i_offset, DIRBLKSIZ,
                    cr, flags, &bp)) != 0) {
                        if (DOINGSOFTDEP(dvp) && newdirbp != NULL)
                                bdwrite(newdirbp);
+                       vnode_pager_setsize(dvp, (u_long)old_isize);
                        return (error);
                }
                dp->i_size = dp->i_offset + DIRBLKSIZ;
                DIP_SET(dp, i_size, dp->i_size);
                dp->i_flag |= IN_CHANGE | IN_UPDATE;
-               vnode_pager_setsize(dvp, (u_long)dp->i_size);
                dirp->d_reclen = DIRBLKSIZ;
                blkoff = dp->i_offset &
                    (VFSTOUFS(dvp->v_mount)->um_mountp->mnt_stat.f_iosize - 1);

Modified: head/sys/ufs/ufs/ufs_vnops.c
==============================================================================
--- head/sys/ufs/ufs/ufs_vnops.c        Wed Jul 20 14:38:02 2016        
(r303089)
+++ head/sys/ufs/ufs/ufs_vnops.c        Wed Jul 20 14:40:56 2016        
(r303090)
@@ -1913,13 +1913,13 @@ ufs_mkdir(ap)
        dirtemplate = *dtp;
        dirtemplate.dot_ino = ip->i_number;
        dirtemplate.dotdot_ino = dp->i_number;
+       vnode_pager_setsize(tvp, DIRBLKSIZ);
        if ((error = UFS_BALLOC(tvp, (off_t)0, DIRBLKSIZ, cnp->cn_cred,
            BA_CLRBUF, &bp)) != 0)
                goto bad;
        ip->i_size = DIRBLKSIZ;
        DIP_SET(ip, i_size, DIRBLKSIZ);
        ip->i_flag |= IN_CHANGE | IN_UPDATE;
-       vnode_pager_setsize(tvp, (u_long)ip->i_size);
        bcopy((caddr_t)&dirtemplate, (caddr_t)bp->b_data, sizeof dirtemplate);
        if (DOINGSOFTDEP(tvp)) {
                /*
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to