openafs.git
6 years agoSOLARIS: Avoid vcache locks when flushing pages for RO vnodes 47/12247/6
Mark Vitale [Tue, 30 Jun 2015 05:54:21 +0000]
SOLARIS: Avoid vcache locks when flushing pages for RO vnodes

We have multiple code paths that hold the following locks at the same
time:

    - avc->lock for a vcache
    - The page lock for a page in 'avc'

In order to avoid deadlocks, we need a consistent ordering for obtaining
these two locks. The code in afs_putpage() currently obtains avc->lock
before the page lock (Obtain*Lock is called before pvn_vplist_dirty).

The code in afs_getpages() also obtains avc->lock before the page lock,
but it does so in a loop for all requested pages (via pvn_getpages()).
On the second iteration of that loop, it obtains avc->lock, and the page
from the first iteration of the loop is still locked. Thus, it obtains a
page lock before locking avc->lock in some cases.

Since we have two code paths that obtain those two locks in a different
order, a deadlock can occur. Fixing this properly requires changing at
least one of those code paths, so the locks are taken in a consistent
order. However, doing so is complex and will be done in a separate
future commit.

For this commit, we can avoid the deadlock for RO volumes by simply
avoiding taking avc->lock in afs_putpages() at all while the pages are
locked. Normally, we lock avc->lock because pvn_vplist_dirty() will call
afs_putapage() for each dirty page (and afs_putapage() requires
avc->lock held). But for RO volumes, we will have no dirty pages
(because RO volumes cannot be written to from a client), and so
afs_putapage() will never be called.

So to avoid this deadlock issue for RO volumes, avoid taking avc->lock
across the pvn_vplist_dirty() call in afs_putpage(). We now pass a dummy
pageout callback function to pvn_vplist_dirty() instead, which should
never be called, and which panics if it ever is.

We still need to hold avc->lock a few other times during afs_putpage()
for other minor reasons, but none of these hold page locks at the same
time, so the deadlock issue is still avoided.

[mmeffie: comments, and fix missing write lock, fix lock releases]
[adeason: revised commit message]

Change-Id: Iec11101147220828f319dae4027e7ab1f08483a6
Reviewed-on: https://gerrit.openafs.org/12247
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoadd rfc3961.h to kernel sources 82/12882/2
Michael Meffie [Wed, 31 Jan 2018 21:52:40 +0000]
add rfc3961.h to kernel sources

Export this header to the kernel sources in the libafs_tree, since it is
needed for the kernel module build.

FIXES 134476

Change-Id: Id359c6d065c259601d14ee5c02b93647f86a0288
Reviewed-on: https://gerrit.openafs.org/12882
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoCellServDB update 14 Mar 2017 80/12880/2
Michael Meffie [Mon, 8 Feb 2016 17:12:22 +0000]
CellServDB update 14 Mar 2017

Update all remaining copies of CellServDB in the tree, and make the
Red Hat packaging use it by default too.

Change-Id: I5a70a7c658ad0056cd10945bb730e84f0edfb730
Reviewed-on: https://gerrit.openafs.org/12880
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoAdd param.h files for recent FreeBSD 63/12863/4
Benjamin Kaduk [Tue, 9 Jan 2018 04:28:24 +0000]
Add param.h files for recent FreeBSD

Add files for FreeBSD 10.4, 11.1, and 12.0 (12-CURRENT), for i386 and amd64.

Change-Id: I904f576914bb965a659750e6302f011acf66ba81
Reviewed-on: https://gerrit.openafs.org/12863
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoFBSD: catch up to missing sysnames 62/12862/4
Benjamin Kaduk [Tue, 9 Jan 2018 03:27:04 +0000]
FBSD: catch up to missing sysnames

Add sysnames for i386 and amd64 10.4, 11.1, and 12.0 (12-CURRENT, at present).

Change-Id: If38ecca7b2b3e40c186b7e9321ce017b4711139c
Reviewed-on: https://gerrit.openafs.org/12862
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoubik: check if epoch is sane before db relabel 40/12640/3
Marcio Barbosa [Wed, 21 Jun 2017 20:24:05 +0000]
ubik: check if epoch is sane before db relabel

The sync-site relabels its database at the end of the first write
transaction. The new label will be equal to the time at which the
sync-site in question first received its coordinator mandate. This time
is stored by a global called ubik_epochTime. In order to make sure that
the new database label is sane, only relabel the database if
ubik_epochTime is within a specific range.

Change-Id: I2408569e5de46d387f63cbc2fab05ea1264a505c
Reviewed-on: https://gerrit.openafs.org/12640
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoubik: update ubik_dbVersion during SDISK_SendFile 16/12716/3
Marcio Barbosa [Mon, 21 Aug 2017 19:50:14 +0000]
ubik: update ubik_dbVersion during SDISK_SendFile

The ubik_dbVersion global represents the sync site's database version
and it is mostly used by the remote sites for sanity checks. Currently,
this global is updated when database changes are made on the sync site
(SDISK_Commit or SDISK_SetVersion), as well as every time we vote "yes"
for the sync-site in a beacon reply. Unfortunately, ubik_dbVersion is
not updated when a copy of the sync site's database is received via
DISK_SendFile, and it won't get updated until our next "yes" vote.
During this window, the current database version will not match
ubik_dbVersion. As a result, any write transaction during this time
frame will fail on the remote site in question.

To fix this problem, do not wait for the next beacon packet to update
ubik_dbVersion when the sync site's database is received; just update
it when we get the new database. Since no write transactions are
allowed while the db is transferring, ubik_dbVersion can be safely
updated.

Change-Id: Ide7a695a69cb3229ad585d9e56c5ddc2efb76dd7
Reviewed-on: https://gerrit.openafs.org/12716
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLINUX: Avoid locking inode in check_dentry_race 68/12868/2
Andrew Deason [Fri, 12 Jan 2018 03:27:28 +0000]
LINUX: Avoid locking inode in check_dentry_race

Currently, check_dentry_race locks the parent inode in order to ensure
it is not running in parallel with d_splice_alias for the same inode.
(For old Linux kernel versions; see commit b0461f2d: "LINUX:
Workaround d_splice_alias/d_lookup race".)

However, it is possible to hit this area of code when the parent inode
is already locked. When someone tries to create a file, directory, or
symlink, Linux tries to lookup the dentry for the target path, to see
if it already exists. While looking up the last component of the path,
Linux locks the directory, and if it finds a dentry for the target
name, it calls d_invalidate on it while the parent directory is
locked.

For a dentry with a NULL inode, we'll then try to lock the parent
inode in check_dentry_race. But since the inode is already locked, we
will deadlock.

From a user's point of view, the hang can be reproduced by doing
something similar to:

    $ mkdir dir # succeeds
    $ rmdir dir
    $ ls -l dir
    ls: cannot access dir: No such file or directory
    $ mkdir dir # hangs

To avoid this, we can just change which lock we're using to avoid
check_dentry_race/d_splice_alias from running in parallel. Instead of
locking the parent inode, introduce a new global lock (called
dentry_race_sem), and lock that in check_dentry_race and around our
d_splice_alias call. We know that those are the only two users of this
new lock, so this should avoid any such deadlocks.

This does potentially reduce performance, since all tasks that hit
check_dentry_race or d_splice_alias will take the same global lock.
However, this at least still allows us to make use of negative
dentries, and this entire code path only applies to older Linux
kernels. It could be possible to add a new lock into struct vcache
instead, but using a global lock like this commit does is much
simpler.

Change-Id: Ide0f21145c83d6fbb34c637d8a36c8cd21549940
Reviewed-on: https://gerrit.openafs.org/12868
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: fix conditional for kernel-debuginfo files directive 74/12874/2
Michael Meffie [Wed, 17 Jan 2018 22:33:50 +0000]
redhat: fix conditional for kernel-debuginfo files directive

Commit 443dd5367e0cd9050ad39a6594c5be521271b4e9 added support for a
separate debuginfo package for the kernel module.  Unfortunately, the
%files directive for the kernel module debuginfo package was incorrectly
placed in the %if stanza of the build_userspace condition, so the
rpmbuild fails when attempting to build just the kernel module.

That is, when running rpmbuild with the options:

    rpmbuild --define "build_userspace 0" --define "build_modules 1" ...

rpmbuild fails with:

    RPM build errors:
       Installed (but unpackaged) file(s) found:
       /usr/lib/debug/lib/modules/.../extra/openafs/openafs.ko.debug

Fix this by moving the new %files directive out of the build_userspace
conditional.

Change-Id: I46e74b660048022a4cc4327835c6055402a34ccf
Reviewed-on: https://gerrit.openafs.org/12874
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoautoconf: refactor linux-checks.m4 44/12844/4
Michael Meffie [Sat, 30 Dec 2017 22:59:38 +0000]
autoconf: refactor linux-checks.m4

Further refactoring of the autoconf macros. Divy up the linux kernel
checks into smaller files.

This is a non-functional change. Care has been taken preserve the
ordering of the autoconf tests. Except for whitespace, the generated
configure file has not been changed by this refactoring.  This has been
verified with a 'diff -u -w -B' comparison of the generated configure
file before and after applying this commit.

Change-Id: I5ea4c9e3a0aeff1767ef561bdb8361781694ee28
Reviewed-on: https://gerrit.openafs.org/12844
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoautoconf: refactor ostype.m4 43/12843/4
Michael Meffie [Sat, 30 Dec 2017 17:12:59 +0000]
autoconf: refactor ostype.m4

Further refactoring of the autoconf macros. Move more linux and solaris
specific checks into their own files.

This is a non-functional change. Care has been taken preserve the
ordering of the autoconf tests. Except for whitespace, the generated
configure file has not been changed by this refactoring.  This has been
verified with a 'diff -u -w -B' comparison of the generated configure
file before and after applying this commit.

Change-Id: Ib3e7b1270826970c541a695230f4e3cd13cf9e3d
Reviewed-on: https://gerrit.openafs.org/12843
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoautoconf: refactor acinclude.m4 42/12842/4
Michael Meffie [Fri, 29 Dec 2017 19:24:28 +0000]
autoconf: refactor acinclude.m4

The acinclude.m4 is very large and often requires to be changed for
unrelated commits.  Divy up the large acinclude.m4 into a number of
smaller files to avoid so many contentions and to make the autoconf
system easier to maintain.

This is a non-functional change. Care has been taken preserve the
ordering of the autoconf tests. Except for whitespace, the generated
configure file has not been changed by this refactoring.  This has been
verified with a 'diff -u -w -B' comparison of the generated configure
file before and after applying this commit.

Change-Id: I70e7f846dea0055d00a60a47422aa73bff25c4c6
Reviewed-on: https://gerrit.openafs.org/12842
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agorx: remove trailing semicolons from FBSD mutex operations 53/12853/2
Benjamin Kaduk [Fri, 5 Jan 2018 04:00:15 +0000]
rx: remove trailing semicolons from FBSD mutex operations

Since the first introduction of FreeBSD support, the macros
(MUTEX_ENTER, etc.) for kernel mutex operations have included
trailing semicolons, unique among all the platforms.

This did not cause problems until the recent work on rx event
handlers, which put a MUTEX_ENTER() in the body of an 'if' clause
with no brackets, and attempted to follow it with an 'else' clause.
This results in the following (rather obtuse) compiler error:

   /root/openafs/src/rx/rx.c:3666:5: error: expected expression
       else
       ^

Which is more visible in the preprocessed source, as

   if (condition)
       expression;;
   else
       other_expression;

is clearly invalid C.

To fix the FreeBSD kernel module build, remove the unneeded semicolons.

Change-Id: I191009ad412852dcc03cd71a0982fe41a953301d
Reviewed-on: https://gerrit.openafs.org/12853
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agolibuafs: remove stale afs_nfsdisp.lo rule 02/12802/3
Benjamin Kaduk [Sat, 9 Dec 2017 17:44:51 +0000]
libuafs: remove stale afs_nfsdisp.lo rule

afs_nfsdisp.lo is not used, so we do not need a build rule for it.

Change-Id: I4ca53a4823b0ccd5bfd769867f6766bd05ea4ceb
Reviewed-on: https://gerrit.openafs.org/12802
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoReplace <rpc/types.h> with <rx/xdr.h> 00/12800/5
Benjamin Kaduk [Sat, 9 Dec 2017 17:37:59 +0000]
Replace <rpc/types.h> with <rx/xdr.h>

Our in-tree xdr.h appears to have started life as a concatenation of
rpc/types.h and rpc/xdr.h, and should include all the needed functionality.
Indeed, commit 7293ddf325b149cae60d3abe7199d08f196bd2b9 even indicates
that we expect to be using our in-tree XDR everywhere anyway, so the
system XDR is superfluous.

Note that afs/sysincludes.h (not afsincludes.h!) already includes
rx/xdr.h ifndef AFS_LINUX22_ENV.

This change should help systems running glibc 2.26 or newer, which has
stopped providing the Sun RPC headers by default.

While here remove some duplicate includes of rpc/types.h in the
AIX-specific sources.

The Solaris NFS translator bits cannot really be changed, since the system
headers are used and have tight interdependencies.

Update rxgen to not emit rpc/types.h inclusion.

[mmeffie: squash 12801 to not emit rpc/types.h from rxgen]

Change-Id: I0b195216affa06ab9e259cb0bab0c8286a1636d9
Reviewed-on: https://gerrit.openafs.org/12800
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLINUX: Avoid d_invalidate() during afs_ShakeLooseVCaches() 30/12830/7
Mark Vitale [Fri, 1 Dec 2017 01:26:46 +0000]
LINUX: Avoid d_invalidate() during afs_ShakeLooseVCaches()

With recent changes to d_invalidate's semantics (it returns void in Linux 3.11,
and always returns success in RHEL 7.4), it has become increasingly clear that
d_invalidate() is not the best function for use in our best-effort
(nondisruptive) attempt to free up vcaches that is afs_ShakeLooseVCaches().
The new d_invalidate() semantics always force the invalidation of a directory
dentry, which contradicts our desire to be nondisruptive, especially when
that directory is being used as the current working directory for a process.
Our call to d_invalidate(), intended to merely probe for whether a dentry
can be discarded without affecting other consumers, instead would cause
processes using that dentry as a CWD to receive ENOENT errors from getcwd().

