bozo: Require BNODE_LOCK for DirAccessOK

DirAccessOK() currently uses two static vars (lastTime, lastResult) to
cache the result of the function to avoid overly-frequent stat()s. These
are not documented as being protected by any locks. Currently they
cannot be accessed by two different threads at the same time; the only
callers are:

- SBOZO_GetInstanceInfo(), which calls it with BNODE_LOCK held
- main(), which calls it before our rx service threads are started

But this is fragile and not documented. To avoid potential issues in the
future, document DirAccessOK() as requiring BNODE_LOCK, assert that we
have BNODE_LOCK in DirAccessOK(), and acquire BNODE_LOCK before calling
DirAccessOK() from main().

While we're here, move the declarations for the two static vars so
they're next to each other, so it's a little more obvious that we have
some static variables here.

Change-Id: I4e0e55cd8a7ebbb681e4da937efcc9c37633e3ab
Reviewed-on: https://gerrit.openafs.org/15837
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Andrew Deason 2024-08-19 18:18:36 -05:00
parent 00b31c7bae
commit 6e5cbd7ccb
2 changed files with 11 additions and 6 deletions

View File

@ -1360,10 +1360,13 @@ StatEachEntry(IN struct bozo_bosEntryStats *stats)
return 1;
}
/* DirAccessOK - checks the mode bits on the AFS dir and decendents and
/*
* DirAccessOK - checks the mode bits on the AFS dir and decendents and
* returns 0 if some are not OK and 1 otherwise. For efficiency, it doesn't do
* this check more often than every 5 seconds. */
* this check more often than every 5 seconds.
*
* @pre BNODE_LOCK must be held
*/
int
DirAccessOK(void)
{
@ -1372,11 +1375,13 @@ DirAccessOK(void)
return 1;
#else
static afs_uint32 lastTime = 0;
afs_uint32 now = FT_ApproxTime();
static int lastResult = -1;
afs_uint32 now = FT_ApproxTime();
int result;
int i;
BNODE_ASSERT_LOCK();
if ((now - lastTime) < 5)
return lastResult;
lastTime = now;

View File

@ -1174,6 +1174,8 @@ main(int argc, char **argv, char **envp)
signal(SIGFPE, bozo_insecureme);
#endif
BNODE_LOCK();
/* Write current state of directory permissions to log file */
DirAccessOK();
@ -1203,8 +1205,6 @@ main(int argc, char **argv, char **envp)
/* opened the cell databse */
bozo_confdir = tdir;
BNODE_LOCK();
code = bnode_Init();
if (code) {
printf("bosserver: could not init bnode package, code %d\n", code);