vfs: fix sys_open error handling

When VOP_OPEN fails, fdrop will be called to release
the recently created file pointer, and later on,
the vnode associated with the recently released file
pointer is unlocked.
The problem is that vn_unlock, function to unlock a
vnode, asserts vnode refcnt to be greater than zero,
and fdrop releases the associated dentry, which in
turn, releases the associated vnode. Thefore, assert
is likely to fail.

Solution is to firstly call vn_unlock, then lately
call fdrop.

Found it while cooking the patch to return EINVAL when
O_DIRECT is requested on a ZFS file, which causes
VOP_OPEN to fail.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zfs: return failure when O_DIRECT is requested

First of all, let me say that O_DIRECT semantics cannot
be easily supported within ZFS due to its Copy-on-Write
nature, and currently it's not.
Unlike ZFS on Linux, opening a ZFS file with O_DIRECT
flag on OSv returns success, where it should fail with
EINVAL instead. Returning success results in fooling
the application that O_DIRECT is supported by the
underlying file system, which definitely isn't a good
thing. That being said, as ZFS on Linux, let's handle
the case properly.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
fs: fix namei lookup

On Linux, if we stat or lstat names like "/tmp/", we get the same result as if
we do it for "/tmp".

On OSv, stat works as expected, but lstat does not. This is because we have to
look at the last element of the path separately to see if it is a link, and we
do that by looking at the last "/" character. The current algorithm will treat
everything after the last "/" as the thing to look for. But in a directory like
"/tmp/", we would be looking for an empty string.

Reviewed-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: enhance tst-stat

Let's also test cases in which stat is expected to succeed. Also, if we are not
dealing with symlinks, stat and lstat should behave the same. Test some tricky
cases for that one.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>