A previous commit (c3bbf0b4444db88192eea4580ac9e9ca3de0d286) tried to address
this issue by calling d_prune_aliases() instead of d_invalidate(), but
d_prune_aliases() does not recursively descend into children of the given
dentry while pruning, leaving it an incomplete solution for our use-case.

To address these issues, modify the shakeloose routine TryEvictDentries() to
call shrink_dcache_parent() and maybe __d_drop() for directories, and
d_prune_aliases() for non-directories, instead of d_invalidate().  (Calls to
d_prune_aliases() for directories have already been removed by reverting commit
c3bbf0b4444db88192eea4580ac9e9ca3de0d286.)

Just like d_invalidate(), shrink_dcache_parent() has been around "forever"
(since pre-git v2.6.12).  Also like d_invalidate(), it "walks" the parent
dentry's subdirectories and "shrinks" (unhashes) unused dentries.  But unlike
d_invalidate(), shrink_dcache_parent() will not unhash an in-use dentry, and
has never changed its signature or semantics.

d_prune_aliases() has also been available "forever", and has also never changed
its signature or semantics.  The lack of recursive descent is not an issue for
non-directories, which cannot have such children.

[kaduk@mit.edu: apply review feedback to fix locking and avoid extraneous
changes, and reword commit message]

Change-Id: Icb6138ee5785e0ef82a9b85b1d2651dfd0830043
Reviewed-on: https://gerrit.openafs.org/12830
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: consolidate duplicate code in osi_TryEvictDentries 92/12792/5
Mark Vitale [Thu, 30 Nov 2017 22:56:13 +0000]
LINUX: consolidate duplicate code in osi_TryEvictDentries

The two stanzas for HAVE_DCACHE_LOCK are now functionally identical;
remove the preprocessor conditionals and duplicate code.

Minor functional change is incurrred for very old (before 2.6.38) Linux
versions that have dcache_lock; we are now obtaining the d_lock as well.

This is safe because d_lock is also quite old (pre-git, 2.6.12), and it
is a spinlock that's only held for checking d_unhashed.  Therefore, it
should have negligible performance impact.  It cannot cause deadlocks or
violate locking order, because spinlocks can't be held across sleeps.

Change-Id: I08faf204e6bd82c4401cdf6048d12cd551dd18fc
Reviewed-on: https://gerrit.openafs.org/12792
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Andrew Deason <adeason@dson.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: consolidate duplicate code in canonical_dentry 91/12791/5
Mark Vitale [Thu, 30 Nov 2017 21:51:32 +0000]
LINUX: consolidate duplicate code in canonical_dentry

The two stanzas for HAVE_DCACHE_LOCK are now identical;
remove the preprocessor conditionals and duplicate code.

No functional change should be incurred by this commit.

Change-Id: I15cd4631d1932dcfb920313acb82fcbe570087e8
Reviewed-on: https://gerrit.openafs.org/12791
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: add afs_d_alias_lock & _unlock compat wrappers 90/12790/5
Mark Vitale [Thu, 30 Nov 2017 21:46:16 +0000]
LINUX: add afs_d_alias_lock & _unlock compat wrappers

Simplify some #ifdefs for HAVE_DCACHE_LOCK by pushing them down into
new helpers in osi_compat.h.

No functional change should be incurred by this commit.

Change-Id: Ia0dc560bc84c8db4b84ddcc77a17bab5fbf93af9
Reviewed-on: https://gerrit.openafs.org/12790
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: create afs_linux_dget() compat wrapper 89/12789/5
Mark Vitale [Thu, 30 Nov 2017 21:08:38 +0000]
LINUX: create afs_linux_dget() compat wrapper

For dentry operations that cover multiple dentry aliases of
a single inode, create a compatibility wrapper to hide differences
between the older dget_locked() and the current dget().

No functional change should be incurred by this commit.

Change-Id: I2bb0d453417f37707018f6ba5859903c3d34c8ff
Reviewed-on: https://gerrit.openafs.org/12789
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoRevert "LINUX: do not use d_invalidate to evict dentries" 88/12788/5
Mark Vitale [Thu, 30 Nov 2017 18:45:27 +0000]
Revert "LINUX: do not use d_invalidate to evict dentries"

Linux recently changed the semantics of d_invalidate() to:
- return void
- invalidate even a current working directory

OpenAFS commit c3bbf0b4444db88192eea4580ac9e9ca3de0d286 switched libafs
to use d_prune_aliases() instead.

However, since that commit, several things have happened:
- RHEL 7.4 changed the semantics of d_invalidate() such that it
  invalidates the cwd, but did NOT change the return type to void.
  This broke our autoconf test for detecting the new semantics.
- Further research reveals that d_prune_aliases() was not the best
  choice for replacing d_invalidate().  This is because for directories,
  d_prune_aliases() doesn't invalidate dentries when they are referenced
  by its children, and it doesn't walk the tree trying to invalidate
  child dentries.  So it can leave dentries dangling, if the only
  references to thos dentries are via children.

In preparation for future commits, revert
c3bbf0b4444db88192eea4580ac9e9ca3de0d286 .

Change-Id: Iafbef23a6070180c0e21eb01a2d59385ef52f55c
Reviewed-on: https://gerrit.openafs.org/12788
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoRevert "LINUX: eliminate unused variable warning" 87/12787/4
Mark Vitale [Thu, 30 Nov 2017 19:04:48 +0000]
Revert "LINUX: eliminate unused variable warning"

This reverts commit 19599b5ef5f7dff2741e13974692fe4a84721b59
to allow also reverting commit
c3bbf0b4444db88192eea4580ac9e9ca3de0d286 .

Change-Id: I2780fe68d352f0f1def198f21127ec944d1d2c1d
Reviewed-on: https://gerrit.openafs.org/12787
Reviewed-by: Andrew Deason <adeason@dson.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux 4.15: check for 2nd argument to pagevec_init 24/12824/3
Stephan Wiesand [Fri, 22 Dec 2017 13:40:32 +0000]
Linux 4.15: check for 2nd argument to pagevec_init

Linux 4.15 removes the distinction between "hot" and "cold" cache
pages, and pagevec_init() no longer takes a "cold" flag as the
second argument. Add a configure test and use it in osi_vnodeops.c .

Change-Id: Ia5287b409b2a811d2250c274579e6f15fd18fdbb
Reviewed-on: https://gerrit.openafs.org/12824
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Tested-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux: use plain page_cache_alloc 23/12823/2
Stephan Wiesand [Fri, 22 Dec 2017 13:17:09 +0000]
Linux: use plain page_cache_alloc

Linux 4.15 removes the distinction between "hot" and "cold" cache
pages, and no longer provides page_cache_alloc_cold(). Simply use
page_cache_alloc() instead, rather than adding yet another test.

Change-Id: I34e734223927030f7ff252acb61120366a808ad6
Reviewed-on: https://gerrit.openafs.org/12823
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Tested-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: separate debuginfo package for kmod rpm 67/11867/4
Pat Riehecky [Thu, 12 Mar 2015 19:33:10 +0000]
redhat: separate debuginfo package for kmod rpm

