From 5a21be491adc6acd3cc01990910c5675393be953 Mon Sep 17 00:00:00 2001
From: Andrew Deason <adeason@sinenomine.net>
Date: Wed, 29 Aug 2012 11:34:06 -0500
Subject: [PATCH] LINUX: Indent osi_machdep.h maze

This one isn't so bad, actually, but it still benefits from some
indentation.

Reviewed-on: http://gerrit.openafs.org/8018
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
(cherry picked from commit 579048cb1ec24b09a869928ceb521c8db4201a43)

Change-Id: I91bddcafe4141c5e6789b01cc4be1a879b6464d1
Reviewed-on: http://gerrit.openafs.org/9330
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Ken Dreyer <ktdreyer@ktdreyer.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
---
 src/afs/LINUX/osi_machdep.h |  240 +++++++++++++++++++++----------------------
 1 file changed, 120 insertions(+), 120 deletions(-)

diff --git a/src/afs/LINUX/osi_machdep.h b/src/afs/LINUX/osi_machdep.h
index a2c16f5..9260733 100644
--- a/src/afs/LINUX/osi_machdep.h
+++ b/src/afs/LINUX/osi_machdep.h
@@ -17,60 +17,60 @@
 
 #include <linux/version.h>
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
-#define AFS_LINUX26_ONEGROUP_ENV 1
+# define AFS_LINUX26_ONEGROUP_ENV 1
 #endif
 
 /* Only needed for xdr.h in glibc 2.1.x */
 #ifndef quad_t
-#define quad_t __quad_t
-#define u_quad_t __u_quad_t
+# define quad_t __quad_t
+# define u_quad_t __u_quad_t
 #endif
 
 #undef getuerror
 
 #ifdef STRUCT_TASK_STRUCT_HAS_TGID
-#define getpid() current->tgid
-#ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
-#define getppid() current->real_parent->tgid
-#elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
-#define getppid() current->parent->tgid
-#else
-#define getppid() current->p_opptr->tgid
-#endif
+# define getpid() current->tgid
+# ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
+#  define getppid() current->real_parent->tgid
+# elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
+#  define getppid() current->parent->tgid
+# else
+#  define getppid() current->p_opptr->tgid
+# endif
 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */
-#define getpid() current->pid
-#ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
-#define getppid() current->real_parent->pid
-#elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
-#define getppid() current->parent->pid
-#else
-#define getppid() current->p_opptr->pid
-#endif
+# define getpid() current->pid
+# ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
+#  define getppid() current->real_parent->pid
+# elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
+#  define getppid() current->parent->pid
+# else
+#  define getppid() current->p_opptr->pid
+# endif
 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */
 
 #ifdef RECALC_SIGPENDING_TAKES_VOID
-#define RECALC_SIGPENDING(X) recalc_sigpending()
+# define RECALC_SIGPENDING(X) recalc_sigpending()
 #else
-#define RECALC_SIGPENDING(X) recalc_sigpending(X)
+# define RECALC_SIGPENDING(X) recalc_sigpending(X)
 #endif
 
 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
-#define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
-#define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
+# define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
+# define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
-#define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
-#define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
+# define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
+# define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
 #else
-#define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
-#define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
+# define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
+# define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
 #endif
 
 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
-#define TASK_STRUCT_RLIM rlim
+# define TASK_STRUCT_RLIM rlim
 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
-#define TASK_STRUCT_RLIM signal->rlim
+# define TASK_STRUCT_RLIM signal->rlim
 #else
-#error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
+# error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
 #endif
 
 
@@ -83,13 +83,13 @@ static inline time_t osi_Time(void) {
     return xtime.tv_sec;
 }
 #else
-#define osi_Time() (xtime.tv_sec)
+# define osi_Time() (xtime.tv_sec)
 #endif
 
 
 
 #ifdef AFS_LINUX_64BIT_KERNEL
