Commit Graph

679 Commits (master)

Author SHA1 Message Date
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
Peter Lieven 9cb49494c7 pdu: drop the rpc->encodebuf
the only call thar really needs a big encodebuf is WRITE. So give each
PDU its private encodebuf. This avoids the need to memcpy the data from
the static rpc->encodebuf to the pdu->outdata.data.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-06-02 09:12:53 +02:00
Peter Lieven 21c466254a libnfs: avoid a bounce buffer in pread if possible
there are cases where we do not need the bounce buffer. So avoid
the overhead of malloc, memcpy and free.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-31 22:03:02 +02:00
Peter Lieven 14492d5c65 pagecache: allow readahead and pagecache options to coexist
before this setting readahead would always modify the pagecache,
but it might be desireable to have a greater pagecache and only
a reasonable small readahead.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-31 12:05:20 +02:00
Peter Lieven 5a660d5afc libnfs-sync: make send_nfsd_probes portable
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-31 12:03:10 +02:00
Peter Lieven 36d687cdbc pagecache: avoid time() syscall if the cache has no ttl
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-31 08:34:17 +02:00
Peter Lieven 453db33f07 pdu: fix potential overflow in rpc_get_pdu_size
(size & 0x7fffffff) + 4 can overflow an int returning
a negative number.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-30 16:13:39 +02:00
Peter Lieven 295057aba4 socket: really handle count == 0 in rpc_read_from_socket
in commit b319b97 the check for count == 0 was introduced, but
it was accidently reverted in commit f681a2c if pdu->inpos < 4.

This patch fixes this issue resulting in deadlocks and removes
the somewhat redundant receive code.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-30 16:13:32 +02:00
Peter Lieven 922ae3ef4d libnfs: fix compiler warnings on 32bit systems
Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-17 09:10:22 +02:00
Peter Lieven 3e2847226f libnfs: add a pagecache
this adds support for a simple read cache to avoid unnecassary request
to the NFS storage. libnfs by design cannot benefit from the kernel page
cache and suffers from performance penalties in some cases when compared
with a file accessed via kernel NFS.

This patch exposes 3 new API calls:
 void nfs_set_pagecache(struct nfs_context *nfs, uint32_t v);
 void nfs_set_pagecache_ttl(struct nfs_context *nfs, uint32_t v);
 void nfs_pagecache_invalidate(struct nfs_context *nfs, struct nfsfh *nfsfh);

As well as the two new URL parameters pagecache and pagecache_ttl.

pagecache is defined in number of pages where a page is always NFS_BLKSIZE (4kB).
pagecache_ttl takes the page timeout in seconds where 0 means infinite.

Signed-off-by: Peter Lieven <pl@kamp.de>
2016-05-13 12:03:40 +02:00
Ronnie Sahlberg a5408bfa09 zdr string decode: don't memcpy when src and dst pointers are the same
If we are decoding a zdr string and the called did not provide
a pointer/buffer for us. We can just return the string to the rx buffer
immediately and avoid calling libnfs_zdr_opaque().

This avoids wasting cpu cycles on running a memcpy where src and dst buffers
are the same.
2016-03-21 22:06:59 -07:00
Ronnie Sahlberg 3c26ce1e6b Merge pull request #143 from jbkempf/android_ndk_statvfs
Android: only redefine statvfs if it is not already defined
2016-03-14 19:16:28 -07:00
Kuldeep Kumar 83d1005c6b sync apis with timeout values
Add support to timeout sync functions.
Add a field to the rpc context to specify the timeout for functions.
Currently only sync functions support a timeout.
2016-03-14 19:04:53 -07:00
Jean-Baptiste Kempf 41c41aec0b Android: only redefine statvfs if it is not already defined
It is defined with recent platforms version 21 and more recent
2016-03-11 00:09:16 +01:00
Ronnie Sahlberg 8372dbe7d1 Discard readahead cache on pwrite and truncate too
Reported by Dirk Jagdmann

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-24 18:03:48 -08:00
Ronnie Sahlberg cb923a2f54 link/rename uses two directories. We must drop both drom the dircache.
Link and Rename are special since they will process two (often) different
directories. We need to drop both directories from the cache and also do so
BEFORE we clear/steal the data->fh.data.data_val pointer.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-10 22:43:35 -08:00
Ronnie Sahlberg 458f6c2be5 Add option and method to disable/enable directory caching
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-07 16:06:00 -08:00
Ronnie Sahlberg 6d5628bcab Drop the directory cache if we do things that stalify the data
Add calls to explicitely drop the directory cache everytime we do things
that might make the data stale.
Such as adding / removing objects to a directory, changing metadata for
objects etc.