Place the debuginfo for the kmod into its own rpm so that
it doesn't have to track against the userspace packages.

FIXES 132034

Change-Id: I60a753275d896a89c1f6896c653d78a4e1fe7e2c
Reviewed-on: https://gerrit.openafs.org/11867
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoAvoid gcc warning 13/12813/4
Christof Hanke [Mon, 18 Dec 2017 15:58:39 +0000]
Avoid gcc warning

When using the configure option --enable-checking with gcc 7.2.1,
the compilation fails with

vutil.c:860:20: error: â€˜%s’ directive writing up to 255 bytes into \
a region of size 63 [-Werror=format-overflow=]

This can be seen in the logs of the openSUSE Tumbleweed builder
for e.g. build 2368.
Avoid this warning by using snprintf which is provided by libroken
for all platforms.

Change-Id: I6acd3a1c06760abc8144c0892812c3bb50477227
Reviewed-on: https://gerrit.openafs.org/12813
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agomacos: make the OpenAFS client aware of APFS 43/12743/2
Marcio Barbosa [Thu, 12 Oct 2017 15:42:40 +0000]
macos: make the OpenAFS client aware of APFS

Apple has introduced a new file system called APFS. Starting from High
Sierra, APFS replaces Mac OS Extended (HFS+) as the default file system
for solid-state drives and other flash storage devices.

The current OpenAFS client is not aware of APFS. As a result, the
installation of the current client into an APFS volume will panic the
machine.

To fix this problem, make the OpenAFS client aware of APFS.

Change-Id: Ib5ac88b87f348744864f4e33f1f222efbc852d41
Reviewed-on: https://gerrit.openafs.org/12743
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agomacos: packaging support for MacOS X 10.13 42/12742/3
Marcio Barbosa [Fri, 6 Oct 2017 13:01:12 +0000]
macos: packaging support for MacOS X 10.13

This commit introduces the new set of changes / files required to
successfully create the dmg installer on OS X 10.13 "High Sierra".

Change-Id: Id9da3cf959627a13d8cfd1d1d7412820e46ad63e
Reviewed-on: https://gerrit.openafs.org/12742
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agomacos: add support for MacOS 10.13 41/12741/3
Marcio Barbosa [Tue, 3 Oct 2017 20:01:56 +0000]
macos: add support for MacOS 10.13

This commit introduces the new set of changes / files required to
successfully build the OpenAFS source code on OS X 10.13 "High Sierra".

Change-Id: I51928279d97c9d86c67db7de5eb7fc9d317fd381
Reviewed-on: https://gerrit.openafs.org/12741
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoFix macro used to check kernel_read() argument order 08/12808/2
Benjamin Kaduk [Fri, 15 Dec 2017 01:54:57 +0000]
Fix macro used to check kernel_read() argument order

The m4 macro implementing the configure check is called
LINUX_KERNEL_READ_OFFSET_IS_LAST, but it defines a preprocessor symbol
that is just KERNEL_READ_OFFSET_IS_LAST.  Our code needs to check
for the latter being defined, not the former.

Reported by Aaron Ucko.

Change-Id: Id7cd3245b6a8eb05f83c03faee9c15bab8d0f6e8
Reviewed-on: https://gerrit.openafs.org/12808
Reviewed-by: Anders Kaseorg <andersk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoOPENAFS-SA-2017-001: rx: Sanity-check received MTU and twind values
Benjamin Kaduk [Mon, 4 Dec 2017 23:20:57 +0000]
OPENAFS-SA-2017-001: rx: Sanity-check received MTU and twind values

Rather than blindly trusting the values received in the
(unauthenticated) ack packet trailer, apply some minmial sanity checks
to received values.  natMTU and regular MTU values are subject to
Rx minmium/maximum packet sizes, and the transmit window cannot drop
below one without risk of deadlock.

The maxDgramPackets value that can also be present in the trailer
already has sufficient sanity checking.

Extremely low MTU values (less than 28 == RX_HEADER_SIZE) can cause us
to set a negative "maximum usable data" size that gets used as an
(unsigned) packet length for subsequent allocation and computation,
triggering an assertion when the connection is used to transmit data.

FIXES 134450

Change-Id: I37698ff166da47a57aa0d1962ae8effc74e30851

6 years agoafs: Fix bounds check in PNewCell 82/12782/2
Benjamin Kaduk [Tue, 28 Nov 2017 04:17:28 +0000]
afs: Fix bounds check in PNewCell

Reported by the opensuse buildbot:

CC [M] /home/buildbot/opensuse-tumbleweed-i386-builder/build/src/libafs/MODLOAD-4.13.12-1-default-MP/rx_packet.o
/home/buildbot/opensuse-tumbleweed-i386-builder/build/src/afs/afs_pioctl.c: In function â€˜PNewCell’:
/home/buildbot/opensuse-tumbleweed-i386-builder/build/src/afs/afs_pioctl.c:3075:55: error: â€˜*’ in boolean context, suggest â€˜&&’ instead [-Werror=int-in-bool-context]
     if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

The bug was introduced in commit 718f85a8b6.

Change-Id: Iae55a99e35266aa763fb431f2acc4eba09fa5357
Reviewed-on: https://gerrit.openafs.org/12782
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agorx: fix call refcount leak in error case 81/12781/2
Benjamin Kaduk [Tue, 28 Nov 2017 04:07:53 +0000]
rx: fix call refcount leak in error case

The recent event handling normalization in commit
304d758983b499dc568d6ca57b6e92df24b69de8 had event handlers switch
to dropping their reference on the associated connection/call just
before return.  An early return case was missed in the conversion,
leading to a refcount leak in an error case.

Change-Id: Ie3d0bc9474fdbc09be9c753f4d0192c8cca68351
Reviewed-on: https://gerrit.openafs.org/12781
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoafs: fix kernel_write / kernel_read arguments 69/12769/3
Marcio Barbosa [Thu, 16 Nov 2017 22:24:03 +0000]
afs: fix kernel_write / kernel_read arguments

The order / content of the arguments passed to kernel_write and
kernel_read are not right. As a result, the kernel will panic if one of
the functions in question is called.

[kaduk@mit.edu: include configure check for multiple kernel_read()
variants, per linux commits bdd1d2d3d251c65b74ac4493e08db18971c09240
and e13ec939e96b13e664bb6cee361cc976a0ee621a]

FIXES 134440

Change-Id: I4753dee61f1b986bbe6a12b5568d1a8db30c65f8
Reviewed-on: https://gerrit.openafs.org/12769
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agotests: fix out of bounds access in the rx-event test 62/12762/3
Michael Meffie [Mon, 6 Nov 2017 22:37:46 +0000]
tests: fix out of bounds access in the rx-event test

Use the NUMEVENTS symbol which defines the array size instead of an
incorrect hard coded number when checking if a second event can be added
to be fired at the same time.  This fixes a potential out of bounds
access of the event test array.

Also update the comment which incorrectly mentions the incorrect number
of events in the test.

Change-Id: I4f993b42e53e7e6a42fa31302fd1baa70e9f5041
Reviewed-on: https://gerrit.openafs.org/12762
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoSprinkle rx_GetConnection() for concision 72/12772/2
Benjamin Kaduk [Thu, 16 Nov 2017 10:49:49 +0000]
Sprinkle rx_GetConnection() for concision

Instead of inlining the body (taking the lock, incrementing the
refcount, and dropping the lock), use the convenience function
designed for this purpose.

Change-Id: I674d389e61e42710ef340e202992748e66c5e763
Reviewed-on: https://gerrit.openafs.org/12772
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agorx: fix mutex leak in error case 71/12771/2
Benjamin Kaduk [Thu, 16 Nov 2017 10:48:02 +0000]
rx: fix mutex leak in error case

Reported by Mark Vitale

Change-Id: I3269fbb0f87285bcb9af64f4ad81791177582e6d
Reviewed-on: https://gerrit.openafs.org/12771
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoAdd event-related mutex assertions 57/12757/5
Benjamin Kaduk [Wed, 1 Nov 2017 00:49:09 +0000]
Add event-related mutex assertions

In utility functions that access fields of type struct rxevent *,
assert that the appropriate lock is held for the access in question.

These assertions are only compiled in when built with -DOPR_DEBUG_LOCKS,
which can be enbled by --debug-locks at configure time.

Change-Id: I16885a4d37a0f094f0d365c54e8157ed92070c69
Reviewed-on: https://gerrit.openafs.org/12757
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoStandardize rx_event usage 56/12756/7
Benjamin Kaduk [Sun, 8 Oct 2017 03:42:38 +0000]
Standardize rx_event usage

Go over all consumers of the rx event framework and normalize its usage
according to the following principles:

rxevent_Post() is used to create an event, and it returns an event
handle (with a reference on the event structure) that can be used
to cancel the event before its timeout fires.  (There is also an
additional reference on the event held by the global event tree.)
In all(*) usage within the tree, that event handle is stored within
either an rx_connection or an rx_call.  Reads/writes to the member variable
that holds the event handle require either the conn_data_lock or call
lock, respectively -- that means that in most cases, callers of
rxevent_Post() and rxevent_Cancel() will be holding one of those
aforementioned locks.  The event handlers themselves will need to
modify the call/connection object according to the nature of the
event, which requires holding those same locks, and also a guarantee
that the call/connection is still a live object and has not been
deallocated!  Whether or not rxevent_Cancel() succeeds in cancelling
the event before it fires, whenever passed a non-NULL event structure
it will NULL out the supplied pointer and drop a reference on the
event structure.  This is the correct behavior, since the caller
has asked to cancel the event and has no further use for the event
handle or its reference on the event structure.  The caller of
rxevent_Cancel() must check its return value to know whether or
not the event was cancelled before its handler was able to run.

The interaction window between the call/connection lock and the lock
protecting the red/black tree of pending events opens up a somewhat
problematic race window.  Because the application thread is expected
to hold the call/connection lock around rxevent_Cancel() (to protect
the write to the field in the call/connection structure that holds
an event handle), and rxevent_Cancel() must take the lock protecting
the red/black tree of events, this establishes a lock order with the
call/connection lock taken before the eventTree lock.  This is in
conflict with the event handler thread, which must take the eventTree
lock first, in order to select an event to run (and thus know what
additional lock would need to be taken, by virtue of what handler
function is to be run).  The conflict is easy to resolve in the
standard way, by having a local pointer to the event that is obtained
while the event is removed from the red/black tree under the eventTree
lock, and then the eventTree lock can be dropped and the event run
based on the local variable referring to it.  The race window occurs
when the caller of rxevent_Cancel() holds the call/connection lock,
and rxevent_Cancel() obtains the eventTree lock just after the event
handler thread drops it in order to run the event.  The event handler
function begins to execute, and immediately blocks trying to obtain
the call/connection lock.  Now that rxevent_Cancel() has the eventTree
lock it can proceed to search the tree, fail to find the indicated event
in the tree, clear out the event pointer from the call/connection
data structure, drop its caller's reference to the event structure,
and return failure (the event was not cancelled).  Only then does the
caller of rxevent_Cancel() drop the call/connection lock and allow
the event handler to make progress.

