build: Add 'werror' option to Makefile

Add 'werror' option to Makefile that can be used to disable the -Werror
GCC option temporarily as follows:

  make werror=0

This is useful when fixing up build breakage caused by addition of new
default compiler warnings.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: Fix printf format string

Spotted by GCC with '-Wformat=1':

../../bsd/sys/netinet/tcp_subr.c: In function ‘tcp_log_addr’:
../../bsd/sys/netinet/tcp_subr.c:2286:3: warning: unknown conversion type character ‘b’ in format [-Wformat=]
   sprintf(sp, " tcpflags 0x%b", th->th_flags, PRINT_TH_FLAGS);
   ^
../../bsd/sys/netinet/tcp_subr.c:2286:3: warning: too many arguments for format [-Wformat-extra-args]

BSD has some nice printf extension for printing out bitfields. We don't
so switch to hexadecimal output.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
drivers/xenfront-xenbus: Fix scanf() variable type

Spotted by GCC with '-Wformat=1':

../../drivers/xenfront-xenbus.cc: In function ‘XenbusState xenbus_get_state(device_t)’:
../../drivers/xenfront-xenbus.cc:219:80: warning: format ‘%d’ expects argument of type ‘int*’, but argument 6 has type ‘XenbusState* {aka xenbus_state*}’ [-Wformat=]
     xs_scanf(XST_NIL, dev->get_node_path().c_str(), "state", NULL, "%d", &state);

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
x64: fix xapic INIT IPI

xapic::init_ipi() shifts apic_id by 24, unaware that xapic::ipi will do it
again.  The result is that the boot processor is reset instead of the
auxiliary processor.

Remove the extraneous shift.

Found by booting with QEMU without kvm.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
x64: fix APIC ID register read on QEMU

The expression *p >> 24, where p is an unsigned*, is optimized by
the compiler to *((u8*)p + 3) - reading the most significant byte only and
dropping the shift.

When this optimization is applied to reading the APIC ID, QEMU
returns zero for all processors, since the manual requires reading
entire words.

Fix by using a volatile pointer, disabling the optimization.

Note that QEMU is technically correct here though it violates all known
real x86 implementations.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
cpio: simplify stream creation

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
acpi: timer.set() requires an absolute value

The sched::timer set() function expects an absolute time value. Fix an
incorret use of it AcpiOsWaitSemaphore().

Signed-off-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: omit source file from autodependencies

When converting a source file from .c to .cc, make will complain that the
old source file was missing.  This is annoying, especially when bisecting
or compile-testing a patch set.

Fix by removing the source file dependency.  Since the dependency is alread
specified explicitly by the makefile, no information is lost.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
vfs: fix ancestry check in rename()

Renaming to destination which is a substring of the source path
but not its parent should succeed:

  rename("/tmp/one_two", "/tmp/one") == 0

Renaming to a child should fail:

  rename("/tmp/", "/tmp/child") == -1 && errno = EINVAL

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
vfs: namei() should return ENOTDIR when component is not a directory

The call to namei("/dir/file/") currently fails with ENOENT when
"/dir/file" exists. A more standard way is to return ENOTDIR
instead. This way calls to stat, open, rename, etc. will be in
line with the POSIX spec.

It is also useful to rename() implementation which needs to
differentiate behaviour between the case in which target does not
exist and the case in which it does but the path has trailing slash
and the last component is not a directory.

In addition to that the check was performed in an inconsistent matter
- only when dentry lookup failed. This change makes the check
performed always.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
vfs: fix incorrect rename() behavior with trailing slashes

Fix 1. Renaming existing directory to existing file when the
destination path has trailing slash should fail:

  rename("/tmp/dir", "/tmp/file/") == -1 && errno == ENOTDIR

Fix 2. Renaming exisitng directory to nonexisting path when the path
has trailing slash should succeed:

  rename("/tmp/dir", "/tmp/im_missing/") == 0

Fix 3. Renaming exisitng file to nonexisting path when the path
has trailing slash should fail:

  rename("/tmp/file", "/tmp/im_missing/") == -1 && errno == ENOTDIR

Reference:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html

This change also adds a bunch of test cases for various conditions
mentioned in the spec. Note that for some cases where the raname()
should fail there are discrepancies between Linux and OSv in error
codes set by the call. To my understanding, the spec is ambiguous.
There are conditions which match more than one error code
description. The tests are therefore allowing the call to set error
code from a set of matching error codes (eg. both EEXIST and ENOTEMPTY
are allowed when applicable). If we decide that OSv should return
exactly the same error codes as Linux for the same conditions, this
can be changed later.

vfs: rename() should fail if paths differ only with trailing slash

This should fail:

  rename("/tmp/file", "/tmp/file/")

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
vfs: rename() should fail if either path ends with . or ..

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
vfs: make rename() return ENOENT when one of the paths is empty

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Extend the test whitelist

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
runjava: Add missing delegation to OSv system classloader

When system classloader is used as a parent some of its protected
methods are called to lookup resources.

This also adds delegation for all remaining protected and public
methods.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
x64: fix TLS segment alignment

The TLS segment is a little wierd in that it grows backwards from percpu_base
instead of forwards.  This causes the alignment code to calculate wrong
offsets when the segment size is 8 (mod 16).  A failure was seen where
::percpu_base was set at offset 0xfffffffffffffa08 in code that was in the
same translation unit as ::percpu_base, and 0xfffffffffffffa10 elsewhere.
This caused all dynamic_percpu instances to crash.

Fix by aligning the segment size.  For good measure, align also the segment
base, both to a cacheline boundary.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
external: update gcc to 4.8.2

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: Remove tst-zfs-simple.so

The tst-zfs-simple.so test case has serverd its purpose for bringup.  As
OSv build relies on working ZFS now, there's no need to run the tests.

Furthermore, we have the full ztest stress test in the tree:

  bsd/cddl/contrib/opensolaris/cmd/ztest/ztest.c

which we can use if needed.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
Start documenting condvar

Add Doxygen comments to the condvar class. Only the C++ interface
(condvar's methods) is documented, not the alternative C interface
(condvar_* functions).

A reminder: run "doxygen" and point your browser to doxyout/html/index.html
to see the API documentation we have so far.

A lot can still be added to this condvar documentation, including a
good introduction to how to use condition variables, why they have
a mutex, etc. But it's at least a start.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Small fix to condvar->wait() return code

We want to return 0, not ETIMEDWAIT, if a wake_one/all() was consumed.
In one racy case, we returned the wrong one (we received a wakeup, but
still returned ETIMEDWAIT).

This probably doesn't matter at all in practice...

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>