[XFS] clean up xfs_swapext

- stop using vnodes
- use proper multiple label goto unwinding
- give the struct file * variables saner names

SGI-PV: 971186
SGI-Modid: xfs-linux-melb:xfs-kern:30366a

Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>

authored by

Christoph Hellwig and committed by
Lachlan McIlroy
35fec8df 199037c5

+26 -41
+26 -41
fs/xfs/xfs_dfrag.c
··· 52 xfs_swapext_t __user *sxu) 53 { 54 xfs_swapext_t *sxp; 55 - xfs_inode_t *ip=NULL, *tip=NULL; 56 - xfs_mount_t *mp; 57 - struct file *fp = NULL, *tfp = NULL; 58 - bhv_vnode_t *vp, *tvp; 59 int error = 0; 60 61 sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); 62 if (!sxp) { 63 error = XFS_ERROR(ENOMEM); 64 - goto error0; 65 } 66 67 if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) { 68 error = XFS_ERROR(EFAULT); 69 - goto error0; 70 } 71 72 /* Pull information for the target fd */ 73 - if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) || 74 - ((vp = vn_from_inode(fp->f_path.dentry->d_inode)) == NULL)) { 75 error = XFS_ERROR(EINVAL); 76 - goto error0; 77 } 78 79 - ip = xfs_vtoi(vp); 80 - if (ip == NULL) { 81 - error = XFS_ERROR(EBADF); 82 - goto error0; 83 - } 84 - 85 - if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) || 86 - ((tvp = vn_from_inode(tfp->f_path.dentry->d_inode)) == NULL)) { 87 error = XFS_ERROR(EINVAL); 88 - goto error0; 89 } 90 91 - tip = xfs_vtoi(tvp); 92 - if (tip == NULL) { 93 - error = XFS_ERROR(EBADF); 94 - goto error0; 95 - } 96 97 if (ip->i_mount != tip->i_mount) { 98 - error = XFS_ERROR(EINVAL); 99 - goto error0; 100 } 101 102 if (ip->i_ino == tip->i_ino) { 103 - error = XFS_ERROR(EINVAL); 104 - goto error0; 105 } 106 107 - mp = ip->i_mount; 108 - 109 - if (XFS_FORCED_SHUTDOWN(mp)) { 110 - error = XFS_ERROR(EIO); 111 - goto error0; 112 } 113 114 error = xfs_swap_extents(ip, tip, sxp); 115 116 - error0: 117 - if (fp != NULL) 118 - fput(fp); 119 - if (tfp != NULL) 120 - fput(tfp); 121 - 122 - if (sxp != NULL) 123 - kmem_free(sxp, sizeof(xfs_swapext_t)); 124 - 125 return error; 126 } 127
··· 52 xfs_swapext_t __user *sxu) 53 { 54 xfs_swapext_t *sxp; 55 + xfs_inode_t *ip, *tip; 56 + struct file *file, *target_file; 57 int error = 0; 58 59 sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); 60 if (!sxp) { 61 error = XFS_ERROR(ENOMEM); 62 + goto out; 63 } 64 65 if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) { 66 error = XFS_ERROR(EFAULT); 67 + goto out_free_sxp; 68 } 69 70 /* Pull information for the target fd */ 71 + file = fget((int)sxp->sx_fdtarget); 72 + if (!file) { 73 error = XFS_ERROR(EINVAL); 74 + goto out_free_sxp; 75 } 76 77 + target_file = fget((int)sxp->sx_fdtmp); 78 + if (!target_file) { 79 error = XFS_ERROR(EINVAL); 80 + goto out_put_file; 81 } 82 83 + ip = XFS_I(file->f_path.dentry->d_inode); 84 + tip = XFS_I(target_file->f_path.dentry->d_inode); 85 86 if (ip->i_mount != tip->i_mount) { 87 + error = XFS_ERROR(EINVAL); 88 + goto out_put_target_file; 89 } 90 91 if (ip->i_ino == tip->i_ino) { 92 + error = XFS_ERROR(EINVAL); 93 + goto out_put_target_file; 94 } 95 96 + if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { 97 + error = XFS_ERROR(EIO); 98 + goto out_put_target_file; 99 } 100 101 error = xfs_swap_extents(ip, tip, sxp); 102 103 + out_put_target_file: 104 + fput(target_file); 105 + out_put_file: 106 + fput(file); 107 + out_free_sxp: 108 + kmem_free(sxp, sizeof(xfs_swapext_t)); 109 + out: 110 return error; 111 } 112