Commit Graph

555 Commits (65de83140aa6264b75a8cb5eda9e0ba1b1f56b9b)

Author SHA1 Message Date
Ronnie Sahlberg b7fd060bc6 Do not fail the session just because the reply we got can not be matched to a pdu
The command might have simply timed out and this will not match anything in our
wait queue.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-31 21:06:36 -07:00
Ronnie Sahlberg 173ad2b1f3 Change how auto-reconnect works
For NFS sessions, change the autoreconnect options to be :
-1:  (default) retry connectiong back to the server forever. Just like
normal NFS clients do.
0: Do not attempt reconnecting at all. Immediately fail and return an
error back to the application on session loss.
>=1: Retry connecting to the server this many times before giving up.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-31 19:46:18 -07:00
MilhouseVH eee1b4f7f2 use-after-free: quick hack 2017-05-14 16:18:05 -07:00
Ronnie Sahlberg 6afd405587 Merge branch 'master' into issues-215 2017-05-11 18:51:13 -07:00
Ronnie Sahlberg f8ce80d454 Merge branch 'master' into issues-216 2017-05-11 18:30:30 -07:00
Ronnie Sahlberg f6895705c4 Merge pull request #220 from kevin-vigor/master
Fix crash on timed out mount-nfs calls.
2017-05-11 18:26:01 -07:00
Kevin Vigor 4cd723fb7a Fix crash on timed out mount-nfs calls.
If wait_for_nfs_reply() times out, nfs_mount can return with RPCs
still pending. In that case when the RPCs complete (perhaps because
someone calls destroy_context()), the callbacks run, and private_data
is pointing at what was the stack-allocated cb_data structure. Stack
smashing and segfaulty fun ensue.

