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>
Merge branch 'master' of https://github.com/cloudius-systems/osv