From bbdc6ae49518a4be7230ab673370e9231e2f72e7 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Mon, 3 Sep 2012 14:56:26 +0200 Subject: Add interface for file hole punching. This adds an interface to "punch holes" (deallocate space) in VFS files. The interface is identical to the Solaris VOP_SPACE interface. This interface is necessary for TRIM support on file vdevs. This is implemented using Linux fallocate(FALLOC_FL_PUNCH_HOLE), which was introduced in 2.6.38. For a brief time before 2.6.38 this was done using the truncate_range inode operation, which was quickly deprecated. This patch only supports FALLOC_FL_PUNCH_HOLE. This adds support for the truncate_range() inode operation to VOP_SPACE() for file hole punching. This API is deprecated and removed in 3.5, so it's only useful for old kernels. On tmpfs, the truncate_range() inode operation translates to shmem_truncate_range(). Unfortunately, this function expects the end offset to be inclusive and aligned to the end of a page. If it is not, the kernel will stop with a BUG_ON(). This patch fixes the issue by adapting to the constraints set forth by shmem_truncate_range(). Signed-off-by: Brian Behlendorf Closes #168 --- include/sys/vnode.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/sys') diff --git a/include/sys/vnode.h b/include/sys/vnode.h index 03462bd70..99614d55b 100644 --- a/include/sys/vnode.h +++ b/include/sys/vnode.h @@ -66,6 +66,9 @@ #define FNODSYNC 0x10000 /* fsync pseudo flag */ #define FNOFOLLOW 0x20000 /* don't follow symlinks */ +#define F_FREESP 11 /* Free file space */ + + /* * The vnode AT_ flags are mapped to the Linux ATTR_* flags. * This allows them to be used safely with an iattr structure. @@ -185,6 +188,8 @@ extern int vn_remove(const char *path, uio_seg_t seg, int flags); extern int vn_rename(const char *path1, const char *path2, int x1); extern int vn_getattr(vnode_t *vp, vattr_t *vap, int flags, void *x3, void *x4); extern int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4); +extern int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag, + offset_t offset, void *x6, void *x7); extern file_t *vn_getf(int fd); extern void vn_releasef(int fd); extern int vn_set_pwd(const char *filename); @@ -197,6 +202,7 @@ void spl_vn_fini(void); #define VOP_SEEK vn_seek #define VOP_GETATTR vn_getattr #define VOP_FSYNC vn_fsync +#define VOP_SPACE vn_space #define VOP_PUTPAGE(vp, o, s, f, x1, x2) ((void)0) #define vn_is_readonly(vp) 0 #define getf vn_getf -- cgit v1.2.3