From 78fa995d09ba58a0cc290d307b71be58830217ee Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 31 Oct 2014 13:52:41 +0000 Subject: [PATCH] Add PUFFS support for fallocate and fdiscard operations --- sys/fs/puffs/puffs_msgif.h | 21 ++++++++-- sys/fs/puffs/puffs_vnops.c | 84 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 8 deletions(-) diff --git a/sys/fs/puffs/puffs_msgif.h b/sys/fs/puffs/puffs_msgif.h index a87bff5159e5..46acaef3c9c5 100644 --- a/sys/fs/puffs/puffs_msgif.h +++ b/sys/fs/puffs/puffs_msgif.h @@ -1,4 +1,4 @@ -/* $NetBSD: puffs_msgif.h,v 1.81 2014/08/16 16:19:41 manu Exp $ */ +/* $NetBSD: puffs_msgif.h,v 1.82 2014/10/31 13:52:41 manu Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved. @@ -86,11 +86,12 @@ enum { PUFFS_VN_ADVLOCK, PUFFS_VN_LEASE, PUFFS_VN_WHITEOUT, PUFFS_VN_GETPAGES, PUFFS_VN_PUTPAGES, PUFFS_VN_GETEXTATTR, PUFFS_VN_LISTEXTATTR, PUFFS_VN_OPENEXTATTR, PUFFS_VN_DELETEEXTATTR, - PUFFS_VN_SETEXTATTR, PUFFS_VN_CLOSEEXTATTR + PUFFS_VN_SETEXTATTR, PUFFS_VN_CLOSEEXTATTR, PUFFS_VN_FALLOCATE, + PUFFS_VN_FDISCARD, /* NOTE: If you add an op, decrement PUFFS_VN_SPARE accordingly */ }; -#define PUFFS_VN_MAX PUFFS_VN_CLOSEEXTATTR -#define PUFFS_VN_SPARE 32 +#define PUFFS_VN_MAX PUFFS_VN_FDISCARD +#define PUFFS_VN_SPARE 30 /* * These signal invalid parameters the file system returned. @@ -666,6 +667,18 @@ struct puffs_vnmsg_deleteextattr { struct puffs_kcred pvnr_cred; /* OUT */ }; +struct puffs_vnmsg_fallocate { + struct puffs_req pvn_pr; + off_t pvnr_off; /* OUT */ + off_t pvnr_len; /* OUT */ +}; + +struct puffs_vnmsg_fdiscard { + struct puffs_req pvn_pr; + off_t pvnr_off; /* OUT */ + off_t pvnr_len; /* OUT */ +}; + /* * For cache reports. Everything is always out-out-out, no replies */ diff --git a/sys/fs/puffs/puffs_vnops.c b/sys/fs/puffs/puffs_vnops.c index 365ce6952de8..2608430bcdce 100644 --- a/sys/fs/puffs/puffs_vnops.c +++ b/sys/fs/puffs/puffs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: puffs_vnops.c,v 1.195 2014/10/31 13:51:33 manu Exp $ */ +/* $NetBSD: puffs_vnops.c,v 1.196 2014/10/31 13:52:41 manu Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.195 2014/10/31 13:51:33 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.196 2014/10/31 13:52:41 manu Exp $"); #include #include @@ -73,6 +73,8 @@ int puffs_vnop_symlink(void *); int puffs_vnop_rename(void *); int puffs_vnop_read(void *); int puffs_vnop_write(void *); +int puffs_vnop_fallocate(void *); +int puffs_vnop_fdiscard(void *); int puffs_vnop_fcntl(void *); int puffs_vnop_ioctl(void *); int puffs_vnop_inactive(void *); @@ -113,8 +115,8 @@ const struct vnodeopv_entry_desc puffs_vnodeop_entries[] = { { &vop_setattr_desc, puffs_vnop_checkop }, /* setattr */ { &vop_read_desc, puffs_vnop_checkop }, /* read */ { &vop_write_desc, puffs_vnop_checkop }, /* write */ - { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ - { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ + { &vop_fallocate_desc, puffs_vnop_fallocate }, /* fallocate */ + { &vop_fdiscard_desc, puffs_vnop_fdiscard }, /* fdiscard */ { &vop_fsync_desc, puffs_vnop_fsync }, /* REAL fsync */ { &vop_seek_desc, puffs_vnop_checkop }, /* seek */ { &vop_remove_desc, puffs_vnop_checkop }, /* remove */ @@ -2498,6 +2500,80 @@ puffs_vnop_write(void *v) return error; } +int +puffs_vnop_fallocate(void *v) +{ + struct vop_fallocate_args /* { + const struct vnodeop_desc *a_desc; + struct vnode *a_vp; + off_t a_pos; + off_t a_len; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + struct puffs_node *pn = VPTOPP(vp); + struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount); + PUFFS_MSG_VARS(vn, fallocate); + int error; + + mutex_enter(&pn->pn_sizemtx); + + PUFFS_MSG_ALLOC(vn, fallocate); + fallocate_msg->pvnr_off = ap->a_pos; + fallocate_msg->pvnr_len = ap->a_len; + puffs_msg_setinfo(park_fallocate, PUFFSOP_VN, + PUFFS_VN_FALLOCATE, VPTOPNC(vp)); + + PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fallocate, vp->v_data, NULL, error); + error = checkerr(pmp, error, __func__); + PUFFS_MSG_RELEASE(fallocate); + + switch (error) { + case 0: + break; + case EAGAIN: + error = EIO; + /* FALLTHROUGH */ + default: + goto out; + } + + if (ap->a_pos + ap->a_len > vp->v_size) { + uvm_vnp_setsize(vp, ap->a_pos + ap->a_len); + puffs_updatenode(pn, PUFFS_UPDATESIZE, vp->v_size); + } +out: + mutex_exit(&pn->pn_sizemtx); + + return error; +} + +int +puffs_vnop_fdiscard(void *v) +{ + struct vop_fdiscard_args /* { + const struct vnodeop_desc *a_desc; + struct vnode *a_vp; + off_t a_pos; + off_t a_len; + } */ *ap = v; + struct vnode *vp = ap->a_vp; + struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount); + PUFFS_MSG_VARS(vn, fdiscard); + int error; + + PUFFS_MSG_ALLOC(vn, fdiscard); + fdiscard_msg->pvnr_off = ap->a_pos; + fdiscard_msg->pvnr_len = ap->a_len; + puffs_msg_setinfo(park_fdiscard, PUFFSOP_VN, + PUFFS_VN_FALLOCATE, VPTOPNC(vp)); + + PUFFS_MSG_ENQUEUEWAIT2(pmp, park_fdiscard, vp->v_data, NULL, error); + error = checkerr(pmp, error, __func__); + PUFFS_MSG_RELEASE(fdiscard); + + return error; +} + int puffs_vnop_print(void *v) {