Fix non-functional chdir()

I don't know how chdir() ever worked - apparently it didn't!

It took an argument "pathname", and then declared a local "path" and used
that, not pathname, as the path :-) Obviously, a call to task_conv, which
converts a relative "pathname" to an absolute "path", was missing...

chdir() is still a mess and incompatible in the error cases with Linux's
chdir(). I'll fix that, and add a test, in a follow-up patch.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
build: Force version.h regeneration

Force version.h generation to make sure the version number matches the
git version.  I noticed the problem after tagging v0.05-rc1 and noticing
that OSv happily reported the same version even after applying patches.

Use the special ".PHONY" target suggested by Tomek to avoid breakage
from previous attempt that is documented in commit 996fdfd ('Revert
"build: Force version.h generation"').

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
DHCP: Repeat DHCP discovery on timeout

It is a bad practice to have DHCP discovery without timeout
and retries. In case discovery packet gets lost boot stucks.

Beside this there is an interesting phenomena on some systems.
A few first DHCP discovery packets sent on boot get lost in some cases.

This started to happen from time to time on my KVM system and almost
every time on my Xen system after installing recent Fedora Core updates.
Packet leaves VM's interface but never arrives to bridge interface.
The packet itself built properly and arrives to DHCP server just fine
after a few retransmissions.

Most probably this phenomena is a bug (or limitation) in the current
Linux bridge version so this patch is actually a work-around, but
since in general case it is a good idea to have DHCP timeouts/retries
it worth to have it anyway.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
rcu: allow initializing with a pointer

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
rcu: add a Disposer template parameter so an rcu_ptr<> can own its resource

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: convert netport.c to C++

Allows making ifnet a C++ class.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
bsd: reconcile sys/param.h with system header

Include the system header and remove duplicate definitions.

Change some solaris imports to use _GNU_SOURCE to make rlim64_t defined
consistently.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: add ntoh()/hton() for in_addr

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: add comparison operator for in_addr

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: enable ifnet constructor/destructor

This allows placing C++ objects in ifnet.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: fix sblock()

sblock() takes sb_rwlock for reading, and is the only such locker, so it
clearly has no effect.

Change it to acquire the lock for writing, so it serializes access to the
socket buffer as intended.

Bug introduced in 6296cbabf89f10b.

Reviewed-by: Glauber Costa <glommer@cloudius-systems.com>
Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: replace sockbuf::sb_rwlock with a waitqueue

sb_rwlock is used to serialize concurrent writers (or readers) to the same
socket buffer, but is quite expensive as it requires 4 atomic operations
per transaction, even if there is no contention.

Replace it with a waitqueue, and use the sockbuf::sb_mtx for serialization.
This still has exactly the same cost, but we can later move sblock() and
sbunlock() into contexts where the sockbuf::sb_mtx is already acquired.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
net: optimize sblock(), sbunlock()

Instead of acquiring sockbuf::sb_mtx inside sblock() and sbunlock(), rely
on the caller to take the lock for us.  Expand existing lock hold regions
in callers to make it so.  This reduces acquisitions of sb_mtx.

As a side effect, copies to and from userspace are done under the lock.
This can affect MSG_NOWAIT with demand paging major faults, but these are
screwed anyway.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
test case for dladdr()

Test case for dladdr(), to make sure it returns correct symbol in these cases:
 - addr is less than 'vfprintf'. Should returns another symbol.
 - addr is equals to 'vfprintf'. Should returns 'vfprintf' as the result.
 - addr is bigger than 'vfprintf', and also inside of it. Should returns 'vfprintf' as the result.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Takuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
loader: add cwd and env options

Add cwd (current directory) and env (environment variable) option to the
loader. Can be useful for certain applications that expect to be in a
certain directory, or certain environment variables to exist.

Example usage:

   run.py -e "--cwd=/tmp /usr/bin/something.so"

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
open(): add O_DIRECTORY flag

This patch adds the O_DIRECTORY flag to sys_open(), which causes the open
to fail with ENOTDIR if the given file is any type of file but a directory.

We need this flag as part of a correct implementation of chdir() (which
should fail on a non-directory file), and it is also required for Linux
compatibility (the O_DIRECTORY flag exists since Linux 2.1.126).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
chdir(): Fix error path, and add test

This patch fixes chdir() on a normal file, which used to succeed (!?),
but now will fail as it should, with ENOTDIR.

The patch also adds an exhaustive test for chdir's success and error cases.
Before the latest chdir() patches, most of these tests would fail, and now
all of them succeed.

This test is standard C++ & Posix code, so it can be run also on Linux.
This is important for verifing that whatever we expect from OSv, Linux
really does the same.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
include: Move sched.hh to include/osv

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
include: Move align.hh to include/osv

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
include: Move interrupt.hh to include/osv

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