Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs/ufs simplify and correct.



details:   https://anonhg.NetBSD.org/src/rev/c16a3f837c59
branches:  trunk
changeset: 333312:c16a3f837c59
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Oct 29 01:13:28 2014 +0000

description:
simplify and correct.

diffstat:

 sys/ufs/ufs/ufs_extern.h |   4 +-
 sys/ufs/ufs/ufs_inode.c  |  78 +++++++++++++++++++++--------------------------
 sys/ufs/ufs/ufs_vnops.c  |  26 +--------------
 3 files changed, 40 insertions(+), 68 deletions(-)

diffs (208 lines):

diff -r 5fbaa4c37138 -r c16a3f837c59 sys/ufs/ufs/ufs_extern.h
--- a/sys/ufs/ufs/ufs_extern.h  Wed Oct 29 01:08:31 2014 +0000
+++ b/sys/ufs/ufs/ufs_extern.h  Wed Oct 29 01:13:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_extern.h,v 1.76 2014/10/21 10:39:26 slp Exp $      */
+/*     $NetBSD: ufs_extern.h,v 1.77 2014/10/29 01:13:28 christos Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -111,7 +111,7 @@
 /* ufs_inode.c */
 int    ufs_reclaim(struct vnode *);
 int    ufs_balloc_range(struct vnode *, off_t, off_t, kauth_cred_t, int);
-int    ufs_wapbl_truncate(struct vnode *, uint64_t, uint64_t, uint64_t);
+int    ufs_truncate(struct vnode *, uint64_t, kauth_cred_t);
 
 /* ufs_lookup.c */
 void   ufs_dirbad(struct inode *, doff_t, const char *);
diff -r 5fbaa4c37138 -r c16a3f837c59 sys/ufs/ufs/ufs_inode.c
--- a/sys/ufs/ufs/ufs_inode.c   Wed Oct 29 01:08:31 2014 +0000
+++ b/sys/ufs/ufs/ufs_inode.c   Wed Oct 29 01:13:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_inode.c,v 1.91 2014/10/21 10:39:26 slp Exp $       */
+/*     $NetBSD: ufs_inode.c,v 1.92 2014/10/29 01:13:28 christos Exp $  */
 
 /*
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.91 2014/10/21 10:39:26 slp Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.92 2014/10/29 01:13:28 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -87,7 +87,6 @@
        struct mount *transmp;
        mode_t mode;
        int error = 0;
-       int logged = 0;
 
        UFS_WAPBL_JUNLOCK_ASSERT(vp->v_mount);
 
@@ -102,26 +101,8 @@
 #ifdef UFS_EXTATTR
                ufs_extattr_vnode_inactive(vp, curlwp);
 #endif
-               if (ip->i_size != 0) {
-                       uint64_t incr = MNINDIR(ip->i_ump) <<
-                           vp->v_mount->mnt_fs_bshift; /* Power of 2 */
-                       uint64_t base = UFS_NDADDR <<
-                           vp->v_mount->mnt_fs_bshift;
-                       /*
-                        * When journaling, only truncate one indirect block
-                        * at a time
-                        */
-                       if (vp->v_mount->mnt_wapbl && ip->i_size > base + incr) {
-                               error = ufs_wapbl_truncate(vp, incr, base, 0);
-                       }
-                       if (!error) {
-                               error = UFS_WAPBL_BEGIN(vp->v_mount);
-                               if (error)
-                                       goto out;
-                               logged = 1;
-                               error = UFS_TRUNCATE(vp, (off_t)0, 0, NOCRED);
-                       }
-               }
+               if (ip->i_size != 0)
+                       error = ufs_truncate(vp, 0, NOCRED);
 #if defined(QUOTA) || defined(QUOTA2)
                (void)chkiq(ip, -1, NOCRED, 0);
 #endif
@@ -137,16 +118,12 @@
        }
 
        if (ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) {
-               if (!logged++) {
-                       int err;
-                       err = UFS_WAPBL_BEGIN(vp->v_mount);
-                       if (err)
-                               goto out;
-               }
+               error = UFS_WAPBL_BEGIN(vp->v_mount);
+               if (error)
+                       goto out;
                UFS_UPDATE(vp, NULL, NULL, 0);
+               UFS_WAPBL_END(vp->v_mount);
        }
