At least TARGET_ARCH, which is used by the release build, is causing
havoc for packages built by gmake, as gmake appends ${TARGET_ARCH} to
the ${COMPILE.c} compiler command line.
To be on the safe side, clear the environment completely when calling
into the pkgsrc build.

On syncache_socket() abort path, the inp's {fport,lport,faddr,laddr}
is either incomplete or half destroyed, which causes tcp_soport()
mapping the socket to a wrong CPU. However, in syncache code, inp
is only accessed or created by its owner CPU, i.e. we are already on
the inp's owner CPU during the socket aborting.

Add soabort_oncpu(), which calls pru_abort directly. Use it on
syncache_socket() abort path.

The nata driver previously assumed that an interrupt which has the
interrupt and active bits set in the busmaster status register is not a
valid/completed interrupt. In these situations if would return without
acknowledging the irq, leading to an interrupt livelock situation.

This condition of INTERRUPT|ACTIVE occured on two different machines
both equipped with different versions of an ICH SATA controller, when
accessing an attached SATA ATAPI (DVD) drive by TSScorp (Samsung
OEM/bulk). Specifically, natapicam seems to trigger this condition on
attach. It seems that the drive is unhappy with the INQUIRY command
sent by natapicam. Related artifacts appear when trying to access a
video DVD (possibly due to missing region/css key).

Under the hood it seems that the drive reports an error condition
(visible in the ALT/STATUS register), but does not clear the ACTIVE bit
of the busmaster status. As a result the nata driver could be waiting
for the completion of the transfer, while the SATA busmaster would keep
the interrupt line asserted.

We work around this issue by following the precedent of other operating
systems and ignoring the ACTIVE bit if the INTERRUPT bit is set.
Specifically, we wait a little bit to accomodate for possibly faulty
hardware which might assert the irq before the transfer is completely
finished. Nevertheless, we do not reject interrupt proecessing if the
INTERRUPT bit is set in the busmaster status register.

The previous attempt at fixing a deadlock due to a hammer_buffer being
held cached across long-blocking procedures failed to catch all cases.
Implement a more complete and less invasive fix. These buffers are
typically held in the hammer_cursor structure.

Instead of trying to release such cached data buffers proactively,
we instead allow hammer_del_buffers() to return a temporary failure when
called from the reservation code. If hammer_del_buffers() is unable to
completely eradicate underlying buffers due to them being referenced via
the above cache entities the related hammer_reserve structure is simply
re-added to the delayed-release queue.

The related big-block are thus not reused until all such cached entites
have been dereferenced. The relaxed requirements on the cached entities
removes the possibility of a deadlock in the invalidation code and also
simplifies hammer_io_inval()'s handling of the hammer_buffer<->buffer_cache
coupling case.

Clean out any cached cursor->data_buffer when unlocking a cursor. The
underlying buffer cache buffer could become stale and if we do not release
our hammer_buffer reference on it other threads may deadlock trying to
getblk() the buffer cache buffer in order to invalidate it.

Fix a bug where an exiting process becomes a zombie, entering the SZOMB
state, but then receives a stop signal before it can be reaped. If this
occurs the process was incorrectly placed in SSTOP and then later made
SACTIVE again, preventing it from being reaped.

Symptoms were: process shows up in ps in a DEL state but does not show
up in kgdb's 'info thread' list. Process is the zombie list and is still
a child of init, but it's state is SACTIVE instead of SZOMB and p_xstat
(last signal taken) is SIGSTOP or SIGTSTP.

hammer_vop_rmdir() maintains a cursor at the directory entry being deleted,
and then calls hammer_ip_check_directory_empty() to check if the directory
is empty. The check code creates a second, nested cursor.

Any locks on the first cursor must be released in order to allow the
function to block while scanning the second cursor to avoid possible
deadlocks.

getq determines the initial size of its queue array based on the st_size
of the queue directory. If the queue directory is on a HAMMER file
system, this size will be reported as 0. However the following array
growing logic just doubles the array size, thus always staying at 0.

There seems to be very little documentary evidence outside this
implementation to suggest a these checks are neccessary, and more
than one camera-formatted flash disk fails the check, but mounts
successfully on most other systems.

Fix a bug in vinvalbuf(). vinvalbuf() is usually called when attempting
to reclaim a vnode but can sometimes be called with V_SAVE when attempting
to make a vnode reclaimable. In the latter case write races with other
threads can create new dirty buffers after the FSYNC returns.

Only assert that dirty buffers are not present if the vnode is undergoing
reclamation.

Add code similar to what was done in physio to use a bounce buffer
if user data supplied to the CAM pass-throug device is not 16-byte aligned.
The user data was previously unconditionally vmapbuf()'d and the unaligned
pointer passed through to the device layer, causing NATA to barf badly on
SATA devices.

Someone noticed that the installer generated a wrong ifconfig_<if> line
in /etc/rc.conf if used under VMWare and with the lnc(4) driver. Strange
about that is, that this only happens with that particular driver. My em(4)
interface under VMWare is detected properly and the rc.conf entry is
correct.

The value of the interface variable is corrupted somewhere between the
invocation of dhclient and the asprintf. This commit saves the interface
name in string directly after the dhclient invocation which fixes the
problem described above.

This commit is more a work-around than a real fix. If someone comes up with
a better fix, I'm happy to back this out and test the new one. Until now, this
makes the network configuration in the installer with VMWare and lnc(4) work.

The installer tried to unmount all mount points in order (e.g. /var/tmp
should be unmounted before /var). The code had a bug which prevent it from
doing it correctly. It seems that nobody noticed the bug, because the default
file system layout does not suggest subdir mounts. With the introduction of
PFS and subdir mounts (e.g. a /var/crash PFS), the bug showed up.

Simplify the code a bit and sort the mounted file systems in reverse
lexicographical order.