Instead of just dropping the cache, we could use the wcc data.
IF wcc->before is the same timestamp as what we have in the cache
then we can just perform the same mutate on what we have in the cache
to reflect the new state and bump the timestamp of the cache to be wcc->after.
That would be a lot of work though and I am not convinced it is worth it.
After all, the cache is just an optimization to make directory operation
faster.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-06 16:26:35 -08:00
Ronnie Sahlberg b5f961c076 Dir cache: compare also mtime.nseconds when validating the cache
Compare BOTH the seconds field and the nanoseconds field when checking if
the cached directory structure is valid or not.
Linux knfsd and other modern servers actually do set the nanosecond field
so why not check it.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-02-06 16:04:03 -08:00
Ronnie Sahlberg 4476f11b9d Try to avoid allocating memory during zdr string decoding
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-31 16:16:35 -08:00
Ronnie Sahlberg 62daa224d9 Remove the zdr_malloc call when decoding a BYTES blob
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-31 16:15:20 -08:00
Ronnie Sahlberg e3cf674856 Use a single allocation for zdr_mem and the payload
Lets use a single allocation instead of two in the zdr_mem handler.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-31 16:13:47 -08:00
Ronnie Sahlberg 8c391edb17 Use a single allocation for both rpc_pdu and zde_decode_buf
We can save one malloc by storing both the rpc_pdu and decoding buffer
in the same memory block.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-31 16:12:36 -08:00
Ronnie Sahlberg 04363a9274 New version 1.10.0
The biggest changes in this release are:
 - Fix a leak where we leaked one rdpe_cb_data structure on each open_dir()
 - Make building the utils optional
 - Android: the correct define is __ANDROID__ not ANDROID
 - Win32: Use _U_ instead of ATTRIBURE((unused))
 - Win32: Fix nfs_stat declaration for Win32
 - Various fixes for mingw builds
 - Make rpc->connect_cb a one shot callback and improve documentation
 - Remove the FUSE module. It now lives in its own repo
 - Fix POLLERR/POLLHUP handling to properly handle session failures and to
   try to auto-reconnect

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-31 16:06:44 -08:00
Ronnie Sahlberg d827447242 Don't leak a rpde_cb_data structure on each opendir()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2016-01-16 18:37:07 -08:00
Ronnie Sahlberg 66876e2879 Merge pull request #131 from jbkempf/win32_mingw
Support Win32 compilation with Mingw
2016-01-16 08:51:31 -08:00
Jean-Baptiste Kempf d02d5d0f5e The correct NDK define for Android is __ANDROID__
The ANDROID macro is not recommended
2016-01-09 13:35:11 +01:00
Jean-Baptiste Kempf 4f0d26258e Win32: Fix nfs_stat declaration for Win32
So that the definition and declaration match.

There might be another way, with stat64i32 but I'm not confident it will
work with MSVC
2016-01-08 23:41:56 +01:00
Jean-Baptiste Kempf 3ca22dcfdd Win32: Add win32_compat.h include 2016-01-08 23:23:00 +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 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
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 2a95006567 Merge pull request #122 from plieven/fix_recv
socket: also reconnect on write errors
2015-09-06 06:57:32 -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
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
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 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 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
Peter Lieven dc70b92dc6 socket: reset written bytes for head outqueue element
We could be in the middle of writing a PDU while we start reconnecting.

Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:45:15 +02:00
Peter Lieven cf420d32d0 socket: use FIONREAD ioctl only for UDP
under Linux poll might return POLLIN even if there are no bytes available for read.
See select(2) manpage for surious readiness under BUGS.

As a consequence we start dropping TCP connections which are still alive.

Signed-off-by: Peter Lieven <pl@kamp.de>

Conflicts:
	lib/socket.c
2015-06-19 13:45:03 +02:00
Peter Lieven 99ae3c01c4 add some debug output
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:43:55 +02:00
Ronnie Sahlberg 68b0298102 Add missing NULLing of data->continue_data for READDIR
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-26 19:50:00 -07:00
Ronnie Sahlberg d8ba04d9c6 READDIRPLUS: use lookup on entries where the server did not return any attr
Some servers sometimes do not return attrivbutes for files in the RDP
replies. So we need to fallback to using LOOKUPs for these entries
just like we always have to do in the READDIR case.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-05-25 16:53:56 -07:00
Ronnie Sahlberg 63d40b1737 Revert "Remove unused variable from socket.c"
This reverts commit d74a938775.
2015-03-12 20:52:52 -07:00
MilhouseVH d74a938775 Remove unused variable from socket.c 2015-03-12 05:29:56 +00:00
Ronnie Sahlberg 84607f4821 Add -Wall -Werror and friends
Update the configure to add some sanity -W arguments.
A good start is probably :
  -Wall -Werror -Wshadow -Wno-write-strings -Wstrict-prototypes
  -Wpointer-arith -Wcast-align -Wno-strict-aliasing