Fix by ensuring no RPCs are pending before returning from nfs_mount()
by disconnecting on errors.
2017-05-11 15:19:01 -06:00
Earl Chew 5a2afb8872 Deliver poll(2) errors to callbacks when running the sync event loop
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-11 07:00:49 -07:00
Earl Chew f986a53835 Only process pdus once when propagating cancellations or errors
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-10 19:20:34 -07:00
Ronnie Sahlberg 367ef3b189 Merge pull request #213 from earlchew/issues-212
Allow autoreconnect to be disabled
2017-05-10 18:13:56 -07:00
Ronnie Sahlberg 2db0878396 Use clock_gettime(CLOCK_MONOTONIC_COARSE) if/when available
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-10 18:11:00 -07:00
Ronnie Sahlberg 14adfbfc4b Merge pull request #211 from earlchew/issues-210
Check result of FSINFO before using result in nfs_mount_10_cb()
2017-05-09 22:26:23 -07:00
Ronnie Sahlberg d8d9e5556b Merge pull request #214 from earlchew/issues-206-01
Return an error if either readmax or writemax are less than NFSMAXDATA2
2017-05-09 22:07:18 -07:00
Earl Chew 2f041424d5 Return an error if either readmax or writemax are less than NFSMAXDATA2
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 21:55:03 -07:00
Earl Chew 5e43d0a92f Allow autoreconnect to be disabled
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 21:43:31 -07:00
Earl Chew 63d6679132 Check result of FSINFO before using result in nfs_mount_10_cb()
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 21:35:30 -07:00
Ronnie Sahlberg bf7d983812 Merge pull request #208 from earlchew/issues-200
Latch error return from nfs_mount_8_cb()
2017-05-09 21:29:22 -07:00
Earl Chew 6e99d36587 Latch error return from nfs_mount_8_cb()
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 21:22:46 -07:00
Earl Chew c7995b4fec Revert "Provide error return from nfs_mount_8_cb()"
This reverts commit a4de2ec926.

Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 21:22:06 -07:00
Ronnie Sahlberg 13c253673b We do not need an async version of readlink2
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-09 14:56:44 -07:00
Ronnie Sahlberg 973d368867 Merge pull request #194 from earlchew/issues-187
nfs_readlink2: Return symlink without incurring ENAMETOOLONG
2017-05-09 14:55:27 -07:00
Ronnie Sahlberg 519686356c Export the nfs_readlink2[_async] symbols from the win32/64 DLL
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-09 14:53:12 -07:00
Ronnie Sahlberg ebd98bf966 Merge branch 'master' into issues-199 2017-05-09 14:49:58 -07:00
Ronnie Sahlberg 36d5cf8a1c Merge pull request #204 from earlchew/issues-200
Provide error return from nfs_mount_8_cb()
2017-05-09 14:33:03 -07:00
Ronnie Sahlberg 5b28ab5d53 Include sys/sysmacros.h on platforms that have it
This addresses issue 202

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-09 14:30:14 -07:00
Earl Chew a4de2ec926 Provide error return from nfs_mount_8_cb()
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 07:15:11 -07:00
Earl Chew be6fd2b098 Free inbuf in rpc_destroy_context()
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-09 07:10:23 -07:00
Earl Chew e74846219a nfs_readlink2: Return symlink without incurring ENAMETOOLONG
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-08 21:56:50 -07:00
Earl Chew e788078e20 Revert "nfs_readlink2: Return symlink without incurring ENAMETOOLONG"
This reverts commit 1af36b4c77.

Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-08 21:55:54 -07:00
Ronnie Sahlberg ea3ee73e23 Merge pull request #192 from earlchew/issue-191
nfs_open: Support O_NOFOLLOW
2017-05-08 21:00:55 -07:00
Ronnie Sahlberg 15c7b4c33a Add mkdir2() to the symbols we export for win32/64
and will at some point restrict export to for .so libraries as well.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-08 20:54:36 -07:00
Ronnie Sahlberg 2589086ce5 Merge pull request #193 from earlchew/issues-189
nfs_mkdir2: Include permissions when creating a new directory
2017-05-08 20:52:55 -07:00
Ronnie Sahlberg 3ad4ac1b1e Merge branch 'master' of github.com:sahlberg/libnfs 2017-05-08 18:40:10 -07:00
Ronnie Sahlberg b5c5d5901e Add support for rpc timeouts to the async interface
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-08 18:38:42 -07:00
Ronnie Sahlberg 58ee12fcc7 Merge pull request #198 from earlchew/issues-197
Release callback data on nfs_create_2_cb() failure
2017-05-08 15:55:01 -07:00
Earl Chew b356c06eca Release callback data on nfs_create_2_cb() failure
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-08 15:44:48 -07:00
Earl Chew 1af36b4c77 nfs_readlink2: Return symlink without incurring ENAMETOOLONG
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-05 07:57:28 -07:00
Earl Chew adcfda60fa nfs_mkdir2: Include permissions when creating a new directory
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-05 07:55:09 -07:00
Earl Chew 9bd2ceddd3 nfs_open: Support O_NOFOLLOW
Signed-off-by: Earl Chew <earl_chew@yahoo.com>
2017-05-05 07:50:35 -07:00
Ronnie Sahlberg 64f7e73ded Fix bug in nfs_link when using the wrong(invalid) handle when dropping cache
This should be a fix for issue 186

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-02 17:50:47 -07:00
Ronnie Sahlberg 24064e96d2 Add example util for nfs_link()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-02 17:36:27 -07:00
Ronnie Sahlberg a523f84353 Clamp read/write max size for servers that accept huge PDUs
Clamp the max read write size we handle to NFS_MAX_XFER_SIZE for servers
that advertize very large PDU support instead of erroring out.

Fix for issue #188

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-05-01 20:37:35 -07:00
Kevin Vigor 9e2dc9795a Make nfs_close_async call flush on the file handle before disposing of it. 2017-04-03 14:30:03 -06:00
Max Kellermann 43feceea8d don't call rpc_free_pdu() after rpc_queue_pdu() failure
rpc_queue_pdu() already calls rpc_free_pdu() in its failure code
path.  Doing that again would constitute a double free bug.
2017-03-08 14:29:06 +01:00
Ronnie Sahlberg 70df81c16a Merge pull request #173 from rosslagerwall/reconnect-retries
socket: Limit reconnect retries to 10
2017-03-02 17:07:13 -08:00
Daniel Abrecht 7882711c8c Fix crosscompile with *-w64-mingw32-gcc 2017-02-26 18:14:30 +00:00
Ross Lagerwall 08e1cc2f4d socket: Limit reconnect retries to 10
Limit the number of retries when autoreconnecting (to an arbitrary 10)
and return an error to the application if this limit is reached.
Without this, libnfs retries indefinitely and consumes 100% CPU.

See also: https://bugzilla.gnome.org/show_bug.cgi?id=762544

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2017-02-26 09:36:09 +00:00
Ronnie Sahlberg 2e0a67fcb9 Merge branch 'master' of github.com:sahlberg/libnfs 2017-02-19 09:15:43 -08:00
Ronnie Sahlberg 6923a99262 Fix memory leak of nested mount list
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-02-19 09:14:29 -08:00
Max Kellermann 038af3a5ff socket: pass u_long* to ioctlsocket()
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms738573(v=vs.85).aspx
2017-02-10 23:43:21 +01:00
Max Kellermann 03f3cdf9a9 lib/pdu: remove unnecessary NULL check before free()
free(NULL) is explicitly legal.
2017-02-09 12:53:45 +01:00
Max Kellermann 2b3c164db2 lib/pdu: don't clear pointers in rpc_free_pdu()
Pointless, because the containing object is going to be freed.
2017-02-09 12:53:45 +01:00
Max Kellermann 2f703bd84d lib/pdu: fix memory leaks in rpc_allocate_*()
All error code paths must contain cleanup for all allocations until
that point in the function.  Yay for plain C.
2017-02-09 12:52:22 +01:00
Ronnie Sahlberg 906d09f32f Merge pull request #168 from MaxKellermann/cloexec
Use SOCK_CLOEXEC
2017-02-08 17:28:41 -08:00
Max Kellermann 31cb099f50 init: remove pdu from list before invoking callback
If the callback does anything fishy that modifies the linked list,
libnfs may crash after returning.  So doing any pending list removals
before invoking the callbacks is safer.
2017-02-08 12:14:52 +01:00
Max Kellermann 26d90c0663 lib/socket: use SOCK_CLOEXEC in create_socket() 2017-02-08 11:53:00 +01:00
Max Kellermann 46448bccb4 lib/socket: add function create_socket()
Prepare for SOCK_CLOEXEC support.
2017-02-08 11:52:32 +01:00
Ronnie Sahlberg 1d6600652c Merge pull request #167 from MaxKellermann/static
init: move static to beginning of declaration
2017-02-04 17:34:44 -08:00
Max Kellermann ddc37a365e init: move static to beginning of declaration
Fixes gcc's -Wold-style-declaration.

Signed-off-by: Max Kellermann <max.kellermann@gmail.com>
2017-02-03 19:56:35 +01:00
Max Kellermann 03ac15de5e Allow passing void* buffers, and make write buffers const
Enables callers to pass any opaque data chunk without having to cast
it explicitly.

A write never modifies the source buffer, and thus the pointer should
be const.

Signed-off-by: Max Kellermann <max.kellermann@gmail.com>
2017-02-03 19:42:12 +01:00
Ronnie Sahlberg d6a21b2bda Make rpc_set{g|u}id() public
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-01-30 17:47:18 -08:00
Peter Lieven 25ce137d45 socket: Batch pdu read in rpc_read_from_socket
rpc_read_from_socket can currently only read one PDU in each rpc_service invocation even
if there is more data available on the socket. This patch reads all PDUs until the socket
would block.

Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-12 14:52:51 +01:00
Peter Lieven c711c568c1 rpc: track the number of pdus in the waitpdu queues
Signed-off-by: Peter Lieven <pl@kamp.de>
2017-01-12 14:38:11 +01:00
Peter Lieven bd16e8db5c Revert "socket: batch pdu read in function rpc_read_from_socket"
The ioctl version breaks Qemu. I will post an updated once we found
a good solution in libiscsi and then adapt it to libnfs.

This reverts commit 003b3c7ce2.
2017-01-05 12:13:56 +01:00
Ronnie Sahlberg 77ae1fbed4 Merge pull request #158 from plieven/for_upstream
For upstream
2016-12-26 17:22:34 -08:00
Ronnie Sahlberg 01ca79972a WIN32: SO_TYPE is a char on windows not int.
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-26 17:05:01 -08:00
Ronnie Sahlberg ca67c18db2 Fix compiler warning for min/max version being unset (which can not happen)
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-26 16:51:28 -08:00
Peter Lieven 003b3c7ce2 socket: batch pdu read in function rpc_read_from_socket
rpc_read_from_socket can currently only read one PDU in each rpc_service invocation even
if there is more data available on the socket. This patch reads all PDUs available on
the socket when rpc_read_from_socket is entered.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-12-22 15:43:58 +01:00
Peter Lieven a22464c380 socket: avoid to realloc the rpc->inbuf
we always read 4 bytes to get the PDU size and than realloc
these 4 bytes to the full size of the PDU. Avoid this by
using a static buf for the record marker.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-12-22 15:43:54 +01:00
Peter Lieven a0249fe9a6 socket: don't leak buf in case of rpc_process_pdu error
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-12-22 15:43:49 +01:00
Ronnie Sahlberg 2d348242c5 Make zdr_malloc() visible outside of libnfs-zdr.c
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg 57a9bd8565 Automatically detect if a server context fd is a UDP socket or not
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg eb6b39125c Initial rpc server support
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg 6f860fd874 Add ZDR* and void* as arguments to zr_void so that it can be used as a zdrproc_t
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg 7596d0f300 Use a static sockaddr_storage for rpc.udp_dest
There is no need to allocate and deallocate this structue every time
we update the udp destinateion.

For the client side, where we set the destination just once per lifetime
of the context it might not matter too much but once we add udp server support
we will need to update the sockaddr for every rpc we receive.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg 853474d387 Add NFSv4 protocol definitions
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-17 10:44:12 -08:00
Ronnie Sahlberg 9eaa36c4bf Remove sockaddr argument to rpc_connect_sockaddr_async
We always use the rpc->s as the sockaddr so no need to pass it by argument

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-01 15:02:46 -08:00
Ronnie Sahlberg dccffb86ee Create a new helper function to set the sockaddr for a rpc context
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-01 15:02:34 -08:00
Ronnie Sahlberg 6f8b2f85ca socketsize is of type socklen_t not int
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-12-01 08:37:55 -08:00
Ronnie Sahlberg 11f85665fc Add a PDU flag for discard after sending.
Add a flags field to rpc_pdu and add a flag that indicates that the PDU
should be discarded as soon as it has been written to the socket.
We do not put it on the waitpdu queue nor do we wait for a reply.

This will later be used for when we are sending replies back to a client
when operating in a server context.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-11-29 05:12:03 -08:00
Ronnie Sahlberg 6f27daf6d4 Create a generic RPC NULL function
This allows us to use the NULL function for any arbitrary
program/version from rpc_connect_program() instead of the hardcoded support
for mount v3 and nfs v3

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-11-27 12:50:06 -08:00
Ronnie Sahlberg 468424c475 ZDR_ARRAY: remove the check for element-size * num-objects
In zdr_array we can not use the check that num_elements * element_size
will fit inside the remaining bytes in the ZDR buffer.
The reason for this is that IF it is an array of unions, then
element-size will have the size of the largest arm in that union.

