Commit Graph

161 Commits (ece11036ff6894f7c7d447e7a3d64c0cd49d9aa2)

Author SHA1 Message Date
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
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 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 548e2bea4b nfs_open: add support for O_APPEND 2014-04-18 09:32:01 -07: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 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
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 6c60e2822f IPv6: If we use IPv6 then we need to use PMAP 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
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
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 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 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