afs: Add static attribute to internal functions When building against a Linux 6.8 kernel, functions that are missing prototypes or declarations are flagged. We can add the static attribute to functions that are not referenced outside of the file that implements them to avoid having these functions flagged by the compiler. These functions are flagged due to missing prototypes when building against a Linux 6.8 kernel (which sets the -Wmissing-declarations and -Wmissing-prototypes compiler flags as default). Linux 6.8 commit: 'Makefile.extrawarn: turn on missing-prototypes globally' (0fcb70851f). When building against a kernel with CONFIG_WERROR=y, the build fails. There are no functional changes in this commit. Change-Id: I24c78a3167f6a81da4f62267cf901024468ae6b3 Reviewed-on: https://gerrit.openafs.org/15625 Tested-by: BuildBot <buildbot@rampaginggeek.com> 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>
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>
afs: Avoid creating unused conns In afs_LoopServers and PCallBackAddr, we loop over our known servers to issue an RPC, but we skip over servers on various conditions. For most of those, we skip over the server before creating the relevant conn (via afs_ConnBySA), but not for the SRVADDR_ISDOWN/afs_HaveCallBacksFrom check. If we skip over the server for that reason, we'll create an afs_conn and rx_connection, and then release our refs without using them. This doesn't cause any big problems, but it does create extra connections and peers that linger around for at least a couple of hours (until they get cleaned up by afs_GCUserData). It's very easy to avoid these extra useless conns; just perform the SRVADDR_ISDOWN/afs_HaveCallBacksFrom check before we call afs_ConnBYSA. This also makes the check a bit more consistent with the other checks we do. Change-Id: Ie49b87e5dd755f77364502528a02c14944e8c23d Reviewed-on: https://gerrit.openafs.org/14637 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
FBSD: Use CK_STAILQ_FOREACH for ifaces on FBSD 12 FreeBSD 12 changed how network interfaces and network addresses are linked together; we're supposed to use CK_STAILQ_FOREACH to traverse them now, instead of TAILQ_FOREACH. To try to keep this change simpler, introduce a new macro, AFS_FBSD_NET_FOREACH, which picks the right macro to use. Based on a commit by tcreech@tcreech.com. Change-Id: Iab0f93701dd60dcf4237a7fbbf461019bceaeb38 Reviewed-on: https://gerrit.openafs.org/13999 Reviewed-by: Tim Creech <tcreech@tcreech.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
FBSD: Add proper locks when traversing net ifaces When traversing the list of network interfaces, or the list of addresses for a network interface, we're supposed to lock the relevant resource with IFNET_RLOCK, if_addr_rlock, or IN_IFADDR_RLOCK. Add these locks around our code that examines network interfaces, to avoid issues if the interface or address list changes while we're traversing them. While we're doing this, move around some "AFS_DARWIN_ENV || AFS_FBSD_ENV" ifdefs, since these were getting a bit hard to read. This commit adds some duplicated code, but the result should be easier to follow. Also for FreeBSD 12, we must be in NET_EPOCH_ENTER when calling ifa_ifwithnet/rx_ifaddr_withnet (it panics if we don't, with INVARIANTS). Add the needed NET_EPOCH_ENTER/EXIT calls, but do so a bit higher up the call stack, since the returned structures are potentially no longer valid after we NET_EPOCH_EXIT. Since this means we're calling these in a few places in libafs, create a couple of rx abstractions (RX_NET_EPOCH_ENTER) to handle the relevant ifdefs. [adeason@dson.org: Various adjustments to locking calls; splitting up DARWIN/FBSD ifdefs.] Change-Id: I65d63b99b6f6ef3254325cce9338be27ef78478c Reviewed-on: https://gerrit.openafs.org/13998 Reviewed-by: Tim Creech <tcreech@tcreech.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Indent ifdef maze in afs_server.c Change-Id: I223b932490ca1e89711844e41cbff2cd9b50a0f4 Reviewed-on: https://gerrit.openafs.org/13996 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
afs: prevent double release of global lock afs_xvcb afs_GetServer calls ReleaseWriteLock(&afs_xvcb) twice within a few lines. The second one is spurious. Commits b18653de7ae90491c2e75f4a98410581655d776c 'xserver lock order violation' and f2bf60ed4f1323cd6f74f2f01114f7e4f714db53 'xvcb lock order violation' were written by the same author at the same time and apparently were victims of a bad merge. Discovered during a lock audit project as a panic during afsd startup: assertion failed: (&afs_xvcb)->excl_locked == WRITE_LOCK, file: /home/mvitale/src/sna-openafs/src/afs/afs_server.c, line: 2089 afs_GetServer is called frequently by many threads and so this bug could easily have released another thread's write lock on afs_xvcb. Remove the spurious second release. Change-Id: I495f4775e18ed37cfbccd03b5f25594586864b83 Reviewed-on: https://gerrit.openafs.org/14411 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Remove osi_GetuTime osi_GetuTime has always been #define'd to be the same thing as osi_GetTime, ever since OpenAFS 1.0. Get rid of this redundant macro, and just use osi_GetTime instead. Change-Id: Ic826aeaa17314019b79cfb2df04a79309aa31db5 Reviewed-on: https://gerrit.openafs.org/14236 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Convert all osi_timeval_t to osi_timeval32_t Since commit 130144850c6d05bc69e06257a5d7219eb98697d8 "xstat: cm xstat time values are 32 bit", OpenAFS has had two timeval definitions: osi_timeval_t and osi_timeval32_t. Since they are functionally equivalent, convert all references to osi_timeval_t to osi_timeval32_t. This makes clear that this struct is always expected to contain 32-bit members for tv_sec and tv_usec. There are still a few platforms where osi_timeval32_t is mistakenly defined with 64-bit members; these will be addressed in future commits. No functional change should be incurred by this commit. Change-Id: I3e8e44235e813571723fcd114194f6cb83de90e4 Reviewed-on: https://gerrit.openafs.org/14215 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: Drop GLOCK for RXAFS_GetCapabilities We are hitting the net here; we certainly should not be holding AFS_GLOCK while waiting for the server's response. Found via FreeBSD WITNESS. Change-Id: Ie727db27adaeed23ac8cff7665143bae2ce2ede8 Reviewed-on: https://gerrit.openafs.org/14181 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
FBSD: Remove pre-8 code Commit 123f0fb1 (config: remove support for old FreeBSD releases) removed our support for FreeBSD releases before FreeBSD 8. However, various areas of code still reference the symbols from those old versions (e.g. AFS_FBSD53_ENV). Remove our ifdef logic for these old symbols, according to the following rules: - In FBSD-specific dirs, assume AFS_FBSD80_ENV is always true (as well as the symbols for earlier versions) - In non-FBSD dirs, convert AFS_FBSD80_ENV to AFS_FBSD_ENV (and do the same for all earlier versions) This allows us to remove code that was specific to older FreeBSD versions, and simplify some ifdef conditionals. Also remove the definitions for AFS_FBSD80_ENV and earlier versions in our existing param.h files. With this commit, the functions afs_start, afs_vop_lock, afs_vop_unlock, and afs_vop_islocked are now always unreferenced, so remove them. Change-Id: Ia5a5ba5ee5b71a86cb4514305e20f1bb34487100 Reviewed-on: https://gerrit.openafs.org/13812 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Tim Creech <tcreech@tcreech.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
The interminable rework of afs_random() Commit f0a3d477d6109697645cfdcc17617b502349d91b restructured the operation on tv_usec to avoid using undefined behavior, but in the process introduced a behavior change. Historically (at least as far back as AFS-3.3), we masked off the low nybble (four bits) of tv_usec before adding the low byte (eight bits) of the rxi_getaddr() output. Why there was a desire to combine two sources of input for the overlapping four bits remains unclear, but restore the historical behavior for now, as the intent of commit f0a3d477d6109697645cfdcc17617b502349d91b was to not introduce any behavior changes. Change-Id: Icb8bc1edd34ca29c3094b976436177b18bfc8d1d Reviewed-on: https://gerrit.openafs.org/13759 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
FBSD: Call CURVNET_SET/CURVNET_RESTORE for VIMAGE In commit 9703b023 (FBSD: VIMAGE support), we changed a couple of our variable references to their V_* equivalents, to accommodate kernels with VIMAGE turned on. This allows us to build, but causes us to crash whenever we hit that code when VIMAGE is enabled, because the relevant macros reference 'curvnet', which is NULL outside of networking code. What we're supposed to do is to set 'curvnet' before entering networking code by calling 'CURVNET_SET(xxx)', and reset it afterwards by calling 'CURVNET_RESTORE()'. We must make exactly one _RESTORE call for each _SET, and they are supposed to be run at the same level of scope. So to avoid the crashes, make the relevant CURVNET_* calls whenever we look at networking info. We currently only do this in a few places: - In afs_SetServerPrefs, to try to detect if a given server address is in the same network as one our local interfaces (V_in_ifaddrhead) - In rxi_GetIFInfo, for some MTU-related info (V_ifnet) - In rxi_FindIfnet, for some MTU-related info (ifa_ifwithnet) As for what vnet we actually set 'curvnet' to, we could set it to the vnet of the current thread (TD_TO_VNET(curthread)), or we could set it to the vnet of an associated network object (a socket, an interface, etc). Since all of our network-related code goes through Rx, in this commit we set curvnet to the vnet of the Rx socket (rx_socket->so_vnet). Note that VIMAGE is optional in 11-RELEASE, but is turned on by default in 12.0-RELEASE. For more information, see: https://wiki.freebsd.org/VIMAGE/porting-to-vimage [adeason@dson.org: Reworded commit message; moved some code around.] Change-Id: If631b8942d7ee5cfe38a8f0c32b282d015f0bf35 Reviewed-on: https://gerrit.openafs.org/12580 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
rework afs_random() yet again clang 7 notes that ~0 is signed and that left-shifting into the sign bit is undefined behvaior. Use a new construction to clear the low byte of tv_usec with only bitwise operations that are independent of the width of tv_usec and stay within the realm of C's defined behavior. Change-Id: I3e4f0fa4a8b8b72df23ef0c8ad7c4a229ac942f3 Reviewed-on: https://gerrit.openafs.org/13474 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: Free 'addrs' array Currently, 3 places in libafs allocate an 'addrs' array in a very similar way to loop through our list of servers: ForceAllNewConnections(), afs_LoopServers(), and PCallBackAddr(). Of these, only afs_LoopServers actually frees the array. ForceAllNewConnections and PCallBackAddr leak the memory, but these are only hit from infrequent pioctls that can only be run by root, so the impact is small. Fix ForceAllNewConnections and PCallBackAddr to free the array. Change-Id: Ic348e29cefa7c41cbcb30f738f943e8d022a97f0 Reviewed-on: https://gerrit.openafs.org/13355 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
afs: fix afs_xserver deadlock in afsdb refresh When setting up a new volume, the cache manager calls afs_GetServer() to setup the server object for each fileserver associated with the volume. The afs_GetServer() function locks afs_xserver and then, among other things, calls afs_GetCell() to lookup the cell info by cell number. When the cache manager is running in afsdb mode, afs_GetCell() will attempt to refresh the cell info if the time-to-live has been exceeded since the last call to afs_GetCell(). During this refresh the AFSDB calls afs_GetServer() to update the vlserver information. The afsdb handler thread and the thread processing the volume setup become deadlocked since the afs_xserver lock is already held at this point. This bug will manifest when the DNS SRV record TTL is smaller than the time the fileservers respond to the GetCapabilities RPC within afs_GetServer() and there are multiple read-only servers for a volume. Avoid the deadlock by using the afs_GetCellStale() variant within afs_GetServer(). This variant returns the memory resident cell info without the afsdb upcall and the subsequent afs_GetServer() call. Change-Id: Iad57870f84c5e542a5ee20f00ea03b3fc87683a1 Reviewed-on: https://gerrit.openafs.org/12652 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
libafs: reduce stack space Allocate temporary vrequests to reduce the amount of stack space used. Change-Id: I8c50a3af3028512003a02e46a2960b9b135213a5 Reviewed-on: http://gerrit.openafs.org/11003 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil> Reviewed-by: D Brashear <shadow@your-file-system.com>
afs: Pass rx connection to print_internet_address Make print_internet_address take an rx_connection, so it can print out more information based on rx info. Currently it does not use the connection; this commit is just for adding the connection to the interface, and adjusting all of the callers to cope. There should be no behavior change. Change-Id: I410ffe43b7b6fc4d5c82666529c9263969820185 Reviewed-on: http://gerrit.openafs.org/8409 Reviewed-by: Derrick Brashear <shadow@your-file-system.com> Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com> Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs_server: afs_SetServerPrefs() can never be called with null The one and only call site never calls afs_SetServerPrefs() with a null pointer, and some but not all of the paths through the #ifdefs assume this. Remove code that checks for this; it confuses both humans and the static analyzer. Change-Id: Ie3f7319cebde9ec3078af2defcebb80692aa95f2 Reviewed-on: http://gerrit.openafs.org/7912 Reviewed-by: Derrick Brashear <shadow@dementix.org> Tested-by: Derrick Brashear <shadow@dementix.org>