#endif
#include "osi_compat.h"
+#ifndef CURRENT_TIME
+# if defined(HAVE_LINUX_KTIME_GET_COARSE_REAL_TS64)
+# define AFS_CURRENT_TIME(x) (ktime_get_coarse_real_ts64((x)))
+# else
+# ifdef IATTR_TAKES_64BIT_TIME
+# define AFS_CURRENT_TIME(x) do {*(x) = current_kernel_time64();} while (0)
+# else
+# define AFS_CURRENT_TIME(x) do {*(x) = current_kernel_time();} while (0)
+# endif
+# endif
+#else
+# define AFS_CURRENT_TIME(x) do {*(x) = CURRENT_TIME;} while(0)
+#endif
+
int cache_fh_type = -1;
int cache_fh_len = -1;
-afs_lock_t afs_xosi; /* lock is for tvattr */
extern struct osi_dev cacheDev;
extern struct vfsmount *afs_cacheMnt;
extern struct super_block *afs_cacheSBp;
tip = dp->d_inode;
tip->i_flags |= S_NOATIME; /* Disable updating access times. */
- /* note that if this is ever changed to recover from errors, we will need
- * to put this reference back */
- mntget(afs_cacheMnt);
-
#if defined(STRUCT_TASK_STRUCT_HAS_CRED)
/* Use stashed credentials - prevent selinux/apparmor problems */
filp = afs_dentry_open(dp, afs_cacheMnt, O_RDWR, cache_creds);
if (IS_ERR(filp))
filp = afs_dentry_open(dp, afs_cacheMnt, O_RDWR, current_cred());
#else
- filp = dentry_open(dp, afs_cacheMnt, O_RDWR);
+ filp = dentry_open(dget(dp), mntget(afs_cacheMnt), O_RDWR);
#endif
- if (IS_ERR(filp))
- osi_Panic("Can't open file: %d\n", (int) PTR_ERR(filp));
+ if (IS_ERR(filp)) {
+ afs_warn("afs: Cannot open cache file (code %d). Trying to continue, "
+ "but AFS accesses may return errors or panic the system\n",
+ (int) PTR_ERR(filp));
+ filp = NULL;
+ }
+
+ dput(dp);
+
return filp;
}
osi_Panic("UFSOpen called for non-UFS cache\n");
}
if (!afs_osicred_initialized) {
- /* valid for alpha_osf, SunOS, Ultrix */
+ /* valid for SunOS, Ultrix */
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->size = i_size_read(FILE_INODE(afile->filp));
+ if (afile->filp) {
+ afile->size = i_size_read(FILE_INODE(afile->filp));
+ }
AFS_GLOCK();
+
+ if (!afile->filp) {
+ osi_FreeLargeSpace(afile);
+ return NULL;
+ }
+
afile->offset = 0;
afile->proc = (int (*)())0;
return (void *)afile;
afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
{
AFS_STATCNT(osi_Stat);
- 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;
- ReleaseWriteLock(&afs_xosi);
return 0;
}
code = afs_osi_Stat(afile, &tstat);
if (code || tstat.size <= asize)
return code;
- ObtainWriteLock(&afs_xosi, 321);
AFS_GUNLOCK();
afs_linux_lock_inode(inode);
#ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
#endif
newattrs.ia_size = asize;
newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
- newattrs.ia_ctime = CURRENT_TIME;
+ AFS_CURRENT_TIME(&newattrs.ia_ctime);
/* avoid notify_change() since it wants to update dentry->d_parent */
+#ifdef HAVE_LINUX_SETATTR_PREPARE
+ code = setattr_prepare(file_dentry(afile->filp), &newattrs);
+#else
code = inode_change_ok(inode, &newattrs);
+#endif
if (!code)
code = afs_inode_setattr(afile, &newattrs);
if (!code)
#endif
afs_linux_unlock_inode(inode);
AFS_GLOCK();
- ReleaseWriteLock(&afs_xosi);
return code;
}
struct iovec iov;
afs_int32 code;
+ memset(&auio, 0, sizeof(auio));
+ memset(&iov, 0, sizeof(iov));
+
AFS_STATCNT(osi_Read);
/*
* down. No point in crashing when we are already shutting down
*/
if (!afile) {
- if (!afs_shuttingdown)
+ if (afs_shuttingdown == AFS_RUNNING)
osi_Panic("osi_Read called with null param");
else
return -EIO;
struct iovec iov;
afs_int32 code;
+ memset(&auio, 0, sizeof(auio));
+ memset(&iov, 0, sizeof(iov));
+
AFS_STATCNT(osi_Write);
if (!afile) {
- if (!afs_shuttingdown)
+ if (afs_shuttingdown == AFS_RUNNING)
osi_Panic("afs_osi_Write called with null param");
else
return -EIO;
afile->offset += code;
} else {
if (code == ENOSPC)
- afs_warnuser
- ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
+ afs_WarnENOSPC();
if (code > 0) {
code = -code;
}
osi_rdwr(struct osi_file *osifile, struct uio *uiop, int rw)
{
struct file *filp = osifile->filp;
+#ifdef AFS_FILE_NEEDS_SET_FS
mm_segment_t old_fs = {0};
+#endif /* AFS_FILE_NEEDS_SET_FS */
int code = 0;
struct iovec *iov;
size_t count;
savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur;
current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
+#ifdef AFS_FILE_NEEDS_SET_FS
if (uiop->uio_seg == AFS_UIOSYS) {
/* Switch into user space */
old_fs = get_fs();
set_fs(get_ds());
}
+#endif /* AFS_FILE_NEEDS_SET_FS */
while (code == 0 && uiop->uio_resid > 0 && uiop->uio_iovcnt > 0) {
iov = uiop->uio_iov;
pos = uiop->uio_offset;
if (rw == UIO_READ)
- code = filp->f_op->read(filp, iov->iov_base, count, &pos);
+ code = afs_file_read(filp, iov->iov_base, count, &pos);
else
- code = filp->f_op->write(filp, iov->iov_base, count, &pos);
+ code = afs_file_write(filp, iov->iov_base, count, &pos);
if (code < 0) {
code = -code;
code = 0;
}
+#ifdef AFS_FILE_NEEDS_SET_FS
if (uiop->uio_seg == AFS_UIOSYS) {
/* Switch back into kernel space */
set_fs(old_fs);
}
+#endif /* AFS_FILE_NEEDS_SET_FS */
current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim;