Commit Graph

78 Commits (f965ec74cf2c14c0e28318c1d80afe3755e847a3)

Author SHA1 Message Date
Ronnie Sahlberg f965ec74cf ps2ee: PS2 EE support
Initial support for building a library for PS2 EmotionEngine

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2021-09-17 07:27:44 +10:00
Damian c14a5acb51 Porting to PS3 2020-08-14 19:30:00 -03:00
Damian c7ad0762d8 Porting library to PS3 (psl1ght) 2020-08-14 11:47:39 -03:00
Ronnie Sahlberg 548fa961a8 Return "" instead of NULL for empty errors in nfs_get_error()
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2019-12-16 13:21:27 +10:00
crusader-mike 9d5427bbd4 fixed few MSVC warnings; fixed missing exports 2019-10-09 17:08:10 -05:00
David Lam 71ef9e3ee0 Fix invalid left-shift of pid_t type by casting to large enough type 2018-12-18 15:50:21 -08:00
Daniel Abrecht b3fd3ca7e4 Move win32/win32_compat.h to include/win32/win32_compat.h 2018-04-16 19:42:38 +00:00
Ronnie Sahlberg dc9669abd5 Fix compiler warnings about cast from char* -> uint32_t*
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2017-07-08 16:33:55 +10:00
Chris Richards fb1efbe51c Increased resolution of PDU timeout from seconds to milliseconds 2017-07-08 09:47:51 +10:00
Ronnie Sahlberg 6afd405587 Merge branch 'master' into issues-215 2017-05-11 18:51:13 -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 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 ebd98bf966 Merge branch 'master' into issues-199 2017-05-09 14:49:58 -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
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 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
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
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 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 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 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
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
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 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 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
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
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
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 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 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 99ae3c01c4 add some debug output
Signed-off-by: Peter Lieven <pl@kamp.de>
2015-06-19 13:43:55 +02: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 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 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
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
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 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
Ronnie Sahlberg 3af0c02237 Set default uid/gid to 65534/nobody for ANDROID 2014-03-12 19:31:20 -07:00
Ronnie Sahlberg f0cb804219 Improve error reporting when unmarshalling of message headers fail. 2014-03-11 18:52:48 -07:00
Ronnie Sahlberg 6d89ace041 Merge pull request #43 from plieven/master
URL parsing functions and minor fixes + enhancements
2013-12-25 16:11:29 -08:00
Ronnie Sahlberg 35280fd7a4 Grow the marshalling buffer from 64k to 1M so we can marshall really large WRITE3s 2013-12-24 13:03:50 -08:00
Peter Lieven 9126c9c036 add uid and gid URL param to specify alternate uid and/or gid
This allows to connect with an alternate uid or gid than that
of the current user.

Example:
 examples/nfs-ls nfs://10.0.0.1/export?uid=1000&gid=33

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:03:26 +01:00
Peter Lieven 1c8b4547ce add tcp-syncnt URL param to adjust TCP_SYNCNT sockopt
This allows indirect support for a configurable connect timeout.

Linux uses a exponential backoff for SYN retries starting
with 1 second.

This means for a value n for TCP_SYNCNT, the connect will
effectively timeout after 2^(n+1)-1 seconds.

Example:
 examples/nfs-ls nfs://10.0.0.1/export?tcp-syncnt=1

Signed-off-by: Peter Lieven <pl@kamp.de>
2013-12-23 14:03:18 +01:00
Ronnie Sahlberg 6fda9871a0 Mix in the pid in the top 16 bits for the initial xid.
This helps for users which rapidly fork a lot of processes that then
immediately create a new context (I am looking at you dbench)
to awoid having lots of processes starting and using overlapping xid values.
2013-10-25 16:16:43 -07:00