Linux 3.8: session_keyring changes
[openafs.git] / src / afs / LINUX / osi_compat.h
index a4b83a1..c840482 100644 (file)
 # endif
 #endif
 
+#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
+
 #ifndef HAVE_LINUX_DO_SYNC_READ
 static inline int
 do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
@@ -176,14 +186,24 @@ afs_linux_key_alloc(struct key_type *type, const char *desc, uid_t uid,
 }
 
 # 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);
@@ -432,7 +452,7 @@ afs_kern_path(char *aname, int flags, struct nameidata *nd) {
 }
 #else
 static inline int
-afs_kern_path(char *aname, int flags, struct path *path) {
+afs_kern_path(char *aname, int flags, afs_linux_path_t *path) {
     return kern_path(aname, flags, path);
 }
 #endif
@@ -441,7 +461,7 @@ static inline void
 #if defined(HAVE_LINUX_PATH_LOOKUP)
 afs_get_dentry_ref(struct nameidata *nd, struct vfsmount **mnt, struct dentry **dpp) {
 #else
-afs_get_dentry_ref(struct path *path, struct vfsmount **mnt, struct dentry **dpp) {
+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)
@@ -502,7 +522,7 @@ afs_get_dentry_ref(struct path *path, struct vfsmount **mnt, struct dentry **dpp
 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)
-    struct path path;
+    afs_linux_path_t path;
     struct file *filp;
     path.mnt = mnt;
     path.dentry = dp;
@@ -514,4 +534,50 @@ 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;
+}
+
 #endif /* AFS_LINUX_OSI_COMPAT_H */