Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/ufs/ufs Move and unify indirect block truncate algorithm...
details: https://anonhg.NetBSD.org/src/rev/fa5122f75e78
branches: trunk
changeset: 333165:fa5122f75e78
user: slp <slp%NetBSD.org@localhost>
date: Tue Oct 21 10:39:26 2014 +0000
description:
Move and unify indirect block truncate algorithm into a separate function.
Reviewed by joerg.
diffstat:
sys/ufs/ufs/ufs_extern.h | 3 +-
sys/ufs/ufs/ufs_inode.c | 75 +++++++++++++++++++++++++++++------------------
sys/ufs/ufs/ufs_vnops.c | 46 ++++++++++------------------
3 files changed, 65 insertions(+), 59 deletions(-)
diffs (204 lines):
diff -r 863534acbbf7 -r fa5122f75e78 sys/ufs/ufs/ufs_extern.h
--- a/sys/ufs/ufs/ufs_extern.h Tue Oct 21 09:07:07 2014 +0000
+++ b/sys/ufs/ufs/ufs_extern.h Tue Oct 21 10:39:26 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_extern.h,v 1.75 2014/05/25 13:48:40 hannken Exp $ */
+/* $NetBSD: ufs_extern.h,v 1.76 2014/10/21 10:39:26 slp Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -111,6 +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);
/* ufs_lookup.c */
void ufs_dirbad(struct inode *, doff_t, const char *);
diff -r 863534acbbf7 -r fa5122f75e78 sys/ufs/ufs/ufs_inode.c
--- a/sys/ufs/ufs/ufs_inode.c Tue Oct 21 09:07:07 2014 +0000
+++ b/sys/ufs/ufs/ufs_inode.c Tue Oct 21 10:39:26 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_inode.c,v 1.90 2014/05/08 08:21:53 hannken Exp $ */
+/* $NetBSD: ufs_inode.c,v 1.91 2014/10/21 10:39:26 slp Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.90 2014/05/08 08:21:53 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_inode.c,v 1.91 2014/10/21 10:39:26 slp Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -102,40 +102,25 @@
#ifdef UFS_EXTATTR
ufs_extattr_vnode_inactive(vp, curlwp);
#endif
- error = UFS_WAPBL_BEGIN(vp->v_mount);
- if (error)
- goto out;
- logged = 1;
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) {
- 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;
- while (!error && ip->i_size > base + 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);
- if (error)
- break;
- UFS_WAPBL_END(vp->v_mount);
- error = UFS_WAPBL_BEGIN(vp->v_mount);
- if (error)
- goto out;
- }
+ if (vp->v_mount->mnt_wapbl && ip->i_size > base + incr) {
+ error = ufs_wapbl_truncate(vp, incr, base, 0);
}
- if (!error)
+ 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 defined(QUOTA) || defined(QUOTA2)
(void)chkiq(ip, -1, NOCRED, 0);
@@ -309,3 +294,35 @@
kmem_free(pgs, pgssize);
return error;
}
+
+int
+ufs_wapbl_truncate(struct vnode *vp, uint64_t incr, uint64_t base,
+ uint64_t newsize)
+{
+ struct inode *ip = VTOI(vp);
+ int error;
+
+ error = UFS_WAPBL_BEGIN(vp->v_mount);
+ if (error)
+ return error;
+
+ while (ip->i_size > base + 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);
+ if (error)
+ break;
+ UFS_WAPBL_END(vp->v_mount);
+ error = UFS_WAPBL_BEGIN(vp->v_mount);
+ if (error)
+ return error;
+ }
+ UFS_WAPBL_END(vp->v_mount);
+
+ return error;
+}
+
diff -r 863534acbbf7 -r fa5122f75e78 sys/ufs/ufs/ufs_vnops.c
--- a/sys/ufs/ufs/ufs_vnops.c Tue Oct 21 09:07:07 2014 +0000
+++ b/sys/ufs/ufs/ufs_vnops.c Tue Oct 21 10:39:26 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ufs_vnops.c,v 1.222 2014/10/18 08:33:30 snj Exp $ */
+/* $NetBSD: ufs_vnops.c,v 1.223 2014/10/21 10:39:26 slp 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.222 2014/10/18 08:33:30 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.223 2014/10/21 10:39:26 slp Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@@ -464,6 +464,8 @@
int error;
kauth_action_t action;
bool changing_sysflags;
+ uint64_t incr;
+ uint64_t base;
vap = ap->a_vap;
vp = ap->a_vp;
@@ -579,39 +581,25 @@
error = EPERM;
goto out;
}
- error = UFS_WAPBL_BEGIN(vp->v_mount);
- if (error)
- 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) {
- 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;
- while (!error && ip->i_size > base + incr &&
- ip->i_size > vap->va_size + 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,
- cred);
- if (error == 0) {
- UFS_WAPBL_END(vp->v_mount);
- error =
- UFS_WAPBL_BEGIN(vp->v_mount);
- }
- }
+ if (vp->v_mount->mnt_wapbl && ip->i_size > base + incr) {
+ error = ufs_wapbl_truncate(vp, incr, base,
+ vap->va_size);
}
- if (!error)
+ 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);
+ UFS_WAPBL_END(vp->v_mount);
+ }
if (error)
goto out;
break;
Home |
Main Index |
Thread Index |
Old Index