Fixup the paces in the code that triggers.
(one of which is readahead code which is perhaps broken?)

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-03-10 21:06:38 -07:00
Ronnie Sahlberg e775160243 new version 1.9.7
- Auto-traverse mounts. With this option (default to on) libnfs will
   autodiscover and handle any nested submounts.
 - Remove nfs_get_current_offset. Applications should use seek instead of this function.
 - Add umask() support.
 - Change set_tcp_sockopt() to be static.
 - Android fix for nfs-ls
 - Make S_IFLNK available on windows.
 - Fix a use after free.
 - Fix a bug where truncate() treated offset as 32bit.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-02-09 19:16:56 -08:00
Ross Lagerwall bf52e348ad libnfs: Fix use after free
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2015-02-02 23:32:32 +00:00
Ronnie Sahlberg f6e7505baa libnfs: make continue_int 64 bit to avoid sign extension bug for truncate()
Make the continue_int field we use through the internal callbacks a uint64_t
instead of an int.
This fixes a bug for the truncate function where we pass the offset to truncate
to via this field.

The bug is that otherwise we first truncate the field to an int and then
in the callback we cast this int back to a uint64_t again.

If the user called truncate with an offset that is >= 2^31
then :
IF the 1<<31 bit is cleared then we would truncate to (offset & 0xffffffff)
IF the 1<<31 bit is set, we would instead truncate to (offset | 0xffffffff00000000)

Reported-by: doktorstick at github
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-26 17:11:10 -08:00
Ross Lagerwall 368ee352a6 opendir_cb: Retrieve attributes for a top-level submount correctly
Fix retrieving the attributes for a submount in nfs_opendir when
the submount is an entry of '/'.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2015-01-18 22:18:18 +00:00
Ronnie Sahlberg d1c2c47ff0 Add auto-traverse-mount URL argument and default it to TRUE
Add a URL argument to enable/disable the use of automatic traversal of nested
mounts for a libnfs context. Default it to enabled.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:49:08 -08:00
Ronnie Sahlberg 1eea1c4647 opendir_cb: use attributes from the nested mount in opendir
When opendir_cb encounters an entry that refers to a nested mount, then
replace the attributes with those attributes we collected for this export
during the mount and return those instead.

This makes traversing a director that crosses into a different filesystem
on the server transparent to the client.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:32:31 -08:00
Ronnie Sahlberg 27348486f6 nfs_lookuppath_async: replace path components with nested mount filehandles
Durng nfs_lookuppath_async, check if the requested path traverses into
a nested mountpoint and if so, skip resolving that part of thre path and just
use the filehandle for the nested mount.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:29:14 -08:00
Ronnie Sahlberg c7190d3078 nested_mounts: collect fattr3 data for all nested mounts
During the mount process, once we have connected to NFSd we need to collect
the file attributes for all the filehandles that are associated with
nested mounts.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:24:17 -08:00
Ronnie Sahlberg 08ad1b80c0 nested_mounts: collect filehandles for all nested mounts during nfs_mount()
During the mount process, call MOUNT3 EXPORT and collect a list of all
exports on the server. For any export that is a nested mount to the current
directory we are trying to mount call out to MOUNT3 MNT and collect the
filehandle for those mounts.

Track all nested mounts and their filehandles in a list from the nfs_context.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:19:13 -08:00
Ronnie Sahlberg 7378a13fa6 nfs_mount: rename nfs_mount_10/9/8_cb to nfs_mount_11/10/9_cb
Rename these callback functions to make space for two new functions
nfs_mount_7/8_cb which we will be using to collect information about
nested mounts in a later patch.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:09:37 -08:00
Ronnie Sahlberg 63d893575c opendir_cb: use a fattr3 pointer instead of dereferencing every time
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-17 11:00:48 -08:00
Ronnie Sahlberg 7b46c2bc3e READDIR: Bake the file type into the mode we return
NFS reports type in a separate to mode, where mode only contains
the protection bits. This makes it inconvenient to use when porting programs
since under posix the type is supposed to be part of the mode bits (S_IFMT)

When unmarshalling the directory entries into a nfsdirent structure, bake
the S_IF* file type into where the S_IFMT bits would be.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2015-01-12 20:32:29 -08:00
Ronnie Sahlberg d18b335622 Merge branch 'master' of github.com:sahlberg/libnfs 2015-01-08 07:29:35 -08:00
Mike Cui ac76768170 set_tcp_sockopt should be static, otherwise it prevents linking with libiscsi
which has function of the same name, also not static.

