afs: Avoid always-false NULL test on AFSTOV(avc) GCC-12 is flagging a comparison with the following diagnostic: src/afs/afs_vcache.c:3161:25: error: the comparison will always evaluate as ‘false’ for the address of ‘v’ will never be NULL [-Werror=address] 3161 | AFSTOV(avc) == NULL || vType(avc) == VDIR || | ^~ When the vcache structure does not have the vnode embedded the expansion of the AFSTOV macro results in: ((avc)->v) which tests contents of a 'v'. When the vcache structure does have the vnode embedded, the expansion of the macro results in: (&(avc)->v) which tests the address of 'v', which will never be NULL in this case. Update afs.h to add a new define 'AFS_VCACHE_EMBEDDED_VNODE' when the vcache structure contains an embedded vnode structure. Restructure the preprocessor statements for the AFSTOV definition Avoid testing AFSTOV(x) against NULL when AFS_VCACHE_EMBEDDED_VNODE is defined. The diagnostic is changed from a warning to an error when configured with --enable-checking. Change-Id: Ib72647fa23e5a7ecd96772b04c6ef76540f44535 Reviewed-on: https://gerrit.openafs.org/14956 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Increase NUSERS to 2k The current value of NUSERS (16) is very small when the client has a large number of PAGs. When we have a few thousand (or even just a few hundred), the length of the unixuser hash chains can be come long enough to cause noticeable differences in performance. Looking up unixuser structs is a very common code path, since we need to do this for pretty much any file access that's not already cached at the VFS layer. To alleviate this, increase NUSERS to 2k. This is certainly not necessary on all systems (such as those that never use authentication, or only have a few PAGs), but the overhead is a very small constant amount of memory. Change-Id: I17b32f192656db9ffc97ac47b0923a02803977a3 Reviewed-on: https://gerrit.openafs.org/14959 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
UKERNEL: Remove flock -> usr_flock redirection In order to replace 'struck flock' with 'struct usr_flock' and 'flock()' with 'usr_flock()', the current version of src/afs/UKERNEL/sysincludes.h defines flock to usr_flock. This can cause problems when trying to use libroken in UKERNEL code, because roken.h redefines flock. To avoid conflicts with libroken (included in a future commit), add a new UKERNEL specific AFS_FLOCK -> usr_flock redirection. Doing so, the flock -> usr_flock redirection can be removed. While here, also remove 'usr_flock()' as it shouldn't be called and is not defined in any header file. Change-Id: Ia71811513ab6655f60d8b63fc18b26be663ab4dc Reviewed-on: https://gerrit.openafs.org/14913 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Remove redundant AFS_LINUX_ENV test After our Linux checks were converted to AFS_LINUX_ENV in commit 6329a523 (Change AFS*_LINUXnn_ENV to AFS*_LINUX_ENV), the extra AFS_LINUX_ENV check in this line doesn't make any sense. Get rid of it. Change-Id: I4196744b1a6674469efef04aa487a50743084656 Reviewed-on: https://gerrit.openafs.org/14935 Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Save size of sysname_info->name In preparation for a future commit, save the size of sysname_info->name by adding a new field (name_size) into the sysname_info struct. Also, remove the sysname_info->allocked field, since now we can find out if memory has been allocated by checking if sysname_info->name_size is different than zero. No functional change should be incurred by this commit. Change-Id: Id0f5a646b2d82fda5344d53c9fc8b3407f2ea805 Reviewed-on: https://gerrit.openafs.org/14912 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs.h: fix out of tree build failures There are several compiler errors and warnings when building an out of tree program that includes "afs/afs.h". - Errors for unknown type names 'afs_ucred_t' and 'wait_queue_head' .../afs/afs.h:1542:16: error: unknown type name ‘afs_ucred_t’ ... | afs_set_cr_uid(afs_ucred_t *cred, uid_t uid) { .../afs/afs.h:1605:5: error: unknown type name ‘wait_queue_head_t’ ... | wait_queue_head_t cond; - Warnings about declaring structures within missing declarations for the structs: osi_File, dcache and afs_FetchOutput .../afs/afs.h:1486:36: warning: ‘struct osi_file’ declared inside parameter list will not be visible outside of this definition or declaration ... | int (*read)(void *rock, struct osi_file *tfile, afs_uint32 offset, - Unable to find the file for the include opr/jhash.h The missing type name 'afs_ucred_t' is due to miss-placed declarations for some kernel only functions. The type name 'wait_queue_head' is a data type for Linux kernel modules. The warnings for the missing declarations are due to either references to the structures before they are declared, or because they are not available in any of the other public header files. To fix the unknown type name afs_ucred_t, relocate the function declarations that reference 'afs_ucred_t' into the KERNEL only section (since afs_ucred_t is a kernel specific type). To fix the unknown type name 'wait_queue_head', relocate the afs_event structure and the afs_evhasht variable to be within the KERNEL only section. To resolve the warnings associated with the structures, simply declare the structure names before they are referenced. All references that are resulting in the warnings are declarations for pointers. Relocate the include for opr/jhash.h and the define for VCSIZE into the kernel block. Change-Id: I4135ff25b76d3221c7779c279ed829000ce31f1c Reviewed-on: https://gerrit.openafs.org/14857 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Remove kdump Remove the obsolete kdump debugging tool from the tree. Remove and clean up the preprocessor tests associated with KDUMP, KDUMP_RX_LOCK and KDUMP_KERNEL. Clean up the autoconf and Makefiles to remove kdump and the associated autoconf and Makefile vars XLIBELFA and XLIBKVM. The kdump utility has not been well maintained; for some platforms it fails to build (e.g. Solaris 11). For Linux, the makefile does not even try to compile the kdump source but instead creates the kdump file via touch. The intended functionality of kdump has been replaced by various kernel debugging tools, such as dtrace or systemtap. Change-Id: I23fd82f2b96ba58d1b431af76fdf0afe7d7274b9 Reviewed-on: https://gerrit.openafs.org/14623 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
IRIX: Remove pre-65 code Commit d1923139 (irix kill efs and start pruning pre-65) removed all files that defined AFS_SGI64_ENV and earlier, but didn't remove that code that depended on those defines. In addition, there has been code in the tree that checks for AFS_SGI53_ENV since OpenAFS 1.0, but nothing has ever defined Irix 5.3 support in OpenAFS. Remove all of this obsolete code. Change all references to AFS_SGIXX_ENV to AFS_SGI_ENV, and assume AFS_SGI_ENV is defined in all IRIX dirs. Consolidate some of the resulting ifdef logic appropriately. Change-Id: I9dd426296e04801980b805a5e195063762b23189 Reviewed-on: https://gerrit.openafs.org/14230 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
FBSD: Use user creds for afs_vop_putpages() Currently, the FBSD afs_vop_putpages uses the credentials of the current process for writing data back to the fileserver. Usually this works, but sometimes we're being called from syncer(4), which runs as root instead of as the user accessing the relevant file. This means that instead of using the tokens from the user that wrote to the relevant file, we use whatever tokens belong to uid 0. This usually causes an EACCES error when trying to write the data back to the fileserver, causing us to store EACCES (13) in avc->vc_error, and possibly causing a message in the kernel log like so: afs: failed to store file (0/13) Since we set vc_error during these errors, this can also cause access to the file to fail for the normal user process until vc_error is cleared (such as when the file is closed). To avoid this, store the credentials of the current user that successfully opens the file for writing (in avc->cred), and use those creds for writing back data to the fileserver. This is the same approach that LINUX uses as of commit 70c8deab (Use user credentials for Linux writepage()), and the NFS client code in FreeBSD itself (see the usage of n_writecred in struct nfsnode as of 12.1-RELEASE). Change-Id: I592d709b68d746bbdb326dfd7d012d6de829b905 Reviewed-on: https://gerrit.openafs.org/14164 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
FBSD: Skip page flush in afs_DoPartialWrite Currently, the FBSD afs_vop_putpages() will call afs_write(), which can then go through afs_DoPartialWrite -> afs_StoreAllSegments -> osi_VM_StoreAllSegments -> vm_object_page_clean, which will then try to go through afs_vop_putpages() again. In this call stack, we're only calling afs_StoreAllSegments to reduce our dirty cache chunks (afs_StoreAllSegments does nothing if we don't have that many dirty cache chunks); we don't need to reduce dirty pages, so calling osi_VM_StoreAllSegments is not needed. To avoid calling osi_VM_StoreAllSegments in this situation, add a new flag AFS_NOVMSYNC, which skips the osi_VM_StoreAllSegments call and just flushes the dirty cache chunks. Use this flag in afs_DoPartialWrite on FBSD, and slightly refactor the ifdefs to reduce some code duplication. Change-Id: Id6bf9a7f4ac6d5f09b0249ca6ed11674d556e909 Reviewed-on: https://gerrit.openafs.org/14163 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>
SOLARIS: provide cache manager stats via kstat Provide statistical information via the solaris kstat framework. Data can be examined with the kstat tool or the kstat userspace api. The kstat module is called openafs. Three kstat names are provided. The "param" name provides cache manager parameters as given by the cmdebug -cache program. # kstat -m openafs -n param The "cache" name provides cache manager statistics as given by the xstats plus some additional cache related stats. The "cache" name also provides the libafs kernel module version string and the current local cellname. # kstat -m openafs -n cache The "rx" name provides general rx statistics as given by rxdebug -rxstat. # kstat -m openafs -n rx Change-Id: Ic07e3b58fa5c79145f12f8519a6f7fce0d91138b Reviewed-on: https://gerrit.openafs.org/13170 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Retire AFS_MOUNT_AFS Currently, the AFS_MOUNT_AFS #define is used to mean two completely different things: - The string "afs", corresponding to the first argument to mount(2) on many platforms and some related calls inside libafs (e.g. getnewvnode() on FBSD). - An integer identifying the AFS filesystem (e.g. gfsadd() on AIX). Depending on the platform and the build context (UKERNEL vs KERNEL), AFS_MOUNT_AFS gets defined to one of those two things. This is very confusing, and has led to mistakes in the past, such as those fixed in commit 446457a1 (afs: Set AFS_VFSFSID to a numerical value). To avoid such confusion, get rid of AFS_MOUNT_AFS completely, and replace it with two new symbols: - AFS_MOUNT_STR, the string "afs". - AFS_FSNO, the integer given to gfsadd() et al. When AFS_MOUNT_AFS is split this way, AFS_MOUNT_STR then is always defined to the same value, so remove it from the param.h files for our platforms. Instead, define it in afs.h for libafs use, and in afsd_kernel.c (the only place outside of src/afs that uses it). Also remove the logic for conditionally defining MOUNT_AFS from the param.h files, moving the logic to the same locations as AFS_MOUNT_STR. Note that this commit removes the numeric definition for AFS_MOUNT_AFS in param.sgi_65.h (aka AFS_FSNO). We never actually used this value, since AFS_FSNO is not used on IRIX; instead, we tend to use the 'afs_fstype' global instead of a constant number. Change-Id: I6cbf051dc938cd1c456cbe236c0afe99a3c3dd87 Reviewed-on: https://gerrit.openafs.org/14323 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: more cache truncation stats Add counters for cache too full and waiting to drain occurrences. These will be used in later commits to indicate how often the cache truncation is required and how often the cache manager is waiting for cache truncation to complete. Change-Id: I4aa802729f0910dff1fb3e90b2d44d36df8bf8f3 Reviewed-on: https://gerrit.openafs.org/13168 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Set AFS_VFSFSID to a numerical value Currently when UKERNEL is defined, AFS_VFSFSID is always set to AFS_MOUNT_AFS, which is a string for many platforms for UKERNEL. Update src/afs/afs.h to insure that the define for AFS_VFSFSID is a numeric value when building UKERNEL. Clean up the preprocessor indentation in src/afs/afs.h in the area around the AFS_VFSFSID defines. Thanks to adeason@sinenomine.net for pointing out a much easier solution for resolving this problem. Change-Id: I618fc4c89029a6cca2ca6f530b8f65399299a9d1 Reviewed-on: https://gerrit.openafs.org/14279 Reviewed-by: Andrew Deason <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Log warning when we detect too many vcaches Currently, afs_ShakeLooseVCaches has a kind of warning that is logged when we fail to free up any vcaches. This information can be useful to know, since it may be a sign that users are trying to access way more files than our configured vcache limit, hindering performance as we constantly try to evict and re-create vcaches for files. However, the current warning is not clear at all to non-expert users, and it can only occur for non-dynamic vcaches (which is uncommon these days). To improve this, try to make a general determination if it looks like the stat cache is "stressed", and log a message if so after afs_ShakeLooseVCaches runs (for all platforms, regardless of dynamic vcaches). Also try to make the message a little more user-friendly, and only log it (at most) once per 4 hours. Determining whether the stat cache looks stressed or not is difficult and arguably subjective (especially for dynamic vcaches). This commit draws a few arbitrary lines in the sand to make the decision, so at least something will be logged in the cases where users are constantly accessing way more files than our configured vcache limit. Change-Id: I022478dc8abb7fdef24ccc06d477b349cca759ac Reviewed-on: https://gerrit.openafs.org/13255 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>
afs: Remove osi_VMDirty_p The function osi_VMDirty_p is mentioned in a few places in src/afs, but it has always been ifdef'd or commented out, ever since OpenAFS 1.0. Remove the dead code. Change-Id: Ia7cad718114d91adf9e403e29f9ac976c3f08bfd Reviewed-on: https://gerrit.openafs.org/14023 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Avoid panics in afs_InvalidateAllSegments Currently, afs_InvalidateAllSegments panics when afs_GetValidDSlot fails. We panic in these cases because afs_InvalidateAllSegments cannot simply return an error to its callers; we must invalidate all segments for the given vcache, or we risk serving incorrect data to userspace as explained in the comments. Instead of panicing, though, we could simply sleep and retry the operation until it succeeds. Implement this, retrying every 10 seconds, and logging a message every hour that we're stuck (in case we're stuck for a long time). When we retry the operation, do so in a background request, to avoid a somewhat common situation on Linux where we always get I/O errors from the cache when the calling process has a SIGKILL pending. Create a new background op for this, BOP_INVALIDATE_SEGMENTS. With this, the relevant vcache will be effectively unusable for the entire time we're stuck in this situation (avc->lock will be write-locked), but this is at least better than panicing the whole machine. Change-Id: Icdc58a94f0cd5857903836d94e5cf7814ce7e088 Reviewed-on: https://gerrit.openafs.org/13677 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com>
Remove references to SunOS 4 We already removed support for Solaris versions before Solaris 8, in commit e4c2810f ("Remove support for Solaris pre-8"), but there are still some references to SunOS (meaning SunOS 4) in the tree. This is even older than Solaris (aka SunOS 5), so get rid of these. This commit removes most references to SunOS 4 regarding platform support, and a few comments. This also removes a few comments that were just wrong or nonsensical (e.g. CMAPPED in afs.h is used by other platforms; some comments in platform-specific osi_file.c files referenced SunOS for some reason). Change-Id: I0dd3176c582409176fd898f9c9539fbd833ea789 Reviewed-on: https://gerrit.openafs.org/13506 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>