This race is not necessarily problematic if appropriate care is taken,
but in the previous code such was not the case.  In particular, it
is a common idiom for the firing event to call rxevent_Put() on itself,
to release the handle stored in the call/connection that could have
been used to cancel the event before it fired.  Failing to do so would
result in a memory leak of event structures; however, rxevent_Put() does
not check for a NULL argument, so a segfault (NULL dereference) was
observed in the test suite when the race occurred and the event handler
tried to rxevent_Put() the reference that had already been released by
the unsuccessful rxevent_Cancel() call.  Upon inspection, many (but not
all) of the uses in rx.c were susceptible to a similar race condition
and crash.

The test suite also papers over a related issue in that the event handler
in the test suite always knows that the data structure containing the
event handle will remain live, since it is a global array that is allocated
for the entire scope of the test.  In rx.c, events are associated with
calls and connections that have a finite lifetime, so we need to take care
to ensure that the call/connection pointer stored in the event remains
valid for the duration of the event's lifecycle.  In particular, even an
attempt to take the call/connection lock to check whether the corresponding
event field is NULL is fraught with risk, as it could crash if the lock
(and containing call/connection) has already been destroyed!  There are
several potential ways to ensure the liveness of the associated
call/connection while the event handler runs, most notably to take care
in the call/connection destruction path to ensure that all associated
events are either successfully cancelled or run to completion before
tearing down the call/connection structure, and to give the pending event
its own reference on the associated call/connection.  Here, we opt for
the latter, acknowledging that this may result in the event handler thread
doing the full call/connection teardown and delay the firing of subsequent
events.  This is deemed acceptable, as pending events are for intentionally
delayed tasks, and some extra delay is probably acceptable.  (The various
keepalive events and the challenge event could delay the user experience
and/or security properties if significantly delayed, but I do not believe
that this change admits completely unbounded delay in the event handler
thread, so the practical risk seems minimal.)

Accordingly, this commit attempts to ensure that:

* Each event holds a formal reference on its associated call/connection.
* The appropriate lock is held for all accesses to event pointers in
  call/connection structures.
* Each event handler (after taking the appropriate lock) checks whether
  it raced with rxevent_Cancel() and only drops the call/connection's
  reference to the event if the race did not occur.
* Each event handler drops its reference to the associated call/connection
  *after* doing any actions that might access/modify the call/connection.
* The per-event reference on the associated call/connection is dropped by
  the thread that removes the event from the red/black tree.  That is,
  the event handler function if the event runs, or by the caller of
  rxevent_Cancel() when the cancellation succeed.
* No non-NULL event handles remain in a call/connection being destroyed,
  which would indicate a refcounting error.

(*) There is an additional event used in practice, to reap old connections,
    but it is effectively a background task that reschedules itself
    periodically, with no handle to the event retained so as to be able
    to cancel it.  As such, it is unaffected by the concerns raised here.

While here, standardize on the rx_GetConnection() function for incrementing
the reference count on a connection object, instead of inlining the
corresponding mutex lock/unlock and variable access.

Also enable refcount checking unconditionally on unix, as this is a
rather invasive change late in the 1.8.0 release process and we want
to get as much sanity checking coverage as possible.

Change-Id: I27bcb932ec200ff20364fb1b83ea811221f9871c
Reviewed-on: https://gerrit.openafs.org/12756
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoAdjust rx-event test to exercise cancel/fire race 55/12755/2
Benjamin Kaduk [Thu, 5 Oct 2017 04:03:44 +0000]
Adjust rx-event test to exercise cancel/fire race

We currently do not properly handle the case where a thread runs
rxevent_Cancel() in parallel with the event-handler thread attempting
to fire that event, but the test suite only picked up on this issue
in a handful of the Debian automated builds (somewhat less-resourced
ones, perhaps).

Modify the event scheduling algorithm in the test so as to create a
larger chunk of events scheduled to fire "right away" and thereby
exercise the race condition more often when we proceed to cancel
a quarter of events "right away".

Change-Id: I50f55fd532901147cfda1a5f40ef949bf3270401
Reviewed-on: https://gerrit.openafs.org/12755
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agogtx: link against libtinfo if termlib is seperated 60/12760/4
Michael Laß [Thu, 2 Nov 2017 20:16:49 +0000]
gtx: link against libtinfo if termlib is seperated

If ncurses is built with "./configure --with-termlib=tinfo", gtx fails
to link because of an undefined reference to the LINES symbol which is
then provided by libtinfo.so and not libncurses.so.

If ncurses is present, additionally check whether LINES is provided by
ncurses or tinfo and set $LIB_curses accordingly.

This change is based on a patch provided by Bastian Beischer.

FIXES 134420

Change-Id: I3e29c61405d90d0b850bafe4c51125bef433452b
Reviewed-on: https://gerrit.openafs.org/12760
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoCorrect m4 conditionals in curses.m4 38/12738/2
Benjamin Kaduk [Mon, 16 Oct 2017 21:53:22 +0000]
Correct m4 conditionals in curses.m4

AS_IF does not invoke the test(1) shell builtin for us, so we must
take care to consistently use it ourself.

While here, sprinkle some missing double-quotes around variable
expansions in AS_IF statements in this file.

Submitted by Bastian Beischer.

FIXES 134414

Change-Id: Iccfe311011f17de6317cf64abdc58b0812b81b8c
Reviewed-on: https://gerrit.openafs.org/12738
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux: Use kernel_read/kernel_write when __vfs variants are unavailable 29/12729/3
Damien Diederen [Mon, 18 Sep 2017 10:18:39 +0000]
Linux: Use kernel_read/kernel_write when __vfs variants are unavailable

We hide the uses of set_fs/get_fs behind a macro, as those functions
are likely to soon become unavailable:

> Christoph Hellwig suggested removing all calls outside of the core
> filesystem and architecture code; Andy Lutomirski went one step
> further and said they should all go.

    https://lwn.net/Articles/722267/

Change-Id: Ib668f8fdb62ca01fe14321c07bd14d218744d909
Reviewed-on: https://gerrit.openafs.org/12729
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: avoid rpmbuild exclude directives 33/12733/2
Michael Meffie [Sat, 22 Jul 2017 02:30:43 +0000]
redhat: avoid rpmbuild exclude directives

Older versions of rpmbuild do not support the files exclude directive,
so fall back to the old way in which we remove the files to be excluded
and list the files to be included.

Change-Id: If64df382ef372aa1078f1703a34942a1930bdc88
Reviewed-on: https://gerrit.openafs.org/12733
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: move .krb variants to the kauth-client subpackage 32/12732/2
Michael Meffie [Sat, 22 Jul 2017 02:16:44 +0000]
redhat: move .krb variants to the kauth-client subpackage

Move the deprecated klog.krb, pagsh.krb, and tokens.krb programs and man
pages to the optional openafs-kauth-client subpackage.

Change-Id: I09a2e36b60f9d47726a6a314a26db88e44575567
Reviewed-on: https://gerrit.openafs.org/12732
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: specify man pages without wildcards 31/12731/2
Michael Meffie [Thu, 20 Jul 2017 08:13:04 +0000]
redhat: specify man pages without wildcards

Currently, some of the man pages are specified with the full name and
some are specified with a wildcard for the filename extension. Instead,
specify all the man pages without a wildcards to be more consistent and
to avoid putting incorrect man pages in packages.

This change removes a stray copy the klog.krb5.1 man page from
openafs-kauth-client subpackage and moves the AuthLog/AuthLog.dir man
pages to the optional openafs-kauth-server subpackage.

Change-Id: Id30a6174c532a9a00f850d6ca2722158293d5118
Reviewed-on: https://gerrit.openafs.org/12731
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: remove afsd.fuse man page 30/12730/2
Michael Meffie [Fri, 21 Jul 2017 22:05:48 +0000]
redhat: remove afsd.fuse man page

The afsd.fuse binary is not currently packaged; do not package the man
page.

Change-Id: Ia0dd4fa72dc8a87e2c835798b6fbe1213d71da5f
Reviewed-on: https://gerrit.openafs.org/12730
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoubik: avoid DISK_Begin on sites that didn't vote for sync 15/12715/3
Marcio Barbosa [Mon, 21 Aug 2017 18:21:54 +0000]
ubik: avoid DISK_Begin on sites that didn't vote for sync

As already described on 7c708506, SDISK_Begin fails on remotes if
lastYesState is not set. To fix this problem, 7c708506 does not allow
write transactions until we know that lastYesState is set on at least
quorum (ubik_syncSiteAdvertised == 1). In other words, if enough sites
received a beacon packet informing that a sync-site was elected, write
transactions will be allowed. This means that ubik_syncSiteAdvertised
can be true while lastYesState is not set in a few sites.

Consider the following scenario in a cell with frequent write
transactions:

Site A => Sync-site (up)
Site B => Remote 1 (up)
Site C => Remote 2 (down - unreachable)

Since A and B are up, we have quorum. After the second wave of beacons,
ubik_syncSiteAdvertised will be true and write transactions will be
allowed. At some point, C is not unreachable anymore. Site A sends a
copy of its database to C, but C did not vote for A yet (lastYesState ==
0). A new write transaction is initialized and, since lastYesState is
not set on C, DISK_Begin fails on this remote site and C is marked as
down. Since C is reachable, A will mark this remote site as up. The
sync-site will send its database to C, but C did not vote for A yet. A
new write transaction is initialized and, since lastYesState is not set
on C, DISK_Begin fails on this remote site and C is marked as down. In a
cell with frequent write transactions, this cycle will repeat forever.
As a result, the sync-site will be constantly sending its database to C
and quorum will be operating with less sites, increasing the chances
of re-elections.

To fix this problem, do not call DISK_Begin on remotes that did not
vote for the sync-site yet.

Change-Id: I27f5122a089064e7b83beba3533261d8a4e31c64
Reviewed-on: https://gerrit.openafs.org/12715
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux: Test for __vfs_write rather than __vfs_read 28/12728/3
Damien Diederen [Mon, 18 Sep 2017 09:59:40 +0000]
Linux: Test for __vfs_write rather than __vfs_read

The following commit:

    commit eb031849d52e61d24ba54e9d27553189ff328174
    Author: Christoph Hellwig <hch@lst.de>
    Date:   Fri Sep 1 17:39:23 2017 +0200

        fs: unexport __vfs_read/__vfs_write

