loader: prepare commands later

It is important that we parse the command line as early as we can, because the
global switches (like --verbose) controls the general behavior of the system.
But actually preparing the command lines to run can come later, right before we
actually go execute the commands.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader: set an environment variable with the amount of cpus we have

This patch creates an environment variable, OSV_CPUS, that will be present at
boot and as the name implies, contains the amount of cpus we have in the
system.

This can be useful to create appliances whose parameters will be conditional to
the number of cpus in the system. Other properties can easily follow.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader: support environment variables in command line

This patch extends our prepare_command function to take a variable in the
command line.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
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>
arch-dtb: cascading props should ignore current node

strangely enough, in device trees the current node properties
are ignored when cascading (for #address-cells and reg).

Signed-off-by: Claudio Fontana <claudio.fontana@huawei.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
remove prototype of non existing function

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: Fix missing in6addr_loopback

Reported-by: James Peach <jorgar@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>