Linux 6.8: Use roken's strlcpy() in kernel module The Linux 6.8 commit 'string: Remove strlcpy()' (d26270061a) removed the the strlcpy function from the Linux kernel. The replacement function, strscpy(), cannot be used as a drop-in replacement as its currently a Linux kernel specific function and there are differences in the returned value. We can use roken's strlcpy() (provided in roken/strlcpy.c). Create a configure test to that defines its own strlcpy() to test if the kernel doesn't provide one itself. Note, we need to use a different function signature for strlcpy() from what the kernel might have otherwise the test build succeeds when the kernel does provide a strlcpy(). Update the OpenAFS kernel specific roken.h to define the prototype for strlcpy when it's not present in the Linux kernel. We need to match the defines used in the 'real' roken.h so the roken/strlcpy.c can build properly. Add defines for ROKEN_LIB_FUNCTION, ROKEN_LIB_CALL and ROKEN_LIB_VARIABLE to the kernel roken.h Update Linux's osi_machdep.h to include roken.h so the strlcpy protoype is available. Update the Linux MakefileProto to include the strcpy-kernel object when building the kernel module. Change-Id: I64a5743ba94134538853f51cd6e7a8df19127624 Reviewed-on: https://gerrit.openafs.org/15646 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 6.7: convert to inode a/mtime accessor funcs The Linux 6.7 commit "fs: new accessor methods for atime and mtime" (077c212f03) is a follow up to the Linux 6.6 commit "fs: add ctime accessors infrastructure" (9b6304c1d5) With the above 6.7 commit, the inode's i_atime and i_mtime are renamed to __i_atime and __i_mtime and accessing these members should use the new accessor functions. This commit is similar to the OpenAFS commit "Linux 6.6: convert to ctime accessor functions" (072c7934cd1) Add autoconf tests to detect when we need to use the new accessors and introduce new wrapper functions to get and set an inode's atime and mtime. Note, unlike the (072c7934cd1) commit, we need to add support for reading an inode's atime and mtime, so this commit has the getters for the atime and mtime members. Change-Id: Ide818c946ed98a1401ef59864c2cdb4eccee9c99 Reviewed-on: https://gerrit.openafs.org/15597 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux: Fix to use time_t instead of time64_t In commit 'Linux 6.6: convert to ctime accessor functions' (072c7934cd) the functiom afs_inode_set_ctime was defined to use time64_t when it should have used a time_t as the data type for the sec parameter. See the commit 'LINUX 5.6: define time_t and use timespec/timespec64' (78049987aa). The time64_t data type was introduced in Linux 3.17. A build failure will occur when building on kernels prior to Linux 3.17. Change-Id: I9b3ce32f8885cde969583cfc74294cdabc54e698 Reviewed-on: https://gerrit.openafs.org/15595 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux 6.6: convert to ctime accessor functions The Linux 6.6 commit "fs: add ctime accessors infrastructure" (9b6304c1d5) added accessor functions for an inode's ctime member. A follow on commit "fs: rename i_ctime field to __i_ctime" (13bc244578) changed the name of the inode member ctime to __i_ctime to indicate it's a private member. Add an autoconf test for the ctime accessor function 'inode_set_ctime()'. Add an afs_inode_set_ctime to LINUX/osi_machdep.h that is either defined as a macro to Linux's inode_set_ctime, or implements a static inline function to set a inode's ctime. Convert the setting of an inode's ctime to use afs_inode_set_ctime(). For more information behind the Linux change, see the commit message for: "Merge tag 'v6.6-vfs.ctime' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs" (615e95831) Change-Id: I920aac8029fc3e2c9b7741341b434802403a4577 Reviewed-on: https://gerrit.openafs.org/15560 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Tested-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 6.3: Use mnt_idmap for inode op functions Through a series of Linux 6.3 commits starting with: 'f2fs: project ids aren't idmapped' (64b4cdf22f) and ending with 'fs: move mnt_idmap' (3707d84c13) the inode operations functions were changed to take a mnt_idmap structure instead of a user_namespace structure. These were pulled in via the the merge commit: 'Pull vfs idmapping updates from Christian Brauner' (05e6295f7b) The commit message for the merge contains background and overall information for this conversion. The above change simply changes the functions to use a different structure (mnt_idmap instead of user_namespace). For afs, it is a simple change to swap the structures. But for some of the Linux calls (generic_fillattr(), setattr_prepare(), and inode_op->setattr()) we would like to use the Linux symbol nop_mnt_idmap, but that symbol is exported as GPL only. Instead, we will obtain its address from the current task structure at libafs initialization (much the same way as obtaining current user namespace for afs_ns). Add autoconf tests to determine if inode_operations.create() uses the mnt_idmap structure. If so set a generic configure define for "IOP_TAKES_MNT_IDMAP". Update afs's inode operations functions to take and use a mnt_idmap instead of a user_namespace. At libafs initialization, obtain the mnt_idmap from the current task and save it as an afs global variable, afs_mnt_idmap, to be used where needed. Change-Id: Ie48b3941860998ddc7f54be48959fc62119bf48e Reviewed-on: https://gerrit.openafs.org/15347 Reviewed-by: Mark Vitale <mvitale@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Cleanup usage of LINUX_VERSION_CODE for older kernels 2.6.18 is the minimum supported linux kernel level. There are preprocessor checks for specific kernel versions that predate 2.6.18. Refactor the use of the LINUX_VERSION_CODE that checks for kernel versions older than 2.6.18. In addition, there are a couple of locations where the kernel version is checked with an additional test to see if module_param or module_param_array are defined. These checks are used to determine whether to use the macros module_param/module_param_array or to use the macro MODULE_PARM. The macros module_param and module_param_array were present in Linux prior to 2.6.12. The macro MODULE_PARM was marked as deprecated prior to 2.6.12 and removed in Linux 2.6.17 (8d3b33f67fd '[PATCH] Remove MODULE_PARM'). Remove the preprocessor checks for module_param/module_param_array and remove the use of MODULE_PARM. The updates should have no functional changes. Change-Id: I1dc5dca1252abfc865917757989df235c75059a6 Reviewed-on: https://gerrit.openafs.org/14389 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Cleanup AFS_*LINUX_ENV usage Commit 6329a523f6305541871bc3d1694065e7b17abe77 changed all occurrences of AFS_*LINUXnn_ENV to AFS_*LINUX_ENV, but did not perform any refactoring of the use of these variables. This commit completes the task by refactoring the preprocessor conditionals that involved removing dead code or collapsing statements. The updates should have no functional changes. Change-Id: I10fbefb7c862de2ec35ab77cafa2391e6e59f388 Reviewed-on: https://gerrit.openafs.org/14388 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Change AFS*_LINUXnn_ENV to AFS*_LINUX_ENV The minimum Linux kernel that is now supported is linux-2.6.18. The Linux versioned preprocessor macros AFS_*LINUXnn_ENV are no longer needed to distinguish the different levels of Linux and can be merged into just a single set of macros. Perform a global change of _LINUX\d+_ENV to _LINUX_ENV. e.g. AFS_LINUX24_ENV -> AFS_LINUX_ENV AFS_USR_LINUX24_ENV -> AFS_USR_LINUX_ENV AFS_AMD64_LINUX20_ENV -> AFS_AMD64_LINUX_ENV Replace the multiple definitions for the versioned 'AFS*_LINUXnn_ENV' with just single non-version definitions 'AFS*_LINUX_ENV'. Apart from replacing the now-redundant #define directives and tidying up a few comments at the close of a preprocessor block to match their current form, this commit was done using a mechanical change of the variable names and did not reduce preprocessor statements that could now be combined or eliminated. Nor does this commit remove dead code. A follow-up commit (Cleanup AFS_*LINUX_ENV usage) will handle these changes. The updates should have no functional changes. Change-Id: I71e32ca9818d28f82b4f23679868d1b9a62c44bd Reviewed-on: https://gerrit.openafs.org/14387 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux 5.11: Test 32bit compat with in_compat_syscall Linux 5.11 removed the TIF_IA32 thread flag with commit: x86: Reclaim TIF_IA32 and TIF_X32 (8d71d2bf6efec) The flag TIF_IA32 was being used by openafs to determine if the task was handling a syscall request from a 32 bit process. Building against a Linux 5.11 kernel results in a build failure as TIF_IA32 is undefined. The function 'in_compat_syscall' was introduced in Linux 4.6 as the preferred method to determine if a syscall needed to handle a compatible call (e.g. 32bit application). To resolve the build problem, use 'in_compat_syscall' if present (Linux 4.6 and later) to determine if the syscall needs to handle a compatibility mode call. Add autoconf check for in_compat_syscall. Notes about in_compat_syscall: In Linux 4.6 'in_compat_syscall' was defined for all architectures with a generic return of 'is_compat_task', but allows architecture specific overriding implementations (x86 and sparc). At 4.6 (and later), the function 'is_compat_task' is defined only for the following architectures to return: Arch Returns ======= ============================== arm64 test_thread_flag(TIF_32BIT); mips test_thread_flag(TIF_32BIT_ADDR) parisc test_ti_thread_flag(task_thread_info(t), TIF_32BIT) powerpc is_32bit_task() s390 test_thread_flag(TIF_31BIT) sparc test_thread_flag(TIF_32BIT) If the Linux kernel is not built with compat mode, is_compat_task and in_compat_syscall is set to always return 0 Linux commit that introduced in_compat_syscall: compat: add in_compat_syscall to ask whether we're in a compat syscall (5180e3e24fd3e8e7) Change-Id: I59deebfe5d8cddaf845b15ef69e65a684a961280 Reviewed-on: https://gerrit.openafs.org/14499 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux: Refactor test for 32bit compat Refactor the preprocessor checks for determining the method to test for 32bit compatibility (64bit kernel performing work for a 32bit task) into a common inline function, 'afs_in_compat_syscall' that is defined in LINUX/osi_machdep.h. Update osi_ioctl.c and afs_syscall.c to use afs_in_compat_syscall. Add include afs/sysincludes into osi_machdep.h to ensure linux/compat.h is pulled for the functions called in afs_in_compat_syscall. Change-Id: I6610cc19fedd909de8e8941ded05ed1608e52403 Reviewed-on: https://gerrit.openafs.org/14500 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Always define our own osi_timeval32_t Since OpenAFS 1.0, osi_GetTime has taken a timeval-like pointer, which contains 32-bit fields (the actual type has been called either osi_timeval_t or osi_timeval32_t over time). For platforms that have a native timeval-like type with 32-bit fields, we just define osi_timeval32_t to that type, and elsewhere we define our own struct to be osi_timeval32_t. For platforms that use the native timeval, we can then define osi_GetTime() to just be, e.g., microtime(). This approach is difficult to maintain, though, because we must keep track of whether 'struct timeval' contains 32-bit fields on each platform, which can depend on many factors. It's easy to make mistakes (the current tree already contains mistakes), and there's not much benefit. To avoid all of this, just always define osi_timeval32_t to be our own struct with afs_int32 fields, and provide definitions for osi_GetTime that convert from the native time struct to our osi_timeval32_t. This does mean that for some platforms we do an unnecessary type conversion, but this is a small price to pay for more straightforward and maintainable code. To be a little more sure that our types are correct, change osi_GetTime to be defined as an inline function instead of a macro. At the same time, do a similar conversion for the KERNEL implementation of the rx clock_GetTime function. Get rid of platform-specific mess, and do a straightforward type conversion between osi_timeval32_t and struct clock in an inline function. Change-Id: I18819acb556a2a7f1b6da6994db9783c48108934 Reviewed-on: https://gerrit.openafs.org/14238 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
LINUX 5.6: define osi_timeval32_t for 32-bit Linux For 32-bit Linux (e.g., arch i586), AFS_LINUX_64BIT_KERNEL is not defined, so osi_timeval32_t is defined as a typedef of the native 'timeval'. However, as of commit c766d1472c70d25ad475cf56042af1652e792b23 "y2038: hide timeval/timespec/itimerval/itimerspec types" (Linux 5.6), the native timeval struct is no longer available. On such a kernel, the OpenAFS build will fail because osi_timeval32_t is not properly defined. Instead, add new conditionals to properly define osi_timeval32_t for this platform. Change-Id: I1eddeeb3651dcd3c55920ab1d2ad2838f4729bdd Reviewed-on: https://gerrit.openafs.org/14216 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Refactor osi_vnhold/AFS_FAST_HOLD Make a few changes to osi_vnhold and AFS_FAST_HOLD: - Currently, the second argument of osi_vnhold ("retry") is never used by any implementation. Get rid of it. - AFS_FAST_HOLD() is the same as osi_vnhold(). Get rid of AFS_FAST_HOLD, and just have all callers use osi_vnhold instead. - Allow osi_vnhold to return an error, and adjust callers to handle it. - Change osi_vnhold to be a real function, instead of a macro, to make nontrivial implementations less cumbersome. Most platforms never return an error from osi_vnhold(), so the added code paths to check the return value of osi_vnhold() will not trigger. However, this lets us add future commits that do make osi_vnhold() return an error. Change-Id: Id2f3717be6c305d06305685247ac789815e1ebf7 Reviewed-on: https://gerrit.openafs.org/13971 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
LINUX 5.6: define time_t and use timespec/timespec64 The time_t type and the structure timeval were removed for use in kernel space code in Linux commits: 412c53a680a97cb1ae2c0ab60230e193bee86387 y2038: remove unused time32 interfaces c766d1472c70d25ad475cf56042af1652e792b23 y2038: hide timeval/timespec/itimerval/itimerspec types Add an autoconf test for the time_t type. If time_t is missing, define the time_t type when building the kernel module. Change the vattr structure in LINUX/osi_vfs.h to use timespec/timespec64 instead of the timeval structure. Conditionalize the definition of gettimeofday (needed by rand-fortuna.c) in crypto/hcrypto/kernel/config.h. It is unused by the Linux kernel module and the function uses struct timeval that is no longer available. Change-Id: Idc9a1ded748f833d804164d29c49c9aee26ae8f5 Reviewed-on: https://gerrit.openafs.org/14083 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux_5.0: replace do_gettimeofday with ktime_get_real_ts64 In Kernel commit e4b92b108c6cd6b311e4b6e85d6a87a34599a6e3 the do_gettimeofday function was removed. According to the Linux Documentation/core-api/timekeeping.rst ktime_get_real_ts64 is the direct replacement for do_gettimeofday Updated the macro osi_GetTime to use ktime_get_real_ts64 if it is available. Change-Id: I7fcd49958de83a6a040e40bd310a228247c481b2 Reviewed-on: https://gerrit.openafs.org/13433 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux 4.20: current_kernel_time is gone With Linux commit 976516404ff3fab2a8caa8bd6f5efc1437fed0b8 'y2038: remove unused time interfaces' (4.20-rc1), current_kernel_time() has been removed. Many y2038-compliant time APIs were introduced with Linux commit fb7fcc96a86cfaef0f6dcc0665516aa68611e736 'timekeeping: Standardize on ktime_get_*() naming' (4.18). According to Documentation/core-api/timekeeping.rst, a suitable replacement for: struct timespec current_kernel_time(void) would be: void ktime_get_coarse_real_ts64(struct timespec64 *ts)) Add an autoconf test and equivalent logic to deal. Change-Id: I4ff622ad40cc6d398267276d13493d819b877350 Reviewed-on: https://gerrit.openafs.org/13391 Tested-by: Mark Vitale <mvitale@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Linux: Include linux/uaccess.h rather than asm/uaccess.h if present Starting with Linux 4.12 there is a module build error on s390 due to asm/uaccess.h using a macro defined in the common header. The common header has been around since 2.6.18 and has always included asm/uaccess.h, so switch to using the common header whenever it is present. Change-Id: Iaab0d7652483a2a2b1f144f3e90b6d3b902c146d Signed-off-by: Seth Forshee <seth.forshee@canonical.com> Reviewed-on: https://gerrit.openafs.org/12714 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux: only include cred.h if it exists Commit c89fd17df1032ec2eacc0d0c9b73e19c5e8db7d2 introduced an explicit include of linux/cred.h since the latest kernel no longer includes it implicitly in sched.h. Alas, older kernels (like 2.6.18) don't have this file. Add a configure test for the existence of cred.h and only include it if actually present. Change-Id: Ia7e38160492b1e03cdb257e4b2bef4d18c4a28fb Reviewed-on: https://gerrit.openafs.org/12593 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Linux v4.11: cred.h is no longer included in sched.h With Linux commit e26512fea5bcd6602dbf02a551ed073cd4529449, cred.h is no longer included in sched.h. Several components of libafs which require cred.h were picking it by including sched.h. Instead, explicitly add an include for cred.h. cred.h begins with a customary one-shot to prevent multiple loads: #ifndef _LINUX_CRED_H #define _LINUX_CRED_H Therefore we don't need a new autoconf test or preprocessor conditional to prevent redundant includes on older Linux releases. Change-Id: Ifc496c83141d2cfbd417133feb6d87c1146e5014 Reviewed-on: https://gerrit.openafs.org/12574 Tested-by: Mark Vitale <mvitale@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Joe Gorse <jhgorse@gmail.com> Tested-by: Joe Gorse <jhgorse@gmail.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Linux 4.9: deal with demise of GROUP_AT Linux commit 81243eacfa40 "cred: simpler, 1D supplementary groups" refactors the group_info struct, removing some members (which OpenAFS references only through the GROUP_AT macro) and adding a gid member. The GROUP_AT macro is also removed from the tree. Add an autoconfigure test for the new group_info member gid and define a replacement GROUP_AT macro to do the right thing under the new regime. Change-Id: I85a52c0ae0d91fc141a523f443a4ffc05eb72a2b Reviewed-on: https://gerrit.openafs.org/12390 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>