Commit Graph

772 Commits (6f860fd874bfb78ac1a74285fefecc339258bb03)

Author SHA1 Message Date
Jean-Baptiste Kempf cd53647f53 Win32: link utils with winsock2 2016-01-08 23:23:00 +01:00
Jean-Baptiste Kempf 3ca22dcfdd Win32: Add win32_compat.h include 2016-01-08 23:23:00 +01:00
Jean-Baptiste Kempf 6adcfdcd56 Win32: Mingw has utimbuf 2016-01-08 23:08:11 +01:00
Jean-Baptiste Kempf 76daf49d2d Win32: Mingw has timezone and mingw_gettimeofday 2016-01-08 23:08:06 +01:00
Jean-Baptiste Kempf 6d30222b04 Win32: use lower-case for Windows headers
This does not change a thing for MSVC, but This is needed for
Cross-Compiling with Mingw/Mingw-w64
2016-01-08 22:29:50 +01:00
Ronnie Sahlberg 6f4ff8621f Handle POLLERR/POLLHUP properly and try to reconnect on failure
POLLERR and POLLHUP handling in rpc_service() could not deal with
session failures or auto reconnect.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-28 08:02:15 -08:00
Ronnie Sahlberg 034c277c71 Make rpc->connect_cb a one-shot callback
It makes no sense to have socket.c keep invoking this callback over and over.
Just change it to become one-shot.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-24 18:01:19 -08:00
Ronnie Sahlberg aea2810c1e Do not use ioctl(FIONREAD) for UDP sockets
The linux kernel does not check the UDP checksum until the application tries
to read if from the socket.

This means that the socket might be readable, but when we try to read
the data, or inspect how much data is available, the packets will be discarded
by the kernel.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-24 12:21:33 -08:00
Ronnie Sahlberg 1ec2d0c5b7 Add check that we have the full RM before starting to read the PDU data
If we are trying to read (part of?) the RM, we can not assume that as long
as recv() returned non-error that we have the full RM.
We must check before we proceed to try to read the actual PDU data.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-12-24 12:06:45 -08:00
Ronnie Sahlberg f681a2c167 Revert some commits that cause subtle API issues
We can not have a static rpc->inbuf buffer since that will no longer guarantee
that the received buffer is valid for the duration of callbacks.

One of the problems is that if we issue new (sync) RPCs from within a
callback, that will overwrite and invalidate the receive buffer that
we passed to the callback.

Revert "init: do not leak rpc->inbuf"
This reverts commit f7bc4c8bb1.

Revert "socket: we have to use memmove in rpc_read_from_socket"
This reverts commit 24429e95b8.

Revert "socket: make rpc->inbuf static and simplify receive logic"
This reverts commit 7000a0aa04.
2015-12-24 12:06:22 -08:00
Ronnie Sahlberg dc8d86628d Remove FUSE NFS filesystem
Remove the fuse module from the examples subdirectory.
This module is now a standalone repo :
https://github.com/sahlberg/fuse-nfs

And it comes with proper build rules, documentation etc etc.
It is a useful module and it has now graduated to become its own
repo.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-10-19 18:59:38 -07:00
Ronnie Sahlberg 4d102bd24d Improve the documentation for *_get_fd/*_which_events/*_service
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-10-19 18:57:30 -07:00
Ronnie Sahlberg d73d4f3305 rpc_reconnect_requeue: return -1 if autoreconnect is not enabled
This funciton is called from rpc_service when it has detected that
a socket has errored out during reading/writing.
However, since this fucntion returns 0 (==success) for the case where
autoreconnect is not enabled, this means that for an errored socket we
will return 0 (==success) from rpc_service() back to the application.

Change rpc_reconnect_requeue to return -1 when invoked and autoreconnect
is disabled so that applications will receive an error back from rpc_service.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-10-19 18:57:17 -07:00
Ronnie Sahlberg 82d2a22807 Merge pull request #130 from plieven/fix_fd
fix some reconnect issues
2015-09-28 19:25:17 -07:00
Peter Lieven ddd9e2f7e9 socket: keep fd the same across reconnects
There is no guarantee that we get the same fd again when
reestablishing a session. But if the fd changes during a
reconnect we might up with a client application busy polling
on the old fd.

Qemu registers a read handler on the current fd, but is
not realizing fd changes. So we busy poll on the old fd for good.
Things are working (except for the busy polling) until
a drain all is issued. At this point Qemu deadlocks.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-09-22 14:54:48 +02:00
Peter Lieven 7b7aef6b6d socket: keep reconnecting if a reconnect fails
otherwise we end up eating up all socket errors in rpc_service and then
believe we are connected, but the next call to rpc_read_from_socket
fails because the socket is closed. we then reconnect anyway.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-09-22 14:40:59 +02:00
Ronnie Sahlberg e453431d00 Merge pull request #129 from agraf/fuse-commands
Fuse commands
2015-09-11 05:01:04 -07:00
Alexander Graf 883f660430 fuse_nfs: Add fsync
Libnfs already has exports for fsync, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:24:47 +02:00
Alexander Graf 9439361243 fuse_nfs: Add truncate
Libnfs already has exports for truncate, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:24:09 +02:00
Alexander Graf b66121610d fuse_nfs: Add chown
Libnfs already has exports for chown, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:23:35 +02:00
Alexander Graf 315112b923 fuse_nfs: Add chmod
Libnfs already has exports for chmod, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:23:03 +02:00
Alexander Graf d1709ab573 fuse_nfs: Add link
Libnfs already has exports for link, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:22:29 +02:00
Alexander Graf 37fd16ee08 fuse_nfs: Add rename
Libnfs already has exports for rename, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:21:31 +02:00
Alexander Graf 50aabd0729 fuse_nfs: Add symlink
Libnfs already has exports for symlink, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:20:49 +02:00
Alexander Graf 618b6ea030 fuse_nfs: Add mknod
Libnfs already has exports for mknod, hook them up to the fuse example.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 11:19:52 +02:00
Ronnie Sahlberg c7204781b1 Merge pull request #128 from agraf/fuse-symlinks
Fuse symlinks
2015-09-10 17:34:29 -07:00
Alexander Graf 39d1f3693c fuse_nfs: Add symlink support
The fuse framework allows us to directly expose symlinks from NFS to the user,
just like a real NFS mount would. All we need to do is call lstat rather
than stat and implement a readlink function.

With this patch I can successfully chroot into a rootfs mounted using
fuse_nfs.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 00:23:48 +02:00
Alexander Graf e81f9e23ab fuse_nfs: Consider st_.tim as struct timespec
At least in my version of glibc the members st_mtim, st_ctim and st_atim
are defined as struct timespec rather than struct timeval, thus
containing a tv_nsec field rather than tv_usec.

Use the proper struct fields instead, fixing compilation on Linux.

Signed-off-by: Alexander Graf <agraf@suse.de>
2015-09-11 00:22:09 +02:00
Ronnie Sahlberg 2a95006567 Merge pull request #122 from plieven/fix_recv
socket: also reconnect on write errors
2015-09-06 06:57:32 -07:00
Ronnie Sahlberg 96142f98ff Merge pull request #127 from plieven/for_upstream
socket: fix deadlock in rpc_reconnect_requeue
2015-09-06 06:55:55 -07:00
Ronnie Sahlberg c859ac8bd7 Merge branch 'master' of github.com:sahlberg/libnfs 2015-09-06 06:53:47 -07:00
Ronnie Sahlberg c078a42353 Fix OSX build.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-09-06 06:52:44 -07:00
Peter Lieven 5c7a0f04e6 socket: fix deadlock in rpc_reconnect_requeue
the requeueing code is broken because we access pdu->next
after we mangled it in rpc_return_to_queue.

This leads to losing of waitqueue elements and more severe
a deadlock as soon as more than one waitpdu queue has elements.

Reason for that is that the first elements of the first
two queues are linked to each other.

Example:
waitpdu[0]->head = pduA ; pduA->next = pduB; pduB->next = NULL;
waitpdu[1]->head = pduC ; pduC->next = NULL;
outqueue->head = NULL;

After the for loop for waitpdu[0] queue the outqueue looks like

outqueue->head = pduA; pduA->next = NULL;

At this point pduB is lost!

In the for loop for waitpdu[1] queue the outqueue looks like this
after the first iteration:

outqueue->head = pduC; pduC->next = pduA; pduA->next = NULL;

We now fetch pdu->next of pduC which is pduA.

In the next iteration we put pduA in front of pduC. pduA->next
is then pduC and pduC->next is pduA. => Deadlock.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-08-28 21:13:37 +02:00
Ronnie Sahlberg aea3b9be1c Merge pull request #125 from alonbl/build
build: add m4 directory to source tree
2015-08-23 15:28:14 -07:00
Alon Bar-Lev 8338c7e27f build: add m4 directory to source tree
m4 directory is required for autotools generation, the use of bootstrap
script is nice helper, however, the autoreconf -ivf should be usable
for autotools based checkout without any other action.

these days the bootstrap script is kinda useless, in the old days it was
a very complex set of autoconf/automake/libtool/gettext commands.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2015-08-24 01:05:00 +03:00
Ronnie Sahlberg cc69b9c189 Merge pull request #123 from plieven/fix_rpc_error
init: do not write to stderr in rpc_set_error
2015-08-06 05:40:42 -07:00
Peter Lieven 29ab169d2b init: do not write to stderr in rpc_set_error
only log error if debug >= 1.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-08-06 10:12:04 +02:00
Peter Lieven aacee393ca socket: also reconnect on write errors
This also return -1 for rpc_service if rpc_reconnect_requeue fails.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-08-06 09:53:49 +02:00
Ronnie Sahlberg e466dc6b03 Merge pull request #121 from plieven/fix_recv
socket: handle count == 0 in rpc_read_from_socket
2015-08-04 16:12:43 -07:00
Peter Lieven b319b976dc socket: handle count == 0 in rpc_read_from_socket
An EOF is signalled through a POLLIN event and subsequen recvs return
always 0. Handle this condition and reconnect. Otherwise we might
deadlock here.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-08-04 14:55:28 +02:00
Ronnie Sahlberg 2288339ed4 Merge pull request #120 from plieven/m4_fix
bootstrap: create m4 directory
2015-08-02 11:04:27 -07:00
Ronnie Sahlberg 8f06fc9d92 New version 1.9.8
- Disable multithreading in fuse_nfs
- Add -Wall and -Werror compiler flags (and fix issues found by it)
- Add nfs-cat utility
- Switch to using nfs_[f]stat64 instead of the deprecated nfs_[f]stat call
  in all examples
- If the server does not return any atttributes for entries in READDIRPLUS
  then try to fetch them using lookup instead.
- Reconnection fixes
- Enforce the max pdu size and add sanity checks when reading PDUs from
  the socket.
- Stop using ioctl(FIONREAD) to find out how many bytes to read, and treat
  0 as an indication of a problem. Some applications call their POLLIN handlers
  spuriosly even when there is no data to read, which breaks this check in
  libnfs.
- Add basic support to do logging.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-08-02 10:18:25 -07:00
Peter Lieven b09a55f3d3 bootstrap: create m4 directory
newer versions of autotools fail if the directory is not there.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-07-14 14:20:48 +02:00
Ronnie Sahlberg 68941809a8 Merge pull request #118 from plieven/for_upstream
For upstream
2015-06-23 14:17:35 -07:00
Peter Lieven 9bff07490f add basic support for setting a log level
only logging to stderr is supported at the moment. Per default
there is no output. Its possible to set the log level via
debug url parameter.

Example:
 nfs-ls nfs://127.0.0.1/export?debug=2

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-23 08:55:11 +02:00
Peter Lieven f7bc4c8bb1 init: do not leak rpc->inbuf
additionally free(NULL) is a NOP. So simplify the code

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 16:22:20 +02:00
Peter Lieven 24429e95b8 socket: we have to use memmove in rpc_read_from_socket
I was errornously believing that the areas could not overlap.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 15:54:54 +02:00
Peter Lieven beaa838637 fix some compiler warnings
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:49:17 +02:00
Peter Lieven 7000a0aa04 socket: make rpc->inbuf static and simplify receive logic
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:45:26 +02:00
Peter Lieven 82aec93f12 socket: limit memory allocation when reading from socket
the write limit of libnfs has been 1M since a long time.
Restrict rtmax and wrmax to 1M and error out otherwise.

Limit the PDU size when reading from socket to rule out
malicious servers forcing us to allocate a lot of memory.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:45:20 +02:00