--- /dev/null
+/* Kernel compatibility routines
+ *
+ * This file contains definitions to provide compatibility between different
+ * versions of the Linux kernel. It is an ifdef maze, but the idea is that
+ * by concentrating the horror here, the rest of the tree may remaing a
+ * little cleaner...
+ */
+
+#ifndef AFS_LINUX_OSI_COMPAT_H
+#define AFS_LINUX_OSI_COMPAT_H
+
+#ifndef DO_SYNC_READ
+static inline int
+do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
+ return generic_file_read(fp, buf, count, offp);
+}
+
+static inline int
+do_sync_write(struct file *fp, char *buf, size_t count, loff_t *offp) {
+ return generic_file_write(fp, buf, count, offp);
+}
+
+#endif /* DO_SYNC_READ */
+
+static inline int
+afs_posix_lock_file(struct file *fp, struct file_lock *flp) {
+#ifdef POSIX_LOCK_FILE_WAIT_ARG
+ return posix_lock_file(fp, flp, NULL);
+#else
+ flp->fl_flags &=~ FL_SLEEP;
+ return posix_lock_file(fp, flp);
+#endif
+}
+
+static inline void
+afs_posix_test_lock(struct file *fp, struct file_lock *flp) {
+#if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
+ struct file_lock conflict;
+ if (posix_test_lock(fp, flp, &conflict)) {
+ locks_copy_lock(flp, &conflict);
+ flp->fl_type = F_UNLCK;
+ }
+#elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
+ struct file_lock *conflict;
+ if (conflict = posix_test_lock(fp, flp)) {
+ locks_copy_lock(flp, conflict);
+ flp->fl_type = F_UNLCK;
+ }
+#else
+ posix_test_lock(fp, flp);
+#endif
+}
+
+#ifdef DCACHE_NFSFS_RENAMED
+static inline void
+afs_linux_clear_nfsfs_renamed(struct dentry *dp) {
+ spin_lock(&dp->d_lock);
+ dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
+ spin_unlock(&dp->d_lock);
+}
+
+static inline void
+afs_linux_set_nfsfs_renamed(struct dentry *dp) {
+ spin_lock(&dp->d_lock);
+ dp->d_flags |= DCACHE_NFSFS_RENAMED;
+ spin_unlock(&dp->d_lock);
+}
+#else
+static inline void afs_linux_clear_nfsfs_renamed(void) { return; }
+static inline void afs_linux_set_nfsfs_renamed(void) { return; }
+#endif
+
+#ifndef HAVE_KERNEL_HLIST_UNHASHED
+static void
+hlist_unhashed(const struct hlist_node *h) {
+ return (!h->pprev == NULL);
+}
+#endif
+
+#if defined(WRITEPAGE_ACTIVATE)
+#define AOP_WRITEPAGE_ACTIVATE WRITEPAGE_ACTIVATE
+#endif
+
+#if defined(HAVE_WRITE_BEGIN) && !defined(HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN)
+static inline struct page *
+grab_cache_page_write_begin(struct address_space *mapping, pgoff_t index,
+ unsigned int flags) {
+ return __grab_cache_page(mapping, index);
+}
+#endif
+
+#endif
#include "afs/afs_bypasscache.h"
#endif
+#include "osi_compat.h"
#include "osi_pagecopy.h"
#ifdef pgoff2loff
/* Some uses of BKL are perhaps not needed for bypass or memcache--
* why don't we try it out? */
extern struct afs_cacheOps afs_UfsCacheOps;
-#define maybe_lock_kernel() \
- do { \
- if(afs_cacheType == &afs_UfsCacheOps) \
- lock_kernel(); \
- } while(0);
+static inline void
+afs_maybe_lock_kernel(void) {
+ if(afs_cacheType == &afs_UfsCacheOps)
+ lock_kernel();
+}
-#define maybe_unlock_kernel() \
- do { \
- if(afs_cacheType == &afs_UfsCacheOps) \
- unlock_kernel(); \
- } while(0);
-
+static inline void
+afs_maybe_unlock_kernel(void) {
+ if(afs_cacheType == &afs_UfsCacheOps)
+ unlock_kernel();
+}
/* This function converts a positive error code from AFS into a negative
* code suitable for passing into the Linux VFS layer. It checks that the
* this function before being returned to the kernel.
*/
-static inline int afs_convert_code(int code) {
+static inline int
+afs_convert_code(int code) {
if ((code >= 0) && (code <= MAX_ERRNO))
return -code;
else
* operation. This helper function avoids obtaining it for VerifyVCache calls
*/
-static inline int afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
+static inline int
+afs_linux_VerifyVCache(struct vcache *avc, cred_t **retcred) {
cred_t *credp = NULL;
struct vrequest treq;
int code;
* so we optimise by not using it */
osi_FlushPages(vcp, NULL); /* ensure stale pages are gone */
AFS_GUNLOCK();
-#ifdef DO_SYNC_READ
code = do_sync_read(fp, buf, count, offp);
-#else
- code = generic_file_read(fp, buf, count, offp);
-#endif
AFS_GLOCK();
}
ReleaseWriteLock(&vcp->lock);
if (code == 0) {
AFS_GUNLOCK();
-#ifdef DO_SYNC_READ
code = do_sync_write(fp, buf, count, offp);
-#else
- code = generic_file_write(fp, buf, count, offp);
-#endif
AFS_GLOCK();
}
cred_t *credp = crref();
struct afs_fakestat_state fakestat;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
AFS_STATCNT(afs_readdir);
afs_PutFakeStat(&fakestat);
out1:
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
return code;
}
cred_t *credp = crref();
int code;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_open(&vcp, fp->f_flags, credp);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
cred_t *credp = crref();
int code = 0;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_close(vcp, fp->f_flags, credp);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
struct inode *ip = FILE_INODE(fp);
cred_t *credp = crref();
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_fsync(VTOAFS(ip), credp);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
struct vcache *vcp = VTOAFS(FILE_INODE(fp));
cred_t *credp = crref();
struct AFS_FLOCK flock;
-#if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
- struct file_lock conflict;
-#elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
- struct file_lock *conflict;
-#endif
/* Convert to a lock format afs_lockctl understands. */
memset((char *)&flock, 0, sizeof(flock));
if ((code == 0 || flp->fl_type == F_UNLCK) &&
(cmd == F_SETLK || cmd == F_SETLKW)) {
-#ifdef POSIX_LOCK_FILE_WAIT_ARG
- code = posix_lock_file(fp, flp, 0);
-#else
- flp->fl_flags &=~ FL_SLEEP;
- code = posix_lock_file(fp, flp);
-#endif
+ code = afs_posix_lock_file(fp, flp);
if (code && flp->fl_type != F_UNLCK) {
struct AFS_FLOCK flock2;
flock2 = flock;
* kernel, as lockctl knows nothing about byte range locks
*/
if (code == 0 && cmd == F_GETLK && flock.l_type == F_UNLCK) {
-#if defined(POSIX_TEST_LOCK_CONFLICT_ARG)
- if (posix_test_lock(fp, flp, &conflict)) {
- locks_copy_lock(flp, &conflict);
- flp->fl_type = F_UNLCK;
- crfree(credp);
- return 0;
- }
-#elif defined(POSIX_TEST_LOCK_RETURNS_CONFLICT)
- if ((conflict = posix_test_lock(fp, flp))) {
- locks_copy_lock(flp, conflict);
- flp->fl_type = F_UNLCK;
- crfee(credp);
- return 0;
- }
-#else
- posix_test_lock(fp, flp);
+ afs_posix_test_lock(fp, flp);
/* If we found a lock in the kernel's structure, return it */
if (flp->fl_type != F_UNLCK) {
crfree(credp);
return 0;
}
-#endif
}
/* Convert flock back to Linux's file_lock */
if (afs_shuttingdown)
return EIO;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
#ifdef notyet
afs_fill_inode(AFSTOV(vcp), &vattr);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
return afs_convert_code(code);
}
int valid;
struct afs_fakestat_state fakestate;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
afs_InitFakeStat(&fakestate);
shrink_dcache_parent(dp);
d_drop(dp);
}
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
return valid;
bad_dentry:
(void) afs_InactiveVCache(vcp, NULL);
}
AFS_GUNLOCK();
-#ifdef DCACHE_NFSFS_RENAMED
- spin_lock(&dp->d_lock);
- dp->d_flags &= ~DCACHE_NFSFS_RENAMED;
- spin_unlock(&dp->d_lock);
-#endif
+ afs_linux_clear_nfsfs_renamed(dp);
iput(ip);
}
vattr.va_mode = mode;
vattr.va_type = mode & S_IFMT;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_create(VTOAFS(dip), (char *)name, &vattr, NONEXCL, mode,
&vcp, credp);
}
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
}
struct dentry *newdp = NULL;
int code;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_lookup(VTOAFS(dip), (char *)comp, &vcp, credp);
ip = AFSTOV(vcp);
afs_getattr(vcp, &vattr, credp);
afs_fill_inode(ip, &vattr);
- if (
-#ifdef HAVE_KERNEL_HLIST_UNHASHED
- hlist_unhashed(&ip->i_hash)
-#else
- ip->i_hash.pprev == NULL
-#endif
- )
+ if (hlist_unhashed(&ip->i_hash))
insert_inode_hash(ip);
}
dp->d_op = &afs_dentry_operations;
}
newdp = d_splice_alias(ip, dp);
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
/* It's ok for the file to not be found. That's noted by the caller by
const char *name = dp->d_name.name;
struct vcache *tvc = VTOAFS(dp->d_inode);
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
if (VREFCOUNT(tvc) > 1 && tvc->opens > 0
&& !(tvc->f.states & CUnlinked)) {
struct dentry *__dp;
}
tvc->uncred = credp;
tvc->f.states |= CUnlinked;
-#ifdef DCACHE_NFSFS_RENAMED
- spin_lock(&dp->d_lock);
- dp->d_flags |= DCACHE_NFSFS_RENAMED;
- spin_unlock(&dp->d_lock);
-#endif
+ afs_linux_set_nfsfs_renamed(dp);
} else {
osi_FreeSmallSpace(__name);
}
if (!code)
d_drop(dp);
out:
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
}
struct vattr vattr;
const char *name = dp->d_name.name;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
VATTR_NULL(&vattr);
vattr.va_mask = ATTR_MODE;
vattr.va_mode = mode;
}
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
}
struct dentry *rehash = NULL;
/* Prevent any new references during rename operation. */
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
if (!d_unhashed(newdp)) {
d_drop(newdp);
if (rehash)
d_rehash(rehash);
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
return afs_convert_code(code);
ancr->offset = offset;
ancr->length = PAGE_SIZE;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
code = afs_ReadNoCache(avc, ancr, credp);
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
goto done; /* skips release page, doing it in bg thread */
}
#endif
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
AFS_DISCON_LOCK();
afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE, ICL_TYPE_POINTER, ip,
code);
AFS_DISCON_UNLOCK();
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
if (!code) {
/* XXX valid for no-cache also? Check last bits of files... :)
* Cognate code goes in afs_NoCacheFetchProc. */
base = (((loff_t) pp->index) << PAGE_CACHE_SHIFT) + offset;
credp = crref();
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp),
if (vcp->f.states & CPageWrite) {
ReleaseWriteLock(&vcp->lock);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
kunmap(pp);
-#if defined(WRITEPAGE_ACTIVATE)
- return WRITEPAGE_ACTIVATE;
-#else
return AOP_WRITEPAGE_ACTIVATE;
-#endif
}
vcp->f.states |= CPageWrite;
ReleaseWriteLock(&vcp->lock);
ICL_TYPE_INT32, code);
AFS_GUNLOCK();
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
crfree(credp);
kunmap(pp);
long status;
if (PageReclaim(pp)) {
-#if defined(WRITEPAGE_ACTIVATE)
- return WRITEPAGE_ACTIVATE;
-#else
return AOP_WRITEPAGE_ACTIVATE;
-#endif
}
inode = (struct inode *)mapping->host;
do_it:
status = afs_linux_writepage_sync(inode, pp, 0, offset);
SetPageUptodate(pp);
-#if defined(WRITEPAGE_ACTIVATE)
- if ( status != WRITEPAGE_ACTIVATE )
-#else
if ( status != AOP_WRITEPAGE_ACTIVATE )
-#endif
UnlockPage(pp);
if (status == offset)
return 0;
{
struct page *page;
pgoff_t index = pos >> PAGE_CACHE_SHIFT;
-#if defined(HAVE_GRAB_CACHE_PAGE_WRITE_BEGIN)
page = grab_cache_page_write_begin(mapping, index, flags);
-#else
- page = __grab_cache_page(mapping, index);
-#endif
*pagep = page;
return 0;
char *p = (char *)kmap(page);
int code;
- maybe_lock_kernel();
+ afs_maybe_lock_kernel();
AFS_GLOCK();
code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
AFS_GUNLOCK();
if (code < 0)
goto fail;
p[code] = '\0'; /* null terminate? */
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
SetPageUptodate(page);
kunmap(page);
return 0;
fail:
- maybe_unlock_kernel();
+ afs_maybe_unlock_kernel();
SetPageError(page);
kunmap(page);