Same fix needs to go in to libiscsi.
2015-01-05 09:25:27 -08:00
Ronnie Sahlberg 0c1a5c464c libnfs.c: add support for nfs_umask
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-09 14:00:15 -08:00
Ronnie Sahlberg b53cd4d76c libnfs.c: remove function nfs_get_current_offset
Remove this function (that no one uses) since this is what
lseek(SEEK_CUR, 0) does.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-09 13:41:28 -08:00
Ronnie Sahlberg 5f6442d1b2 libnfs.c: fix typo, it is readahead not readahaed
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-12-05 08:44:15 -08:00
Ronnie Sahlberg 080d231129 New version 1.9.6
- Add O_TRUNC support for nfs_create
 - Handle OOM during create
 - Return more stats fields as part of readdir since we get these for "free"
   when we use READDIRPLUS
 - Follow symlinks during path resolution
 - Add lchown, lstat and lutimes
 - Replace all [u_]quad types with [u]int types in our RPC layer
 - Solaris build fixes

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-11-25 06:47:55 -08:00
Ross Lagerwall 23b10e1f18 libnfs: Add access2()
Add nfs_access2(), like nfs_access() but it returns the individual
statuses of R_OK, W_OK and X_OK rather than a single success or failure
status.  This saves the latency and overhead of multiple lookups if an
application tries to determine the status of each of R_OK, W_OK and
X_OK.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-09-14 15:41:04 +01:00
Ross Lagerwall c50173cf0d libnfs: Give correct access() results for directories
Map ACCESS3_{MODIFY,EXTEND,DELETE} to W_OK and ACCESS3_{LOOKUP,EXECUTE}
to X_OK so that nfs_access() gives sensible results for directories.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-09-14 15:38:57 +01:00
Ronnie Sahlberg bce63d849c types: remove the [u_]quad type and replace with [u]int64
All current platforms have a quad type that maps to a 64bit scalar.
But there are platforms where quad maps to a 64bit non-scalar.

Replace quad with int64 in the protocol definitions and the ZDR layer
so that these fields will map to a 64 bit scalar also on those platforms
where quad can not be used.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-08-16 14:51:53 -07:00
Ronnie Sahlberg cc3e372de4 socket.c: we need netinet/in.h on some platforms 2014-08-14 18:56:39 -07:00
Ronnie Sahlberg a8c840e834 Merge pull request #97 from rosslagerwall/read-close-crash
libnfs: Don't perform operations on nfsfh after user callback
2014-08-11 06:15:16 -07:00
Mike Frysinger e48cfe9622 fix implicit decls of rpc_{g,s}et_error
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-08-11 06:08:33 -07:00
Mike Frysinger 8d4559dc14 fix typo in chmod funcs
These were accidentally calling chown instead of chmod.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-08-11 06:08:33 -07:00
Mike Frysinger 10a1a78115 fix implicit decl warnings
Include the proper headers to fix warnings like:
libnfs-sync.c:1529:3: warning: implicit declaration of function 'gettimeofday' [-Wimplicit-function-declaration]
libnfs-zdr.c:506:2: warning: implicit declaration of function 'getuid' [-Wimplicit-function-declaration]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

sys/time.h needs to be protected with an ifdef

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-08-11 06:08:05 -07:00
Ross Lagerwall 9cac8a6340 libnfs: Don't perform operations on nfsfh after user callback
Since the user callback may perform operations on the nfsfh (e.g. it
might close it), all updates should be done before the user callback is
called.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-08-10 12:18:56 +01:00
Ross Lagerwall 408cd870b8 libnfs: Fix segfault if O_TRUNC fails when creating
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-08-07 20:45:42 +01:00
Ross Lagerwall 8d59066720 libnfs: Add lchmod
Add lchmod which is like chmod but operates on the symbolic link itself
if the destination is a symbolic link.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:26:54 +01:00
Ross Lagerwall 6505b53967 libnfs: Add lutimes
Add lutimes which is like utimes but operates on the symbolic link
itself if the destination is a symbolic link.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:26:54 +01:00
Ross Lagerwall bf769f960d libnfs: Add lstat
Add lstat which is like stat but operates on the symbolic link itself if
the destination is a symbolic link.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:26:54 +01:00
Ross Lagerwall 5935a28a0e libnfs: Add lchown
Add lchown which is like chown but operates on the symbolic link itself
if the destination is a symbolic link.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:26:54 +01:00
Ross Lagerwall 1d15199152 libnfs.c: Follow symlinks during path resolution
Follow symlinks during path resolution.  If the symlink points outside
the mount, -ENOENT is returned.  This is slightly different behavior
from the in-kernel NFS client where symlinks pointing outside the mount
get resolved to local paths.

The algorithm for symlink resolution is simple and stupid.  If a symlink
is encountered, the path is rewritten and path resolution begins again
from the root filehandle.  A count is kept to prevent loops.  This is
not particularly efficient but it is good enough for now.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:24:17 +01:00
Ross Lagerwall c4d5f5b874 libnfs.c: Fix a warning
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-27 21:22:34 +01:00
Ronnie Sahlberg 42f916635d Merge pull request #90 from rosslagerwall/stat-improvements
Stat improvements
2014-07-23 17:30:13 -07:00
Ross Lagerwall 3e020c15fd libnfs: Add fstat64, analagous to stat64
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-20 23:13:16 +01:00
Ross Lagerwall fc08ac459c libnfs: Set as much stat information as possible
Set as much stat information as possible for stat, stat64, fstat and
readdir.

