[XFS] stop re-checking permissions in xfs_swapext

xfs_swapext should simplify check if we have a writeable file descriptor
instead of re-checking the permissions using xfs_iaccess. Add an
additional check to refuse O_APPEND file descriptors because swapext is
not an append-only write operation.

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

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 f6aa7f21 35fec8df

+11 -9
+11 -9
fs/xfs/xfs_dfrag.c
··· 74 74 goto out_free_sxp; 75 75 } 76 76 77 + if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) { 78 + error = XFS_ERROR(EBADF); 79 + goto out_put_file; 80 + } 81 + 77 82 target_file = fget((int)sxp->sx_fdtmp); 78 83 if (!target_file) { 79 84 error = XFS_ERROR(EINVAL); 80 85 goto out_put_file; 86 + } 87 + 88 + if (!(target_file->f_mode & FMODE_WRITE) || 89 + (target_file->f_flags & O_APPEND)) { 90 + error = XFS_ERROR(EBADF); 91 + goto out_put_target_file; 81 92 } 82 93 83 94 ip = XFS_I(file->f_path.dentry->d_inode); ··· 164 153 165 154 xfs_lock_inodes(ips, 2, 0, lock_flags); 166 155 locked = 1; 167 - 168 - /* Check permissions */ 169 - error = xfs_iaccess(ip, S_IWUSR, NULL); 170 - if (error) 171 - goto error0; 172 - 173 - error = xfs_iaccess(tip, S_IWUSR, NULL); 174 - if (error) 175 - goto error0; 176 156 177 157 /* Verify that both files have the same format */ 178 158 if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {