percpu_xmit: Use a proper memory order in clear_pending()

std::memory_order_release -> std::memory_order_seq_cst
We need to ensure that clear_pending() is not reordered with _mg.pop()
in poll_until().

We use a "relaxed" ordering in the clear_pending() itself (renamed to
clear_pending_weak()) and if _mg.pop() returns FALSE we put an
std::atomic_thread_fence(std::memory_order_seq_cst) and call for
_mg.pop() again to ensure the proper ordering.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
vfs: fix errno in sendfile()

The man-page of sendfile() says to return the following on errors:

EBADF  The input file was not opened for reading or the output file was
       not opened for writing.

EINVAL Descriptor is not valid or locked, or an mmap(2)-like operation
       is not available for in_fd.

But sendfile() on Linux returns EBADF when the descriptor is not valid.
It return EINVAL when writing to the file has failed.  Change sendfile()
to behave the same as Linux.

Also, replace C style code with C++ such as using mmu::page_size instead
of PAGESIZE.

Reviewed-by: Nadav Har'El <nyh@cloudius-systems.com>
Signed-off-by: Jaspal Singh Dhillon <jaspal.iiith@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
tests: fix tst-sendfile.cc

Fix test to expect EBADF on a bad fd.
Use std::thread to allow the test to be compiled and run on linux.
Move the setup part (socket(),bind(),listen()) of server outside the thread.

Signed-off-by: Jaspal Singh Dhillon <jaspal.iiith@gmail.com>
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>