-       if (logged)
-               UFS_WAPBL_END(vp->v_mount);
 out:
        /*
         * If we are done with the inode, reclaim it
@@ -295,25 +272,23 @@
        return error;
 }
 
-int
-ufs_wapbl_truncate(struct vnode *vp, uint64_t incr, uint64_t base,
-    uint64_t newsize)
+static int
+ufs_wapbl_truncate(struct vnode *vp, uint64_t newsize, kauth_cred_t cred)
 {
        struct inode *ip = VTOI(vp);
-       int error;
+       int error = 0;
+       uint64_t base, incr;
 
-       error = UFS_WAPBL_BEGIN(vp->v_mount);
-       if (error)
-               return error;
-
-       while (ip->i_size > base + incr) {
+       base = UFS_NDADDR << vp->v_mount->mnt_fs_bshift;
+       incr = MNINDIR(ip->i_ump) << vp->v_mount->mnt_fs_bshift;/* Power of 2 */
+       while (ip->i_size > base + incr &&
+           (newsize == 0 || ip->i_size > newsize + incr)) {
                /*
                 * round down to next full indirect
                 * block boundary.
                 */
-               uint64_t nsize =
-                   base + ((ip->i_size - base - 1) & ~(incr - 1));
-               error = UFS_TRUNCATE(vp, nsize, 0, NOCRED);
+               uint64_t nsize = base + ((ip->i_size - base - 1) & ~(incr - 1));
+               error = UFS_TRUNCATE(vp, nsize, 0, cred);
                if (error)
                        break;
                UFS_WAPBL_END(vp->v_mount);
@@ -321,6 +296,23 @@
                if (error)
                        return error;
        }
+       return error;
+}
+
+int
+ufs_truncate(struct vnode *vp, uint64_t newsize, kauth_cred_t cred)
+{
+       int error;
+
+       error = UFS_WAPBL_BEGIN(vp->v_mount);
+       if (error)
+               return error;
+
+       if (vp->v_mount->mnt_wapbl)
+               error = ufs_wapbl_truncate(vp, newsize, cred);
+
+       if (error == 0)
+               error = UFS_TRUNCATE(vp, newsize, 0, cred);
        UFS_WAPBL_END(vp->v_mount);
 
        return error;
diff -r 5fbaa4c37138 -r c16a3f837c59 sys/ufs/ufs/ufs_vnops.c
--- a/sys/ufs/ufs/ufs_vnops.c   Wed Oct 29 01:08:31 2014 +0000
+++ b/sys/ufs/ufs/ufs_vnops.c   Wed Oct 29 01:13:28 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_vnops.c,v 1.223 2014/10/21 10:39:26 slp Exp $      */
+/*     $NetBSD: ufs_vnops.c,v 1.224 2014/10/29 01:13:28 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.223 2014/10/21 10:39:26 slp Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.224 2014/10/29 01:13:28 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ffs.h"
@@ -464,8 +464,6 @@
        int             error;
        kauth_action_t  action;
        bool            changing_sysflags;
-       uint64_t        incr;
-       uint64_t        base;
 
        vap = ap->a_vap;
        vp = ap->a_vp;
@@ -581,25 +579,7 @@
                                error = EPERM;
                                goto out;
                        }
-                       incr = MNINDIR(ip->i_ump) <<
-                           vp->v_mount->mnt_fs_bshift; /* Power of 2 */
-                       base = UFS_NDADDR <<
-                           vp->v_mount->mnt_fs_bshift;
-                       /*
-                        * When journaling, only truncate one indirect block
-                        * at a time.
-                        */
-                       if (vp->v_mount->mnt_wapbl && ip->i_size > base + incr) {
-                               error = ufs_wapbl_truncate(vp, incr, base,
-                                   vap->va_size);
-                       }
-                       if (!error) {
-                               error = UFS_WAPBL_BEGIN(vp->v_mount);
-                               if (error)
-                                       goto out;
-                               error = UFS_TRUNCATE(vp, vap->va_size, 0, cred);
-                               UFS_WAPBL_END(vp->v_mount);
-                       }
+                       error = ufs_truncate(vp, vap->va_size, cred);
                        if (error)
                                goto out;
                        break;



Home | Main Index | Thread Index | Old Index