unexports both __vfs_read and __vfs_write, but keeps the former in
fs.h--as it is is still being used by another part of the tree.

This situation results in a false positive in our Autoconf check,
which does not see the export statements, and ends up marking the
corresponding API as available.

That, in turn, causes some code which assumes symmetry with
__vfs_write to fail to compile.

Switch to testing for __vfs_write, which correctly marks the API as
unavailable.

Change-Id: I392f2b17b4de7bd81d549c84e6f7b5ef05e1b999
Reviewed-on: https://gerrit.openafs.org/12728
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agovol: Fix two buffers being one char too short 22/12722/2
Anders Kaseorg [Sat, 2 Sep 2017 03:37:07 +0000]
vol: Fix two buffers being one char too short

Fixes these warnings:

namei_ops.c: In function 'namei_copy_on_write':
namei_ops.c:1328:31: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
  snprintf(path, sizeof(path), "%s-tmp", name.n_path);
                               ^~~~~~~~
namei_ops.c:1328:2: note: 'snprintf' output between 5 and 260 bytes into a destination of size 259
  snprintf(path, sizeof(path), "%s-tmp", name.n_path);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vol_split.c: In function 'split_volume':
vol_split.c:576:22: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
     sprintf(symlink, "#%s", V_name(newvol));
                      ^~~~~
vol_split.c:576:5: note: 'sprintf' output between 2 and 33 bytes into a destination of size 32
     sprintf(symlink, "#%s", V_name(newvol));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: If212ebc29fa3fe10fe1e2f70dfb5f7509c269ae9
Reviewed-on: https://gerrit.openafs.org/12722
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLinux: Include linux/uaccess.h rather than asm/uaccess.h if present 14/12714/3
Seth Forshee [Tue, 22 Aug 2017 12:59:11 +0000]
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>

6 years agoredhat: move bosserver and fssync-debug man pages 01/12601/3 BP-openafs-stable-1_8_x
Michael Meffie [Sat, 15 Apr 2017 00:38:27 +0000]
redhat: move bosserver and fssync-debug man pages

Move the bosserver and fssync-debug/dafssync-debug man pages to the
openafs-server package, which distributes those programs.

Change-Id: I9c84ad485834177fd43b28acd444d3d54c648cc8
Reviewed-on: https://gerrit.openafs.org/12601
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: kauth client and server sub-packages 00/12600/3
Michael Meffie [Fri, 14 Apr 2017 01:48:06 +0000]
redhat: kauth client and server sub-packages

Move the kaserver and kauth client programs to conditionally built
packages called openafs-kauth-server and openafs-kauth-client.
Packagers can build these by specifying '--with kauth'. They are not
built by default to discourage use.

This commit subsumes the openafs-kpasswd package into the
openafs-kauth-client package.

Change-Id: I1322f05d7fe11d466c9ed71a5059c21b759d95ab
Reviewed-on: https://gerrit.openafs.org/12600
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: do not package kauth by default 97/12597/4
Michael Meffie [Mon, 10 Apr 2017 19:06:02 +0000]
redhat: do not package kauth by default

Do not package kaserver and related programs by default to discourage
use. Add the '--with kauth' rpmbuild option to allow packagers to
continue include the kauth programs for compatibility.

Change-Id: I8bf9f6dc221afc22ed6c9a33cf101d705e6c4920
Reviewed-on: https://gerrit.openafs.org/12597
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoDefault to crypt mode for unix clients 68/12668/3
Benjamin Kaduk [Mon, 31 Jul 2017 01:57:05 +0000]
Default to crypt mode for unix clients

Though the protection offered by rxkad, even with rxkad-k5 and rxkad-kdf, is
insufficient to protect traffic from a determined attacker, it remains the
case that the internet is not a safe place for user data to travel in the
clear, and has not been for a long time.  The Windows client encrypts by
default, and all or nearly all the Unix client packaging scripts set crypt
mode by default.  Catch up to reality and default to crypt mode in the
Unix cache manager.

Change-Id: If0061ddca3bedf0df1ade8cb61ccb710ec1181d4
Reviewed-on: https://gerrit.openafs.org/12668
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoubik: remove useless signal call 73/12673/3
Marcio Barbosa [Mon, 31 Jul 2017 19:27:10 +0000]
ubik: remove useless signal call

The current version does not have a corresponding LWP_WaitProcess call
for the beacon_globals.ubik_amSyncSite global. As a result, the
LWP_NoYieldSignal(&beacon_globals.ubik_amSyncSite) signal call can be
safely removed.

Change-Id: I72c4ccfe8e68551673dc728dd699ba8c561d76d1
Reviewed-on: https://gerrit.openafs.org/12673
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agodoc: add a document to describe rx debug packets 77/12677/2
Michael Meffie [Wed, 2 Aug 2017 19:25:45 +0000]
doc: add a document to describe rx debug packets

This document gives a basic description of Rx debug packets, the
protocol to exchange debug packets, and the version history.

Change-Id: Ic040d336c1e463f7da145f1a292c20c5d5f215df
Reviewed-on: https://gerrit.openafs.org/12677
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agodoc: add kolya's rx-spec to doc/txt 76/12676/3
Michael Meffie [Wed, 2 Aug 2017 00:36:18 +0000]
doc: add kolya's rx-spec to doc/txt

Add rx protocol spec and rx debug spec written by Nickolia Zeldovich.

Rx protocol specification draft (2002)
Nickolai Zeldovich, kolya@MIT.EDU

Change-Id: I65a9a83a8889503f3a82c8fde7a87f84d2736c8d
Reviewed-on: https://gerrit.openafs.org/12676
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agodoc: relocate notes from arch to txt 75/12675/2
Michael Meffie [Wed, 2 Aug 2017 00:10:32 +0000]
doc: relocate notes from arch to txt

The doc/txt directory has become the de facto home for text-based
technical notes. Relocate the contents of the doc/arch directory to
doc/txt. Relocate doc/examples to doc/txt/examples.

Update the doc/README file to be more current and remove old work in
progress comments.

Change-Id: Iaa53e77eb1f7019d22af8380fa147305ac79d055
Reviewed-on: https://gerrit.openafs.org/12675
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoAdd NEWS entry for recent ubik changes 79/12679/2
Benjamin Kaduk [Wed, 2 Aug 2017 01:50:37 +0000]
Add NEWS entry for recent ubik changes

Of the ubik-fix-write-after-recovery topic, this seems like the most
noteworthy portion, with the other bits wrapped up in the preface.

Change-Id: Icc1afb9f851ef2d7ade49c2382cc023997f1bf26
Reviewed-on: https://gerrit.openafs.org/12679
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoubik: update epoch as soon as sync-site is elected 09/12609/8
Marcio Barbosa [Fri, 21 Jul 2017 03:02:15 +0000]
ubik: update epoch as soon as sync-site is elected

The ubik_epochTime represents the time at which the coordinator first
received its coordinator mandate. However, this global is currently not
updated at the moment when a new sync-site is elected. Instead,
ubik_epochTime is only updated at the very end of the first write
transaction, when a new database label is written (in udisk_commit).
This causes at least 2 different issues:

For one, this means that we change ubik_epochTime while a remote
transaction is in progress. If VOTE_Beacon is called after
ubik_epochTime is updated, but before the remote transaction ends, the
remote sites will detect that the transaction id in ubik_currentTrans is
wrong (via urecovery_CheckTid(), since the epoch doesn't match), and
they will abort the transaction. This means the transaction will fail,
and it may cause a loss of quorum until another election is completed.

Another issue is that ubik_epochTime can be 0 at the beginning of a
write transaction, if this is the first election that this site has won.
Since ubik_epochTime is used to construct transaction ids, this means
that we can have different transactions that originate from different
sites at different times, but they have the same epoch in their tid.
For example, say a write transaction starts with epoch 0, but the
originating site is killed/interrupted before finishing. That write
transaction will linger on remote sites in ubik_currentTrans with an
epoch of 0 (since the originating site will never call
DISK_ReleaseLocks, or DISK_Abort, etc). Normally the sync site will kill
such a lingering transaction via urecovery_CheckTid, but since the epoch
is 0, and the election winner's epoch is also 0, the transaction looks
valid and may never be killed. If that transaction is holding a lock on
the database, this means that the database will forever remain locked,
effectively preventing any access to the db on that site.

To fix both of these issues, update ubik_epochTime with the current
time as soon as we win the election. This ensures that the epoch is not
updated in the middle of a transaction, and it ensures that all
transactions are created with a unique epoch: the epoch of the election
that we won.

Note that with this commit, we do not ever set ubik_epochTime to the
magic value of '2' during database init. The special '2' epoch only
needs to be set in the database itself, and it is never an actual epoch
that represents a real quorum that went through the election process.
The database will be labelled with a 'real' epoch after the first write,
like normal.

[kaduk@mit.edu: comment the locking strategy in ubeacon_Interact()]

Change-Id: I6cdcf5a73c1ea564622bfc8ab7024d9901af4bc8
Reviewed-on: https://gerrit.openafs.org/12609
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLINUX: afs_create infinite fetchStatus loop 51/12651/5
Joe Gorse [Thu, 6 Jul 2017 19:47:24 +0000]
LINUX: afs_create infinite fetchStatus loop

For a file in a directory with the CStatd bit cleared, we can get
an infinite fetchStatus loop.

In afs_create(), afs_getDCache() may return NULL due to an error.
If unchecked it will loop which may produce multiple fetchStatus()
calls to the fileserver.

Credit: Yadav Yadavendra for identifying and analysing this issue.

Change-Id: Iecd77d49a5f3e8bb629396c57246736b39aa935f
Reviewed-on: https://gerrit.openafs.org/12651
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoUpdate NEWS for volume stats default change 78/12678/2
Benjamin Kaduk [Thu, 3 Aug 2017 00:31:17 +0000]
Update NEWS for volume stats default change

Change-Id: I1a184bf638609866f6f7f1d11c224dfee1113eef
Reviewed-on: https://gerrit.openafs.org/12678
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agovolser: preserve volume stats by default 74/12674/4
Michael Meffie [Tue, 1 Aug 2017 21:21:13 +0000]
volser: preserve volume stats by default

Commit dfceff1d3a66e76246537738720f411330808d64 added the
-preserve-vol-stats flag to the volume server. This enabled a change in
the volume server to preserve volume usage statistics during reclone and
restore operations. Otherwise, volume usage counters of read-only
volumes are cleared when volumes are released, making it difficult to
track usage with the volume stats.

Make this feature the default behavior of the volume server and provide
the option -clear-vol-stats to use the old behavior if so desired.  This
change makes the -preserve-vol-stats the default, and keeps it as a
hidden flag for sites which may already have that flag set in the
BosConfig.

Since this changes a default behavior of the volume server, this change
is only appropriate on a major or minor release boundary, not in the
middle of a stable series.

Change-Id: I3706ede64b7b18a80b39ebd55f2e1824bb7dbc57
Reviewed-on: https://gerrit.openafs.org/12674
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoubik: avoid early DISK_Begin calls we know will fail 92/12592/3
Marcio Barbosa [Mon, 22 May 2017 16:55:32 +0000]
ubik: avoid early DISK_Begin calls we know will fail

Currently, we can start a write transaction on a site immediately after
it is elected as the sync site. However, after commit d47beca1,
SDISK_Begin on remote sites will fail right after an election occurs
(since lastYesState is not set, and so urecovery_AllBetter will fail).
And after commit fac0b742, this error is always noticed and propagated
back to the application.

As a result, when we try to write immediately after a sync site is
elected, the transaction will fail with UNOQUORUM, the remote sites will
be marked as down, and we may lose quorum and require another election
to be performed. This can easily happen repeatedly for a site that
frequently tries to make changes to a ubik database.

To avoid marking other sites down and going through another election
process, do not allow write transactions until we know that lastYesState
is set on the remote sites. We do this by waiting until the next wave of
beacons are sent, which tell the remote sites that we are the sync site.
In other words, only allow write transactions after the sync site knows
that the remote sites also know that the sync site has been elected.

With this commit, a write transaction immediately after an election
will still fail with UNOQUORUM, but we avoid triggering an error on the
remote sites, and avoid losing quorum in this situation.

Change-Id: I9e1a76b4022e6d734af1165d94c12e90af04974d
Reviewed-on: https://gerrit.openafs.org/12592
Reviewed-by: Andrew Deason <adeason@dson.org>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoubik: allow remote dbase relabel if up to date 13/12613/4
Marcio Barbosa [Wed, 21 Jun 2017 20:42:37 +0000]
ubik: allow remote dbase relabel if up to date

When a site is elected the sync-site, its database is not immediately
relabeled. The database in question will be relabeled at the end of the
first write transaction (in udisk_commit). To do so, the dbase->version
is updated on the sync-site first (1) and then the versions of the
remote sites are updated through SDISK_SetVersion() (2).

In order to make sure that the remote site holds the same database as
the sync-site, the SDISK_SetVersion() function checks if the current
version held by the remote site (ubik_dbVersion) is equal to the
original version stored by the sync-site (oldversionp). If
ubik_dbVersion is not equal to oldversionp, SDISK_SetVersion() will
fail with USYNC.

However, ubik_dbVersion can be updated by the vote thread at any time.
That is, if the sync site calls VOTE_Beacon() on the remote site between
events (1) and (2), the remote site will set ubik_dbVersion to the new
version, while ubik_dbase->version is still set to the old version. As
a result, ubik_dbVersion will not be equal to oldversionp and
SDISK_SetVersion() will fail with USYNC. This failure may cause a loss
of quorum until another election is completed.

To fix this problem, let SDISK_SetVersion() relabel the database when
ubik_dbase->version is equal to oldversionp. In order to try to only
affect the scenario described above, also check if ubik_dbVersion is
equal to newversionp.

Change-Id: I97e6f8cacd1c9bca0b4c72374c058c5fe5b638b3
Reviewed-on: https://gerrit.openafs.org/12613
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoafs: fix repeated BulkStatus calls for directories. 10/12610/7
Joe Gorse [Wed, 10 May 2017 15:38:25 +0000]
afs: fix repeated BulkStatus calls for directories.

There is a filetype comparison check in afs_DoBulkStat just after
BulkFetch RPC. This check will fail for directories even though
bulkStatus was done for directories.

This code is apparently necessary for Darwin, but it causes this problem
otherwise. Thus it is removed from the rest of the builds using the
AFS_DARWIN_ENV preprocessor variable.

Credit: Yadav Yadavendra for identifying and analysing this issue.

Change-Id: I9645f0e7a3327cb5f20cdf3ba2bf1cc5b1509bb5
Reviewed-on: https://gerrit.openafs.org/12610
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agorelocate old afs docs to doc/txt 62/12662/2
Michael Meffie [Thu, 20 Jul 2017 04:12:05 +0000]
relocate old afs docs to doc/txt

Move the afs/DOC files to the top-leve doc/txt directory, since this has
become the home for developer oriented documentation.

Change-Id: I128d338c69534b4ee6043105a7cfd390b280afe3
Reviewed-on: https://gerrit.openafs.org/12662
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoIncorporate old release notes into NEWS 61/12661/3
Michael Meffie [Thu, 20 Jul 2017 03:48:42 +0000]
Incorporate old release notes into NEWS

Cleanup the doc/txt directory by incorporating the old release
notes into the NEWS file.

Change-Id: I63911fc5cb0b476e201148c6d3fa3441f4746ab7
Reviewed-on: https://gerrit.openafs.org/12661
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoUpdate NEWS for 1.8.0pre2 60/12660/2
Michael Meffie [Thu, 20 Jul 2017 02:39:51 +0000]
Update NEWS for 1.8.0pre2

Change-Id: I5f83e81f25177bde1ea691e756359563e80ee3f2
Reviewed-on: https://gerrit.openafs.org/12660
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoImport NEWS from openafs-stable-1_6_x 59/12659/2
Michael Meffie [Thu, 20 Jul 2017 03:09:01 +0000]
Import NEWS from openafs-stable-1_6_x

Import change descriptions for 1.6.20.1, 1.6.20.2, 1.6.21.

Change-Id: Ib4f06c7046eb6e1bb0a1ccfb9f6c45191154fe0e
Reviewed-on: https://gerrit.openafs.org/12659
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux: fix whitespace in osi_sysctl.c 65/12665/3
Stephan Wiesand [Wed, 26 Jul 2017 13:18:08 +0000]
Linux: fix whitespace in osi_sysctl.c

Remove dozens of trailing spaces and make consistent use of tabs
for indentation throughout the file.

Change-Id: Ibbd17d2b9828590ffd84b76aac70646e9fe9cb2c
Reviewed-on: https://gerrit.openafs.org/12665
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: Workaround d_splice_alias/d_lookup race 38/12638/3
Andrew Deason [Thu, 15 Jun 2017 20:32:41 +0000]
LINUX: Workaround d_splice_alias/d_lookup race

Before Linux kernel commit 4919c5e45a91b5db5a41695fe0357fbdff0d5767,
d_splice_alias in some cases can d_rehash the given dentry without
attaching it to the given inode, right before the dentry is unhashed
again. This means that for a few moments, that negative dentry is
visible to __d_lookup, and thus is visible to path lookup and can be
given to afs_linux_dentry_revalidate.

Currently, afs_linux_dentry_revalidate will say that the dentry is
valid, because d_time and other fields are set; it's just not attached
to an inode. This causes an ENOENT error on lookup, even though the
file is there (and no OpenAFS code said otherwise).

Normally this race is rare, but it can be frequently exercised if
we access the same directory via different names at the same time.
This can happen with multiple mountpoints to the same volume, or by
accessing an @sys directory via its abbreviated and expanded forms.

To get around this, make afs_linux_dentry_revalidate check negative
'dentry's to see if they are unhashed. We also lock the parent inode,
in order to guarantee that a problematic d_splice_alias call isn't
running at the same time (and thus, we know the dentry will not be
unhashed immediately afterwards). This slows down
afs_linux_dentry_revalidate for valid negative 'dentry's a little, but
it allows us to use negative dentry's at all.

Linux kernel commit 4919c5e45a91b5db5a41695fe0357fbdff0d5767 fixes
this issue, which was included in 2.6.34, so don't do this workaround
for 2.6.34 and on.

Change-Id: I8e58ebed4441151832054b1ef3f1aa5af1c4a9b5
Reviewed-on: https://gerrit.openafs.org/12638
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLinux 4.13: use designated initializers where required 63/12663/4
Stephan Wiesand [Mon, 24 Jul 2017 09:37:54 +0000]
Linux 4.13: use designated initializers where required

struct path is declared with the "designated_init" attribute,
and module builds now use -Werror=designated-init. Cope.

And as pointed out by Michael Meffie, struct ctl_table has
the same requirement now, so use a designated initializer
for the final element of the sysctl table too.

Change-Id: I0ec45aac961dcefa0856a15ee218085626a357c7
Reviewed-on: https://gerrit.openafs.org/12663
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoafs: fix afs_xserver deadlock in afsdb refresh 52/12652/3
Michael Meffie [Fri, 7 Jul 2017 15:11:12 +0000]
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>

6 years agoafs: restore force_if_down check when getting connections 53/12653/3
Michael Meffie [Tue, 11 Jul 2017 12:51:08 +0000]
afs: restore force_if_down check when getting connections

Commit cb9e029255420608308127b0609179a46d9983ad removed the
force_if_down check in afs_ConnBySA, which effictively turned on
force_if_down flag for every call to afs_ConnBySA. This caused
afs_ConnBySA to always return connections, even for server addresses
marked down and force_if_down set to 0.

One serious consequence of this bug is the cache manager will retry the
preferred vlserver indefinitely when it is unreachable. This is because
the loop in afs_ConnMHosts always tries hosts in preferred order and
expects afs_ConnBySA to return a NULL if the server address has no
connections because it is marked down.

Restore the check for server addresses marked down to honor the
force_if_down flag again so we do not get connections for down servers
unless requested.

Change-Id: Ia117354929a62b0cedc218040649e9e0b8d8ed23
Reviewed-on: https://gerrit.openafs.org/12653
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: fix rpmbuild command line option defaults 96/12596/4
Michael Meffie [Mon, 10 Apr 2017 18:23:12 +0000]
redhat: fix rpmbuild command line option defaults

Fix the handling of default values for the various rpmbuild options
which can be given. These have been broken as code was shuffled around
over the years.

Remove obsolete comments about detecting what to build based on the
architecture.

Provide the '--without authlibs' option to disable the openafs-authlibs
package.

Change-Id: I6c8db1f3163ee241f9a4d1282345a0ddeabd284c
Reviewed-on: https://gerrit.openafs.org/12596
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agomkvers: fix potential buffer overflow 57/12657/2
Christof Hanke [Tue, 18 Jul 2017 10:04:11 +0000]
mkvers: fix potential buffer overflow

The space allocated for outputFileBuf is only 2 bytes larger than
sizeof(VERS_FILE). But we add potentially 4 extra bytes like
".txt" or ".xml". Just allocate enough space for all file suffices.

Change-Id: Ic0f97590be208deaf9c4a5c25e21056ea9d2cd6f
Reviewed-on: https://gerrit.openafs.org/12657
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoafs_linux_lookup: Avoid d_add on afs_lookup error 37/12637/5
Andrew Deason [Thu, 15 Jun 2017 20:29:17 +0000]
afs_linux_lookup: Avoid d_add on afs_lookup error

Currently, afs_linux_lookup looks roughly like this pseudocode:

{
    code = afs_lookup(&vcp);
    if (!code) {
        ip = AFSTOV(vcp);
        error = process_ip(ip);
        if (error) {
            goto done;
        }
    }
    process_dp(dp);
    newdp = d_splice_alias(ip, dp);
 done:
    cleanup();
}

Note that if there is an error while processing the looked-up inode
(ip), we jump over d_splice_alias. But if we encounter an error from
afs_lookup itself, we do not jump over d_splice_alias. This means that
if afs_lookup encounters any error, we initialize the given dentry
(dp) as a negative entry, effectively telling the Linux kernel that
the requested name does not exist.

This is correct for ENOENT errors, of course, but is incorrect for any
other error. For non-ENOENT errors we later return an error from the
function, but this does not invalidate the generated dentry. The
result is that when afs_lookup encounters an error, that error will be
propagated to userspace, but subsequent lookups for the same name will
yield an ENOENT error (until the dentry is invalidated). This can
easily cause a file to seem to mysteriously disappear, if a transient
error like network problems caused the afs_lookup call to fail.

To fix this, treat ENOENT as a non-error, like the comments already
suggest. In our case, ENOENT is not really an error; it just means we
populate the given dentry differently. So if we get ENOENT from
afs_lookup, set our vcache to NULL and clear the error, and continue.

This also has the side effect of not treating ENOENT errors from
afs_CreateAttr identically to ENOENT errors from afs_lookup. That
shouldn't happen, but there have been abuses of the ENOENT error code
in the past, so it is probably better to be cautious.

Many thanks to Gaja Sophie Peters for assistance in tracking down and
testing fixes for this issue, including providing access to test systems
experiencing the buggy behavior.

FIXES 133654

Change-Id: Ia9aab289d5c041557ab6b00f1d41de2edfc97a89
Reviewed-on: https://gerrit.openafs.org/12637
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Joe Gorse <jhgorse@gmail.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: Michael Meffie <mmeffie@sinenomine.net>

6 years agoLINUX: Rearrange afs_linux_lookup cleanup 36/12636/3
Andrew Deason [Thu, 15 Jun 2017 20:29:48 +0000]
LINUX: Rearrange afs_linux_lookup cleanup

Currently, the cleanup and error handling in afs_linux_lookup is
structured similar to this pseudocode:

    if (!code) {
        if (!IS_ERR(newdp)) {
            return no_error;
        } else {
            return newdp_error;
        }
    } else {
        return code_error;
    }

The multiple different nested error cases make this a little complex.
To make this easier to follow for subsequent changes, alter this
structure to be more like this:

    if (IS_ERR(newdp)) {
        return newdp_error;
    }

    if (code) {
        return code_error;
    }

    return no_error;

There should be no functional change in this commit; it is just code
reorganization.

Technically the ordering of these checks is changed, but there is no
combination of conditions that actually results in different code
being hit. That is, if 'code' is nonzero and IS_ERR(newdp) is true,
then we would go through a different path. But that cannot happen,
since if 'code' is nonzero, we have no inode and so IS_ERR(newdp)
cannot be true (d_splice_alias cannot return an error for a NULL
inode). So there is no functional change.

Change-Id: I94a3aef5239358c3d13fe5314044dcc85914d0a4
Reviewed-on: https://gerrit.openafs.org/12636
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Joe Gorse <jhgorse@gmail.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: Michael Meffie <mmeffie@sinenomine.net>

6 years agodoc: Add introduction and credits to ubik.txt 44/12644/4
Stephan Wiesand [Thu, 29 Jun 2017 14:57:42 +0000]
doc: Add introduction and credits to ubik.txt

Credit where it's due. And the remainder of the introduction may
provide some useful context too.

Change-Id: I99c7e599363126c581ae1ac00da67c33acc3687f
Reviewed-on: https://gerrit.openafs.org/12644
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoPut jhutz's ubik analysis in doc/txt 42/12642/2
Benjamin Kaduk [Sun, 25 Jun 2017 18:56:04 +0000]
Put jhutz's ubik analysis in doc/txt

A file in the source tree is much easier to locate than an old
mailing list post; it's quite handy to have this at hand as a
reference.

Change-Id: I5267a2f86b36e92b05249364085bdd33aeb28d1b
Reviewed-on: https://gerrit.openafs.org/12642
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoafs: Improve "Corrupt directory" warning 41/12641/2
Andrew Deason [Fri, 23 Jun 2017 22:20:11 +0000]
afs: Improve "Corrupt directory" warning

This warning is a bit confusing to see, since it doesn't say anything
about AFS (making it unclear where it's coming from), and it lacks a
trailing newline (making it ugly). Fix both of these.

Change-Id: I92a3d07fd193bf99b545aef9b21f52d23c356a2d
Reviewed-on: https://gerrit.openafs.org/12641
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agovol: modify volume updateDate upon salvage change 29/12629/2
Jeffrey Altman [Fri, 2 Jun 2017 02:25:49 +0000]
vol: modify volume updateDate upon salvage change

If the salvager changed the volume, set the VolumeDiskData.updateDate
field so that

  1. the change is visible via "vos examine"

  2. backup services will backup the corrected volume

Teradactyl pointed out the problem which forces cell administrators
to manually trigger a backup for each volume that has been salvaged.

Change-Id: I9a35b92e8abbe3b54b08e64ac13de44442736c72
Reviewed-on: https://gerrit.openafs.org/12629
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agobozo: do not fail silently on unknown bosserver options 30/12630/3
Michael Meffie [Fri, 2 Jun 2017 19:19:26 +0000]
bozo: do not fail silently on unknown bosserver options

Instead of failing silently when the bosserver is started with an
unknown option, print an error message and exit with a non-zero value.
Continue to exit with 0 when the -help option is given to request the
usage message.

This change should help make bosserver startup failures more obvious
when an unsupported option is specified. Example systemd status message:

   systemd[1]: Starting OpenAFS Server Service...
   bosserver[32308]: Unrecognized option: -bogus
   bosserver[32308]: Usage: bosserver [-noauth] ....
   systemd[1]: openafs-server.service: main process exited,
               code=exited, status=1/FAILURE

Change-Id: I8717fb4a788fbcc3d1e2d271dd03511c5b504f10
Reviewed-on: https://gerrit.openafs.org/12630
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agorx: wake up send after 'twind' has been updated 25/12625/2
Jeffrey Altman [Sat, 27 May 2017 18:59:04 +0000]
rx: wake up send after 'twind' has been updated

Beginning in AFS 3.4 and 3.5 the ack trailer includes the size of the
peer's receive window.  This value is used to update the sender's
transmit window (twind).  When the twind is increased the application
thread is signaled to indicate that more packets can be sent.

This change wakes the application thread after twind is updated by
the peer's receive window instead of beforehand.  Failure to do so
can result in 100ms transmit delays when the receive window transitions
from closed to open.

Change-Id: Id129ea93e94612a4b8cce9f8cbddde9c779ff26b
Reviewed-on: https://gerrit.openafs.org/12625
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoLINUX: Switch to new bdi api for 4.12. 14/12614/5
Joe Gorse [Tue, 16 May 2017 07:29:30 +0000]
LINUX: Switch to new bdi api for 4.12.

super_setup_bdi() dynamically allocates backing_dev_info structures
for filesystems and cleans them up on superblock destruction.

Appears with Linux commit fca39346a55bb7196888ffc77d9e3557340d1d0b
Author: Jan Kara <jack@suse.cz>
Date:   Wed Apr 12 12:24:28 2017 +0200

Change-Id: I67eed0fcb8c96733390579847db57fb8a4f0df3e
Reviewed-on: https://gerrit.openafs.org/12614
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoLINUX: CURRENT_TIME macro goes away. 11/12611/2
Joe Gorse [Wed, 10 May 2017 19:46:38 +0000]
LINUX: CURRENT_TIME macro goes away.

Check if the macro exists, define it if it does not.

Change-Id: I9990579f94bfba0804e60fa6ddcc077984cc46c3
Reviewed-on: https://gerrit.openafs.org/12611
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoredhat: update rpm spec file 95/12595/5
Michael Meffie [Fri, 7 Apr 2017 02:50:41 +0000]
redhat: update rpm spec file

Update the spec file to keep up with accumulated changes.

* Correct installation location of db check programs.
* Install afsd to the legacy location to avoid breaking
  init scrips and systemd configs.
* Exclude yet another duplicated copy of kpwvalid.
* libubik_pthread.a is gone.
* Install the kpwvalid man page.
* Continue to remove the obsolete kdb program.
* Update the names of the pam_afs symlinks.
* Add libkopenafs to authlibs.
* Package dafssync-debug man pages.
* Package opr/queue.h in devel.
* Package akeyconvert and man page.
* Do not package fuse version of afsd. A separate sub-package
  for afsd.fuse is warrented, since it adds new libfuse
  dependencies.
* Package new server man pages, including dafsssync-* pages.
* Package libafsrfc3961.a as a devel lib.
* Continue to package kauth programs.

Change-Id: I875c3b8dee53abbc67b0f05f8b291bb58abf41a5
Reviewed-on: https://gerrit.openafs.org/12595
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoFBSD: build fix for FreeBSD 11 75/12575/5
Tim Creech [Sun, 5 Mar 2017 23:13:45 +0000]
FBSD: build fix for FreeBSD 11

r285819 eliminated b_saveaddr from struct buf, while r292373 changed the
arguments to VOP_GETPAGES. The approach used by this patch to address
these changes was inspired by FreeBSD's nfs and samba clients.

Change-Id: Ibcf6b6fde6c86f96aa814af2bca08f1a8b286740
Reviewed-on: https://gerrit.openafs.org/12575
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

6 years agoredhat: convert rpm spec file to make install 94/12594/4
Michael Meffie [Wed, 5 Apr 2017 20:48:36 +0000]
redhat: convert rpm spec file to make install

Convert the build and install from the deprecated 'make dest' to the
modern 'make install' method.

* Clarify the install section by unrolling the shell scripts,
  reorganizing, and improving the comments.
* Remove the gzip glob of the man pages; rpmbuild automatically
  compresses the man pages and will handle symlinks correctly.
* Remove the generated temporary list file and specify files directly.
* Remove the extra tar commands to install the man pages out of the doc
  directory; 'make install..' installs the man pagess.
* Remove code in the install section which determines the sysname. This is
  no longer needed during the install.
* Update the kernel module install commands to accommodate the
  conversion from 'make dest'.

Change-Id: I97ec80185a2b11704b27ea74941b50ff4a5aca8c
Reviewed-on: https://gerrit.openafs.org/12594
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

6 years agoredhat: fix whitespace errors in the rpm spec file 06/12606/2
Michael Meffie [Tue, 25 Apr 2017 22:34:47 +0000]
redhat: fix whitespace errors in the rpm spec file

Remove trailing whitespace characters that have crept into
the rpm spec file over the years.

Change-Id: I08c7ad926ddb524d6938b26513963c28c70b4195
Reviewed-on: https://gerrit.openafs.org/12606
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>

7 years agoLinux: only include cred.h if it exists 93/12593/2
Stephan Wiesand [Tue, 11 Apr 2017 09:58:55 +0000]
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>

7 years agoLinux v4.11: cred.h is no longer included in sched.h 74/12574/2
Mark Vitale [Fri, 24 Mar 2017 01:36:44 +0000]
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>

7 years agoLinux v4.11: signal stuff moved to sched/signal.h 73/12573/2
Mark Vitale [Thu, 23 Mar 2017 22:10:03 +0000]
Linux v4.11: signal stuff moved to sched/signal.h

In Linux commit c3edc4010e9d102eb7b8f17d15c2ebc425fed63c, signal_struct
and other signal handling declarations were moved from sched.h to
sched/signal.h.

This breaks existing OpenAFS autoconf tests for recalc_sigpending() and
task_struct.signal->rlim, so that the OpenAFS kernel module can no
longer build.

Modify OpenAFS autoconfig tests to cope.

Change-Id: Ic9f174b92704eabcbd374feffe5fbeb92c8987ce
Reviewed-on: https://gerrit.openafs.org/12573
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>

7 years agoLinux v4.11: getattr takes struct path 72/12572/4
Joe Gorse [Mon, 20 Mar 2017 14:30:46 +0000]
Linux v4.11: getattr takes struct path

With Linux commit a528d35e8bfcc521d7cb70aaf03e1bd296c8493f

    statx: Add a system call to make enhanced file info available

The Linux getattr inode operation is altered to take two additional
arguments: a u32 request_mask and an unsigned int flags that indicate
the synchronisation mode.  This change is propagated to the
vfs_getattr*() function.

-   int (*getattr) (struct vfsmount *, struct dentry *, struct kstat *);
+   int (*getattr) (const struct path *, struct kstat *,
+                     u32 request_mask, unsigned int sync_mode);

The first argument, request_mask, indicates which fields of the statx
structure are of interest to the userland call. The second argument,
flags, currently may take the values defined in
include/uapi/linux/fcntl.h and are optionally used for cache coherence:

 (1) AT_STATX_SYNC_AS_STAT tells statx() to behave as stat() does.

 (2) AT_STATX_FORCE_SYNC will require a network filesystem to
     synchronise its attributes with the server - which might require
     data writeback to occur to get the timestamps correct.

 (3) AT_STATX_DONT_SYNC will suppress synchronisation with the server in
     a network filesystem.  The resulting values should be considered
     approximate.

This patch provides a new autoconf test and conditional compilation to
cope with the changes in our getattr implementation.

Change-Id: Ie4206140ae249c00a8906331c57da359c4a372c4
Reviewed-on: https://gerrit.openafs.org/12572
Reviewed-by: Joe Gorse <jhgorse@gmail.com>
Tested-by: Joe Gorse <jhgorse@gmail.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

7 years agoPrevent double-starting client on RHEL7 43/12443/3
Jonathon Weiss [Thu, 10 Nov 2016 22:06:18 +0000]
Prevent double-starting client on RHEL7

On RHEL7 if the AFS client is stopped with 'service openafs-client
stop', but that fails for some reason (most commonly because some
process has a file or directory in AFS open) systemd will decide that
the openafs-client is in a failed state when it is actually running.
If one then runs 'service openafs-client start' systemd will start a
new AFS client.  At this point AFS access will continue to work until
the functional AFS client is (successfully) stopped, at which point a
reboot is required to recover.

Have systemd check the status of 'fs sysname' before starting the
AFS client, so we avoid getting into a state that requires a reboot.

Change-Id: I28a5cca746823d69183ea5ce65c10e1725009c5c
Reviewed-on: https://gerrit.openafs.org/12443
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

7 years agoXBSD: do not claim AFS_VM_RDWR_ENV 20/12520/3
Benjamin Kaduk [Tue, 21 Feb 2017 04:18:09 +0000]
XBSD: do not claim AFS_VM_RDWR_ENV

The AFS_VM_RDWR_ENV configuration parameter (defined or not defined
in each platform's param.h) is undocumented, but appears to be an
indication of a property of the platform OS's VFS layer, or perhaps just
of the complexity of the read/write vnops that we implement for it.
That is, AFS_VM_RDWR_ENV is defined when the read/write vnops implement
partial write logic (and presumably when they interact with the OS VM
layer in ways not expressed by the afs_write() abstraction); systems
that do not define AFS_VM_RDWR_ENV can use the afs_write() function
fairly directly as the vnode operation.  Use of AFS_VM_RDWR_ENV
evolved over time, with the original (AFS 3.2/3.3-era) code using a
simple scheme that handled partial writes directly in afs_write()
and avoided complexity in callers. In AFS 3.4, sunos and solaris
gained a more complicated read/write vnop that incorporated the
afs_DoPartialWrite() call itself, and eventually in 3.6 we see the
behavior established at the original IBM import, with all the (Unix)
OSes supported at that time defining AFS_VM_RDWR_ENV.

When DARWIN support was brought in in commit
a41175cfbbf4d06ccfe14ae54bef8b7464ecd80b, its param.h properly did
not define AFS_VM_RDWR_ENV, as OS X uses a VFS interface that shares
some level of abstraction with the traditional BSD VFS and its
read/write/getpages/putpages operations, so the afs_write() behavior
was natural and no extra complications needed for integration with the
VM layer or other optimizations.

However, when the initial FreeBSD support came in a few months later,
it seems to have taken inspiration from the OSes that were supported
in the initial IBM import, and kept the AFS_VM_RDWR_ENV definition.
This was then propagated to all the later BSDs as they were added.

Perhaps the most noticeable consequence of this definition is that
the calls to afs_DoPartialWrite() from afs_write() are bypassed, with
a comment that "[i]f write is implemented via VM, afs_DoPartialWrite()
is called from the high-level write op" (and calls to afs_FakeOpen()
and afs_FakeClose() are similarly skipped).  This means that attempting
to write a file larger than the local cache will hang waiting for
more space to be freed, which will never happen as the vcache remains
locked and will not be written out in the background.

In the absence of a documented meaning for AFS_VM_RDWR_ENV, this
also gives us a proxy that can be used to indicate whether a given
OS's support intended to claim the AFS_VM_RDWR_ENV -- such platforms
will actually contain the call to afs_DoPartialWrite() in the
appropriate vnode operation.  This can be used to sanity-check the
places where AFS_VM_RDWR_ENV is removed by this commit.  Interestingly,
HP-UX does not call afs_DoPartialWrite() but also is clearly in a VFS
that uses a rdwr()-based approach, as the corresponding vnode operation
is implemented by mp_afs_rdwr(), so leave it unchanged for now.

Tim Creech is responsible for noting the lack of calls to
afs_DoPartialWrite() on FreeBSD, and Chaskiel Grundman for the
historical research into pre-OpenAFS AFS behavior.

Designing and implementing more complicated BSD read/write vnops that
incorporate afs_DoPartialWrite() and other improvements is left for
future work.

Change-Id: I8e89855ac31303934f97d0753b64899fb7e3867c
Reviewed-on: https://gerrit.openafs.org/12520
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Antoine Verheijen <apv@ualberta.ca>
Reviewed-by: Tim Creech <tcreech@tcreech.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

7 years agovol: detach offline volumes on dafs 15/12515/4
Marcio Barbosa [Tue, 31 Jan 2017 14:43:18 +0000]
vol: detach offline volumes on dafs

Taking a volume offline always clears the inService bit. Taking a
volume out of service also takes it offline. Therefore, if the
inService flag is false, the volume in question should be offline.
On dafs, an offline volume should be unattached.

The attach2() function does not change the state of the volume received
as an argument to unattached when the inService flag is false. Instead,
this function changes the state of the volume in question to
pre-attached and returns VNOVOL to the client. As result, subsequent
accesses to this volume will make the server try and fail to attach
this offline volume over and over again, writing to the FileLog each
time.

To fix this problem, detach the volume received as an argument if the
inService flag is false. Since the new state of this volume will be
unattached, subsequent accesses will not hit attach2().

This situation where a volume is not offline but is also not in service
can occur if a volume is taken offline with vos offline and some time
later the DAFS fileserver is shutdown and restarted; the volume is
placed into the preattach state by default when the server restarts.
Each access to the volume by clients then causes the fileserver to
attempt to attach the volume, which fails, since the in-service flag in
the volume header is false from the previous vos offline.  The
fileserver will log a warning to the FileLog on each attempt to attach
the volume, and this will fill the FileLog with duplicate messages
corresponding to the number of attempted accesses.

Change-Id: Ifce07c83c1e8dbf250b88b847d331234bdaa9df5
Reviewed-on: https://gerrit.openafs.org/12515
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

7 years agoSOLARIS: prevent BAD TRAP panic with Studio 12.5 58/12558/4
Mark Vitale [Tue, 28 Feb 2017 23:02:39 +0000]
SOLARIS: prevent BAD TRAP panic with Studio 12.5

Starting with Solaris Studio 12.3, it is documented that Solaris kernel
modules (such as libafs) must not use any floating point, vector, or
SIMD/SSE instructions on x86 hardware.  However, each new Studio
compiler release (12.4 and especially 12.5) is more likely to use these
types of instructions by default.

If the libafs kernel module includes any forbidden kernel instructions,
Solaris will panic the system with:
  BAD TRAP:  type=7 (#nm Device not available)

Provide a new autoconfig test to specify the required compiler options
(-xvector=%none -xregs=no%float) when building the OpenAFS kernel module
for Solaris, so that no invalid x86 instructions are used.

In addition, reinstate default kernel module optimization for Solaris.
It had been disabled in commit 80592c53cbb0bce782eb39a5e64860786654be9f
to address this same issue in Studio 12.3 and 12.4.  However, Studio
12.5 started using some SSE instructions even with no optimization.

This commit has been tested with OpenAFS master and Studio 12.5 at all
optimization levels (none, -xO1 through -xO5) and verified to contain no
XMM register instructions via the following command:
  $ gobjdump -dlr libafs64.o | grep xmm | wc -l

Change-Id: Ic3c7860f7d524162fd9178a1dab5dd223722ee43
Reviewed-on: https://gerrit.openafs.org/12558
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>