From: Luke M. <lu...@us...> - 2005-06-22 00:31:25
|
Update of /cvsroot/ipbench/ipbench2/src/tests/nfs_latency/libnfs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9886/libnfs Added Files: init.c init.h Log Message: transform test.c into init.c --- NEW FILE: init.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.h" #include "rpc.h" #include "callback.h" static int finished = 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; finished = 1; }else{ finished = -1; } return; } int init_and_open(char *hostname, char *mountpoint, char *filename, struct cookie *fh){ struct sockaddr_in addr; struct cookie pfh; 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(finished==0){ struct pbuf buf; rpc_recv(&buf, nfs_fd, 1); } if(finished < 0){ return -1; } *fh = nfs_file_handle; return 0; } --- NEW FILE: init.h --- int init_and_open(char *hostname, char *mountpoint, char *filename, struct cookie *fh); |