vfs: Convert mount point list into C++

This converts VFS mount point list to list from the C++ standard
library.

Reviewed-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: Use delete instead of free in vfs_mount.cc

The mount struct is allocated with "new" so use "delete" to deallocate it for
symmetry and to avoid future bugs if a destructor is introduced.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: Use C++ locking in vfs_mount.cc

Use SCOPE_LOCK and WITH_LOCK in vfs_mount.cc.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: kill vcount()

After c59e0fd, vcount isn't used anywhere.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: count_match return failure when mountpt does not match

ZFS allows user to create multiple file systems on a pool. As a part of
the file system creation, ZFS creates a new mount directory and mounts
new file system there. The default mountpoint is /<pool>/<fs name>/.
For example: zfs create tank/fs1 would mount new fs on /tank/fs1.

During path lookup (in namei), we have to find the mount point for
given path. We go through the list of mount points and find the one
which matches the most (function count_match). Once the mount point is
found, namei skips the mount point portion of the path and goes through
rest of the components of path mapping each component to dentry. For
example: if namei(/proc/mounts) is called - namei would find that
mountpoint is /proc and then it will try to map /mount to a dentry.

The count_match() function matches each character of path against given
mountpoint. If a match is found - the function returns number of
characters matched. If a character does not match - it breaks out of
the loop, in which case it must return no match (i.e. set length of the
match to 0).

However, because of bug in mount point matching function (count_match),
when mountpoint '/tank/fs1' is matched against '/tank/fs2', it
incorrectly returns a match and sets the length of the match to 8. As a
result, namei lookup fails - since /2 is not a path. The failure
particularly happens only when
1. strlen(path) == strlen(mountpoint),  AND
2. Last character of path do not match

Example failure run
==================
[/]% run zfs.so create tank/fs1
run_elf(): running main() in the context of thread 0xffff800009d3e050
VFS: mounting zfs at /tank/fs1
zfs: mounting tank/fs1 from device tank/fs1
run: finished with exitcode 0

[/]% run zfs.so create tank/fs2
run_elf(): running main() in the context of thread 0xffff80000b708050
VFS: mounting zfs at /tank/fs2
cannot mount 'tank/fs2': No such file or directory
filesystem successfully created, but not mounted
program /zfs.so returned 1
run: finished with exitcode 1

[/]% ls /tank
ls: could not access /tank/fs2: No such file or directory
.     ..    fs1
==================

Reviewed-with-a-smile-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: simplify namei external loop

Reviewed-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: remove dead code from namei

Reviewed-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
fix so->so_mtx = nullptr;
vfs: Fix race in fdrop

There is a race window between f_count reaches 0 and we set f_count to
INT_MIN. This race would result in multiple call to fp->close() and
rcu_dispose(fp) if we call them in fdrop().

To fix, we move fp->stop_polls and fp->close() from fdrop() into in
fdset() and fdclose(). This will eliminate the multipe call to
fp->close(), as there can be only one call to fdclose() or fdset().

Also, we set f_count to INT_MIN using CAS, this way, we make sure
rcu_dispose(fp) won't be called twice.

Fixes #293.

Signed-off-by: Asias He <asias@cloudius-systems.com>
misc-fclose.cc
Faster
Revert "Faster"

This reverts commit 1568fd285e932a4af3132df21adfdd2b1b8940a5.
close in fdrop