Linux 3.8: session_keyring changes
authorMarc Dionne <marc.c.dionne@gmail.com>
Thu, 10 Jan 2013 00:26:54 +0000 (19:26 -0500)
committerDerrick Brashear <shadow@your-file-system.com>
Mon, 21 Jan 2013 12:29:15 +0000 (04:29 -0800)
The session_keyring is now attached directly to the cred structure
and the thread_group_cred structure (cred->tgcred) no longer exists.

Adapt code that makes use of tgcred, and use the standard rcu based
mechanism to update session_keyring.

Change-Id: If4b88cbc7f9af6343353648837b28541a5088429
Reviewed-on: http://gerrit.openafs.org/8905
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

acinclude.m4
src/afs/LINUX/osi_compat.h
src/afs/LINUX/osi_groups.c
src/afs/LINUX/osi_machdep.h

index 694de8a..7a7cfcf 100644 (file)
@@ -827,6 +827,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
                                       [write_begin], [fs.h])
                 AC_CHECK_LINUX_STRUCT([backing_dev_info], [name],
                                       [backing-dev.h])
+                AC_CHECK_LINUX_STRUCT([cred], [session_keyring], [cred.h])
                 AC_CHECK_LINUX_STRUCT([ctl_table], [ctl_name], [sysctl.h])
                 AC_CHECK_LINUX_STRUCT([dentry_operations], [d_automount], [dcache.h])
                 AC_CHECK_LINUX_STRUCT([inode], [i_alloc_sem], [fs.h])
index ddf8a47..c840482 100644 (file)
@@ -186,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);
@@ -550,4 +560,24 @@ afs_putname(afs_name_t 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 */
index c2a0308..e351344 100644 (file)
@@ -214,14 +214,9 @@ install_session_keyring(struct key *keyring)
     }
 
     /* install the keyring */
-    spin_lock_irq(&current->sighand->siglock);
-    old = task_session_keyring(current);
-    smp_wmb();
-    task_session_keyring(current) = keyring;
-    spin_unlock_irq(&current->sighand->siglock);
-
+    old = afs_set_session_keyring(keyring);
     if (old)
-           key_put(old);
+       key_put(old);
 
 out:
     return code;
index 520b932..a144ab7 100644 (file)
@@ -184,8 +184,13 @@ afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
 # define current_group_info() (current->cred->group_info)
 # define task_gid(task) (task->cred->gid)
 # define task_user(task) (task->cred->user)
-# define task_session_keyring(task) (task->cred->tgcred->session_keyring)
-# define current_session_keyring() (current->cred->tgcred->session_keyring)
+# if defined(STRUCT_CRED_HAS_SESSION_KEYRING)
+#  define task_session_keyring(task) (task->cred->session_keyring)
+#  define current_session_keyring() (current->cred->session_keyring)
+# else
+#  define task_session_keyring(task) (task->cred->tgcred->session_keyring)
+#  define current_session_keyring() (current->cred->tgcred->session_keyring)
+# endif
 
 #else