# endif
#endif
-#ifndef HAVE_LINUX_DO_SYNC_READ
+#if defined(STRUCT_DENTRY_OPERATIONS_HAS_D_AUTOMOUNT) && !defined(DCACHE_NEED_AUTOMOUNT)
+# define DCACHE_NEED_AUTOMOUNT DMANAGED_AUTOMOUNT
+#endif
+
+#ifdef HAVE_LINUX_STRUCT_VFS_PATH
+typedef struct vfs_path afs_linux_path_t;
+#else
+typedef struct path afs_linux_path_t;
+#endif
+
+#if defined(STRUCT_DENTRY_HAS_D_U_D_ALIAS)
+# define d_alias d_u.d_alias
+#endif
+
+#if defined(STRUCT_FILE_HAS_F_PATH)
+# if !defined(f_dentry)
+# define f_dentry f_path.dentry
+# endif
+#endif
+
+#if defined(HAVE_LINUX_LOCKS_LOCK_FILE_WAIT)
+# define flock_lock_file_wait locks_lock_file_wait
+#endif
+
+#if !defined(HAVE_LINUX_DO_SYNC_READ) && !defined(STRUCT_FILE_OPERATIONS_HAS_READ_ITER)
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);
#ifdef LINUX_KEYRING_SUPPORT
static inline struct key *
-afs_linux_key_alloc(struct key_type *type, const char *desc, uid_t uid,
- gid_t gid, key_perm_t perm, unsigned long flags)
+afs_linux_key_alloc(struct key_type *type, const char *desc, afs_kuid_t uid,
+ afs_kgid_t gid, key_perm_t perm, unsigned long flags)
{
# if defined(KEY_ALLOC_NEEDS_STRUCT_TASK)
return key_alloc(type, desc, uid, gid, current, perm, flags);
}
# if defined(STRUCT_TASK_STRUCT_HAS_CRED)
+static inline struct key *
+afs_session_keyring(afs_ucred_t *cred)
+{
+# if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
+ return cred->session_keyring;
+# else
+ return cred->tgcred->session_keyring;
+# endif
+}
+
static inline struct key*
afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
{
key_ref_t key_ref;
- if (cred->tgcred->session_keyring) {
+ if (afs_session_keyring(cred)) {
key_ref = keyring_search(
- make_key_ref(cred->tgcred->session_keyring, 1),
+ make_key_ref(afs_session_keyring(cred), 1),
type, "_pag");
if (IS_ERR(key_ref))
return ERR_CAST(key_ref);
return request_key(type, "_pag", NULL);
}
# endif /* STRUCT_TASK_STRUCT_HAS_CRED */
+
+static_inline struct key *
+afs_set_session_keyring(struct key *keyring)
+{
+ struct key *old;
+#if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
+ struct cred *new_creds;
+ old = current_session_keyring();
+ new_creds = prepare_creds();
+ rcu_assign_pointer(new_creds->session_keyring, keyring);
+ commit_creds(new_creds);
+#else
+ spin_lock_irq(¤t->sighand->siglock);
+ old = task_session_keyring(current);
+ smp_wmb();
+ task_session_keyring(current) = keyring;
+ spin_unlock_irq(¤t->sighand->siglock);
+#endif
+ return old;
+}
#endif /* LINUX_KEYRING_SUPPORT */
#ifdef STRUCT_TASK_STRUCT_HAS_CRED
#endif
#ifdef HAVE_TRY_TO_FREEZE
-static inline void
+static inline int
afs_try_to_freeze(void) {
# ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
- try_to_freeze(PF_FREEZE);
+ return try_to_freeze(PF_FREEZE);
# else
- try_to_freeze();
+ return try_to_freeze();
# endif
}
#else
-static inline void
+static inline int
afs_try_to_freeze(void) {
# ifdef CONFIG_PM
if (current->flags & PF_FREEZE) {
refrigerator(PF_FREEZE);
+ return 1;
}
# endif
+ return 0;
+}
+#endif
+
+/* The commit which changed refrigerator so that it takes no arguments
+ * also added freezing(), so if LINUX_REFRIGERATOR_TAKES_PF_FREEZE is
+ * true, the kernel doesn't have a freezing() function.
+ */
+#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
+static inline int
+freezing(struct task_struct *p)
+{
+# ifdef CONFIG_PM
+ return p->flags & PF_FREEZE;
+# else
+ return 0;
+# endif
}
#endif
static inline int
afs_get_fh_from_dentry(struct dentry *dp, afs_ufs_dcache_id_t *ainode, int *max_lenp) {
if (dp->d_sb->s_export_op->encode_fh)
+#if defined(EXPORT_OP_ENCODE_FH_TAKES_INODES)
+ return dp->d_sb->s_export_op->encode_fh(dp->d_inode, &ainode->raw[0], max_lenp, NULL);
+#else
return dp->d_sb->s_export_op->encode_fh(dp, &ainode->raw[0], max_lenp, 0);
+#endif
#if defined(NEW_EXPORT_OPS)
/* If fs doesn't provide an encode_fh method, assume the default INO32 type */
*max_lenp = sizeof(struct fid)/4;
static inline void
afs_linux_lock_inode(struct inode *ip) {
-#ifdef STRUCT_INODE_HAS_I_MUTEX
+#if defined(HAVE_LINUX_INODE_LOCK)
+ inode_lock(ip);
+#elif defined(STRUCT_INODE_HAS_I_MUTEX)
mutex_lock(&ip->i_mutex);
#else
down(&ip->i_sem);
static inline void
afs_linux_unlock_inode(struct inode *ip) {
-#ifdef STRUCT_INODE_HAS_I_MUTEX
+#if defined(HAVE_LINUX_INODE_LOCK)
+ inode_unlock(ip);
+#elif defined(STRUCT_INODE_HAS_I_MUTEX)
mutex_unlock(&ip->i_mutex);
#else
up(&ip->i_sem);
return code;
}
-static inline int
-afs_kern_path(char *aname, int flags, struct nameidata *nd, struct path *path) {
#if defined(HAVE_LINUX_PATH_LOOKUP)
+static inline int
+afs_kern_path(char *aname, int flags, struct nameidata *nd) {
return path_lookup(aname, flags, nd);
+}
#else
+static inline int
+afs_kern_path(char *aname, int flags, afs_linux_path_t *path) {
return kern_path(aname, flags, path);
-#endif
}
+#endif
static inline void
-afs_get_dentry_ref(struct nameidata *nd, struct path *path, struct vfsmount **mnt, struct dentry **dpp) {
-#if defined(STRUCT_NAMEIDATA_HAS_PATH)
-# if defined(HAVE_LINUX_PATH_LOOKUP)
+#if defined(HAVE_LINUX_PATH_LOOKUP)
+afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **dpp) {
+#else
+afs_get_dentry_ref(afs_linux_path_t *path, struct vfsmount **mnt, struct dentry **dpp) {
+#endif
+#if defined(HAVE_LINUX_PATH_LOOKUP)
+# if defined(STRUCT_NAMEIDATA_HAS_PATH)
*dpp = dget(nd->path.dentry);
if (mnt)
*mnt = mntget(nd->path.mnt);
path_put(&nd->path);
# else
+ *dpp = dget(nd->dentry);
+ if (mnt)
+ *mnt = mntget(nd->mnt);
+ path_release(nd);
+# endif
+#else
*dpp = dget(path->dentry);
if (mnt)
*mnt = mntget(path->mnt);
path_put(path);
-# endif
+#endif
+}
+
+/* wait_event_freezable appeared with 2.6.24 */
+
+/* These implement the original AFS wait behaviour, with respect to the
+ * refrigerator, rather than the behaviour of the current wait_event_freezable
+ * implementation.
+ */
+
+#ifndef wait_event_freezable
+# define wait_event_freezable(waitqueue, condition) \
+({ \
+ int _ret; \
+ do { \
+ _ret = wait_event_interruptible(waitqueue, \
+ (condition) || freezing(current)); \
+ if (_ret && !freezing(current)) \
+ break; \
+ else if (!(condition)) \
+ _ret = -EINTR; \
+ } while (afs_try_to_freeze()); \
+ _ret; \
+})
+
+# define wait_event_freezable_timeout(waitqueue, condition, timeout) \
+({ \
+ int _ret; \
+ do { \
+ _ret = wait_event_interruptible_timeout(waitqueue, \
+ (condition || \
+ freezing(current)), \
+ timeout); \
+ } while (afs_try_to_freeze()); \
+ _ret; \
+})
+#endif
+
+#if defined(STRUCT_TASK_STRUCT_HAS_CRED)
+static inline struct file *
+afs_dentry_open(struct dentry *dp, struct vfsmount *mnt, int flags, const struct cred *creds) {
+#if defined(DENTRY_OPEN_TAKES_PATH)
+ afs_linux_path_t path;
+ struct file *filp;
+ path.mnt = mnt;
+ path.dentry = dp;
+ /* note that dentry_open will path_get for us */
+ filp = dentry_open(&path, flags, creds);
+ return filp;
#else
- *dpp = dget(nd->dentry);
- if (mnt)
- *mnt = mntget(nd->mnt);
- path_release(nd);
+ return dentry_open(dget(dp), mntget(mnt), flags, creds);
+#endif
+}
+#endif
+
+static inline int
+afs_truncate(struct inode *inode, int len)
+{
+ int code;
+#if defined(STRUCT_INODE_OPERATIONS_HAS_TRUNCATE)
+ code = vmtruncate(inode, len);
+#else
+ code = inode_newsize_ok(inode, len);
+ if (!code)
+ truncate_setsize(inode, len);
+#endif
+ return code;
+}
+
+static inline struct proc_dir_entry *
+afs_proc_create(char *name, umode_t mode, struct proc_dir_entry *parent, struct file_operations *fops) {
+#if defined(HAVE_LINUX_PROC_CREATE)
+ return proc_create(name, mode, parent, fops);
+#else
+ struct proc_dir_entry *entry;
+ entry = create_proc_entry(name, mode, parent);
+ if (entry)
+ entry->proc_fops = fops;
+ return entry;
+#endif
+}
+
+static inline int
+afs_dentry_count(struct dentry *dp)
+{
+#if defined(HAVE_LINUX_D_COUNT)
+ return d_count(dp);
+#elif defined(D_COUNT_INT)
+ return dp->d_count;
+#else
+ return atomic_read(&dp->d_count);
+#endif
+}
+
+static inline void
+afs_maybe_shrink_dcache(struct dentry *dp)
+{
+#if defined(HAVE_LINUX_D_COUNT) || defined(D_COUNT_INT)
+ spin_lock(&dp->d_lock);
+ if (afs_dentry_count(dp) > 1) {
+ spin_unlock(&dp->d_lock);
+ shrink_dcache_parent(dp);
+ } else
+ spin_unlock(&dp->d_lock);
+#else
+ if (afs_dentry_count(dp) > 1)
+ shrink_dcache_parent(dp);
+#endif
+}
+
+static inline int
+afs_d_invalidate(struct dentry *dp)
+{
+#if defined(D_INVALIDATE_IS_VOID)
+ d_invalidate(dp);
+ return 0;
+#else
+ return d_invalidate(dp);
+#endif
+}
+
+static inline int
+afs_file_read(struct file *filp, char __user *buf, size_t len, loff_t *pos)
+{
+#if defined(HAVE_LINUX___VFS_READ)
+ return __vfs_read(filp, buf, len, pos);
+#else
+ return filp->f_op->read(filp, buf, len, pos);
+#endif
+}
+
+static inline int
+afs_file_write(struct file *filp, char __user *buf, size_t len, loff_t *pos)
+{
+#if defined(HAVE_LINUX___VFS_READ)
+ return __vfs_write(filp, buf, len, pos);
+#else
+ return filp->f_op->write(filp, buf, len, pos);
#endif
}