Linux: Tidy up freezer code

Linux now provides try_to_freeze(), which can be used to replace
all of our refrigerator code. This has been in the tree for a long
time, and actually predates many of the changes we've been modifying
our code to work with. So, use try_to_freeze wherever we can, and keep
a simpler compatibility function for kernels which are too old to have
it.

Change-Id: Iec50f83382f46d2b17b43da815a75755ea916bc6
Reviewed-on: http://gerrit.openafs.org/1845
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
Simon Wilkinson 2010-04-26 22:13:39 +01:00 committed by Derrick Brashear
parent ef8bd5a29b
commit eef18466d9
4 changed files with 56 additions and 66 deletions

View File

@ -868,7 +868,6 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM
LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_EXIT_STATE
LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_TGID
LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_TODO
LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_THREAD_INFO
LINUX_EXPORTS_TASKLIST_LOCK
LINUX_GET_SB_HAS_STRUCT_VFSMOUNT
@ -876,6 +875,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*)
AC_CHECK_LINUX_HEADER([freezer.h])
LINUX_HAVE_SVC_ADDR_IN
LINUX_REFRIGERATOR
LINUX_HAVE_TRY_TO_FREEZE
LINUX_LINUX_KEYRING_SUPPORT
LINUX_KEY_ALLOC_NEEDS_STRUCT_TASK
LINUX_KEY_ALLOC_NEEDS_CRED

View File

