From 7c90230a7b4fa7cd10e6a6a73661b0cbe1d40409 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Wed, 11 Aug 2010 18:20:59 -0400 Subject: [PATCH] Linux: adapt to truncate sequence changes As part of changes to the truncate sequence, inode_setattr() no longer exists, and all filesystems have to define the setattr op so we can assume that it is not NULL. Introduce a compat inline function afs_inode_setattr that hides the tests and the different versions from the main code. Note that the existing test for the inode_setattr() return type will fail, but the value is no longer used in that case. This is required for 2.6.36 Reviewed-on: http://gerrit.openafs.org/2543 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry-picked from commit eaf3378f537935f6b9843886b43d) Reviewed-on: http://gerrit.openafs.org/2550 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear (cherry picked from commit 58e56d080b8d19117b60f04ecb37af0c6dcafc1a) Change-Id: I4cfdd191c60d7672c80aa3b3789e52c3e5e87666 Reviewed-on: http://gerrit.openafs.org/3519 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- acinclude.m4 | 1 + src/afs/LINUX/osi_compat.h | 20 ++++++++++++++++++++ src/afs/LINUX/osi_file.c | 12 ++---------- src/cf/linux-test4.m4 | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index dcf099cae..d31d1c26e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -818,6 +818,7 @@ case $AFS_SYSNAME in *_linux* | *_umlinux*) LINUX_STRUCT_CTL_TABLE_HAS_CTL_NAME LINUX_HAVE_IGET LINUX_HAVE_I_SIZE_READ + LINUX_HAVE_INODE_SETATTR LINUX_FS_STRUCT_NAMEIDATA_HAS_PATH LINUX_EXPORTS_INIT_MM LINUX_EXPORTS_SYS_CHDIR diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h index bcbb42ac5..df887519d 100644 --- a/src/afs/LINUX/osi_compat.h +++ b/src/afs/LINUX/osi_compat.h @@ -137,3 +137,23 @@ init_once_func(void * foo) { #endif #endif + +static inline int +afs_inode_setattr(struct osi_file *afile, struct iattr *newattrs) { + + int code = 0; + struct inode *inode = OSIFILE_INODE(afile); +#if !defined(HAVE_LINUX_INODE_SETATTR) + code = inode->i_op->setattr(afile->filp->f_dentry, newattrs); +#elif defined(INODE_SETATTR_NOT_VOID) +#if defined(AFS_LINUX26_ENV) + if (inode->i_op && inode->i_op->setattr) + code = inode->i_op->setattr(afile->filp->f_dentry, newattrs); + else +#endif + code = inode_setattr(inode, newattrs); +#else + inode_setattr(inode, newattrs); +#endif + return code; +} diff --git a/src/afs/LINUX/osi_file.c b/src/afs/LINUX/osi_file.c index 1f9e8cf88..2abcea386 100644 --- a/src/afs/LINUX/osi_file.c +++ b/src/afs/LINUX/osi_file.c @@ -21,6 +21,7 @@ #if !defined(HAVE_IGET) #include "h/exportfs.h" #endif +#include "osi_compat.h" int afs_osicred_initialized = 0; struct AFS_UCRED afs_osi_cred; @@ -237,16 +238,7 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize) lock_kernel(); code = inode_change_ok(inode, &newattrs); if (!code) -#ifdef INODE_SETATTR_NOT_VOID -#if defined(AFS_LINUX26_ENV) - if (inode->i_op && inode->i_op->setattr) - code = inode->i_op->setattr(afile->filp->f_dentry, &newattrs); - else -#endif - code = inode_setattr(inode, &newattrs); -#else - inode_setattr(inode, &newattrs); -#endif + code = afs_inode_setattr(afile, &newattrs); unlock_kernel(); if (!code) truncate_inode_pages(&inode->i_data, asize); diff --git a/src/cf/linux-test4.m4 b/src/cf/linux-test4.m4 index 894593c28..6d14b2f87 100644 --- a/src/cf/linux-test4.m4 +++ b/src/cf/linux-test4.m4 @@ -1274,3 +1274,19 @@ _bdi.name = NULL;], if test "x$ac_cv_linux_struct_bdi_has_name" = "xyes"; then AC_DEFINE([STRUCT_BDI_HAS_NAME], 1, [define if struct backing_dev_info has a name member]) fi]) + +AC_DEFUN([LINUX_HAVE_INODE_SETATTR], [ + AC_MSG_CHECKING([for linux inode_setattr()]) + AC_CACHE_VAL([ac_cv_linux_inode_setattr], [ + save_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS -Werror-implicit-function-declaration" + AC_TRY_KBUILD( +[#include ], +[inode_setattr(NULL);], + ac_cv_linux_inode_setattr=yes, + ac_cv_linux_inode_setattr=no) + CPPFLAGS="$save_CPPFLAGS"]) + AC_MSG_RESULT($ac_cv_linux_inode_setattr) + if test "x$ac_cv_linux_inode_setattr" = "xyes"; then + AC_DEFINE([HAVE_LINUX_INODE_SETATTR], 1, [define if your kernel has inode_setattr()]) + fi]) -- 2.39.5