net: don't abort when receive a VLAN frame

bsd/sys/net/if_ethersubr.cc has an assert to check if
incoming frame is a VLAN frame, if so kernel will abort
there, just dropping it may be a bettter choice.

Signed-off-by: Li Yu <raise.sail@gmail.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
mmu: remove unused count_maps code

Signed-off-by: Gleb Natapov <gleb@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
sched: remove unnecessary reschedule_from_interrupt() parameter.

Before commit 202b2cccc14a43d088002a80f7add51e3e4bc4ce,
cpu::reschedule_from_interrupt() needed to know whether we were called
from an interrupt (preempt=true) or as an ordinary function (preempt=false),
to know whether or not to save the FPU state.

As we now save the FPU state at the interrupt code,
reschedule_from_interrupt() no longer needs to deal with this, and so this
patch removes the unneeded paramter "preempt" to that function.

One thing we are losing in this patch is the "sched_preempt" tracepoint,
which we previously had when an interrupt caused an actual context switch
(not just a reschedule call, but actually switching to a different thread).
We still have the "sched_switch" tracepoint which traces all the context
switches, which is probably more interesting anyway.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
sched: remove a bit of dead code.

Before commit 202b2cccc14a43d088002a80f7add51e3e4bc4ce, the scheduler
was responsible for saving the FPU state, so we needed to know whether
the scheduler itself uses it or not. Now that the FPU state is always
saved at interrupt time, we no longer care whether or not the scheduler
uses the FPU, so we can drop this flag.

Also drop the optional "pseudo-float" (integer-based floating point
operations) support from the scheduler. This never had any real
advantage over the actual floating point, and now that we save the
FPU state unconditionally, it makes even less sense to avoid floating
point.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
poll: special case POLLIN on one file descriptor

OpenJDK's SocketInputStream.read() is calling poll() to support
timeout. The call site looks like this:

 pfd.fd = s;
 pfd.events = POLLIN | POLLERR;
 poll(&pfd, 1, timeout);

Our current implementation of poll() is quite complex because it needs
to handle polling on many files. It also allocates memory in several
places:
 - in poll() due to std::vector
 - in poll_install()
 - in net_channel::add_poller
 - in net_channel::del_poller

poll() on one socket can be greatly simplified and we can avoid memory
allocation completely. This change adds special casing for that. It
reduces allocation rate in half in tomcat benchmark with 256 connections.

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
test: add test for poll() on a socket

Signed-off-by: Tomasz Grabiec <tgrabiec@cloudius-systems.com>
Signed-off-by: Avi Kivity <avi@cloudius-systems.com>
tests: add auto-load safe-path init command to gdb

Signed-off-by: Elazar Leibovich <elazarl@gmail.com>
/etc/hosts: Remove non-relevant entry

Closes #324

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
shrinker: Fix osv_register_shrinker visibility for C apps

$ capstan run
Created instance: memory-hog
OSv v0.08
I'm a memory hog!
Failed looking up symbol osv_register_shrinker

Reported-by: Don Marti <dmarti@cloudius-systems.com>
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
release-ec2: Choose availability zone dynamically

It turned out that set of availability zones in each region
may be different for different accounts so one should not
hard code availability zone name but choose it dynamically instead.

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
release-ec2: add parameter for OSv modules list specification

--modules-list parameter introduced

Signed-off-by: Dmitry Fleytman <dmitry@daynix.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: Implement fallocate system call

This patch adds fallocate as a vnode operation, implements the
fallocate function and the system call.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: Fix corner-cases where stat variants report out-dated file size

It turns out that vnode->vn_size will not be always synchronized with the file
system underlying the vnode, and vn_stat will always provide its caller with
the file size known by the vfs layer. The latter is changed to get from the
fs instead.

Found the bug while using stat on a file (in zfs) after its was either truncated
or extended. We probably should change zfs later to update vnode->vn_size whenever
the respective znode->z_size is updated.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
zfs: Implement zfs_fallocate

1) zfs_fallocate is ported from ZFS on Linux along with convoff.
zfs_fallocate being limited to FALLOC_FL_PUNCH_HOLE alone, though
not useful as fallocate require FALLOC_FL_PUNCH_HOLE to be ORed
with FALLOC_FL_KEEP_SIZE.

2) (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE) semantics is implemented
in zfs_fallocate. Relevant changes were introduced into zfs_space.

3) From my conversation with ZFS folks, I realized that FALLOC_FL_KEEP_SIZE
alone could be implemented, but it will probably take a long time, and wouldn't
give us the proportional value.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: Add fallocate testcase

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
virtio-vring: rename db_used() -> update_used_event()

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: implement some more terminal functions

Code comes from musl, but is moved to libc.cc to be together with the other functions
already present there.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
libc: implement the whole mnt* family of functions

We had an implementation of getmntent, but its signature was wrong to begin
with. I doubt it was ever working, since it is not such a common function. But
even then, we lacked other functions in this family, like setmntent.

This patch implements them all. The main matching code comes from musl, but the
end result is significantly different. In particular, I didn't really want to
mess with creating new virtual proc files, symlinks and the such. Instead,
trying to opening a dynamic file (like /proc/mounts) or any of its famous
aliases will return a special value.

Functions like getmntent will be able to parse that value and act accordingly.
The code to show dynamic mounts comes from our old getmntent() implementation,
but it is here modified to not use statics for the strings so we can implement
getmntent_r() correctly.

Fixes #326

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
CC: Lyor Goldstein <lgoldstein@vmware.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
mount: read initial entries from fstab

The main problem with supporting the setmntent function is not the code per se
- which is itself quite trivial. Rather, one expects that if this function (and
addmntent, for instance) is being used, somebody is about to make changes to the
system's initial mount points. We can make this all volatile, but I suspect users
would be frustrated to find out that the modifications made won't be reflected in
the system.

What this patch does, is that it creates an fstab file that is included in the
main build and contains our currently dynamic mounts for proc and dev.  When
OSv finds such a file, it will proceed mounting them.

The results here should be the same except for people booting using
bootfs.manifest, IOW, our initial build. Since we can build fine without those
pseudo filesystems, I didn't really bother doing anything about it.

I know this patch can be a bit polemic, since dynamically building a filesystem
list without depending on any file fits our model a bit better towards being
stateless as much as we can. But I believe it to be the right approach since
it will allow all the *mntent functions to write with the correct expectations.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
CC: Lyor Goldstein <lgoldstein@vmware.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
poll: fix poll_sync() on unconnected sockets

An unconnected socket needs to wait for a connection event; this does not
change sockbuf::sb_cc and so can't be waited on with sbwait().

Detect this and bail out early.

Signed-off-by: Avi Kivity <avi@cloudius-systems.com>