From: Francois Tigeot Date: Thu, 22 Mar 2012 16:51:47 +0000 (+0100) Subject: VFS accounting: handle file truncation on open(2) X-Git-Tag: v3.4.0rc~1160^2 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/18cd8808a42f4ca63dec5ead58586c05a05a909b VFS accounting: handle file truncation on open(2) * Files succesfully opened with O_TRUNC are truncated to zero length. This case was not previously handled, leading to a growing drift between VFS counters and reality. * Fix a buildworld issue caused by the last VFS accounting commit --- diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 27ac2b177d..0bd1afff26 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -104,6 +104,8 @@ vn_open(struct nlookupdata *nd, struct file *fp, int fmode, int cmode) struct vattr *vap = &vat; int error; u_int flags; + uint64_t osize; + struct mount *mp; /* * Certain combinations are illegal @@ -233,11 +235,17 @@ again: if (fmode & O_TRUNC) { vn_unlock(vp); /* XXX */ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* XXX */ + osize = vp->v_filesize; VATTR_NULL(vap); vap->va_size = 0; error = VOP_SETATTR(vp, vap, cred); if (error) goto bad; + error = VOP_GETATTR(vp, vap); + if (error) + goto bad; + mp = vq_vptomp(vp); + VFS_ACCOUNT(mp, vap->va_uid, vap->va_gid, -osize); } /* diff --git a/sys/sys/vfs_quota.h b/sys/sys/vfs_quota.h index d6c438a166..9329109acf 100644 --- a/sys/sys/vfs_quota.h +++ b/sys/sys/vfs_quota.h @@ -34,6 +34,7 @@ #define _SYS_VFSQUOTA_H_ #include +#include #include extern void vq_init(struct mount*); @@ -43,7 +44,9 @@ int vquotactl(const char *path, struct plistref *pref); extern int vfs_accounting_enabled; +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) struct mount* vq_vptomp(struct vnode*); +#endif #endif