Linux 4.5: don't access i_mutex directly
[openafs.git] / src / afs / LINUX / osi_compat.h
index fdddf59..9e2e22a 100644 (file)
@@ -37,7 +37,21 @@ typedef struct vfs_path afs_linux_path_t;
 typedef struct path afs_linux_path_t;
 #endif
 
-#ifndef HAVE_LINUX_DO_SYNC_READ
+#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);
@@ -173,8 +187,8 @@ init_once_func(void * foo) {
 
 #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);
@@ -220,6 +234,26 @@ afs_linux_search_keyring(afs_ucred_t *cred, struct key_type *type)
     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(&current->sighand->siglock);
+    old = task_session_keyring(current);
+    smp_wmb();
+    task_session_keyring(current) = keyring;
+    spin_unlock_irq(&current->sighand->siglock);
+#endif
+    return old;
+}
 #endif /* LINUX_KEYRING_SUPPORT */
 
 #ifdef STRUCT_TASK_STRUCT_HAS_CRED
@@ -411,7 +445,9 @@ afs_init_sb_export_ops(struct super_block *sb) {
 
 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);
@@ -420,7 +456,9 @@ afs_linux_lock_inode(struct inode *ip) {
 
 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);
@@ -463,23 +501,23 @@ afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **
 #else
 afs_get_dentry_ref(afs_linux_path_t *path, struct vfsmount **mnt, struct dentry **dpp) {
 #endif
-#if defined(STRUCT_NAMEIDATA_HAS_PATH)
-# if defined(HAVE_LINUX_PATH_LOOKUP)
+#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(path->dentry);
-    if (mnt)
-       *mnt = mntget(path->mnt);
-    path_put(path);
-# endif
-#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
 }
 
@@ -535,52 +573,6 @@ afs_dentry_open(struct dentry *dp, struct vfsmount *mnt, int flags, const struct
 }
 #endif
 
-#if !defined(STRUCT_FILENAME_HAS_NAME)
-typedef char *afs_name_t;
-
-static inline char *
-afs_name_to_string(afs_name_t s) {
-    return (char *)s;
-}
-
-static inline void
-afs_putname(afs_name_t name) {
-    putname((char *)name);
-}
-#else
-typedef struct filename *afs_name_t;
-
-static inline char *
-afs_name_to_string(afs_name_t s) {
-    return (char *)s->name;
-}
-
-static inline void
-afs_putname(afs_name_t name) {
-    kmem_cache_free(names_cachep, (void *)name);
-}
-#endif
-
-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(&current->sighand->siglock);
-    old = task_session_keyring(current);
-    smp_wmb();
-    task_session_keyring(current) = keyring;
-    spin_unlock_irq(&current->sighand->siglock);
-#endif
-    return old;
-}
-
 static inline int
 afs_truncate(struct inode *inode, int len)
 {
@@ -636,4 +628,35 @@ afs_maybe_shrink_dcache(struct dentry *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
+}
+
 #endif /* AFS_LINUX_OSI_COMPAT_H */