If the array consists of union items that are smaller than the largest arm,
then it becomes likely that this will pack in less than num_elements *
element_size and this it is possible that the array WILL fir in the remaining
bytes.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-11-25 14:47:00 -08:00
Ronnie Sahlberg 2edbd14779 New version 1.11.0
- Reduce the number of memory allocations in the ZDR layer.
 - Check both seconds and nanoseconds field when validating dir cache.
 - Invalidate the dir cache immediately if we do something that would cause
   it to become stale, such as adding/removing objects from the cache.
 - Add options to enable/disable dir caching.
 - Discard readahead cache on [p]write and truncate.
 - Android fixes
 - Windows fixes
 - Support timeouts for sync functions
 - Add an internal pagecache
 - Add nfs_rewinddir(), nfs_seekdir() and nfs_telldir()
 - Fix crash in nfs_truncate()
 - Fix segfault that can trigger if we rpc_disconnect() during the mount.
 - Add support to bind to a specific interface (linux only)

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-10-09 11:23:11 -07:00
Ronnie Sahlberg 235cb45e69 Conditionally define _GNU_SOURCE
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-10-09 11:23:11 -07:00
sahlberg dc8e10df07 WIN32: compiler warnings 2016-09-21 10:49:59 -07:00
sahlberg 6b6d6084d0 WIN32: Fix types for max_watch_len st_dev and st_ino 2016-09-21 09:45:55 -07:00
sahlberg 3d1351bf82 WIN32: make pagecache ttl of type time_t
We both compare and compute using the ttl value with variables of
type time_t. Thus is makes most sense to have ttl as time_t too.
2016-09-21 09:32:45 -07:00
sahlberg e53758fc43 compiler warnings 2016-09-20 17:45:05 -07:00
sahlberg 6d3e9814fa more win32 fixes 2016-09-20 17:44:42 -07:00
sahlberg 4c3d809e07 WIN32: Don't call assert() before all variables are declared.
VisualStudioOnline does not like when you intermingle variable
definitions and code so move the assert() to after the variables
are all declared.
2016-09-20 17:37:48 -07:00
Ronnie Sahlberg 6cde2aca64 Conditionally include unistd.h from libnfs-zdr.c as some platforms lack this header
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-09-20 17:36:19 -07:00
Chris 5f75307a36 Added the ability to bind to a specific interface with the
`nfs_set_interface` and `rpc_set_interface` APIs, or via the
NFS URL `if=<interface>` parameter. This feature requires
`root` permissions.

NOTE: This has only been compiled and tested on Ubuntu 14.04. It's
unlikely that it'll work on other platforms without modification,
particularly around the inclusion of <net/if.h> and IFNAMSIZ define
in `libnfs-private.h`.
2016-09-19 18:31:49 -07:00
Ronnie Sahlberg fac3a95453 Make rpc_disconnect() a no-op if the session is already disconnected
This addresses a bug causing a segfault if we destroy the nfs context/
disconnect the session while the mount_8_cb callbacks for checking the
filehandle for nested mountpoints are still in flight.

Issue found and reported by doktorstick

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-07-05 13:18:17 -07:00
Ronnie Sahlberg 28e01e67b1 Add seekdir and telldir support
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-07-05 10:14:49 -07:00
Ronnie Sahlberg cdbcdfd736 Update some comment and fix typos
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-07-05 09:59:30 -07:00
Ronnie Sahlberg 4388570dc4 Merge pull request #151 from benoit-canet/rewinddir
nfs_rewinddir: introduce additional nfs_rewinddir()
2016-06-21 19:28:20 -07:00
Ronnie Sahlberg 4cc09b972a Fix crash in nfs_truncate due to dereference of uninitialized data
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-06-21 19:25:27 -07:00
Benoît Canet 352fb5bb70 nfs_rewinddir: introduce additional nfs_rewinddir()
Introduce the nfs_rewinddir() utility function used
to cancel previous nfs_readdir() side effects.

Signed-off-by: Benoît Canet <benoit@scylladb.com>
2016-06-07 08:36:27 +02:00
Peter Lieven 10546da322 pagecache: define hash constant as UL
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-06-03 13:46:48 +02:00
Ronnie Sahlberg f9455e5ba5 gcc 5.3 does not allow casting a char * to any longer, so cast via void *
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-06-02 09:20:54 +02:00