@ -9,6 +9,10 @@
#ifndef AFS_LINUX_OSI_COMPAT_H
#define AFS_LINUX_OSI_COMPAT_H
#if defined(HAVE_LINUX_FREEZER_H)
# include <linux/freezer.h>
#endif
#ifndef DO_SYNC_READ
static inline int
do_sync_read(struct file *fp, char *buf, size_t count, loff_t *offp) {
@ -267,6 +271,24 @@ kernel_getsockopt(struct socket *sockp, int level, int name, char *val,
return ret;
}
#endif
#ifdef HAVE_TRY_TO_FREEZE
static inline void
afs_try_to_freeze() {
# ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
try_to_freeze(PF_FREEZE);
# else
try_to_freeze();
# endif
}
#else
static inline void
afs_try_to_freeze() {
# ifdef CONFIG_PM
if (current->flags & PF_FREEZE) {
refrigerator(PF_FREEZE);
# endif
}
#endif

View File

@ -14,9 +14,7 @@
#include "afs/sysincludes.h" /* Standard vendor system headers */
#include "afsincludes.h" /* Afs-based standard headers */
#include "afs/afs_stats.h" /* afs statistics */
#if defined(HAVE_LINUX_FREEZER_H)
#include <linux/freezer.h>
#endif
#include "osi_compat.h"
static char waitV, dummyV;
@ -183,28 +181,8 @@ afs_osi_SleepSig(void *event)
AFS_ASSERT_GLOCK();
AFS_GUNLOCK();
schedule();
#ifdef CONFIG_PM
if (
#ifdef PF_FREEZE
current->flags & PF_FREEZE
#else
#if defined(STRUCT_TASK_STRUCT_HAS_TODO)
!current->todo
#else
#if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
test_ti_thread_flag(current->thread_info, TIF_FREEZE)
#else
test_ti_thread_flag(task_thread_info(current), TIF_FREEZE)
#endif
#endif
#endif
)
#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
refrigerator(PF_FREEZE);
#else
refrigerator();
#endif
#endif
try_to_freeze();
AFS_GLOCK();
if (signal_pending(current)) {
retval = EINTR;
@ -278,33 +256,12 @@ afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
* from artifically increasing. */
AFS_GUNLOCK();
if (aintok) {
if (schedule_timeout(ticks))
if (schedule_timeout(ticks)) {
if (aintok)
code = EINTR;
} else
schedule_timeout(ticks);
#ifdef CONFIG_PM
if (
#ifdef PF_FREEZE
current->flags & PF_FREEZE
#else
#if defined(STRUCT_TASK_STRUCT_HAS_TODO)
!current->todo
#else
#if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
test_ti_thread_flag(current->thread_info, TIF_FREEZE)
#else
test_ti_thread_flag(task_thread_info(current), TIF_FREEZE)
#endif
#endif
#endif
)
#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
refrigerator(PF_FREEZE);
#else
refrigerator();
#endif
#endif
}
try_to_freeze();
AFS_GLOCK();
remove_wait_queue(&evp->cond, &wait);

View File

@ -483,8 +483,10 @@ AC_DEFUN([LINUX_REFRIGERATOR], [
[refrigerator(PF_FREEZE);],
ac_cv_linux_func_refrigerator_takes_pf_freeze=yes,
ac_cv_linux_func_refrigerator_takes_pf_freeze=no)])
AC_MSG_RESULT($ac_cv_linux_func_refrigerator_takes_pf_freeze)])
AC_MSG_RESULT($ac_cv_linux_func_refrigerator_takes_pf_freeze)
if test "x$ac_cv_linux_func_refrigerator_takes_pf_freeze" = "xyes"; then
AC_DEFINE([LINUX_REFRIGERATOR_TAKES_PF_FREEZE], 1, [define if your refrigerator takes PF_FREEZE])
fi])
AC_DEFUN([LINUX_IOP_I_CREATE_TAKES_NAMEIDATA], [
AC_MSG_CHECKING([whether inode_operations.create takes a nameidata])
@ -711,17 +713,6 @@ AC_DEFUN([LINUX_HAVE_D_ALLOC_ANON], [
AC_DEFINE([HAVE_LINUX_D_ALLOC_ANON], 1, [define if your kernel has d_alloc_anon()])
fi])
AC_DEFUN([LINUX_SCHED_STRUCT_TASK_STRUCT_HAS_TODO], [
AC_MSG_CHECKING([for todo in struct task_struct])
AC_CACHE_VAL([ac_cv_linux_sched_struct_task_struct_has_todo], [
AC_TRY_KBUILD(
[#include <linux/sched.h>],
[struct task_struct _tsk;
printk("%d\n", _tsk.todo);],
ac_cv_linux_sched_struct_task_struct_has_todo=yes,
ac_cv_linux_sched_struct_task_struct_has_todo=no)])
AC_MSG_RESULT($ac_cv_linux_sched_struct_task_struct_has_todo)])
AC_DEFUN([LINUX_INIT_WORK_HAS_DATA], [
AC_MSG_CHECKING([whether INIT_WORK has a _data argument])
AC_CACHE_VAL([ac_cv_linux_init_work_has_data], [
@ -1220,5 +1211,25 @@ AC_DEFUN([LINUX_HAVE_KERNEL_SETSOCKOPT], [
AC_MSG_RESULT($ac_cv_linux_have_kernel_setsockopt)
if test "x$ac_cv_linux_have_kernel_setsockopt" = "xyes"; then
AC_DEFINE([HAVE_KERNEL_SETSOCKOPT], 1, [define if your kernel has the kernel_setsockopt function])
AC_DEFUN([LINUX_HAVE_TRY_TO_FREEZE], [
AC_MSG_CHECKING([for try_to_freeze])
AC_CACHE_VAL([ac_cv_linux_have_try_to_freeze], [
AC_TRY_KBUILD(
[#include <linux/sched.h>
#ifdef FREEZER_H_EXISTS
#include <linux/freezer.h>
#endif],
[#ifdef LINUX_REFRIGERATOR_TAKES_PF_FREEZE
try_to_freeze(PF_FREEZE);
#else
try_to_freeze();
#endif
],
ac_cv_linux_have_try_to_freeze=yes,
ac_cv_linux_have_try_to_freeze=no)])
AC_MSG_RESULT($ac_cv_linux_have_try_to_freeze)
if test "x$ac_cv_linux_have_try_to_freeze" = "xyes"; then
AC_DEFINE([HAVE_TRY_TO_FREEZE], 1, [define if your kernel has the try_to_freeze function])
fi])