void do_write() { if (outstanding_writes >= PARALLEL_WRITES) return; if (written < size && !callback) { unsigned s = size-written; s = s > srv->wtpref ? srv->wtpref : s; if (use_lbfs) aiod_read (written, s, wrap (this, &write_obj::lbfs_condwrite, written, s)); else aiod_read (written, s, wrap (this, &write_obj::nfs3_write, written, s)); written += s; } if (!use_lbfs && written == size && !commit) { commit = true; nfs3_commit (); } }
int main(int argc, char *argv[]) { struct addrinfo *srv_addr, hints; int err; enum clnt_stat stat; nfs_ctx *ctx = NULL; LOOKUP3args largs; WRITE3args wr; COMMIT3args ci; if(argc < 6) { fprintf(stderr, "Not enough arguments\nThis tests the asynchronous " "libnfsclient NFS WRITE call interface and " "callback\n" "USAGE: nfs_write <server> <remote_file_dir> " "<file/dirname> <offset> <count>\n" "NOTE: <count> is ignored for now.\n"); return 0; } /* First resolve server name */ hints.ai_family = AF_INET; hints.ai_protocol = 0; hints.ai_socktype = 0; hints.ai_flags = 0; fprintf(stdout, "Resolving name: %s\n", argv[1]); if((err = getaddrinfo(argv[1], NULL, &hints, &srv_addr)) != 0) { fprintf(stderr, "%s: Cannot resolve name: %s: %s\n", argv[0], argv[1], gai_strerror(err)); return -1; } fprintf(stdout, "Creating nfs client context..\n"); ctx = nfs_init((struct sockaddr_in *)srv_addr->ai_addr, IPPROTO_TCP, 0); if(ctx == NULL) { fprintf(stderr, "%s: Cant init nfs context\n", argv[0]); return 0; } freeaddrinfo(srv_addr); mntfh.fhandle3_len = 0; fprintf(stdout, "Sending mount call..\n"); stat = mount3_mnt(&argv[2], ctx, nfs_mnt_cb, NULL); if(stat == RPC_SUCCESS) fprintf(stderr, "NFS MOUNT Call sent successfully\n"); else { fprintf(stderr, "Could not send NFS MOUNT call\n"); return 0; } fprintf(stdout, "Mount call received..\n"); largs.what.dir.data.data_len = mntfh.fhandle3_len; largs.what.dir.data.data_val = mntfh.fhandle3_val; largs.what.name = argv[3]; lfh.fhandle3_len = 0; fprintf(stdout, "Sending lookup call for %s\n", argv[3]); stat = nfs3_lookup(&largs, ctx, nfs_lookup_cb, NULL); if(stat == RPC_SUCCESS) fprintf(stderr, "NFS LOOKUP Call sent successfully\n"); else { fprintf(stderr, "Could not send NFS LOOKUP call\n"); return 0; } /* Dont need the mount file handle anymore. */ mem_free(mntfh.fhandle3_val, mntfh.fhandle3_len); fprintf(stdout, "Waiting for lookup reply..\n"); nfs_complete(ctx, RPC_BLOCKING_WAIT); fprintf(stdout, "Lookup reply received..\n"); wr.file.data.data_len = lfh.fhandle3_len; wr.file.data.data_val = lfh.fhandle3_val; wr.offset = atol(argv[4]); wr.count = strlen(wrdat); //wr.count = atol(argv[5]); wr.stable = UNSTABLE; wr.data.data_len = strlen(wrdat); wr.data.data_val = wrdat; res = NULL; fprintf(stdout, "Sending write call\n"); stat = nfs3_write(&wr, ctx, nfs_write_cb, NULL); if(stat == RPC_SUCCESS) fprintf(stderr, "NFS WRITE Call sent successfully\n"); else { fprintf(stderr, "Could not send NFS WRITE call\n"); return 0; } fprintf(stdout, "Waiting for write reply..\n"); nfs_complete(ctx, RPC_BLOCKING_WAIT); free_WRITE3res(res); fprintf(stdout, "Write reply received..\n"); ci.file.data.data_len = lfh.fhandle3_len; ci.file.data.data_val = lfh.fhandle3_val; ci.offset = atol(argv[4]); ci.count = strlen(wrdat); fprintf(stdout, "Sending commit request..\n"); stat = nfs3_commit(&ci, ctx, nfs_commit_cb, NULL); if(stat == RPC_SUCCESS) fprintf(stderr, "NFS COMMIT Call sent successfully\n"); else { fprintf(stderr, "Could not send NFS COMMIT call\n"); return 0; } fprintf(stdout, "Waiting for commit reply..\n"); nfs_complete(ctx, RPC_BLOCKING_WAIT); fprintf(stdout, "Received commit reply..\n"); return 0; }