Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Use vmem_free() in dfl_free() and add dfl_alloc() #543

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/sys/dkioc_free_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ typedef struct dkioc_free_list_s {
} dkioc_free_list_t;

static inline void dfl_free(dkioc_free_list_t *dfl) {
kmem_free(dfl, DFL_SZ(dfl->dfl_num_exts));
vmem_free(dfl, DFL_SZ(dfl->dfl_num_exts));
Copy link
Contributor

@behlendorf behlendorf Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be a dfl_alloc() counterpart to prevent this kind of issue. I see it's directly calling vmem_alloc() in the trim code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make perfect sense. I think the only reason we don't have one is because illumos doesn't have one. I do like the idea of adding one. We've already got the kmem/vmem difference from the upstream and I suppose a dfl_alloc() would make the intention more obvious for future porting efforts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then let's add one. We're already forced to diverge slightly here, let's diverge in a way which can in theory be pushed back upstream.

}

static inline dkioc_free_list_t *dfl_alloc(uint64_t dfl_num_exts, int flags) {
return vmem_zalloc(DFL_SZ(dfl_num_exts), flags);
}

#endif /* _SPL_DKIOC_UTIL_H */
15 changes: 15 additions & 0 deletions module/spl/spl-vnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
offset_t offset, void *x6, void *x7)
{
int error = EOPNOTSUPP;
#ifdef FALLOC_FL_PUNCH_HOLE
int fstrans;
#endif

if (cmd != F_FREESP || bfp->l_whence != 0)
return (EOPNOTSUPP);
Expand All @@ -580,13 +583,25 @@ int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag,
ASSERT(bfp->l_start >= 0 && bfp->l_len > 0);

#ifdef FALLOC_FL_PUNCH_HOLE
/*
* May enter XFS which generates a warning when PF_FSTRANS is set.
* To avoid this the flag is cleared over vfs_sync() and then reset.
*/
fstrans = spl_fstrans_check();
if (fstrans)
current->flags &= ~(PF_FSTRANS);

/*
* When supported by the underlying file system preferentially
* use the fallocate() callback to preallocate the space.
*/
error = -spl_filp_fallocate(vp->v_file,
FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
bfp->l_start, bfp->l_len);

if (fstrans)
current->flags |= PF_FSTRANS;

if (error == 0)
return (0);
#endif
Expand Down