Fill in dev to the given fsid.
Fill in rdev to the given major and minor numbers.
Set the file type bits in the mode from the type returned by the server.
Set the number of blocks used based on the number of bytes used in
blocks of size 512 (which is what stat(2) uses), rounded up.
Fill in the nanosecond timestamps.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-20 22:06:34 +01:00
Ross Lagerwall ece11036ff libnfs.c: Handle OOM condition
Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-20 08:13:45 +01:00
Ross Lagerwall 370c59e351 libnfs.c: Support use of O_TRUNC with nfs_create
Simplify usage for application programmers by supporting the use of
O_TRUNC with nfs_create.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-20 08:08:39 +01:00
Ronnie Sahlberg 8dea7c3e2d Merge pull request #88 from rosslagerwall/76-no-autoreconnect
libnfs.c: Fix autoreconnect
2014-07-19 16:01:13 -07:00
Ronnie Sahlberg fda800dc02 Merge pull request #86 from rosslagerwall/75-create
libnfs.c: add nfs_create
2014-07-19 15:58:30 -07:00
Ronnie Sahlberg e591967437 Merge pull request #87 from rbalint/master
Use sockaddr_in6 on FreeBSD
2014-07-19 15:56:59 -07:00
Ronnie Sahlberg b9e5039f49 New version 1.9.5
This version removes old ONC-RPC symbols and automatically includes the
RPC/ZDR layer include from the raw low level headers.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-07-19 15:47:35 -07:00
Petr Salinger 18c94b4633 Use sockaddr_in6 instead of sockaddr6_in 2014-07-19 18:07:13 +02:00
Ross Lagerwall 28ee9de2e4 libnfs.c: Fix autoreconnect
Since rpc_connect_async sets autoreconnect to 0, turn autoreconnect on
after the connection has completed, not before.

This fixes #76.

Signed-off-by: Ross Lagerwall <rosslagerwall@gmail.com>
2014-07-19 11:35:23 +01:00
Ross Lagerwall 037a1061dd libnfs.c: add nfs_create
Add a new family of functions, nfs_create, like nfs_creat but takes an
additional flags argument which allows extra flags like O_SYNC, O_EXCL
and O_APPEND to be specified.
2014-07-17 22:32:09 +01:00
Ronnie Sahlberg 3c769bb1bd New version 1.9.4
New version of libnfs:

- IPv6 support
- Support for Portmapper version 3 and an example portmap client.
- Directory caching top make repeated opendir() calls faster
- Readahead support
- Build manpages for the utilities (==nfs-ls)
- Support for O_APPEND
- Rename the list macros to avoid collission on *BSD

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-29 14:57:45 -07:00
Ronnie Sahlberg 07d06b250c libnfs.c: Change the directory cache to a smaller more reasonable value
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-29 14:42:28 -07:00
Ronnie Sahlberg be243cfa9b Merge pull request #82 from plieven/readahead
add readahead support
2014-06-29 14:41:28 -07:00
Peter Lieven 3ca2aac9a4 add readahead support
This patch add support for an internal readahead machanism. The maximum readahead
size can be specified via URL parameter readahead. This should significantly
speed up small sequential reads.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-23 16:31:32 +02:00
Ronnie Sahlberg 390ff38ad1 libnfs.c: add nlink to nfsdirent so we can get it for 'free'
update the nfs-ls utility to just use nfsdirent as is instead of having to
stat the files.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-08 11:40:35 -07:00
Ronnie Sahlberg 56e96539ef libnfs.c: add a simple dircache to libnfs
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-08 11:24:18 -07:00
Ronnie Sahlberg 20379f03fc libnfs.c: always pass the attributes to the callback for recursive lookups
Always pass a fattr3 structure to the callbacks for the internal function
to perform recursive lookups : nfs_lookuppath_async().
This will allow us to access for example the mtime for an object before we
start performing any expensive functions.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-08 11:24:09 -07:00
Ronnie Sahlberg f0888d12d9 init.c: fixup the mangled lgplv2.1 boilerplate
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-08 07:34:54 -07:00
Ronnie Sahlberg 1a6ec3ee76 init.c: use list macro when removing pdus from the wait list
Use the macro when removing the pdus in the wait list from the queues.
Also make sure to remove them from the right queue, from waitqueue and not
the outqueue for PDUs we have already sent out.

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-06-08 07:21:43 -07:00
Peter Lieven 7a750aea1c socket: fix broken connect for non broadcast traffic
commit 1c1e09a completely broke connects for non broadcast
traffic since it forgot to copy the server address into
the socket_storage struct.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-06-08 14:20:12 +02:00
Ronnie Sahlberg 8a52596b74 slist.h: Change SLIST_* to LIBNFS_LIST_* to avoid name clash on *BSD
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-05-14 19:11:03 -07:00
Ronnie Sahlberg 548e2bea4b nfs_open: add support for O_APPEND 2014-04-18 09:32:01 -07:00
Ronnie Sahlberg a87bb233a8 Merge branch 'xid-hash' 2014-04-10 19:59:28 -07:00
Ronnie Sahlberg 0275da678b Merge pull request #71 from Memphiz/nolinger
[socket] - disable linger by setting SO_LINGER to 0 seconds
2014-04-10 18:21:13 -07:00
Memphiz bd2f43c8a6 [osx] - fix compile 2014-04-10 20:35:44 +02:00
Memphiz 74b037ec46 [socket] - disable linger by setting SO_LINGER to 0 seconds 2014-04-10 20:34:11 +02:00
Arne Redlich 567a94d937 Fix the file position handling of the read and write calls
Since the interface is modelled after the libc calls we should try to match
their behaviour to avoid unpleasant surprises:
* read / write (sync and async flavours) update the file position
* pread / pwrite (sync and async flavours) do not update the file position
.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-04-03 18:05:32 -07:00
Arne Redlich 9e6ac3d4ee libnfs-sync: nfs_{read,write}: use their _async counterparts internally
Previously nfs_read and nfs_write used to use nfs_pread and nfs_pwrite respectively.
In preparation of getting the file position handling right this has to be detangled.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-04-03 18:04:41 -07:00
Arne Redlich 1f1b6cb0a7 nfs_lseek{,_async}: allow negative offsets and guard against file positions < 0
Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-04-03 18:03:21 -07:00
Mark Hills 63f36a0923 Track waiting requests in a hash table, by xid
NFS servers can respond to requests in any order, and they do. In our
tests there is also some clustering to the responses; it could be
because eg. requests are served synchronously if the data is in the cache.

