From: Luke M. <lu...@us...> - 2005-06-23 04:27:56
|
Update of /cvsroot/ipbench/ipbench2/src/tests/nfs_latency In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19457 Modified Files: Makefile.am nfs_latency.c Added Files: nfs_glue.c nfs_glue.h Log Message: move nfs layer glue code into nfs_glue.c/nfs_glue.h Index: nfs_latency.c =================================================================== RCS file: /cvsroot/ipbench/ipbench2/src/tests/nfs_latency/nfs_latency.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** nfs_latency.c 22 Jun 2005 00:31:14 -0000 1.2 --- nfs_latency.c 23 Jun 2005 04:27:33 -0000 1.3 *************** *** 1,4 **** #include "nfs_latency.h" ! /* a dummy test */ /* --- 1,4 ---- #include "nfs_latency.h" ! #include "nfs_glue.h" /* *************** *** 15,19 **** --- 15,24 ---- nfs_latency_setup(char *hostname, int port, char *arg) { + int x; dbprintf("nfs_latency_setup - %s - %d - %s\n", hostname, port, arg); + + x = init_and_open("192.168.0.1", "/tmp", "bench.file"); + assert(x==0); + return 0; } --- NEW FILE: nfs_glue.h --- int init_and_open(char *hostname, char *mountpoint, char *filename); int generate_request(); int process_reply(uint64_t *timestamp); --- NEW FILE: nfs_glue.c --- #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <assert.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include "nfs_latency.h" /* for microuptime stuff */ #include "libnfs/nfs.h" #include "libnfs/rpc.h" #include "libnfs/xdr.h" #include "libnfs/callback.h" static int initialised = 0; static struct cookie nfs_file_handle; int resolve(char *name, struct sockaddr_in *sock){ struct hostent *hp; if((hp = gethostbyname(name))==NULL) return -1; memset(sock, 0, sizeof(struct sockaddr_in)); memcpy(&sock->sin_addr, hp->h_addr, hp->h_length); assert(hp->h_addrtype == PF_INET); sock->sin_family = PF_INET; sock->sin_port = htons(0); return 0; } static void open_cb(uintptr_t token, int status, struct cookie *fh, fattr_t *pattrs){ static int idem = 0; assert(idem==0); idem = 1; if(status==NFS_OK){ nfs_file_handle = *fh; initialised = 1; }else{ initialised = -1; } return; } int init_and_open(char *hostname, char *mountpoint, char *filename){ struct sockaddr_in addr; struct cookie pfh; microuptime_calibrate(); if(resolve(hostname, &addr) < 0){ printf("error resolving \"%s\"\n", hostname); exit(-1); } callback_init(10,100000); map_init(&addr); mnt_init(&addr); nfs_init(&addr); mnt_get_export_list(); mnt_mount(mountpoint, &pfh); nfs_lookup(&pfh, filename, open_cb, 0); while(initialised==0){ struct pbuf buf; rpc_recv(&buf, nfs_fd, 1); } if(initialised < 0){ return -1; } return 0; } #define READ_OFFSET 0 #define READ_SIZE 1024 uint64_t last_sample = 0; static void read_callback(struct callback *c, struct pbuf *pbuf){ assert(c->func==read_callback); assert(last_sample==0); /* XXX we should really check the NFS error code here */ last_sample = c->param.time.timestamp; } /* * instead of using nfs_read(), we generate ourselves a read with a * special timing callback. */ static int generate_read_request(){ struct pbuf pbuf; struct callback c; readargs_t args; /* set up callback */ c.func = read_callback; c.param.time.timestamp = time_stamp(); /* set up buffer */ initbuf(&pbuf, NFS_NUMBER, NFS_VERSION, NFSPROC_READ); args.file = nfs_file_handle; args.offset = READ_OFFSET; args.count = READ_SIZE; args.totalcount = 0; /* unused as per RFC */ addtobuf(&pbuf, &args, sizeof(args), 1); return rpc_send(&pbuf, nfs_fd, c); } /* * In the future this can be used to generate a varied workload. */ int generate_request(){ assert(initialised==1); return generate_read_request(); } int process_reply(uint64_t *timestamp){ struct pbuf pbuf; assert(initialised==1); last_sample=0; /* do a non-blocking recv */ rpc_recv(&pbuf, nfs_fd, 0); if(last_sample==0) return -1; *timestamp = last_sample; return 0; } Index: Makefile.am =================================================================== RCS file: /cvsroot/ipbench/ipbench2/src/tests/nfs_latency/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 22 Jun 2005 00:31:14 -0000 1.3 --- Makefile.am 23 Jun 2005 04:27:33 -0000 1.4 *************** *** 5,11 **** plugin_CPPFLAGS=-I$(top_srcdir)/src ! LIBNFS_FILES=libnfs/callback.c libnfs/init.c libnfs/mount.c libnfs/nfs.c libnfs/portmap.c libnfs/rpc.c libnfs/xdr.c libnfs/callback.h libnfs/init.h libnfs/nfs.h libnfs/nfsrpc.h libnfs/rpc.h libnfs/xdr.h ! libnfs_latency_la_SOURCES=nfs_latency.c plugin.c nfs_latency.h $(LIBNFS_FILES) libnfs_latency_la_LIBADD = ../../lib/libipbench.la --- 5,11 ---- plugin_CPPFLAGS=-I$(top_srcdir)/src ! LIBNFS_FILES=libnfs/callback.c libnfs/mount.c libnfs/nfs.c libnfs/portmap.c libnfs/rpc.c libnfs/xdr.c libnfs/callback.h libnfs/nfs.h libnfs/nfsrpc.h libnfs/rpc.h libnfs/xdr.h ! libnfs_latency_la_SOURCES=nfs_glue.c nfs_latency.c plugin.c nfs_glue.h nfs_latency.h $(LIBNFS_FILES) libnfs_latency_la_LIBADD = ../../lib/libipbench.la |