From f4b9cb0e0f3775612130933709b4f326e562bbb0 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 31 May 2011 23:50:44 +1000 Subject: [PATCH] Add example of NFS/FSINFO async call --- examples/nfsclient-raw.c | 60 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/examples/nfsclient-raw.c b/examples/nfsclient-raw.c index 9de1ea6..3ccc949 100644 --- a/examples/nfsclient-raw.c +++ b/examples/nfsclient-raw.c @@ -20,7 +20,7 @@ */ #define SERVER "10.1.1.27" -#define EXPORT "/VIRTUAL" +#define EXPORT "/shared" #include #include @@ -28,17 +28,58 @@ #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" +#include "libnfs-raw-nfs.h" struct client { char *server; char *export; uint32_t mount_port; int is_finished; + struct nfs_fh3 rootfh; }; +void nfs_fsinfo_cb(struct rpc_context *rpc, int status, void *data, void *private_data) +{ + struct client *client = private_data; + FSINFO3res *res = data; + + if (status == RPC_STATUS_ERROR) { + printf("nfs/fsinfo call failed with \"%s\"\n", (char *)data); + exit(10); + } + if (status != RPC_STATUS_SUCCESS) { + printf("nfs/fsinfo call to server %s failed, status:%d\n", client->server, status); + exit(10); + } + + printf("Got reply from server for NFS/FSINFO procedure.\n"); + printf("Read Max:%d\n", (int)res->FSINFO3res_u.resok.rtmax); + printf("Write Max:%d\n", (int)res->FSINFO3res_u.resok.wtmax); + client->is_finished = 1; +} + + +void nfs_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data) +{ + struct client *client = private_data; + + if (status != RPC_STATUS_SUCCESS) { + printf("connection to RPC.MOUNTD on server %s failed\n", client->server); + exit(10); + } + + printf("Connected to RPC.NFSDD on %s:%d\n", client->server, client->mount_port); + printf("Send FSINFO request\n"); + if (rpc_nfs_fsinfo_async(rpc, nfs_fsinfo_cb, &client->rootfh, client) != 0) { + printf("Failed to send fsinfo request\n"); + exit(10); + } +} + void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private_data) { struct client *client = private_data; + mountres3 *mnt = data; if (status == RPC_STATUS_ERROR) { printf("mount/mnt call failed with \"%s\"\n", (char *)data); @@ -50,7 +91,21 @@ void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private } printf("Got reply from server for MOUNT/MNT procedure.\n"); - client->is_finished = 1; + client->rootfh.data.data_len = mnt->mountres3_u.mountinfo.fhandle.fhandle3_len; + client->rootfh.data.data_val = malloc(client->rootfh.data.data_len); + memcpy(client->rootfh.data.data_val, mnt->mountres3_u.mountinfo.fhandle.fhandle3_val, client->rootfh.data.data_len); + + printf("Disconnect socket from mountd server\n"); + if (rpc_disconnect(rpc, "normal disconnect") != 0) { + printf("Failed to disconnect socket to mountd\n"); + exit(10); + } + + printf("Connect to RPC.NFSDD on %s:%d\n", client->server, 2049); + if (rpc_connect_async(rpc, client->server, 2049, nfs_connect_cb, client) != 0) { + printf("Failed to start connection\n"); + exit(10); + } } @@ -73,7 +128,6 @@ void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *privat printf("Failed to send mnt request\n"); exit(10); } - } void mount_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data) -- 2.34.1