Windows: cm_MergeStatus now returns an error code

cm_MergeStatus() can fail if the AFSFetchStatus InterfaceVersion
field does not have the value 0x1 as that is the only version that
is defined by the protocol.  The return code will be CM_ERROR_INVAL.
cm_MergeStatus() returns 0 on success.

Update all of the call sites.

Change-Id: Iddf56f68dfa26b0f11744b905a70d7d39ad853d1
Reviewed-on: http://gerrit.openafs.org/8402
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: cm_IsStatusValid

Break out validity checking for AFSFetchStatus responses into
a new function.

Change-Id: I15d2ed12ed2d9ca9a24d6f717243d823db22d30c
Reviewed-on: http://gerrit.openafs.org/8403
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: Treat invalid AFSFetchStatus as VBUSY

Modify cm_Analyze() to accept an AFSFetchStatus parameter which
when set is verified for validity.  If the status info is invalid,
then consider the response equivalent to VBUSY and attempt to
query an alternate file server (if any.)   Log the invalid status
info to the Windows Application Event Log as a Warning.

When cm_Analyze() is processing the response of an RPC that returns
multiple AFSFetchStatus structures, pass in the one that corresponds
with the source object.

Change-Id: I84be22f332ff6fd7bc9620347f958538a3412380
Reviewed-on: http://gerrit.openafs.org/8404
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: Prevent SMB unitialized variable access

smb_ReceiveNTTranCreate would make use of 'fidp' before it was
allocated.

Change-Id: Ib4a7262ba09f15049f1855535250638c2e5d17a4
Reviewed-on: http://gerrit.openafs.org/8411
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: use hKUserMap to read afslogon username

hkTemp is not the correct registry handle.  Use hkUserMap

Change-Id: I44776b6dd46bb0ecac0c729bf80ed9261ddf7a67
Reviewed-on: http://gerrit.openafs.org/8412
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
fileserver: check value of -cb argument

The value of the -cb argument for the fileserver was not checked correctly.
The fileserver refused to start for any number of callbacks.

Change-Id: I25fe9d81ba20d286f36999a554c94fda4ef7fb2f
Reviewed-on: http://gerrit.openafs.org/8420
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
vol: allow non-dafs volume utils to attach with V_READONLY again

Allow non-fileserver, non-dafs, programs to attach volumes with the
V_READONLY mode again. This was lost during the code changes for
dafs.

The caller sends a fssync request to the fileserver, which updates the
on-disk contents of the volume headers, before the caller reads the
volume headers, allowing the caller to have the most recent info about
the volume. The fileserver still has the volume in use.

Later in the attachment process, the inUse check is skipped for the case
of a non-fileserver process which is attaching the volume using the
V_READONLY mode, otherwise the attachment would incorrectly mark the
volume as needing to be salvaged.

Note: The mode checks in VMustCheckOutVolume() are correct. We must
checkout the volume when attaching with the V_READONLY mode. This
fix updates the VShouldCheckInUse(), in which an additional
exception was added to cover the case for V_READONLY mode from a non-
fileserver process.

Note: A check is added in the dafs version of attach to avoid overwriting the
inUse field when a volume utility is attaching a volume in V_READONLY mode.
Currently, V_READONLY is not used by dafs, but this was done to avoid future
errors.

Change-Id: I09d3af1e74087d0627399392e662e5075d41cdeb
Reviewed-on: http://gerrit.openafs.org/8339
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
fix stale volume info from vos examine (non-dafs)

A volume examine on a non-dafs volume server/fileserver can show old
information, including old volume update time, for up to about 20
minutes. The non-dafs volume server reads the volume information
from the volume headers, which are updated by the fileserver only
periodically to avoid excessive i/o.

Before dafs, when the volume server performed a volume examine, the
volume server would send a fssync command to the fileserver with the
request FSYNC_NEEDVOLUME and mode V_READONLY. The fileserver writes
the current memory contents to disk on this fssync command. The
volume server would then attach the volume, reading the current
volume data.

The dafs volume/fileserver avoids this extra i/o by using a new set
of fssync commands to retrieve the volume information from the
fileserver. However, the non-dafs volume server does not use the new
fssync commands and reads the volume headers from disk.

Revert the volume attachment processing for the non-dafs volume
server to request the volume with the V_READONLY mode. This causes
the fileserver to update the volume headers, allowing the volume
server to read the up to date volume header data.

Sadly, this adds another dafs ifdef to the already twisty maze of
passages that all look alike.

This changes the volserver to use the V_READONLY attachment mode
only for the case of getting a single volume, as that what was
done in 1.4.x.

Change-Id: Ibee25bfcfb087e73ccbc17e181a99da49a7751ae
Reviewed-on: http://gerrit.openafs.org/8327
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
afs: Pass rx connection to print_internet_address

Make print_internet_address take an rx_connection, so it can print out
more information based on rx info. Currently it does not use the
connection; this commit is just for adding the connection to the
interface, and adjusting all of the callers to cope. There should be
no behavior change.

Change-Id: I410ffe43b7b6fc4d5c82666529c9263969820185
Reviewed-on: http://gerrit.openafs.org/8409
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Simon Wilkinson <simonxwilkinson@gmail.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Windows: afsrpc.dll MAKEDEBUGCALL

Enable debug calls from the pthreaded RX library.

Change-Id: Ie5e98d4408a3eb259e7f5f298f0776931f0d488a
Reviewed-on: http://gerrit.openafs.org/8427
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
libafscp: build as pthreaded for windows