-#define osi_GetTime(V)                                 \
+# define osi_GetTime(V)                                 \
     do {                                               \
        struct timeval __afs_tv;                              \
        do_gettimeofday(&__afs_tv);                           \
@@ -97,7 +97,7 @@ static inline time_t osi_Time(void) {
        (V)->tv_usec = (afs_int32)__afs_tv.tv_usec;           \
     } while (0)
 #else
-#define osi_GetTime(V) do_gettimeofday((V))
+# define osi_GetTime(V) do_gettimeofday((V))
 #endif
 
 #undef gop_lookupname
@@ -149,12 +149,12 @@ typedef struct task_struct afs_proc_t;
 typedef struct cred afs_ucred_t;
 typedef struct cred cred_t;
 
-#define afs_cr_uid(cred) ((cred)->fsuid)
-#define afs_cr_gid(cred) ((cred)->fsgid)
-#define afs_cr_ruid(cred) ((cred)->uid)
-#define afs_cr_rgid(cred) ((cred)->gid)
-#define afs_cr_group_info(cred) ((cred)->group_info)
-#define crhold(c) (get_cred(c))
+# define afs_cr_uid(cred) ((cred)->fsuid)
+# define afs_cr_gid(cred) ((cred)->fsgid)
+# define afs_cr_ruid(cred) ((cred)->uid)
+# define afs_cr_rgid(cred) ((cred)->gid)
+# define afs_cr_group_info(cred) ((cred)->group_info)
+# define crhold(c) (get_cred(c))
 static inline void
 afs_set_cr_uid(cred_t *cred, uid_t uid) {
     cred->fsuid = uid;
@@ -176,11 +176,11 @@ afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
     cred->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)
+# 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)
 
 #else
 
@@ -194,31 +194,31 @@ typedef struct afs_cred {
 } cred_t;
 
 typedef struct afs_cred afs_ucred_t;
-#define afs_cr_group_info(cred) ((cred)->cr_group_info)
+# define afs_cr_group_info(cred) ((cred)->cr_group_info)
 static inline void
 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) {
     cred->cr_group_info = group_info;
 }
 
-#define current_group_info() (current->group_info)
-#if !defined(task_gid)
-#define task_gid(task) (task->gid)
-#endif
-#if !defined(task_uid)
-#define task_uid(task) (task->uid)
-#endif
-#define task_user(task) (task->user)
-#define task_session_keyring(task) (task->signal->session_keyring)
-#define current_session_keyring() (current->signal->session_keyring)
-#define crhold(c) atomic_inc(&(c)->cr_ref)
+# define current_group_info() (current->group_info)
+# if !defined(task_gid)
+#  define task_gid(task) (task->gid)
+# endif
+# if !defined(task_uid)
+#  define task_uid(task) (task->uid)
+# endif
+# define task_user(task) (task->user)
+# define task_session_keyring(task) (task->signal->session_keyring)
+# define current_session_keyring() (current->signal->session_keyring)
+# define crhold(c) atomic_inc(&(c)->cr_ref)
 
 #endif /* defined(STRUCT_TASK_STRUCT_HAS_CRED) */
 
 #if !defined(current_cred)
-#define current_gid() (current->gid)
-#define current_uid() (current->uid)
-#define current_fsgid() (current->fsgid)
-#define current_fsuid() (current->fsuid)
+# define current_gid() (current->gid)
+# define current_uid() (current->uid)
+# define current_fsgid() (current->fsgid)
+# define current_fsuid() (current->fsuid)
 #endif
 
 /* UIO manipulation */
