[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>
This commit is contained in:
Christoph Hellwig 2008-02-05 12:13:07 +11:00 committed by Lachlan McIlroy
parent 199037c598
commit 35fec8df65
1 changed files with 26 additions and 41 deletions

View File

@ -52,76 +52,61 @@ xfs_swapext(
xfs_swapext_t __user *sxu) xfs_swapext_t __user *sxu)
{ {
xfs_swapext_t *sxp; xfs_swapext_t *sxp;
xfs_inode_t *ip=NULL, *tip=NULL; xfs_inode_t *ip, *tip;
xfs_mount_t *mp; struct file *file, *target_file;
struct file *fp = NULL, *tfp = NULL;
bhv_vnode_t *vp, *tvp;
int error = 0; int error = 0;
sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL); sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL);
if (!sxp) { if (!sxp) {
error = XFS_ERROR(ENOMEM); error = XFS_ERROR(ENOMEM);
goto error0; goto out;
} }
if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) { if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) {
error = XFS_ERROR(EFAULT); error = XFS_ERROR(EFAULT);
goto error0; goto out_free_sxp;
} }
/* Pull information for the target fd */ /* Pull information for the target fd */
if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) || file = fget((int)sxp->sx_fdtarget);
((vp = vn_from_inode(fp->f_path.dentry->d_inode)) == NULL)) { if (!file) {
error = XFS_ERROR(EINVAL); error = XFS_ERROR(EINVAL);
goto error0; goto out_free_sxp;
} }
ip = xfs_vtoi(vp); target_file = fget((int)sxp->sx_fdtmp);
if (ip == NULL) { if (!target_file) {
error = XFS_ERROR(EBADF);
goto error0;
}
if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) ||
((tvp = vn_from_inode(tfp->f_path.dentry->d_inode)) == NULL)) {
error = XFS_ERROR(EINVAL); error = XFS_ERROR(EINVAL);
goto error0; goto out_put_file;
} }
tip = xfs_vtoi(tvp); ip = XFS_I(file->f_path.dentry->d_inode);
if (tip == NULL) { tip = XFS_I(target_file->f_path.dentry->d_inode);
error = XFS_ERROR(EBADF);
goto error0;
}
if (ip->i_mount != tip->i_mount) { if (ip->i_mount != tip->i_mount) {
error = XFS_ERROR(EINVAL); error = XFS_ERROR(EINVAL);
goto error0; goto out_put_target_file;
} }
if (ip->i_ino == tip->i_ino) { if (ip->i_ino == tip->i_ino) {
error = XFS_ERROR(EINVAL); error = XFS_ERROR(EINVAL);
goto error0; goto out_put_target_file;
} }
mp = ip->i_mount; if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
error = XFS_ERROR(EIO);
if (XFS_FORCED_SHUTDOWN(mp)) { goto out_put_target_file;
error = XFS_ERROR(EIO);
goto error0;
} }
error = xfs_swap_extents(ip, tip, sxp); error = xfs_swap_extents(ip, tip, sxp);
error0: out_put_target_file:
if (fp != NULL) fput(target_file);
fput(fp); out_put_file:
if (tfp != NULL) fput(file);
fput(tfp); out_free_sxp:
kmem_free(sxp, sizeof(xfs_swapext_t));
if (sxp != NULL) out:
kmem_free(sxp, sizeof(xfs_swapext_t));
return error; return error;
} }