Introduce a hash table so that we are able to find the pdu quickly in
all cases, assuming random distribution of the responses.
2014-04-03 17:52:21 -07:00
Mark Hills d46c3d622b Ensure the next pointer is correct
Fixes a bug where the next pointer was not being explicitly set. We
were ok much of the time due to zero-filled memory, and also we need
this if the same pdu is re-queued.
2014-04-03 17:51:56 -07:00
Mark Hills aec45c6274 Optimisations to the pdu queues
When making many concurrent requests (as is likely in any performance
criticial application), the use of SLIST_REMOVE and SLIST_ADD_END are
a severe bottleneck because of their linear search.

I considered using a double-linked list but it was unnecessary to
allocate the additional memory for each list entry.

Instead, continue to use a single-linked list but retain:

* a pointer to the end of the list; and
* a pointer to the previous entry during a linear search.

The former would makes append operations O(1) time, and the latter
does the same for removal. We can do this because removal only happens
within the linear search, and there is no random access to the queue.
2014-04-03 17:51:04 -07:00
Arne Redlich d5f7880641 nfs_normalize_path: don't strip trailing slash from "/"
Otherwise end up with a null string which is not permitted (RFC 1813, 3.2;
the code checks for it right after the now fixed nullification of "/").

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-03-20 16:58:32 -07:00
Arne Redlich b644665077 nfs_opendir2_cb: plug potential memory leak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-03-20 16:52:53 -07:00
Ronnie Sahlberg 24f45c5452 PORTMAP: Rename pmap3_getaddr_result to pmap3_string_result 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 29258a73c0 PORTMAP: Add support for v3 TADDR2UADDR 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 729266a796 PORTMAP: Add PMAP v3 UADDR2TADDR support 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg b71f7e8291 PORTMAP: Add support for PORTMAP v3 CALLIT 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 5245608a65 PORTMAP: Add v3 GETTIME support 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 6c60e2822f IPv6: If we use IPv6 then we need to use PMAP v3 GETADDR 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 7fbedfdefd PORTMAP: Add support for PORTMAP v3 GETADDR 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 2a32a899ca GETEXPORT: Use rpc_connect_program_async() flow during list exports
and get rid of several now redundant callbacks.
2014-03-19 18:25:50 -07:00
Ronnie Sahlberg f694a287ae RPC_CONNECT: Use the rpc_connect_program_async() flow during nfs_mount() 2014-03-19 18:25:50 -07:00
Ronnie Sahlberg 0f0e352f49 PORTMAP: Rename the functions in PMAP to PMAP2 to desribe the version of PMAP we use.
Future patches will add PMAP3 which we will need for IPv6 support.
2014-03-19 18:25:49 -07:00
Ronnie Sahlberg 1c1e09ad51 IPV6: Add basic IPv6 support
This adds basic IPv6 support to libnfs.
Since libnfs currently only support PORTMAPPER protocol up to version 2
the IPv6 support only works if the server runs Both MOUNT and NFS protocols
on the same ports for IPv6 as for IPv4.