@@ -245,7 +245,7 @@ struct uio {
 #define OSIFILE_INODE(a) FILE_INODE((a)->filp)
 
 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
-#define NEED_IOCTL32
+# define NEED_IOCTL32
 #endif
 
 #include <linux/version.h>
@@ -256,8 +256,8 @@ struct uio {
 extern struct mutex afs_global_lock;
 #else
 extern struct semaphore afs_global_lock;
-#define mutex_lock(lock) down(lock)
-#define mutex_unlock(lock) up(lock)
+# define mutex_lock(lock) down(lock)
+# define mutex_unlock(lock) up(lock)
 #endif
 extern int afs_global_owner;
 
@@ -285,63 +285,63 @@ do { \
 #ifdef AFS_AMD64_LINUX20_ENV
 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
 
-#ifndef __NR_ia32_afs_syscall
-#define __NR_ia32_afs_syscall 137
-#endif
-#ifndef __NR_ia32_setgroups
-#define __NR_ia32_setgroups 81
-#endif
-#ifndef __NR_ia32_setgroups32
-#define __NR_ia32_setgroups32 206
-#endif
-#ifndef __NR_ia32_close
-#define __NR_ia32_close 6
-#endif
-#ifndef __NR_ia32_chdir
-#define __NR_ia32_chdir 12
-#endif
-#ifndef __NR_ia32_break
-#define __NR_ia32_break 17
-#endif
-#ifndef __NR_ia32_stty
-#define __NR_ia32_stty 31
-#endif
-#ifndef __NR_ia32_gtty
-#define __NR_ia32_gtty 32
-#endif
-#ifndef __NR_ia32_ftime
-#define __NR_ia32_ftime 35
-#endif
-#ifndef __NR_ia32_prof
-#define __NR_ia32_prof 44
-#endif
-#ifndef __NR_ia32_lock
-#define __NR_ia32_lock 53
-#endif
-#ifndef __NR_ia32_mpx
-#define __NR_ia32_mpx 56
-#endif
-#ifndef __NR_ia32_exit
-#define __NR_ia32_exit 1
-#endif
-#ifndef __NR_ia32_mount
-#define __NR_ia32_mount 21
-#endif
-#ifndef __NR_ia32_read
-#define __NR_ia32_read 3
-#endif
-#ifndef __NR_ia32_write
-#define __NR_ia32_write 4
-#endif
-#ifndef __NR_ia32_open
-#define __NR_ia32_open 5
-#endif
-#ifndef __NR_ia32_close
-#define __NR_ia32_close 6
-#endif
-#ifndef __NR_ia32_unlink
-#define __NR_ia32_unlink 10
-#endif
+# ifndef __NR_ia32_afs_syscall
+#  define __NR_ia32_afs_syscall 137
+# endif
+# ifndef __NR_ia32_setgroups
+#  define __NR_ia32_setgroups 81
+# endif
+# ifndef __NR_ia32_setgroups32
+#  define __NR_ia32_setgroups32 206
+# endif
+# ifndef __NR_ia32_close
+#  define __NR_ia32_close 6
+# endif
+# ifndef __NR_ia32_chdir
+#  define __NR_ia32_chdir 12
+# endif
+# ifndef __NR_ia32_break
+#  define __NR_ia32_break 17
+# endif
+# ifndef __NR_ia32_stty
+#  define __NR_ia32_stty 31
+# endif
+# ifndef __NR_ia32_gtty
+#  define __NR_ia32_gtty 32
+# endif
+# ifndef __NR_ia32_ftime
+#  define __NR_ia32_ftime 35
+# endif
+# ifndef __NR_ia32_prof
+#  define __NR_ia32_prof 44
+# endif
+# ifndef __NR_ia32_lock
+#  define __NR_ia32_lock 53
+# endif
+# ifndef __NR_ia32_mpx
+#  define __NR_ia32_mpx 56
+# endif
+# ifndef __NR_ia32_exit
+#  define __NR_ia32_exit 1
+# endif
+# ifndef __NR_ia32_mount
+#  define __NR_ia32_mount 21
+# endif
+# ifndef __NR_ia32_read
+#  define __NR_ia32_read 3
+# endif
+# ifndef __NR_ia32_write
+#  define __NR_ia32_write 4
+# endif
+# ifndef __NR_ia32_open
+#  define __NR_ia32_open 5
+# endif
+# ifndef __NR_ia32_close
+#  define __NR_ia32_close 6
+# endif
+# ifndef __NR_ia32_unlink
+#  define __NR_ia32_unlink 10
+# endif
 #endif
 
 #define osi_procname(procname, size) strncpy(procname, current->comm, size)
-- 
1.7.9.6 (Apple Git-31.1)

From 314fcfa35917de0f688374137f0ffa040ea3660d Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 9 Jan 2013 19:26:54 -0500
Subject: [PATCH] Linux 3.8: session_keyring changes

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.

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>
(cherry picked from commit c6d27e322a8d3b352554650473a048235a9c763a)

Change-Id: If0998ee777ab0d196e19162499eb3ee60c5ff85d
Reviewed-on: http://gerrit.openafs.org/8941
Reviewed-by: Ken Dreyer <ktdreyer@ktdreyer.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Paul Smeddle <paul.smeddle@gmail.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
---
 acinclude.m4                |    1 +
 src/afs/LINUX/osi_compat.h  |   34 ++++++++++++++++++++++++++++++++--
 src/afs/LINUX/osi_groups.c  |    9 ++-------
 src/afs/LINUX/osi_machdep.h |    9 +++++++--
 4 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 8c57779..0a05caa 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -812,6 +812,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])
diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
index 2dda136..a777542 100644
--- a/src/afs/LINUX/osi_compat.h
+++ b/src/afs/LINUX/osi_compat.h
@@ -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);
@@ -507,4 +517,24 @@ afs_set_name(afs_name_t aname, char *string) {
 }
 #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 */
diff --git a/src/afs/LINUX/osi_groups.c b/src/afs/LINUX/osi_groups.c
index c2a0308..e351344 100644
--- a/src/afs/LINUX/osi_groups.c
+++ b/src/afs/LINUX/osi_groups.c
@@ -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;
diff --git a/src/afs/LINUX/osi_machdep.h b/src/afs/LINUX/osi_machdep.h
index 9260733..0202d0d 100644
--- a/src/afs/LINUX/osi_machdep.h
+++ b/src/afs/LINUX/osi_machdep.h
@@ -179,8 +179,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
 
-- 
1.7.9.6 (Apple Git-31.1)

From bf9bcd09e6a54eb40e47c7a6cdc060be43be9495 Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Wed, 9 Jan 2013 21:22:27 -0500
Subject: [PATCH] Linux 3.8: vmtruncate removal

vmtruncate had been deprecated for a while and has now been
removed.  Do things the new way based on truncate_setsize.

