From 11155a83949d0566dc9a987261e939c89965cbc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Jul 2008 16:47:56 +1000 Subject: [PATCH] converted all backends to new common format --- .gitignore | 20 ++++ child.c | 283 +++++++----------------------------------------- dbench.c | 76 ++++--------- dbench.h | 97 +++++------------ fileio.c | 312 +++++++++++++++++++++++++++-------------------------- nfsio.c | 304 ++++++++++++++++++++++++++------------------------- proto.h | 73 +------------ sockio.c | 195 +++++++++++---------------------- 8 files changed, 484 insertions(+), 876 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f147ab7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +*.o +*.a +*~ +autom4te.cache +config.log +config.status +configure +dbench +nfsbench +tbench +tbench_srv +config.h +mount.h +mount_xdr.c +nfs.h +mount_client.c +nfs_client.c +nfs_xdr.c +Makefile + diff --git a/child.c b/child.c index 9a3b91c..e6b4845 100644 --- a/child.c +++ b/child.c @@ -29,6 +29,12 @@ #define ival(s) strtol(s, NULL, 0) +static void nb_sleep(int usec) +{ + usleep(usec); +} + + static void nb_target_rate(struct child_struct *child, double rate) { double tdelay; @@ -86,253 +92,40 @@ static void finish_op(struct child_struct *child, struct op *op) /* one child operation */ -static void child_op(struct child_struct *child, char **params, - const char *fname, const char *fname2, const char *status) +static void child_op(struct child_struct *child, const char *opname, + const char *fname, const char *fname2, + char **params, const char *status) { + struct dbench_op op; + unsigned i; + child->lasttime = timeval_current(); - if (!strcmp(params[0],"NTCreateX")) { - if (nb_ops.createx) { - nb_ops.createx(child, fname, ival(params[2]), ival(params[3]), - ival(params[4]), status); - OP_LATENCY(NTCreateX); - } else { - printf("Operation NTCREATEX is not supported\n"); - } - } else if (!strcmp(params[0],"Close")) { - if (nb_ops.close) { - nb_ops.close(child, ival(params[1]), status); - OP_LATENCY(Close); - } else { - printf("Operation CLOSE is not supported\n"); - } - } else if (!strcmp(params[0],"Rename")) { - if (nb_ops.rename) { - nb_ops.rename(child, fname, fname2, status); - OP_LATENCY(Rename); - } else { - printf("Operation RENAME is not supported\n"); - } - } else if (!strcmp(params[0],"Unlink")) { - if (nb_ops.unlink) { - nb_ops.unlink(child, fname, ival(params[2]), status); - OP_LATENCY(Unlink); - } else { - printf("Operation UNLINK is not supported\n"); - } - } else if (!strcmp(params[0],"Deltree")) { - if (nb_ops.deltree) { - nb_ops.deltree(child, fname); - OP_LATENCY(Deltree); - } else { - printf("Operation DELTREE is not supported\n"); - } - } else if (!strcmp(params[0],"Rmdir")) { - if (nb_ops.rmdir) { - nb_ops.rmdir(child, fname, status); - OP_LATENCY(Rmdir); - } else { - printf("Operation RMDIR is not supported\n"); - } - } else if (!strcmp(params[0],"Mkdir")) { - if (nb_ops.mkdir) { - nb_ops.mkdir(child, fname, status); - OP_LATENCY(Mkdir); - } else { - printf("Operation MKDIR is not supported\n"); - } - } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) { - if (nb_ops.qpathinfo) { - nb_ops.qpathinfo(child, fname, ival(params[2]), status); - OP_LATENCY(Qpathinfo); - } else { - printf("Operation QUERY_PATH_INFORMATION is not supported\n"); - } - } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) { - if (nb_ops.qfileinfo) { - nb_ops.qfileinfo(child, ival(params[1]), ival(params[2]), status); - OP_LATENCY(Qfileinfo); - } else { - printf("Operation QUERY_FILE_INFORMATION is not supported\n"); - } - } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) { - if (nb_ops.qfsinfo) { - nb_ops.qfsinfo(child, ival(params[1]), status); - OP_LATENCY(Qfsinfo); - } else { - printf("Operation QUERY_FS_INFORMATION is not supported\n"); - } - } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) { - if (nb_ops.sfileinfo) { - nb_ops.sfileinfo(child, ival(params[1]), ival(params[2]), status); - OP_LATENCY(Sfileinfo); - } else { - printf("Operation SET_FILE_INFORMATION is not supported\n"); - } - } else if (!strcmp(params[0],"FIND_FIRST")) { - if (nb_ops.findfirst) { - nb_ops.findfirst(child, fname, ival(params[2]), - ival(params[3]), ival(params[4]), status); - OP_LATENCY(Find); - } else { - printf("Operation FINDFIRST is not supported\n"); - } - } else if (!strcmp(params[0],"WriteX")) { - if (nb_ops.writex) { - nb_ops.writex(child, ival(params[1]), - ival(params[2]), ival(params[3]), ival(params[4]), - status); - OP_LATENCY(WriteX); - } else { - printf("Operation WRITEX is not supported\n"); - } - } else if (!strcmp(params[0],"LockX")) { - if (nb_ops.lockx) { - nb_ops.lockx(child, ival(params[1]), - ival(params[2]), ival(params[3]), status); - OP_LATENCY(LockX); - } else { - printf("Operation LOCKX is not supported\n"); - } - } else if (!strcmp(params[0],"UnlockX")) { - if (nb_ops.unlockx) { - nb_ops.unlockx(child, ival(params[1]), - ival(params[2]), ival(params[3]), status); - OP_LATENCY(UnlockX); - } else { - printf("Operation UNLOCKX is not supported\n"); - } - } else if (!strcmp(params[0],"ReadX")) { - if (nb_ops.readx) { - nb_ops.readx(child, ival(params[1]), - ival(params[2]), ival(params[3]), ival(params[4]), - status); - OP_LATENCY(ReadX); - } else { - printf("Operation READX is not supported\n"); - } - } else if (!strcmp(params[0],"Flush")) { - if (nb_ops.flush) { - nb_ops.flush(child, ival(params[1]), status); - OP_LATENCY(Flush); - } else { - printf("Operation FLUSH is not supported\n"); - } - } else if (!strcmp(params[0],"GETATTR3")) { - if (nb_ops.getattr3) { - nb_ops.getattr3(child, fname, status); - OP_LATENCY(GETATTR3); - } else { - printf("Operation GETATTR3 is not supported\n"); - } - } else if (!strcmp(params[0],"LOOKUP3")) { - if (nb_ops.getattr3) { - nb_ops.lookup3(child, fname, status); - OP_LATENCY(LOOKUP3); - } else { - printf("Operation LOOKUP3 is not supported\n"); - } - } else if (!strcmp(params[0],"CREATE3")) { - if (nb_ops.create3) { - nb_ops.create3(child, fname, status); - OP_LATENCY(CREATE3); - } else { - printf("Operation CREATE3 is not supported\n"); - } - } else if (!strcmp(params[0],"WRITE3")) { - if (nb_ops.write3) { - nb_ops.write3(child, fname, ival(params[2]), - ival(params[3]), - ival(params[4]), status); - OP_LATENCY(WRITE3); - } else { - printf("Operation WRITE3 is not supported\n"); - } - } else if (!strcmp(params[0],"COMMIT3")) { - if (nb_ops.commit3) { - nb_ops.commit3(child, fname, status); - OP_LATENCY(COMMIT3); - } else { - printf("Operation COMMIT3 is not supported\n"); - } - } else if (!strcmp(params[0],"READ3")) { - if (nb_ops.read3) { - nb_ops.read3(child, fname, ival(params[2]), - ival(params[3]), status); - OP_LATENCY(READ3); - } else { - printf("Operation READ3 is not supported\n"); - } - } else if (!strcmp(params[0],"ACCESS3")) { - if (nb_ops.access3) { - nb_ops.access3(child, fname, ival(params[2]), - ival(params[3]), status); - OP_LATENCY(ACCESS3); - } else { - printf("Operation ACCESS3 is not supported\n"); - } - } else if (!strcmp(params[0],"MKDIR3")) { - if (nb_ops.mkdir3) { - nb_ops.mkdir3(child, fname, status); - OP_LATENCY(MKDIR3); - } else { - printf("Operation MKDIR3 is not supported\n"); - } - } else if (!strcmp(params[0],"RMDIR3")) { - if (nb_ops.rmdir3) { - nb_ops.rmdir3(child, fname, status); - OP_LATENCY(RMDIR3); - } else { - printf("Operation RMDIR3 is not supported\n"); - } - } else if (!strcmp(params[0],"FSSTAT3")) { - if (nb_ops.fsstat3) { - nb_ops.fsstat3(child, status); - OP_LATENCY(FSSTAT3); - } else { - printf("Operation FSSTAT3 is not supported\n"); - } - } else if (!strcmp(params[0],"FSINFO3")) { - if (nb_ops.fsinfo3) { - nb_ops.fsinfo3(child, status); - OP_LATENCY(FSINFO3); - } else { - printf("Operation FSINFO3 is not supported\n"); - } - } else if (!strcmp(params[0],"SYMLINK3")) { - if (nb_ops.symlink3) { - nb_ops.symlink3(child, fname, fname2, status); - OP_LATENCY(SYMLINK3); - } else { - printf("Operation SYMLINK3 is not supported\n"); - } - } else if (!strcmp(params[0],"LINK3")) { - if (nb_ops.link3) { - nb_ops.link3(child, fname, fname2, status); - OP_LATENCY(LINK3); - } else { - printf("Operation LINK3 is not supported\n"); - } - } else if (!strcmp(params[0],"REMOVE3")) { - if (nb_ops.remove3) { - nb_ops.remove3(child, fname, status); - OP_LATENCY(REMOVE3); - } else { - printf("Operation REMOVE3 is not supported\n"); - } - } else if (!strcmp(params[0],"READDIRPLUS3")) { - if (nb_ops.readdirplus3) { - nb_ops.readdirplus3(child, fname, status); - OP_LATENCY(READDIRPLUS3); - } else { - printf("Operation READDIRPLUS3 is not supported\n"); + ZERO_STRUCT(op); + op.child = child; + op.op = opname; + op.fname = fname; + op.fname2 = fname2; + op.status = status; + for (i=0;iops[i]); + return; } - } else if (!strcmp(params[0],"Sleep")) { - nb_sleep(child, ival(params[1]), status); - } else { - printf("[%d] Unknown operation %s in pid %d\n", - child->line, params[0], getpid()); } + + printf("[%u] Unknown operation %s in pid %u\n", + child->line, op.op, (unsigned)getpid()); } @@ -418,16 +211,20 @@ again: status = params[i-1]; for (child=child0;child1 && params[1][0] == '/') { snprintf(fname, sizeof(fname), "%s%s", child->directory, params[1]); all_string_sub(fname,"client1", child->cname); + pcount++; } if (i>2 && params[2][0] == '/') { snprintf(fname2, sizeof(fname2), "%s%s", child->directory, params[2]); all_string_sub(fname2,"client1", child->cname); + pcount++; } if (options.targetrate != 0 || targett == 0.0) { @@ -435,7 +232,7 @@ again: } else { nb_time_delay(child, targett); } - child_op(child, params, fname, fname2, status); + child_op(child, params[0], fname, fname2, params+pcount, status); } } diff --git a/dbench.c b/dbench.c index 41c9f3c..bfedb14 100644 --- a/dbench.c +++ b/dbench.c @@ -110,7 +110,7 @@ static void sig_alarm(int sig) for (i=0;icount == 0) continue; - printf(" %-12s %7u %9.03f %9.03f\n", - op_names[i].name, op1->count, + printf(" %-22s %7u %9.03f %9.03f\n", + nb_ops.ops[i].name, op1->count, 1000*op1->total_time/op1->count, op1->max_latency*1000); } @@ -219,23 +179,23 @@ static void show_one_latency(struct opnames *ops, struct opnames *ops_all) static void report_latencies(void) { - struct opnames sum; - int i, j, n = (sizeof(op_names)/sizeof(op_names[0])); + struct op sum[MAX_OPS]; + int i, j; struct op *op1, *op2; struct child_struct *child; - memset(&sum, 0, sizeof(sum)); - for (i=0;iop); + op2 = &child->ops[i]; op1->count += op2->count; op1->total_time += op2->total_time; op1->max_latency = MAX(op1->max_latency, op2->max_latency); } } - show_one_latency(&sum, &sum); + show_one_latency(sum, sum); if (!options.per_client_results) { return; @@ -246,7 +206,7 @@ static void report_latencies(void) child = &children[i]; printf("Client %u did %u lines and %.0f bytes\n", i, child->line, child->bytes - child->bytes_done_warmup); - show_one_latency(&child->op, &sum); + show_one_latency(child->ops, sum); } } diff --git a/dbench.h b/dbench.h index 8a6f5e8..c9aada6 100644 --- a/dbench.h +++ b/dbench.h @@ -98,6 +98,10 @@ struct op { double max_latency; }; +#define ZERO_STRUCT(x) memset(&(x), 0, sizeof(x)) + +#define MAX_OPS 100 + struct child_struct { int id; int failed; @@ -118,40 +122,7 @@ struct child_struct { double last_bytes; struct timeval last_time; } rate; - struct opnames { - struct op op_NTCreateX; - struct op op_Close; - struct op op_Rename; - struct op op_Unlink; - struct op op_Deltree; - struct op op_Rmdir; - struct op op_Mkdir; - struct op op_Qpathinfo; - struct op op_Qfileinfo; - struct op op_Qfsinfo; - struct op op_Sfileinfo; - struct op op_Find; - struct op op_WriteX; - struct op op_ReadX; - struct op op_LockX; - struct op op_UnlockX; - struct op op_Flush; - struct op op_GETATTR3; - struct op op_MKDIR3; - struct op op_RMDIR3; - struct op op_LOOKUP3; - struct op op_CREATE3; - struct op op_WRITE3; - struct op op_COMMIT3; - struct op op_READ3; - struct op op_ACCESS3; - struct op op_FSSTAT3; - struct op op_FSINFO3; - struct op op_SYMLINK3; - struct op op_REMOVE3; - struct op op_READDIRPLUS3; - struct op op_LINK3; - } op; + struct op ops[MAX_OPS]; void *private; }; @@ -180,46 +151,26 @@ struct options { const char *protocol; }; + +struct dbench_op { + struct child_struct *child; + const char *op; + const char *fname; + const char *fname2; + const char *status; + int params[10]; +}; + +struct backend_op { + const char *name; + void (*fn)(struct dbench_op *); +}; + struct nb_operations { - void (*setup)(struct child_struct *); - void (*deltree)(struct child_struct *, const char *dname); + const char *backend_name; + struct backend_op *ops; + void (*setup)(struct child_struct *child); void (*cleanup)(struct child_struct *child); - - /* CIFS operations */ - void (*flush)(struct child_struct *, int handle, const char *status); - void (*close)(struct child_struct *, int handle, const char *status); - void (*lockx)(struct child_struct *, int handle, uint32_t offset, int size, const char *status); - void (*rmdir)(struct child_struct *, const char *fname, const char *status); - void (*mkdir)(struct child_struct *, const char *dname, const char *status); - void (*rename)(struct child_struct *, const char *old, const char *new, const char *status); - void (*readx)(struct child_struct *, int handle, int offset, int size, int ret_size, const char *status); - void (*writex)(struct child_struct *, int handle, int offset, int size, int ret_size, const char *status); - void (*unlink)(struct child_struct *, const char *fname, int attr, const char *status); - void (*unlockx)(struct child_struct *child,int handle, uint32_t offset, int size, const char *status); - void (*findfirst)(struct child_struct *child, const char *fname, int level, int maxcnt, int count, const char *status); - void (*sfileinfo)(struct child_struct *child, int handle, int level, const char *status); - void (*qfileinfo)(struct child_struct *child, int handle, int level, const char *status); - void (*qpathinfo)(struct child_struct *child, const char *fname, int level, const char *status); - void (*qfsinfo)(struct child_struct *child, int level, const char *status); - void (*createx)(struct child_struct *child, const char *fname, uint32_t create_options, uint32_t create_disposition, int fnum, const char *status); - - /* NFSv3 operations */ - void (*getattr3)(struct child_struct *child, const char *fname, const char *status); - void (*lookup3)(struct child_struct *child, const char *fname, const char *status); - void (*create3)(struct child_struct *child, const char *fname, const char *status); - void (*write3)(struct child_struct *child, const char *fname, int offset, int len, int stable, const char *status); - void (*commit3)(struct child_struct *child, const char *fname, const char *status); - void (*read3)(struct child_struct *child, const char *fname, int offset, int len, const char *status); - void (*access3)(struct child_struct *child, const char *fname, int desired, int granted, const char *status); - void (*mkdir3)(struct child_struct *child, const char *fname, const char *status); - void (*rmdir3)(struct child_struct *child, const char *fname, const char *status); - void (*fsstat3)(struct child_struct *child, const char *status); - void (*fsinfo3)(struct child_struct *child, const char *status); - void (*symlink3)(struct child_struct *child, const char *fname, const char *fname2, const char *status); - void (*remove3)(struct child_struct *child, const char *fname, const char *status); - void (*readdirplus3)(struct child_struct *child, const char *fname, const char *status); - void (*link3)(struct child_struct *child, const char *fname, const char *fname2, const char *status); - void (*rename3)(struct child_struct *child, const char *fname, const char *fname2, const char *status); }; extern struct nb_operations nb_ops; @@ -245,6 +196,8 @@ extern struct nb_operations nb_ops; #define O_DIRECTORY 0200000 #endif +struct nfsio; + #include "proto.h" extern struct options options; diff --git a/fileio.c b/fileio.c index 02b734f..d67a1e1 100644 --- a/fileio.c +++ b/fileio.c @@ -202,65 +202,62 @@ static void fio_setup(struct child_struct *child) child->rate.last_bytes = 0; } -static void fio_unlink(struct child_struct *child, const char *fname, int attr, const char *status) +static void fio_unlink(struct dbench_op *op) { - (void)attr; + resolve_name(op->child, op->fname); - resolve_name(child, fname); - - if (unlink(fname) != expected_status(status)) { + if (unlink(op->fname) != expected_status(op->status)) { printf("[%d] unlink %s failed (%s) - expected %s\n", - child->line, fname, strerror(errno), status); - failed(child); + op->child->line, op->fname, strerror(errno), op->status); + failed(op->child); } - if (options.sync_dirs) sync_parent(child, fname); + if (options.sync_dirs) sync_parent(op->child, op->fname); } -static void fio_mkdir(struct child_struct *child, const char *dname, const char *status) +static void fio_mkdir(struct dbench_op *op) { struct stat st; - (void)child; - (void)status; - resolve_name(child, dname); - if (options.stat_check && stat(dname, &st) == 0) { + resolve_name(op->child, op->fname); + if (options.stat_check && stat(op->fname, &st) == 0) { return; } - mkdir(dname, 0777); + mkdir(op->fname, 0777); } -static void fio_rmdir(struct child_struct *child, const char *fname, const char *status) +static void fio_rmdir(struct dbench_op *op) { struct stat st; - resolve_name(child, fname); + resolve_name(op->child, op->fname); if (options.stat_check && - (stat(fname, &st) != 0 || !S_ISDIR(st.st_mode))) { + (stat(op->fname, &st) != 0 || !S_ISDIR(st.st_mode))) { return; } - if (rmdir(fname) != expected_status(status)) { + if (rmdir(op->fname) != expected_status(op->status)) { printf("[%d] rmdir %s failed (%s) - expected %s\n", - child->line, fname, strerror(errno), status); - failed(child); + op->child->line, op->fname, strerror(errno), op->status); + failed(op->child); } - if (options.sync_dirs) sync_parent(child, fname); + if (options.sync_dirs) sync_parent(op->child, op->fname); } -static void fio_createx(struct child_struct *child, const char *fname, - uint32_t create_options, uint32_t create_disposition, int fnum, - const char *status) +static void fio_createx(struct dbench_op *op) { + uint32_t create_options = op->params[0]; + uint32_t create_disposition = op->params[1]; + int fnum = op->params[2]; int fd, i; int flags = O_RDWR; struct stat st; - struct ftable *ftable = (struct ftable *)child->private; + struct ftable *ftable = (struct ftable *)op->child->private; - resolve_name(child, fname); + resolve_name(op->child, op->fname); if (options.sync_open) flags |= O_SYNC; if (create_disposition == FILE_CREATE) { - if (options.stat_check && stat(fname, &st) == 0) { + if (options.stat_check && stat(op->fname, &st) == 0) { create_disposition = FILE_OPEN; } else { flags |= O_CREAT; @@ -274,28 +271,28 @@ static void fio_createx(struct child_struct *child, const char *fname, if (create_options & FILE_DIRECTORY_FILE) { /* not strictly correct, but close enough */ - if (!options.stat_check || stat(fname, &st) == -1) { - mkdir(fname, 0700); + if (!options.stat_check || stat(op->fname, &st) == -1) { + mkdir(op->fname, 0700); } } if (create_options & FILE_DIRECTORY_FILE) flags = O_RDONLY|O_DIRECTORY; - fd = open(fname, flags, 0600); + fd = open(op->fname, flags, 0600); if (fd == -1 && errno == EISDIR) { flags = O_RDONLY|O_DIRECTORY; - fd = open(fname, flags, 0600); + fd = open(op->fname, flags, 0600); } if (fd == -1) { - if (expected_status(status) == 0) { + if (expected_status(op->status) == 0) { printf("[%d] open %s failed for handle %d (%s)\n", - child->line, fname, fnum, strerror(errno)); + op->child->line, op->fname, fnum, strerror(errno)); } return; } - if (expected_status(status) != 0) { + if (expected_status(op->status) != 0) { printf("[%d] open %s succeeded for handle %d\n", - child->line, fname, fnum); + op->child->line, op->fname, fnum); close(fd); return; } @@ -304,37 +301,38 @@ static void fio_createx(struct child_struct *child, const char *fname, if (ftable[i].handle == 0) break; } if (i == MAX_FILES) { - printf("file table full for %s\n", fname); + printf("file table full for %s\n", op->fname); exit(1); } - ftable[i].name = strdup(fname); + ftable[i].name = strdup(op->fname); ftable[i].handle = fnum; ftable[i].fd = fd; fstat(fd, &st); if (!S_ISDIR(st.st_mode)) { - xattr_fd_write_hook(child, fd); + xattr_fd_write_hook(op->child, fd); } } -static void fio_writex(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status) +static void fio_writex(struct dbench_op *op) { - int i = find_handle(child, handle); + int handle = op->params[0]; + int offset = op->params[1]; + int size = op->params[2]; + int ret_size = op->params[3]; + int i = find_handle(op->child, handle); void *buf; struct stat st; - struct ftable *ftable = (struct ftable *)child->private; + struct ftable *ftable = (struct ftable *)op->child->private; ssize_t ret; if (options.fake_io) { - child->bytes += ret_size; - child->bytes_since_fsync += ret_size; + op->child->bytes += ret_size; + op->child->bytes_since_fsync += ret_size; return; } - (void)status; - buf = calloc(size, 1); if (options.one_byte_write_fix && @@ -344,13 +342,13 @@ static void fio_writex(struct child_struct *child, int handle, int offset, pread(ftable[i].fd, &c, 1, offset); if (c == ((unsigned char *)buf)[0]) { free(buf); - child->bytes += size; + op->child->bytes += size; return; } } else if (((unsigned char *)buf)[0] == 0) { ftruncate(ftable[i].fd, offset+1); free(buf); - child->bytes += size; + op->child->bytes += size; return; } } @@ -358,12 +356,12 @@ static void fio_writex(struct child_struct *child, int handle, int offset, ret = pwrite(ftable[i].fd, buf, size, offset); if (ret == -1) { printf("[%d] write failed on handle %d (%s)\n", - child->line, handle, strerror(errno)); + op->child->line, handle, strerror(errno)); exit(1); } if (ret != ret_size) { printf("[%d] wrote %d bytes, expected to write %d bytes on handle %d\n", - child->line, (int)ret, (int)ret_size, handle); + op->child->line, (int)ret, (int)ret_size, handle); exit(1); } @@ -371,143 +369,144 @@ static void fio_writex(struct child_struct *child, int handle, int offset, free(buf); - child->bytes += size; - child->bytes_since_fsync += size; + op->child->bytes += size; + op->child->bytes_since_fsync += size; } -static void fio_readx(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status) +static void fio_readx(struct dbench_op *op) { - int i = find_handle(child, handle); + int handle = op->params[0]; + int offset = op->params[1]; + int size = op->params[2]; + int ret_size = op->params[3]; + int i = find_handle(op->child, handle); void *buf; - struct ftable *ftable = (struct ftable *)child->private; + struct ftable *ftable = (struct ftable *)op->child->private; if (options.fake_io) { - child->bytes += ret_size; + op->child->bytes += ret_size; return; } - (void)status; - buf = malloc(size); if (pread(ftable[i].fd, buf, size, offset) != ret_size) { printf("[%d] read failed on handle %d (%s)\n", - child->line, handle, strerror(errno)); + op->child->line, handle, strerror(errno)); } free(buf); - child->bytes += size; + op->child->bytes += size; } -static void fio_close(struct child_struct *child, int handle, const char *status) +static void fio_close(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; - int i = find_handle(child, handle); - (void)status; + int handle = op->params[0]; + struct ftable *ftable = (struct ftable *)op->child->private; + int i = find_handle(op->child, handle); close(ftable[i].fd); ftable[i].handle = 0; if (ftable[i].name) free(ftable[i].name); ftable[i].name = NULL; } -static void fio_rename(struct child_struct *child, const char *old, const char *new, const char *status) +static void fio_rename(struct dbench_op *op) { - resolve_name(child, old); - resolve_name(child, new); + const char *old = op->fname; + const char *new = op->fname2; + + resolve_name(op->child, old); + resolve_name(op->child, new); if (options.stat_check) { struct stat st; - if (stat(old, &st) != 0 && expected_status(status) == 0) { + if (stat(old, &st) != 0 && expected_status(op->status) == 0) { printf("[%d] rename %s %s failed - file doesn't exist\n", - child->line, old, new); - failed(child); + op->child->line, old, new); + failed(op->child); return; } } - if (rename(old, new) != expected_status(status)) { + if (rename(old, new) != expected_status(op->status)) { printf("[%d] rename %s %s failed (%s) - expected %s\n", - child->line, old, new, strerror(errno), status); - failed(child); + op->child->line, old, new, strerror(errno), op->status); + failed(op->child); } - if (options.sync_dirs) sync_parent(child, new); + if (options.sync_dirs) sync_parent(op->child, new); } -static void fio_flush(struct child_struct *child, int handle, const char *status) +static void fio_flush(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; - int i = find_handle(child, handle); - (void)status; + int handle = op->params[0]; + struct ftable *ftable = (struct ftable *)op->child->private; + int i = find_handle(op->child, handle); fsync(ftable[i].fd); } -static void fio_qpathinfo(struct child_struct *child, const char *fname, int level, - const char *status) +static void fio_qpathinfo(struct dbench_op *op) { - (void)child; - (void)level; - (void)status; - resolve_name(child, fname); + resolve_name(op->child, op->fname); } -static void fio_qfileinfo(struct child_struct *child, int handle, int level, const char *status) +static void fio_qfileinfo(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; + int handle = op->params[0]; + int level = op->params[1]; + struct ftable *ftable = (struct ftable *)op->child->private; struct stat st; - int i = find_handle(child, handle); - (void)child; + int i = find_handle(op->child, handle); + (void)op->child; (void)level; - (void)status; fstat(ftable[i].fd, &st); - xattr_fd_read_hook(child, ftable[i].fd); + xattr_fd_read_hook(op->child, ftable[i].fd); } -static void fio_qfsinfo(struct child_struct *child, int level, const char *status) +static void fio_qfsinfo(struct dbench_op *op) { + int level = op->params[0]; struct statvfs st; (void)level; - (void)status; - statvfs(child->directory, &st); + statvfs(op->child->directory, &st); } -static void fio_findfirst(struct child_struct *child, const char *fname, int level, int maxcnt, - int count, const char *status) +static void fio_findfirst(struct dbench_op *op) { + int level = op->params[0]; + int maxcnt = op->params[1]; + int count = op->params[2]; DIR *dir; struct dirent *d; char *p; - (void)child; + (void)op->child; (void)level; (void)count; - (void)status; - resolve_name(child, fname); + resolve_name(op->child, op->fname); - if (strpbrk(fname, "<>*?\"") == NULL) { + if (strpbrk(op->fname, "<>*?\"") == NULL) { return; } - p = strrchr(fname, '/'); + p = strrchr(op->fname, '/'); if (!p) return; *p = 0; - dir = opendir(fname); + dir = opendir(op->fname); if (!dir) return; while (maxcnt && (d = readdir(dir))) maxcnt--; closedir(dir); } -void fio_deltree(struct child_struct *child, const char *dname) +static void fio_deltree(struct dbench_op *op) { DIR *d; struct dirent *de; - (void)child; - d = opendir(dname); + d = opendir(op->fname); if (d == NULL) return; for (de=readdir(d);de;de=readdir(d)) { @@ -517,7 +516,7 @@ void fio_deltree(struct child_struct *child, const char *dname) strcmp(de->d_name, "..") == 0) { continue; } - asprintf(&fname, "%s/%s", dname, de->d_name); + asprintf(&fname, "%s/%s", op->fname, de->d_name); if (fname == NULL) { printf("Out of memory\n"); exit(1); @@ -526,11 +525,13 @@ void fio_deltree(struct child_struct *child, const char *dname) continue; } if (S_ISDIR(st.st_mode)) { - fio_deltree(child, fname); + struct dbench_op op2 = *op; + op2.fname = fname; + fio_deltree(&op2); } else { if (unlink(fname) != 0) { printf("[%d] unlink '%s' failed - %s\n", - child->line, fname, strerror(errno)); + op->child->line, fname, strerror(errno)); } } free(fname); @@ -541,9 +542,14 @@ void fio_deltree(struct child_struct *child, const char *dname) static void fio_cleanup(struct child_struct *child) { char *dname; + struct dbench_op op; + + ZERO_STRUCT(op); asprintf(&dname, "%s/clients/client%d", child->directory, child->id); - fio_deltree(child, dname); + op.child = child; + op.fname = dname; + fio_deltree(&op); free(dname); asprintf(&dname, "%s%s", child->directory, "/clients"); @@ -552,17 +558,18 @@ static void fio_cleanup(struct child_struct *child) } -static void fio_sfileinfo(struct child_struct *child, int handle, int level, const char *status) +static void fio_sfileinfo(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; - int i = find_handle(child, handle); + int handle = op->params[0]; + int level = op->params[1]; + struct ftable *ftable = (struct ftable *)op->child->private; + int i = find_handle(op->child, handle); struct utimbuf tm; struct stat st; - (void)child; + (void)op->child; (void)handle; (void)level; - (void)status; - xattr_fd_read_hook(child, ftable[i].fd); + xattr_fd_read_hook(op->child, ftable[i].fd); fstat(ftable[i].fd, &st); @@ -572,19 +579,20 @@ static void fio_sfileinfo(struct child_struct *child, int handle, int level, con utime(ftable[i].name, &tm); if (!S_ISDIR(st.st_mode)) { - xattr_fd_write_hook(child, ftable[i].fd); + xattr_fd_write_hook(op->child, ftable[i].fd); } } -static void fio_lockx(struct child_struct *child, int handle, uint32_t offset, int size, - const char *status) +static void fio_lockx(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; - int i = find_handle(child, handle); + int handle = op->params[0]; + uint32_t offset = op->params[1]; + int size = op->params[2]; + struct ftable *ftable = (struct ftable *)op->child->private; + int i = find_handle(op->child, handle); struct flock lock; - (void)child; - (void)status; + (void)op->child; lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; @@ -595,16 +603,15 @@ static void fio_lockx(struct child_struct *child, int handle, uint32_t offset, i fcntl(ftable[i].fd, F_SETLKW, &lock); } -static void fio_unlockx(struct child_struct *child, - int handle, uint32_t offset, int size, const char *status) +static void fio_unlockx(struct dbench_op *op) { - struct ftable *ftable = (struct ftable *)child->private; - int i = find_handle(child, handle); + int handle = op->params[0]; + uint32_t offset = op->params[1]; + int size = op->params[2]; + struct ftable *ftable = (struct ftable *)op->child->private; + int i = find_handle(op->child, handle); struct flock lock; - (void)child; - (void)status; - lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; lock.l_start = offset; @@ -614,33 +621,30 @@ static void fio_unlockx(struct child_struct *child, fcntl(ftable[i].fd, F_SETLKW, &lock); } -void nb_sleep(struct child_struct *child, int usec, const char *status) -{ - (void)child; - (void)usec; - (void)status; - usleep(usec); -} +static struct backend_op ops[] = { + { "Deltree", fio_deltree }, + { "Flush", fio_flush }, + { "Close", fio_close }, + { "LockX", fio_lockx }, + { "Rmdir", fio_rmdir }, + { "Mkdir", fio_mkdir }, + { "Rename", fio_rename }, + { "ReadX", fio_readx }, + { "WriteX", fio_writex }, + { "Unlink", fio_unlink }, + { "UnlockX", fio_unlockx }, + { "FIND_FIRST", fio_findfirst }, + { "SET_FILE_INFORMATION", fio_sfileinfo }, + { "QUERY_FILE_INFORMATION", fio_qfileinfo }, + { "QUERY_PATH_INFORMATION", fio_qpathinfo }, + { "QUERY_FS_INFORMATION", fio_qfsinfo }, + { "NTCreateX", fio_createx }, + { NULL, NULL} +}; struct nb_operations nb_ops = { + .backend_name = "dbench", .setup = fio_setup, - .deltree = fio_deltree, .cleanup = fio_cleanup, - - .flush = fio_flush, - .close = fio_close, - .lockx = fio_lockx, - .rmdir = fio_rmdir, - .mkdir = fio_mkdir, - .rename = fio_rename, - .readx = fio_readx, - .writex = fio_writex, - .unlink = fio_unlink, - .unlockx = fio_unlockx, - .findfirst = fio_findfirst, - .sfileinfo = fio_sfileinfo, - .qfileinfo = fio_qfileinfo, - .qpathinfo = fio_qpathinfo, - .qfsinfo = fio_qfsinfo, - .createx = fio_createx, + .ops = ops }; diff --git a/nfsio.c b/nfsio.c index 9d28a08..e51ca18 100644 --- a/nfsio.c +++ b/nfsio.c @@ -1,7 +1,5 @@ /* - nfs backend for dbench - - Copyright (C) 2008 by Ronnie Sahlberg (ronniesahlberg@gmail.com) + Copyright (C) by Ronnie Sahlberg 2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,19 +31,45 @@ static char rw_buf[65536]; -void nb_sleep(struct child_struct *child, int usec, const char *status) -{ - (void)child; - (void)usec; - (void)status; - usleep(usec); -} - struct cb_data { struct nfsio *nfsio; char *dirname; }; +static void nfs3_deltree(struct dbench_op *op); + +static void nfs3_cleanup(struct child_struct *child) +{ + char *dname; + struct dbench_op op; + ZERO_STRUCT(op); + + asprintf(&dname, "/clients/client%d", child->id); + op.fname = dname; + op.child = child; + nfs3_deltree(&op); + free(dname); +} + +static void nfs3_setup(struct child_struct *child) +{ + const char *status = "0x00000000"; + + child->rate.last_time = timeval_current(); + child->rate.last_bytes = 0; + + + srandom(getpid() ^ time(NULL)); + child->private = nfsio_connect(options.server, options.export, options.protocol); + + if (child->private == NULL) { + child->failed = 1; + printf("nfsio_connect() failed\n"); + exit(10); + } +} + + static void dirent_cb(struct entryplus3 *e, void *private_data) { struct cb_data *cbd = private_data; @@ -99,15 +123,15 @@ static void dirent_cb(struct entryplus3 *e, void *private_data) free(objname); } -static void nfs3_deltree(struct child_struct *child, const char *dname) +static void nfs3_deltree(struct dbench_op *op) { struct cb_data *cbd; nfsstat3 res; cbd = malloc(sizeof(struct cb_data)); - cbd->nfsio = child->private; - cbd->dirname = discard_const(dname); + cbd->nfsio = op->child->private; + cbd->dirname = discard_const(op->fname); res = nfsio_lookup(cbd->nfsio, cbd->dirname, NULL); if (res != NFS3ERR_NOENT) { @@ -138,254 +162,236 @@ static void failed(struct child_struct *child) exit(1); } -static void nfs3_getattr(struct child_struct *child, const char *fname, const char *status) +static void nfs3_getattr(struct dbench_op *op) { nfsstat3 res; - res = nfsio_getattr(child->private, fname, NULL); - if (res != expected_status(status)) { + res = nfsio_getattr(op->child->private, op->fname, NULL); + if (res != expected_status(op->status)) { printf("[%d] GETATTR \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_lookup(struct child_struct *child, const char *fname, const char *status) +static void nfs3_lookup(struct dbench_op *op) { nfsstat3 res; - res = nfsio_lookup(child->private, fname, NULL); - if (res != expected_status(status)) { + res = nfsio_lookup(op->child->private, op->fname, NULL); + if (res != expected_status(op->status)) { printf("[%d] LOOKUP \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_create(struct child_struct *child, const char *fname, const char *status) +static void nfs3_create(struct dbench_op *op) { nfsstat3 res; - res = nfsio_create(child->private, fname); - if (res != expected_status(status)) { + res = nfsio_create(op->child->private, op->fname); + if (res != expected_status(op->status)) { printf("[%d] CREATE \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_write(struct child_struct *child, const char *fname, int offset, int len, int stable, const char *status) +static void nfs3_write(struct dbench_op *op) { + int offset = op->params[0]; + int len = op->params[1]; + int stable = op->params[2]; nfsstat3 res; - res = nfsio_write(child->private, fname, rw_buf, offset, len, stable); - if (res != expected_status(status)) { + res = nfsio_write(op->child->private, op->fname, rw_buf, offset, len, stable); + if (res != expected_status(op->status)) { printf("[%d] WRITE \"%s\" failed (%x) - expected %x\n", - child->line, fname, - res, expected_status(status)); - failed(child); + op->child->line, op->fname, + res, expected_status(op->status)); + failed(op->child); } - child->bytes += len; + op->child->bytes += len; } -static void nfs3_commit(struct child_struct *child, const char *fname, const char *status) +static void nfs3_commit(struct dbench_op *op) { nfsstat3 res; - res = nfsio_commit(child->private, fname); - if (res != expected_status(status)) { + res = nfsio_commit(op->child->private, op->fname); + if (res != expected_status(op->status)) { printf("[%d] COMMIT \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_read(struct child_struct *child, const char *fname, int offset, int len, const char *status) +static void nfs3_read(struct dbench_op *op) { + int offset = op->params[0]; + int len = op->params[1]; nfsstat3 res = 0; - res = nfsio_read(child->private, fname, rw_buf, offset, len, NULL, NULL); - if (res != expected_status(status)) { + res = nfsio_read(op->child->private, op->fname, rw_buf, offset, len, NULL, NULL); + if (res != expected_status(op->status)) { printf("[%d] READ \"%s\" failed (%x) - expected %x\n", - child->line, fname, - res, expected_status(status)); - failed(child); + op->child->line, op->fname, + res, expected_status(op->status)); + failed(op->child); } - child->bytes += len; + op->child->bytes += len; } -static void nfs3_access(struct child_struct *child, const char *fname, int desired, int granted, const char *status) +static void nfs3_access(struct dbench_op *op) { nfsstat3 res; - res = nfsio_access(child->private, fname, 0, NULL); - if (res != expected_status(status)) { + res = nfsio_access(op->child->private, op->fname, 0, NULL); + if (res != expected_status(op->status)) { printf("[%d] ACCESS \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_mkdir(struct child_struct *child, const char *fname, const char *status) +static void nfs3_mkdir(struct dbench_op *op) { nfsstat3 res; - res = nfsio_mkdir(child->private, fname); - if (res != expected_status(status)) { + res = nfsio_mkdir(op->child->private, op->fname); + if (res != expected_status(op->status)) { printf("[%d] MKDIR \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_rmdir(struct child_struct *child, const char *fname, const char *status) +static void nfs3_rmdir(struct dbench_op *op) { nfsstat3 res; - res = nfsio_rmdir(child->private, fname); - if (res != expected_status(status)) { + res = nfsio_rmdir(op->child->private, op->fname); + if (res != expected_status(op->status)) { printf("[%d] RMDIR \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_fsstat(struct child_struct *child, const char *status) +static void nfs3_fsstat(struct dbench_op *op) { nfsstat3 res; - res = nfsio_fsstat(child->private); - if (res != expected_status(status)) { + res = nfsio_fsstat(op->child->private); + if (res != expected_status(op->status)) { printf("[%d] FSSTAT failed (%x) - expected %x\n", - child->line, res, expected_status(status)); - failed(child); + op->child->line, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_fsinfo(struct child_struct *child, const char *status) +static void nfs3_fsinfo(struct dbench_op *op) { nfsstat3 res; - res = nfsio_fsinfo(child->private); - if (res != expected_status(status)) { + res = nfsio_fsinfo(op->child->private); + if (res != expected_status(op->status)) { printf("[%d] FSINFO failed (%x) - expected %x\n", - child->line, res, expected_status(status)); - failed(child); - } -} - -static void nfs3_cleanup(struct child_struct *child) -{ - char *dname; - - asprintf(&dname, "/clients/client%d", child->id); - nfs3_deltree(child, dname); - free(dname); -} - -static void nfs3_setup(struct child_struct *child) -{ - const char *status = "0x00000000"; - - child->rate.last_time = timeval_current(); - child->rate.last_bytes = 0; - - - srandom(getpid() ^ time(NULL)); - child->private = nfsio_connect(options.server, options.export, options.protocol); - - if (child->private == NULL) { - child->failed = 1; - printf("nfsio_connect() failed\n"); - exit(10); + op->child->line, res, expected_status(op->status)); + failed(op->child); } - } -static void nfs3_symlink(struct child_struct *child, const char *fname, const char *fname2, const char *status) +static void nfs3_symlink(struct dbench_op *op) { nfsstat3 res; - res = nfsio_symlink(child->private, fname, fname2); - if (res != expected_status(status)) { + res = nfsio_symlink(op->child->private, op->fname, op->fname2); + if (res != expected_status(op->status)) { printf("[%d] SYMLINK \"%s\"->\"%s\" failed (%x) - expected %x\n", - child->line, fname, fname2, - res, expected_status(status)); - failed(child); + op->child->line, op->fname, op->fname2, + res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_remove(struct child_struct *child, const char *fname, const char *status) +static void nfs3_remove(struct dbench_op *op) { nfsstat3 res; - res = nfsio_remove(child->private, fname); - if (res != expected_status(status)) { + res = nfsio_remove(op->child->private, op->fname); + if (res != expected_status(op->status)) { printf("[%d] REMOVE \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_readdirplus(struct child_struct *child, const char *fname, const char *status) +static void nfs3_readdirplus(struct dbench_op *op) { nfsstat3 res; - res = nfsio_readdirplus(child->private, fname, NULL, NULL); - if (res != expected_status(status)) { + res = nfsio_readdirplus(op->child->private, op->fname, NULL, NULL); + if (res != expected_status(op->status)) { printf("[%d] READDIRPLUS \"%s\" failed (%x) - expected %x\n", - child->line, fname, res, expected_status(status)); - failed(child); + op->child->line, op->fname, res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_link(struct child_struct *child, const char *fname, const char *fname2, const char *status) +static void nfs3_link(struct dbench_op *op) { nfsstat3 res; - res = nfsio_link(child->private, fname, fname2); - if (res != expected_status(status)) { + res = nfsio_link(op->child->private, op->fname, op->fname2); + if (res != expected_status(op->status)) { printf("[%d] LINK \"%s\"->\"%s\" failed (%x) - expected %x\n", - child->line, fname, fname2, - res, expected_status(status)); - failed(child); + op->child->line, op->fname, op->fname2, + res, expected_status(op->status)); + failed(op->child); } } -static void nfs3_rename(struct child_struct *child, const char *fname, const char *fname2, const char *status) +static void nfs3_rename(struct dbench_op *op) { nfsstat3 res; - res = nfsio_rename(child->private, fname, fname2); - if (res != expected_status(status)) { + res = nfsio_rename(op->child->private, op->fname, op->fname2); + if (res != expected_status(op->status)) { printf("[%d] RENAME \"%s\"->\"%s\" failed (%x) - expected %x\n", - child->line, fname, fname2, - res, expected_status(status)); - failed(child); + op->child->line, op->fname, op->fname2, + res, expected_status(op->status)); + failed(op->child); } } +static struct backend_op ops[] = { + { "Deltree", nfs3_deltree }, + { "GETATTR3", nfs3_getattr }, + { "LOOKUP3", nfs3_lookup }, + { "CREATE3", nfs3_create }, + { "WRITE3", nfs3_write }, + { "COMMIT3", nfs3_commit }, + { "READ3", nfs3_read }, + { "ACCESS3", nfs3_access }, + { "MKDIR3", nfs3_mkdir }, + { "RMDIR3", nfs3_rmdir }, + { "FSSTAT3", nfs3_fsstat }, + { "FSINFO3", nfs3_fsinfo }, + { "SYMLINK3", nfs3_symlink }, + { "REMOVE3", nfs3_remove }, + { "READDIRPLUS3", nfs3_readdirplus }, + { "RENAME3", nfs3_rename }, + { "LINK3", nfs3_link }, + { NULL, NULL} +}; + struct nb_operations nb_ops = { - .setup = nfs3_setup, - .deltree = nfs3_deltree, - .cleanup = nfs3_cleanup, - - .getattr3 = nfs3_getattr, - .lookup3 = nfs3_lookup, - .create3 = nfs3_create, - .write3 = nfs3_write, - .commit3 = nfs3_commit, - .read3 = nfs3_read, - .access3 = nfs3_access, - .mkdir3 = nfs3_mkdir, - .rmdir3 = nfs3_rmdir, - .fsstat3 = nfs3_fsstat, - .fsinfo3 = nfs3_fsinfo, - .symlink3 = nfs3_symlink, - .remove3 = nfs3_remove, - .readdirplus3 = nfs3_readdirplus, - .rename3 = nfs3_rename, - .link3 = nfs3_link, + .backend_name = "nfsbench", + .setup = nfs3_setup, + .cleanup = nfs3_cleanup, + .ops = ops }; diff --git a/proto.h b/proto.h index 336b98d..c2db129 100644 --- a/proto.h +++ b/proto.h @@ -13,33 +13,6 @@ void child_run(struct child_struct *child0, const char *loadfile); /* The following definitions come from fileio.c */ -void nb_unlink(struct child_struct *child, const char *fname, int attr, const char *status); -void nb_mkdir(struct child_struct *child, const char *dname, const char *status); -void nb_rmdir(struct child_struct *child, const char *fname, const char *status); -void nb_createx(struct child_struct *child, const char *fname, - uint32_t create_options, uint32_t create_disposition, int fnum, - const char *status); -void nb_writex(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status); -void nb_readx(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status); -void nb_close(struct child_struct *child, int handle, const char *status); -void nb_rename(struct child_struct *child, const char *old, const char *new, const char *status); -void nb_flush(struct child_struct *child, int handle, const char *status); -void nb_qpathinfo(struct child_struct *child, const char *fname, int level, - const char *status); -void nb_qfileinfo(struct child_struct *child, int handle, int level, const char *status); -void nb_qfsinfo(struct child_struct *child, int level, const char *status); -void nb_findfirst(struct child_struct *child, const char *fname, int level, int maxcnt, - int count, const char *status); -void nb_cleanup(struct child_struct *child); -void nb_deltree(struct child_struct *child, const char *dname); -void nb_sfileinfo(struct child_struct *child, int handle, int level, const char *status); -void nb_lockx(struct child_struct *child, int handle, uint32_t offset, int size, - const char *status); -void nb_unlockx(struct child_struct *child, - int handle, uint32_t offset, int size, const char *status); -void nb_sleep(struct child_struct *child, int usec, const char *status); /* The following definitions come from io.c */ @@ -57,58 +30,18 @@ void do_create(char *fname, int size); /* The following definitions come from libnfs.c */ - -/* The following definitions come from mount_client.c */ - - -/* The following definitions come from mount_xdr.c */ - - -/* The following definitions come from nfs_client.c */ - - -/* The following definitions come from nfs_xdr.c */ - +const char *nfs_error(int error); +void nfsio_disconnect(struct nfsio *nfsio); +struct nfsio *nfsio_connect(const char *server, const char *export, const char *protocol); /* The following definitions come from nfsio.c */ -void nb_sleep(struct child_struct *child, int usec, const char *status); -void nb_deltree(struct child_struct *child, const char *dname); -void nb_cleanup(struct child_struct *child); -void nb_sfileinfo(struct child_struct *child, int handle, int level, const char *status); /* The following definitions come from snprintf.c */ /* The following definitions come from sockio.c */ -void nb_unlink(struct child_struct *child, const char *fname, int attr, const char *status); -void nb_mkdir(struct child_struct *child, const char *dname, const char *status); -void nb_rmdir(struct child_struct *child, const char *fname, const char *status); -void nb_createx(struct child_struct *child, const char *fname, - uint32_t create_options, uint32_t create_disposition, int fnum, - const char *status); -void nb_writex(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status); -void nb_readx(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status); -void nb_close(struct child_struct *child, int handle, const char *status); -void nb_rename(struct child_struct *child, const char *old, const char *new, const char *status); -void nb_flush(struct child_struct *child, int handle, const char *status); -void nb_qpathinfo(struct child_struct *child, const char *fname, int level, - const char *status); -void nb_qfileinfo(struct child_struct *child, int handle, int level, const char *status); -void nb_qfsinfo(struct child_struct *child, int level, const char *status); -void nb_findfirst(struct child_struct *child, const char *fname, int level, int maxcnt, - int count, const char *status); -void nb_cleanup(struct child_struct *child); -void nb_deltree(struct child_struct *child, const char *dname); -void nb_sfileinfo(struct child_struct *child, int handle, int level, const char *status); -void nb_lockx(struct child_struct *child, int handle, uint32_t offset, int size, - const char *status); -void nb_unlockx(struct child_struct *child, - int handle, uint32_t offset, int size, const char *status); -void nb_sleep(struct child_struct *child, int usec, const char *status); /* The following definitions come from socklib.c */ diff --git a/sockio.c b/sockio.c index 8ed6334..16c1944 100644 --- a/sockio.c +++ b/sockio.c @@ -82,121 +82,76 @@ static void sio_setup(struct child_struct *child) } -static void sio_unlink(struct child_struct *child, const char *fname, int attr, const char *status) +static void sio_unlink(struct dbench_op *op) { - (void)child; - (void)attr; - (void)status; - do_packets(child, 39+2+strlen(fname)*2+2, 39); + do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39); } -static void sio_mkdir(struct child_struct *child, const char *dname, const char *status) +static void sio_mkdir(struct dbench_op *op) { - (void)child; - (void)status; - do_packets(child, 39+2+strlen(dname)*2+2, 39); + do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39); } -static void sio_rmdir(struct child_struct *child, const char *fname, const char *status) +static void sio_rmdir(struct dbench_op *op) { - (void)child; - (void)status; - do_packets(child, 39+2+strlen(fname)*2+2, 39); + do_packets(op->child, 39+2+strlen(op->fname)*2+2, 39); } -static void sio_createx(struct child_struct *child, const char *fname, - uint32_t create_options, uint32_t create_disposition, int fnum, - const char *status) +static void sio_createx(struct dbench_op *op) { - (void)child; - (void)create_options; - (void)create_disposition; - (void)fnum; - (void)status; - do_packets(child, 70+2+strlen(fname)*2+2, 39+12*4); + do_packets(op->child, 70+2+strlen(op->fname)*2+2, 39+12*4); } -static void sio_writex(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status) +static void sio_writex(struct dbench_op *op) { - (void)child; - (void)handle; - (void)offset; - (void)ret_size; - (void)status; - do_packets(child, 39+20+size, 39+16); - child->bytes += size; + int size = op->params[2]; + do_packets(op->child, 39+20+size, 39+16); + op->child->bytes += size; } -static void sio_readx(struct child_struct *child, int handle, int offset, - int size, int ret_size, const char *status) +static void sio_readx(struct dbench_op *op) { - (void)child; - (void)handle; - (void)offset; - (void)size; - (void)status; - do_packets(child, 39+20, 39+20+ret_size); - child->bytes += ret_size; + int ret_size = op->params[3]; + do_packets(op->child, 39+20, 39+20+ret_size); + op->child->bytes += ret_size; } -static void sio_close(struct child_struct *child, int handle, const char *status) +static void sio_close(struct dbench_op *op) { - (void)child; - (void)handle; - (void)status; - do_packets(child, 39+8, 39); + do_packets(op->child, 39+8, 39); } -static void sio_rename(struct child_struct *child, const char *old, const char *new, const char *status) +static void sio_rename(struct dbench_op *op) { - (void)child; - (void)status; - do_packets(child, 39+8+2*strlen(old)+2*strlen(new), 39); + const char *old = op->fname; + const char *new = op->fname2; + do_packets(op->child, 39+8+2*strlen(old)+2*strlen(new), 39); } -static void sio_flush(struct child_struct *child, int handle, const char *status) +static void sio_flush(struct dbench_op *op) { - (void)child; - (void)handle; - (void)status; - do_packets(child, 39+2, 39); + do_packets(op->child, 39+2, 39); } -static void sio_qpathinfo(struct child_struct *child, const char *fname, int level, - const char *status) +static void sio_qpathinfo(struct dbench_op *op) { - (void)child; - (void)level; - (void)status; - do_packets(child, 39+16+2*strlen(fname), 39+32); + do_packets(op->child, 39+16+2*strlen(op->fname), 39+32); } -static void sio_qfileinfo(struct child_struct *child, int handle, int level, const char *status) +static void sio_qfileinfo(struct dbench_op *op) { - (void)child; - (void)level; - (void)handle; - (void)status; - do_packets(child, 39+20, 39+32); + do_packets(op->child, 39+20, 39+32); } -static void sio_qfsinfo(struct child_struct *child, int level, const char *status) +static void sio_qfsinfo(struct dbench_op *op) { - (void)child; - (void)level; - (void)status; - do_packets(child, 39+20, 39+32); + do_packets(op->child, 39+20, 39+32); } -static void sio_findfirst(struct child_struct *child, const char *fname, int level, int maxcnt, - int count, const char *status) +static void sio_findfirst(struct dbench_op *op) { - (void)child; - (void)level; - (void)maxcnt; - (void)status; - do_packets(child, 39+20+strlen(fname)*2, 39+90*count); + int count = op->params[2]; + do_packets(op->child, 39+20+strlen(op->fname)*2, 39+90*count); } static void sio_cleanup(struct child_struct *child) @@ -204,70 +159,50 @@ static void sio_cleanup(struct child_struct *child) (void)child; } -static void sio_deltree(struct child_struct *child, const char *dname) +static void sio_deltree(struct dbench_op *op) { - (void)child; - (void)dname; + (void)op; } -static void sio_sfileinfo(struct child_struct *child, int handle, int level, const char *status) +static void sio_sfileinfo(struct dbench_op *op) { - (void)child; - (void)handle; - (void)level; - (void)status; - do_packets(child, 39+32, 39+8); + do_packets(op->child, 39+32, 39+8); } -static void sio_lockx(struct child_struct *child, int handle, uint32_t offset, int size, - const char *status) +static void sio_lockx(struct dbench_op *op) { - (void)child; - (void)handle; - (void)offset; - (void)size; - (void)status; - do_packets(child, 39+12, 39); + do_packets(op->child, 39+12, 39); } -static void sio_unlockx(struct child_struct *child, - int handle, uint32_t offset, int size, const char *status) +static void sio_unlockx(struct dbench_op *op) { - (void)child; - (void)handle; - (void)offset; - (void)size; - (void)status; - do_packets(child, 39+12, 39); + do_packets(op->child, 39+12, 39); } -void nb_sleep(struct child_struct *child, int usec, const char *status) -{ - (void)child; - (void)usec; - (void)status; - usleep(usec); -} +static struct backend_op ops[] = { + { "Deltree", sio_deltree }, + { "Flush", sio_flush }, + { "Close", sio_close }, + { "LockX", sio_lockx }, + { "Rmdir", sio_rmdir }, + { "Mkdir", sio_mkdir }, + { "Rename", sio_rename }, + { "ReadX", sio_readx }, + { "WriteX", sio_writex }, + { "Unlink", sio_unlink }, + { "UnlockX", sio_unlockx }, + { "FIND_FIRST", sio_findfirst }, + { "SET_FILE_INFORMATION", sio_sfileinfo }, + { "QUERY_FILE_INFORMATION", sio_qfileinfo }, + { "QUERY_PATH_INFORMATION", sio_qpathinfo }, + { "QUERY_FS_INFORMATION", sio_qfsinfo }, + { "NTCreateX", sio_createx }, + { NULL, NULL} +}; struct nb_operations nb_ops = { - .setup = sio_setup, - .deltree = sio_deltree, - .cleanup = sio_cleanup, - - .flush = sio_flush, - .close = sio_close, - .lockx = sio_lockx, - .rmdir = sio_rmdir, - .mkdir = sio_mkdir, - .rename = sio_rename, - .readx = sio_readx, - .writex = sio_writex, - .unlink = sio_unlink, - .unlockx = sio_unlockx, - .findfirst = sio_findfirst, - .sfileinfo = sio_sfileinfo, - .qfileinfo = sio_qfileinfo, - .qpathinfo = sio_qpathinfo, - .qfsinfo = sio_qfsinfo, - .createx = sio_createx, + .backend_name = "tbench", + .setup = sio_setup, + .cleanup = sio_cleanup, + .ops = ops }; -- 2.34.1