Change-Id: Iaa9515e572178f44deb670a83daba358c2d4dc74
Reviewed-on: http://gerrit.openafs.org/8428
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
libafscp: Windows TellMeAboutYourSelf response

The address list and uuid are computed in init_afs_cb().  There
is no need for special Windows processing within TellMeAboutYourSelf.

Change-Id: Ica4d2edb69ac9000713b016996a2c58e8b65ee9c
Reviewed-on: http://gerrit.openafs.org/8429
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
afsio: process windows file paths consistently

Windows file paths can use either '\' or '/' as a path
separator.  libafscp on the other hand requires '/' and argv[0]
will always use '\'.

Introduce a new function ConvertAFSPath() which converts the
input path to '/' and converts \\afs to /afs.  A future commit
should access the registry and make use of the NetbiosName and
MountRoot values to perform the conversion correctly.

Change-Id: I14f5f45234ec4beab58751783a25206b3e7eff45
Reviewed-on: http://gerrit.openafs.org/8430
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: torture should not reference roken.h

Do not include roken.h in torture tests.  The torture test
should not be linked to afsroken.dll.

Change-Id: I14d67c2e2f9980906854e0ab72c040eb9437a931
Reviewed-on: http://gerrit.openafs.org/8431
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: Add AFSRedir binaries to Symbol Store

Change-Id: I1b4f2d5fcd4243e9a8a931a223bced33631206b0
Reviewed-on: http://gerrit.openafs.org/8441
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Windows: SYMSTORE the entire WINNT/afsrdr tree

The tools directories need to be imported into the symstore
one directory at a time.

The "build.exe" output files afsredir.sys, afsredirlib.sys and
afsrdfsprovider.dll must be imported from within the kernel
build environment script.

Change-Id: Ida7d84deecfb1ec4f508c5c40fc5576e2cb7b3e4
Reviewed-on: http://gerrit.openafs.org/8445
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>
afs: Never use GetNewDSlot after init

Currently there are two ways to get a dcache via a slot number:
afs_GetNewDSot and afs_GetValidDSlot. afs_GetValidDSlot assumes that
the given slot number refers to a dcache entry that is valid on disk;
with afs_GetNewDSlot, the given slot may not be valid, and if it is
not, an empty 'template' dcache is returned.

afs_GetNewDSlot is useful for initializing cache files, since if a
given dcache slot exists on disk and contains valid data, we use the
dcache like normal. If it does not already exist or does not contain
valid data, we fill in the missing data after afs_GetNewDSlot returns.

However, for all other uses, afs_GetNewDSlot is incorrect, and causes
various serious problems. After we have initialized our dcache
entries, any attempt to read a dcache by slot number should succeed,
since the number of dcache entries never changes after we are started,
and we initialized all of them during client startup.

Some code outside of afs_InitCacheFile was still using
afs_GetNewDSlot; code that reads in a dslot from the free or discard
list. In these cases, if there is any error reading the dcache slot
from disk, we will be given a dcache that has some of its fields not
filled in properly. Notably, we assume that the entry is not on the
global hash table (we set tdc->f.fid.Fid.Volume to 0), and the
tdc->f.inode field is not initialized at all, leaving it set to
whatever was in memory for that tdc before we tried to read the slot
from disk.

This can cause cache corruption, since tdc->f.inode can point to the
inoder for a different existing cache file, so writing to that dcache
modifies the data for another cached file.

To avoid this, modify the non-afs_InitCacheFile callers of
afs_GetNewDSlot to avoid afs_GetNewDSlot. Since these callers read
from the free/discard list, the contents of the dcache entries are not
valid (the cell, volume, dv, etc are not valid), though they must
exist on disk (we have a valid inode number for them). So, create a
new function, afs_GetUnusedDSlot, to get a dcache that must exist on
disk, but does not represent any valid data. Use this for callers that
must get a dslot from the free/discard list.

Add some comments to try and help explain what is going on.

Change-Id: I5b1b7ef4886102a9e145320932b2fd650b5c6f2f
Reviewed-on: http://gerrit.openafs.org/8370
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
afs: Handle easy GetValidDSlot errors

Many callers of GetValidDSlot currently assume they will always get
back a valid dcache, and will panic on getting NULL. However, for many
of these callers, handling the NULL case is quite easy, since the
failure to get a dcache can just result in an error directly, or
obtaining the dcache is best-effort or just an optimization.

This commit just handles the "easy" cases; some other callers require
more complex handling.

Change-Id: I622908de7004ba4cb18ccb26bda0e75b879f65ca
Reviewed-on: http://gerrit.openafs.org/8375
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
afs: Traverse discard/free dslot list if errors

Currently, when we pull a dslot off of the discard or free list, we
just try to get the first entry from the list, and panic if we cannot
get it. Instead, traverse through the whole list, trying to find an
entry we can successfully get. This introduces the helper function
afs_GetDSlotFromList to do this traversal.

This does not yet address the case where we cannot get any entry on
the relevant list.

Change-Id: Iedbcffcbeb5dda61fde8e1d526e793f68c3200b3
Reviewed-on: http://gerrit.openafs.org/8376
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
afs_AllocDCache: return NULL instead of panic

Currently afs_AllocDCache will panic if we cannot get a valid dcache
from the free/discard lists. Instead, return NULL, so the caller can
decide how to handle the error.

Currently the caller will just panic anyway, but that will be
addressed in a future commit.

Change-Id: Iafb539bbda9ef20907ef575699185f111ca39c2b
Reviewed-on: http://gerrit.openafs.org/8377
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>