#include "afs/param.h"
-#include "h/module.h" /* early to avoid printf->printk mapping */
+#include <linux/module.h> /* early to avoid printf->printk mapping */
#include "afs/sysincludes.h" /* Standard vendor system headers */
#include "afsincludes.h" /* Afs-based standard headers */
#include "afs/afs_stats.h" /* afs statistics */
-#include "h/smp_lock.h"
-#include "h/namei.h"
+#include <linux/smp_lock.h>
+#include <linux/namei.h>
#if defined(LINUX_USE_FH)
-#include "h/exportfs.h"
+#include <linux/exportfs.h>
int cache_fh_type = -1;
int cache_fh_len = -1;
#endif
extern struct osi_dev cacheDev;
extern struct vfsmount *afs_cacheMnt;
extern struct super_block *afs_cacheSBp;
+#if defined(STRUCT_TASK_HAS_CRED)
+extern struct cred *cache_creds;
+#endif
struct file *
-afs_linux_raw_open(afs_dcache_id_t *ainode, ino_t *hint)
+afs_linux_raw_open(afs_dcache_id_t *ainode)
{
struct inode *tip = NULL;
struct dentry *dp = NULL;
osi_Panic("Can't get dentry\n");
tip = dp->d_inode;
#endif
- tip->i_flags |= MS_NOATIME; /* Disable updating access times. */
+ tip->i_flags |= S_NOATIME; /* Disable updating access times. */
#if defined(STRUCT_TASK_HAS_CRED)
- filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR, current_cred());
+ /* Use stashed credentials - prevent selinux/apparmor problems */
+ filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR, cache_creds);
+ if (IS_ERR(filp))
+ filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR, current_cred());
#else
filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR);
#endif
if (IS_ERR(filp))
#if defined(LINUX_USE_FH)
- osi_Panic("Can't open file\n");
+ osi_Panic("Can't open file: %d\n", (int) PTR_ERR(filp));
#else
osi_Panic("Can't open inode %d\n", (int) ainode->ufs);
#endif
- if (hint)
- *hint = tip->i_ino;
return filp;
}
{
struct osi_file *afile = NULL;
extern int cacheDiskType;
- struct file *filp = NULL;
+
AFS_STATCNT(osi_UFSOpen);
if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
osi_Panic("UFSOpen called for non-UFS cache\n");
}
if (!afs_osicred_initialized) {
/* valid for alpha_osf, SunOS, Ultrix */
- memset((char *)&afs_osi_cred, 0, sizeof(AFS_UCRED));
+ memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
afs_osicred_initialized = 1;
}
}
memset(afile, 0, sizeof(struct osi_file));
- afile->filp = afs_linux_raw_open(ainode, &afile->inum);
+ afile->filp = afs_linux_raw_open(ainode);
afile->size = i_size_read(FILE_INODE(afile->filp));
AFS_GLOCK();
afile->offset = 0;
afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
{
AFS_STATCNT(osi_Stat);
- MObtainWriteLock(&afs_xosi, 320);
+ ObtainWriteLock(&afs_xosi, 320);
astat->size = i_size_read(OSIFILE_INODE(afile));
astat->mtime = OSIFILE_INODE(afile)->i_mtime.tv_sec;
astat->atime = OSIFILE_INODE(afile)->i_atime.tv_sec;
- MReleaseWriteLock(&afs_xosi);
+ ReleaseWriteLock(&afs_xosi);
return 0;
}
code = afs_osi_Stat(afile, &tstat);
if (code || tstat.size <= asize)
return code;
- MObtainWriteLock(&afs_xosi, 321);
+ ObtainWriteLock(&afs_xosi, 321);
AFS_GUNLOCK();
-#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
- down_write(&inode->i_alloc_sem);
-#endif
#ifdef STRUCT_INODE_HAS_I_MUTEX
mutex_lock(&inode->i_mutex);
#else
down(&inode->i_sem);
#endif
+#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
+ down_write(&inode->i_alloc_sem);
+#endif
newattrs.ia_size = asize;
newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
newattrs.ia_ctime = CURRENT_TIME;
if (!code)
truncate_inode_pages(&inode->i_data, asize);
code = -code;
+#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
+ up_write(&inode->i_alloc_sem);
+#endif
#ifdef STRUCT_INODE_HAS_I_MUTEX
mutex_unlock(&inode->i_mutex);
#else
up(&inode->i_sem);
#endif
-#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
- up_write(&inode->i_alloc_sem);
-#endif
AFS_GLOCK();
- MReleaseWriteLock(&afs_xosi);
+ ReleaseWriteLock(&afs_xosi);
return code;
}
}
-#define FOP_READ(F, B, C) (F)->f_op->read(F, B, (size_t)(C), &(F)->f_pos)
-#define FOP_WRITE(F, B, C) (F)->f_op->write(F, B, (size_t)(C), &(F)->f_pos)
-
/* osi_rdwr
* seek, then read or write to an open inode. addrp points to data in
* kernel space.
osi_rdwr(struct osi_file *osifile, uio_t * uiop, int rw)
{
struct file *filp = osifile->filp;
- KERNEL_SPACE_DECL;
+ mm_segment_t old_fs = {0};
int code = 0;
struct iovec *iov;
- afs_size_t count;
+ size_t count;
unsigned long savelim;
+ loff_t pos;
savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur;
current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
- if (uiop->uio_seg == AFS_UIOSYS)
- TO_USER_SPACE();
+ if (uiop->uio_seg == AFS_UIOSYS) {
+ /* Switch into user space */
+ old_fs = get_fs();
+ set_fs(get_ds());
+ }
/* seek to the desired position. Return -1 on error. */
- if (filp->f_op->llseek) {
- if (filp->f_op->llseek(filp, (loff_t) uiop->uio_offset, 0) != uiop->uio_offset)
- return -1;
- } else
- filp->f_pos = uiop->uio_offset;
+ if (vfs_llseek(filp, (loff_t) uiop->uio_offset, 0) != uiop->uio_offset) {
+ code = -1;
+ goto out;
+ }
while (code == 0 && uiop->uio_resid > 0 && uiop->uio_iovcnt > 0) {
iov = uiop->uio_iov;
continue;
}
+ pos = filp->f_pos;
if (rw == UIO_READ)
- code = FOP_READ(filp, iov->iov_base, count);
+ code = filp->f_op->read(filp, iov->iov_base, count, &pos);
else
- code = FOP_WRITE(filp, iov->iov_base, count);
+ code = filp->f_op->write(filp, iov->iov_base, count, &pos);
+ filp->f_pos = pos;
if (code < 0) {
code = -code;
code = 0;
}
- if (uiop->uio_seg == AFS_UIOSYS)
- TO_KERNEL_SPACE();
+out:
+ if (uiop->uio_seg == AFS_UIOSYS) {
+ /* Switch back into kernel space */
+ set_fs(old_fs);
+ }
current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim;