LINUX 5.3.0: Check for 'recurse' arg in keyring_search
[openafs.git] / src / afs / LINUX / osi_file.c
index e211c05..bb7cb77 100644 (file)
 #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;
@@ -62,8 +75,12 @@ afs_linux_raw_open(afs_dcache_id_t *ainode)
 #else
     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);
 
@@ -81,7 +98,6 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
        osi_Panic("UFSOpen called for non-UFS cache\n");
     }
     if (!afs_osicred_initialized) {
-       /* valid for alpha_osf, 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;
@@ -95,8 +111,16 @@ osi_UFSOpen(afs_dcache_id_t *ainode)
     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;
@@ -134,12 +158,10 @@ int
 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;
 }
 
@@ -172,7 +194,6 @@ osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
     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
@@ -180,7 +201,7 @@ osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 #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
@@ -198,7 +219,6 @@ osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
 #endif
     afs_linux_unlock_inode(inode);
     AFS_GLOCK();
-    ReleaseWriteLock(&afs_xosi);
     return code;
 }
 
@@ -279,8 +299,7 @@ afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
        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;
        }
@@ -352,7 +371,9 @@ int
 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;
@@ -362,11 +383,13 @@ osi_rdwr(struct osi_file *osifile, struct uio *uiop, int rw)
     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;
@@ -403,10 +426,12 @@ osi_rdwr(struct osi_file *osifile, struct uio *uiop, int rw)
        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;