STATIC ssize_t xfs_vn_getxattr( struct dentry *dentry, const char *name, void *data, size_t size) { bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); char *attr = (char *)name; attrnames_t *namesp; int xflags = 0; ssize_t error; namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); if (!namesp) return -EOPNOTSUPP; attr += namesp->attr_namelen; error = namesp->attr_capable(vp, NULL); if (error) return error; /* Convert Linux syscall to XFS internal ATTR flags */ if (!size) { xflags |= ATTR_KERNOVAL; data = NULL; } xflags |= namesp->attr_flag; return namesp->attr_get(vp, attr, (void *)data, size, xflags); }
STATIC int xfs_vn_setxattr( struct dentry *dentry, const char *name, const void *data, size_t size, int flags) { bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); char *attr = (char *)name; attrnames_t *namesp; int xflags = 0; int error; namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); if (!namesp) return -EOPNOTSUPP; attr += namesp->attr_namelen; error = namesp->attr_capable(vp, NULL); if (error) return error; /* Convert Linux syscall to XFS internal ATTR flags */ if (flags & XATTR_CREATE) xflags |= ATTR_CREATE; if (flags & XATTR_REPLACE) xflags |= ATTR_REPLACE; xflags |= namesp->attr_flag; return namesp->attr_set(vp, attr, (void *)data, size, xflags); }
STATIC int xfs_file_close( struct file *filp, fl_owner_t id) { return -bhv_vop_close(vn_from_inode(filp->f_path.dentry->d_inode), 0, file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL); }
STATIC int xfs_file_open( struct inode *inode, struct file *filp) { if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) return -EFBIG; return -bhv_vop_open(vn_from_inode(inode), NULL); }
STATIC int xfs_vn_setattr( struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; unsigned int ia_valid = attr->ia_valid; bhv_vattr_t vattr = { 0 }; int flags = 0; int error; if (ia_valid & ATTR_UID) { vattr.va_mask |= XFS_AT_UID; vattr.va_uid = attr->ia_uid; } if (ia_valid & ATTR_GID) { vattr.va_mask |= XFS_AT_GID; vattr.va_gid = attr->ia_gid; } if (ia_valid & ATTR_SIZE) { vattr.va_mask |= XFS_AT_SIZE; vattr.va_size = attr->ia_size; } if (ia_valid & ATTR_ATIME) { vattr.va_mask |= XFS_AT_ATIME; vattr.va_atime = attr->ia_atime; inode->i_atime = attr->ia_atime; } if (ia_valid & ATTR_MTIME) { vattr.va_mask |= XFS_AT_MTIME; vattr.va_mtime = attr->ia_mtime; } if (ia_valid & ATTR_CTIME) { vattr.va_mask |= XFS_AT_CTIME; vattr.va_ctime = attr->ia_ctime; } if (ia_valid & ATTR_MODE) { vattr.va_mask |= XFS_AT_MODE; vattr.va_mode = attr->ia_mode; if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID)) inode->i_mode &= ~S_ISGID; } if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) flags |= ATTR_UTIME; #ifdef ATTR_NO_BLOCK if ((ia_valid & ATTR_NO_BLOCK)) flags |= ATTR_NONBLOCK; #endif error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL); if (likely(!error)) vn_revalidate(vn_from_inode(inode)); return -error; }
STATIC ssize_t xfs_file_splice_write( struct pipe_inode_info *pipe, struct file *outfilp, loff_t *ppos, size_t len, unsigned int flags) { return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode), pipe, outfilp, ppos, len, flags, 0, NULL); }
STATIC int xfs_file_release( struct inode *inode, struct file *filp) { bhv_vnode_t *vp = vn_from_inode(inode); if (vp) return -bhv_vop_release(vp); return 0; }
STATIC ssize_t xfs_file_splice_read_invis( struct file *infilp, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode), infilp, ppos, pipe, len, flags, IO_INVIS, NULL); }
STATIC int xfs_file_release( struct inode *inode, struct file *filp) { vnode_t *vp = vn_from_inode(inode); int error = 0; if (vp) VOP_RELEASE(vp, error); return -error; }
STATIC int xfs_vm_fault( struct vm_area_struct *vma, struct vm_fault *vmf) { struct inode *inode = vma->vm_file->f_path.dentry->d_inode; bhv_vnode_t *vp = vn_from_inode(inode); ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0)) return VM_FAULT_SIGBUS; return filemap_fault(vma, vmf); }
STATIC int xfs_file_open( struct inode *inode, struct file *filp) { vnode_t *vp = vn_from_inode(inode); int error; if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) return -EFBIG; VOP_OPEN(vp, NULL, error); return -error; }
STATIC ssize_t xfs_file_splice_write_invis( struct pipe_inode_info *pipe, struct file *outfilp, loff_t *ppos, size_t len, unsigned int flags) { vnode_t *vp = vn_from_inode(outfilp->f_dentry->d_inode); ssize_t rval; VOP_SPLICE_WRITE(vp, pipe, outfilp, ppos, len, flags, IO_INVIS, NULL, rval); return rval; }
STATIC ssize_t xfs_file_splice_read( struct file *infilp, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { vnode_t *vp = vn_from_inode(infilp->f_dentry->d_inode); ssize_t rval; VOP_SPLICE_READ(vp, infilp, ppos, pipe, len, flags, 0, NULL, rval); return rval; }
STATIC ssize_t xfs_file_sendfile_invis( struct file *filp, loff_t *pos, size_t count, read_actor_t actor, void *target) { vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode); ssize_t rval; VOP_SENDFILE(vp, filp, pos, IO_INVIS, count, actor, target, NULL, rval); return rval; }
STATIC int xfs_file_fsync( struct file *filp, struct dentry *dentry, int datasync) { bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); int flags = FSYNC_WAIT; if (datasync) flags |= FSYNC_DATA; if (VN_TRUNC(vp)) VUNTRUNCATE(vp); return -bhv_vop_fsync(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1); }
STATIC int xfs_file_mmap( struct file *filp, struct vm_area_struct *vma) { vma->vm_ops = &xfs_file_vm_ops; vma->vm_flags |= VM_CAN_NONLINEAR; #ifdef CONFIG_XFS_DMAPI if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI) vma->vm_ops = &xfs_dmapi_file_vm_ops; #endif /* CONFIG_XFS_DMAPI */ file_accessed(filp); return 0; }
STATIC int xfs_file_fsync( struct file *filp, struct dentry *dentry, int datasync) { struct inode *inode = dentry->d_inode; vnode_t *vp = vn_from_inode(inode); int error; int flags = FSYNC_WAIT; if (datasync) flags |= FSYNC_DATA; VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error); return -error; }
STATIC_INLINE ssize_t __xfs_file_read( struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, int ioflags, loff_t pos) { struct file *file = iocb->ki_filp; bhv_vnode_t *vp = vn_from_inode(file->f_path.dentry->d_inode); BUG_ON(iocb->ki_pos != pos); if (unlikely(file->f_flags & O_DIRECT)) ioflags |= IO_ISDIRECT; return bhv_vop_read(vp, iocb, iov, nr_segs, &iocb->ki_pos, ioflags, NULL); }
/* If the user is attempting to execute a file that is offline then * we have to trigger a DMAPI READ event before the file is marked as busy * otherwise the invisible I/O will not be able to write to the file to bring * it back online. */ STATIC int xfs_file_open_exec( struct inode *inode) { struct xfs_mount *mp = XFS_M(inode->i_sb); if (unlikely(mp->m_flags & XFS_MOUNT_DMAPI)) { if (DM_EVENT_ENABLED(XFS_I(inode), DM_EVENT_READ)) { bhv_vnode_t *vp = vn_from_inode(inode); return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, 0, 0, 0, NULL); } } return 0; }
STATIC int xfs_vm_mprotect( struct vm_area_struct *vma, unsigned int newflags) { vnode_t *vp = vn_from_inode(vma->vm_file->f_dentry->d_inode); int error = 0; if (vp->v_vfsp->vfs_flag & VFS_DMI) { if ((vma->vm_flags & VM_MAYSHARE) && (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) { xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); error = XFS_SEND_MMAP(mp, vma, VM_WRITE); } } return error; }
STATIC_INLINE ssize_t __xfs_file_write( struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, int ioflags, loff_t pos) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; bhv_vnode_t *vp = vn_from_inode(inode); BUG_ON(iocb->ki_pos != pos); if (unlikely(file->f_flags & O_DIRECT)) ioflags |= IO_ISDIRECT; return bhv_vop_write(vp, iocb, iov, nr_segs, &iocb->ki_pos, ioflags, NULL); }
/* If the user is attempting to execute a file that is offline then * we have to trigger a DMAPI READ event before the file is marked as busy * otherwise the invisible I/O will not be able to write to the file to bring * it back online. */ STATIC int xfs_file_open_exec( struct inode *inode) { bhv_vnode_t *vp = vn_from_inode(inode); if (unlikely(vp->v_vfsp->vfs_flag & VFS_DMI)) { xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); xfs_inode_t *ip = xfs_vtoi(vp); if (!ip) return -EINVAL; if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, 0, 0, 0, NULL); } return 0; }
STATIC struct page * xfs_vm_nopage( struct vm_area_struct *area, unsigned long address, int *type) { struct inode *inode = area->vm_file->f_dentry->d_inode; vnode_t *vp = vn_from_inode(inode); xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); int error; ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); error = XFS_SEND_MMAP(mp, area, 0); if (error) return NULL; return filemap_nopage(area, address, type); }
STATIC ssize_t xfs_vn_listxattr( struct dentry *dentry, char *data, size_t size) { bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); int error, xflags = ATTR_KERNAMELS; ssize_t result; if (!size) xflags |= ATTR_KERNOVAL; xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS; error = attr_generic_list(vp, data, size, xflags, &result); if (error < 0) return error; return result; }
STATIC inline ssize_t __xfs_file_read( struct kiocb *iocb, char __user *buf, int ioflags, size_t count, loff_t pos) { struct iovec iov = {buf, count}; struct file *file = iocb->ki_filp; vnode_t *vp = vn_from_inode(file->f_dentry->d_inode); ssize_t rval; BUG_ON(iocb->ki_pos != pos); if (unlikely(file->f_flags & O_DIRECT)) ioflags |= IO_ISDIRECT; VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval); return rval; }
STATIC long xfs_file_ioctl_invis( struct file *filp, unsigned int cmd, unsigned long arg) { struct inode *inode = filp->f_dentry->d_inode; vnode_t *vp = vn_from_inode(inode); int error; VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error); VMODIFY(vp); /* NOTE: some of the ioctl's return positive #'s as a * byte count indicating success, such as * readlink_by_handle. So we don't "sign flip" * like most other routines. This means true * errors need to be returned as a negative value. */ return error; }
STATIC long xfs_file_ioctl( struct file *filp, unsigned int cmd, unsigned long p) { int error; struct inode *inode = filp->f_path.dentry->d_inode; bhv_vnode_t *vp = vn_from_inode(inode); error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p); VMODIFY(vp); /* NOTE: some of the ioctl's return positive #'s as a * byte count indicating success, such as * readlink_by_handle. So we don't "sign flip" * like most other routines. This means true * errors need to be returned as a negative value. */ return error; }
STATIC inline ssize_t __xfs_file_write( struct kiocb *iocb, const char __user *buf, int ioflags, size_t count, loff_t pos) { struct iovec iov = {(void __user *)buf, count}; struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; vnode_t *vp = vn_from_inode(inode); ssize_t rval; BUG_ON(iocb->ki_pos != pos); if (unlikely(file->f_flags & O_DIRECT)) ioflags |= IO_ISDIRECT; VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval); return rval; }
STATIC int xfs_vn_removexattr( struct dentry *dentry, const char *name) { bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); char *attr = (char *)name; attrnames_t *namesp; int xflags = 0; int error; namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); if (!namesp) return -EOPNOTSUPP; attr += namesp->attr_namelen; error = namesp->attr_capable(vp, NULL); if (error) return error; xflags |= namesp->attr_flag; return namesp->attr_remove(vp, attr, xflags); }
/* If the user is attempting to execute a file that is offline then * we have to trigger a DMAPI READ event before the file is marked as busy * otherwise the invisible I/O will not be able to write to the file to bring * it back online. */ STATIC int xfs_file_open_exec( struct inode *inode) { vnode_t *vp = vn_from_inode(inode); xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); int error = 0; xfs_inode_t *ip; if (vp->v_vfsp->vfs_flag & VFS_DMI) { ip = xfs_vtoi(vp); if (!ip) { error = -EINVAL; goto open_exec_out; } if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) { error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, 0, 0, 0, NULL); } } open_exec_out: return error; }