To get full IPv6 support we need to add support for PORTMAPPER version 3
and use it for discovery when using IPv6
2014-03-19 18:25:49 -07:00
Ronnie Sahlberg 7058971155 New version: 1.9.3
Wed Mar 19 2014: Version 1.9.3
 - Add O_TRUNC support to nfs_open()
 - Add a simple but incomplete LD_PRELOAD tool
 - Fixes for some memory leaks and C++ compile support
 - Make ANDROID default uid/gid to 65534
 - Allow the READDIRPLUS emulation to still work if some objects
   in the direcotry can not be lookedup (NFSv4 ACL denying READ-ATTRIBUTES)
 - Have libnfs retry any read/write operations where the server responds
   with a short read/write. Some servers do this when they are overloaded?
2014-03-19 18:12:45 -07:00
Ronnie Sahlberg c44c3ff364 Merge pull request #69 from plieven/for-1.9.3
nfs_{pread,pwrite}_async: fix oom handling and comments
2014-03-18 12:30:40 -07:00
Peter Lieven 40a4373ab8 nfs_{pread,pwrite}_async: fix oom handling and comments
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-18 20:08:33 +01:00
Ronnie Sahlberg 8ae943f608 PORTMAP: Add support for V3 DUMP command
This implements the missing procedure from Issue #65
2014-03-16 14:17:06 -07:00
Peter Lieven ae8168b3eb {pread,pwrite}_async: fix potential segfault in out of memory condition
if there are already requests in flight we cannot return with an error immediately
from the functions since the caller will likely tidy up his data structures directly
and later on we call his callback with private_data that has likely already
been freed.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:16:07 +01:00
Peter Lieven 1eb4be3150 nfs_pread_async: handle short reads
the RFC allows the server to read less bytes than requested even
if not at the EOF.
this patch implements a reissue logic for the reminder of the
read request(s).

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:15:48 +01:00
Peter Lieven 027a767eca nfs_pwrite_async: handle short writes
the RFC allows the server to write less bytes than requested.
this patch implements a reissue logic for the reminder of the
write request(s).

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:07:59 +01:00
Peter Lieven d485997ad3 fix possible wrong cast to 32-bit unsigned
when calculation the max_offset the (unsigned) leads to a cast
to a 32-bit unsigned integer depending on the platform. as a result
we update the max_offset everytime when it grows beyond 2^32.
this leads to a wrong return max_offset value if the callbacks
are received out of order.

Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:07:52 +01:00
Peter Lieven 2449d3f787 introduce nfs_fill_{READ,WRITE}3args
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:07:44 +01:00
Peter Lieven 4d2f9f1132 fix potential overflow in nfs_pread_mcb
Signed-off-by: Peter Lieven <pl@kamp.de>
2014-03-16 20:07:39 +01:00
Ronnie Sahlberg 9a9566a3ee Improve error messages when READDIRPLUS emulation fails.
This addresses issue #62
2014-03-13 06:30:31 -07:00
Ronnie Sahlberg f66ff9931d Dont check for NFS errors in the LOOKUP during READDIRPLUS emulation
On servers with extended attributes, a server copuld be set up to
deny READ-ATTRIBUTES for the libnfs user.
This means that READDIRPLUS will no longer work since it will need to
stat() and thus READ-ATTRIBUTE in order to prepare the response.

Libnfs has READDIRPLUS emulation for the cases where this command fails
by switching to old READDIR to scan all the file names and then a LOOKUP loop for getting the file attributes.

Most of the time the purpose for this emulation is to handle the case where the server simply does not support READDIRPLUS at all, which sometimes is the case for embedded systems with userspace nfs servers.
In this case, where files just have READ-ATTRIBUTE deny for the libnfs user,
this will also fail and trigger the fallback to READDIR + LOOKUP-loop.

If the LOOKUP fails for this loop, then just ignore trying to update the attributes we have for this object, but do not fail the actual READDIRPLUS emulation.

This addresses a permissions issue reported by a XBMC user in issue #60
2014-03-12 21:00:08 -07:00
Ronnie Sahlberg 3af0c02237 Set default uid/gid to 65534/nobody for ANDROID 2014-03-12 19:31:20 -07:00
Ronnie Sahlberg b25c3aedde We only need to spend CPU computing a new error string IFF there was an error
when unmarshalling the reply.
2014-03-12 05:54:38 -07:00
Ronnie Sahlberg f0cb804219 Improve error reporting when unmarshalling of message headers fail. 2014-03-11 18:52:48 -07:00
Ronnie Sahlberg 479302f729 Add a new nfs_stat64() function that operates on a always-64-bit stat structure 2014-03-04 19:40:05 -08:00
Arne Redlich c8f0bac1bb nfs_pread_async: plug potential memleaks
Spotted by clang analyzer.

This also introduces asserts to help clang analyzer avoid reporting
false positives.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 19:00:47 -08:00
Arne Redlich 63d4a0583d nfs_write_async: plug potential memory leaks
Spotted by clang analyzer.

