diff --git a/uts/common/fs/vnode.c b/uts/common/fs/vnode.c index 382369c7fc72..d67d1642868e 100644 --- a/uts/common/fs/vnode.c +++ b/uts/common/fs/vnode.c @@ -21,6 +21,7 @@ /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ @@ -2582,6 +2583,15 @@ vnevent_mountedover(vnode_t *vp, caller_context_t *ct) (void) VOP_VNEVENT(vp, VE_MOUNTEDOVER, NULL, NULL, ct); } +void +vnevent_truncate(vnode_t *vp, caller_context_t *ct) +{ + if (vp == NULL || vp->v_femhead == NULL) { + return; + } + (void) VOP_VNEVENT(vp, VE_TRUNCATE, NULL, NULL, ct); +} + /* * Vnode accessors. */ diff --git a/uts/common/fs/zfs/zfs_vnops.c b/uts/common/fs/zfs/zfs_vnops.c index 6fa1d837008b..78e2a8cce5a6 100644 --- a/uts/common/fs/zfs/zfs_vnops.c +++ b/uts/common/fs/zfs/zfs_vnops.c @@ -2756,6 +2756,9 @@ zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, ZFS_EXIT(zfsvfs); return (err); } + + if (vap->va_size == 0) + vnevent_truncate(ZTOV(zp), ct); } if (mask & (AT_ATIME|AT_MTIME) || @@ -4770,6 +4773,9 @@ zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag, error = zfs_freesp(zp, off, len, flag, TRUE); + if (error == 0 && off == 0 && len == 0) + vnevent_truncate(ZTOV(zp), ct); + ZFS_EXIT(zfsvfs); return (error); } diff --git a/uts/common/sys/vnode.h b/uts/common/sys/vnode.h index d29152346e2c..af9516fe52fb 100644 --- a/uts/common/sys/vnode.h +++ b/uts/common/sys/vnode.h @@ -21,6 +21,7 @@ /* * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, Joyent, Inc. All rights reserved. */ /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ @@ -733,7 +734,8 @@ typedef enum vnevent { VE_CREATE = 5, /* Create with vnode's name which exists */ VE_LINK = 6, /* Link with vnode's name as source */ VE_RENAME_DEST_DIR = 7, /* Rename with vnode as target dir */ - VE_MOUNTEDOVER = 8 /* File or Filesystem got mounted over vnode */ + VE_MOUNTEDOVER = 8, /* File or Filesystem got mounted over vnode */ + VE_TRUNCATE = 9 /* Truncate */ } vnevent_t; /* @@ -1290,6 +1292,7 @@ void vnevent_create(vnode_t *, caller_context_t *); void vnevent_link(vnode_t *, caller_context_t *); void vnevent_rename_dest_dir(vnode_t *, caller_context_t *ct); void vnevent_mountedover(vnode_t *, caller_context_t *); +void vnevent_truncate(vnode_t *, caller_context_t *); int vnevent_support(vnode_t *, caller_context_t *); /* Vnode specific data */