Reviewed-on: http://gerrit.openafs.org/8906
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit d0479bbaf43900d6733c3f7517926ee9813c9610)

Change-Id: Iafc64e19544dec9fcaefad5ad274eac4133f4083
Reviewed-on: http://gerrit.openafs.org/8942
Reviewed-by: Ken Dreyer <ktdreyer@ktdreyer.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Paul Smeddle <paul.smeddle@gmail.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
---
 acinclude.m4               |    1 +
 src/afs/LINUX/osi_compat.h |   14 ++++++++++++++
 src/afs/LINUX/osi_vm.c     |    5 ++---
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 0a05caa..4223bb1 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -824,6 +824,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
 		 AC_CHECK_LINUX_STRUCT([file_operations], [sendfile], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([file_system_type], [mount], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([filename], [name], [fs.h])
+		 AC_CHECK_LINUX_STRUCT([inode_operations], [truncate], [fs.h])
 		 AC_CHECK_LINUX_STRUCT([key_type], [preparse], [key-type.h])
 		 AC_CHECK_LINUX_STRUCT([nameidata], [path], [namei.h])
 		 AC_CHECK_LINUX_STRUCT([proc_dir_entry], [owner], [proc_fs.h])
diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h
index a777542..e8bf003 100644
--- a/src/afs/LINUX/osi_compat.h
+++ b/src/afs/LINUX/osi_compat.h
@@ -537,4 +537,18 @@ afs_set_session_keyring(struct key *keyring)
     return old;
 }
 
+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;
+}
+
 #endif /* AFS_LINUX_OSI_COMPAT_H */
diff --git a/src/afs/LINUX/osi_vm.c b/src/afs/LINUX/osi_vm.c
index 2cd34f9..8bc792e 100644
--- a/src/afs/LINUX/osi_vm.c
+++ b/src/afs/LINUX/osi_vm.c
@@ -51,8 +51,7 @@ osi_VM_FlushVCache(struct vcache *avc, int *slept)
     if (avc->opens != 0)
 	return EBUSY;
 
-    return vmtruncate(ip, 0);
-    return 0;
+    return afs_truncate(ip, 0);
 }
 
 /* Try to invalidate pages, for "fs flush" or "fs flushv"; or
@@ -132,5 +131,5 @@ osi_VM_FlushPages(struct vcache *avc, afs_ucred_t *credp)
 void
 osi_VM_Truncate(struct vcache *avc, int alen, afs_ucred_t *acred)
 {
-    vmtruncate(AFSTOV(avc), alen);
+    afs_truncate(AFSTOV(avc), alen);
 }
-- 
1.7.9.6 (Apple Git-31.1)

From b0a10607f90c4097206bc38cb9bd16e842dbda10 Mon Sep 17 00:00:00 2001
From: Marc Dionne <marc.c.dionne@gmail.com>
Date: Fri, 18 Jan 2013 22:40:03 -0500
Subject: [PATCH] Linux: setpag() may replace credentials

For recent Linux. setpag() may replace the current process' cred
structure with a new one.  This is not a problem for most callers,
but in the case of processing a SetTokens2 pioctl with the setpag
option, the new credentials should be used to determine the target
for the token.

Reviewed-on: http://gerrit.openafs.org/8924
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
(cherry picked from commit b61eac783e8c092cd4ba9f53a2b5ca7d43e08b1b)

Change-Id: I66b5f171318964ff40fe78be24e75519183c3a82
Reviewed-on: http://gerrit.openafs.org/8948
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Paul Smeddle <paul.smeddle@gmail.com>
Reviewed-by: Ken Dreyer <ktdreyer@ktdreyer.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
---
 src/afs/afs_pioctl.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/afs/afs_pioctl.c b/src/afs/afs_pioctl.c
index 3c01be5..98919a3 100644
--- a/src/afs/afs_pioctl.c
+++ b/src/afs/afs_pioctl.c
@@ -1859,6 +1859,9 @@ DECL_PIOCTL(PSetTokens)
     afs_PutCell(tcell, READ_LOCK);
     if (set_parent_pag) {
 	afs_uint32 pag;
+#if defined(AFS_LINUX26_ENV)
+	afs_ucred_t *old_cred = *acred;
+#endif
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 	char procname[256];
 	osi_procname(procname, 256);
@@ -1868,6 +1871,11 @@ DECL_PIOCTL(PSetTokens)
 #else
 	if (!setpag(acred, -1, &pag, 1)) {
 #endif
+#if defined(AFS_LINUX26_ENV)
+	    /* setpag() may have changed our credentials */
+	    *acred = crref();
+	    crfree(old_cred);
+#endif
 	    afs_InitReq(&treq, *acred);
 	    areq = &treq;
 	}
-- 
1.7.9.6 (Apple Git-31.1)