This also introduces asserts to help clang analyzer avoid
reporting false positives.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 19:00:19 -08:00
Arne Redlich 60af7e19d1 rpc_read_from_socket: fix use-after-free due to missing return
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:59:44 -08:00
Arne Redlich 8907aea9eb socket.c: fix format string issues (too few arguments)
These were uncovered by the previously added __attribute__((format(printf))).

Emacs also removed trailing whitespace while at it.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:59:17 -08:00
Arne Redlich 766bb4af75 nfs_rename_continue_1_internal: fix use-after-free
Spotted by clang analyzer.
This introduces another allocation to create a copy of the target path
of a rename in case it needs to be reported via rpc_set_error - it might
be a better idea to avoid the allocation and have a slightly less informative
error message?

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:58:02 -08:00
Arne Redlich bcbb21cdbb nfs_unlink_async: plug potential memory leak
Spotted by clang analyzer

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:57:28 -08:00
Arne Redlich 2257433dd4 nfs_rmdir_async: fix potential memory leak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:55:42 -08:00
Arne Redlich b1a197f5b2 nfs_mkdir_async: fix potential memory leak
Pointed out by clang analyzer

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:55:22 -08:00
Arne Redlich ecc656491a nfs_mknod_async: fix use-after-free
Spotted by clang analyzer

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:54:58 -08:00
Arne Redlich b41762c0d8 nfs_fchown_async: fix use-after-free
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:54:37 -08:00
Arne Redlich faa15589f1 nfs_fchmod_async: fix use-after-free
Spotted by clang analyzer

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:53:22 -08:00
Arne Redlich a26bebefce nfs_opendir2_cb: plug potential memleaks
Spotted by clang analyzer

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:52:34 -08:00
Arne Redlich 2fa14f9b97 free_nfs_cb_data: make static and drop superfluous nullptr checks / assignments
free() can cope with nullptrs and there's no point in null-ing free'd members
as the containing struct is free'd as well.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:52:05 -08:00
Arne Redlich 206a2ff644 free_nfs_cb_data: add assert(data->free_continue_data)
Non-debug builds will trip over the nullptr too - do we rather
want to leak the memory there?

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:50:09 -08:00
Arne Redlich 6b1f14ca01 nfs_fchown_async: fix nullptr dereference
nfs_chown_data is hooked up under nfs_cb_data->continue_data but
no ->free_continue_data is configured, so once free_nfs_cb_data is
invoked it will trip over a nullptr.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:49:03 -08:00
Arne Redlich b6619d88e6 nfs_fchown_async: plug potential memleak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:47:50 -08:00
Arne Redlich a128749648 nfs_creat_async: plug potential memleak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:47:27 -08:00
Arne Redlich feb2fc2f92 nfs_mknod_async: plug potential memory leak
Pointed out by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:47:02 -08:00
Arne Redlich e59193c9f9 nfs_lookuppath_async: plug potential memleak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:46:09 -08:00
Arne Redlich b2fc5c54d9 nfs_opendir_cb: plug potential memory leak
Spotted by clang analyzer.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:45:33 -08:00
Arne Redlich 4b1ae88abb nfs_normalize_path: fix using the results of assignments in while loops
Spotted by clang:
 ../../libnfs.git/lib/libnfs.c:1002:13: warning: using the result of an assignment as a condition without parentheses
       [-Wparentheses]
         while (str = strstr(path, "//")) {
                ~~~~^~~~~~~~~~~~~~~~~~~~
 ../../libnfs.git/lib/libnfs.c:1002:13: note: place parentheses around the assignment to silence this warning
         while (str = strstr(path, "//")) {
                    ^
                (                       )
 ../../libnfs.git/lib/libnfs.c:1002:13: note: use '==' to turn this assignment into an equality comparison
         while (str = strstr(path, "//")) {
                    ^
                    ==

Make the intent clear by adding extra parentheses, and also
remove trailing whitespace from libnfs.c while at it.

Signed-off-by: Arne Redlich <arne.redlich@googlemail.com>
2014-02-19 18:41:34 -08:00
Ronnie Sahlberg be7b4360ac We need to pass a filehandle back for open(O_TRUNC) or else the app will
be unhappy
2014-02-02 17:39:04 -08:00
Ronnie Sahlberg 22a0f15bee Add support for O_TRUNC with nfs_open()
O_TRUNC will attempt to truncate the file when opened with O_RDWR
or O_WRONLY.

Normal posix open(O_RDONLY|O_TRUNC) is undefined.

libnfs nfs_open() only uses the O_TRUNC flag when used in combination with either O_RDWR or O_WRONLY.
When O_TRUNC is used together with O_RDONLY libnfs will silently ignore the O_TRUNC flag.

Libnfs nfs_open(O_RDONLY|O_TRUNC) is thus the same as nfs_open(O_RDONLY)
2014-02-02 12:16:07 -08:00