libnfsclient

libnfsclient is a userland, NFS client ops library. It can be used by user space programs to send NFS client operations like lookup, mount, read, write, etc. This is done by providing a layer over the Sockets interface thereby avoiding the need to go through the file system. Among other usage scenarios, I use it for my NFS benchmarking tool called nfsreplay.

The NFS benchmarking project page is here: NFSBenchmarking

I can be reached at <shehjart AT gelato DOT NO SPAM unsw DOT edu GREEBLIES DOT au>

News

Interface

See AsyncRPC also since libnfsclient is a layer on top of that library.

Client Context: nfs_ctx

Connection to each NFS server is represented by a structure called nfs_ctx. This is opaque to the users and is to be used only as a handle or identifier for:

All interface functions need to be passed the nfs_ctx handle that connects to a particular server.

Initializing the nfs client context is always the first step.

nfs_init

#include <nfsclient.h>

nfs_ctx *nfs_init(struct sockaddr_in *srv, int proto, int connflags);

Returns the handle for the connection to the server in srv, NULL on failure.

Operations

At present, libnfsclient only implements NFSv3 and MOUNT protocol. The interface is described in nfs3Interface.

Error Handling

#include <nfsclient.h>

char * nfsstat3_strerror(int stat);

XDR Translation

The message structures passed to the nfs3_* functions described in nfs3Interface, are converted internally into XDR format before being transmitted.

The message buffers, read from the socket and passed to the callbacks are in XDR format. These have to be first converted into the required message-specific structure. This implies that each callback somehow know what type of reply it will be processing. Again, see examples of how reply messages are converted into message structures, in the callbacks sources in the test/ directory.

For the interface for translating reply message buffers in XDR format to reply-message specific structures, see XDRInterface.

MOUNT and NFS integration

Generally, a client looks up the file handle of an exported file system(..by connecting to the mountd service..) on a server before it proceeds to operate on it. In cases, where the exported file system's filehandle is already known, clients can proceed directly to connect to the NFS service. Both modes are supported.

The Mount protocol interface is synchronous and returns only after a reply is received. This is not true for the NFS 3 protocol. There,a call function will return after atleast sending the request. Before returning, it'll check if a reply was received and if so, the callback for it will be executed, otherwise it just returns. So yes, there is no guarantee that the callback is executed before returning.

Though, this is the default behaviour, it can be changed, i.e. made blocking by setting the flag argument to nfs_init as NFSC_CFL_BLOCKING. In this case, the call functions will behave like the mount interface, i.e. return only after the reply was received and its callback executed.

Handling Callbacks

Callback should be of the following type.

typedef void (*user_cb)(void *msg_buf, int bufsz, void *priv);

Callbacks are called by the library whenever a complete reply is received. The message buffers passed to the callbacks are freed after the callback returns so copy anything out of the buffer if persistence is needed. See AsyncRPC for more info.

Completion Notification

In case, user programs need to explicitly have the pending socket buffers processed and any callbacks executed, the following function can be used.

int nfs_complete(nfs_ctx * ctx, int flag);

Multi-Threading with libnfsclient

All libnfsclient operations take place on the specified nfs client context so separate threads operating on their own nfs_ctxs will work just fine. A synchronisation mechanism will need to be implemented by the user program if sending requests from multiple threads., over a shared nfs_ctx.

Code

libnfsclient and AsyncRPC are part of the nfsreplay source package. See nfsreplay page for instructions.

Building

Building instructions are in the BUILD file in nfsreplay package.

Examples

For examples on usage of the library, see the sources in test/ subdirectory of the nfsreplay source.

Support

Use nfsreplay lists for support and discussion.

IA64wiki: libnfsclient (last edited 2008-03-13 21:42:28 by ShehjarTikoo)

Gelato@UNSW is sponsored by
the University of New South Wales National ICT Australia The Gelato Federation Hewlett-Packard Company Australian Research Council
Please contact us with any questions or comments.