converted all backends to new common format
[tridge/dbench.git] / child.c
diff --git a/child.c b/child.c
index 9a3b91c18b6b75366ddf6a52d628e46aa2855455..e6b4845ad395a75ce9a5512bd59ba3bc4aa53562 100644 (file)
--- a/child.c
+++ b/child.c
 
 #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;i<sizeof(op.params)/sizeof(op.params[0]);i++) {
+               op.params[i] = params[i]?ival(params[i]):0;
+       }
+
+       if (strcasecmp(op.op, "Sleep") == 0) {
+               nb_sleep(op.params[0]);
+               return;
+       }
+
+       for (i=0;nb_ops.ops[i].name;i++) {
+               if (strcasecmp(op.op, nb_ops.ops[i].name) == 0) {
+                       nb_ops.ops[i].fn(&op);
+                       finish_op(child, &child->ops[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;child<child0+options.clients_per_process;child++) {
+                       int pcount = 1;
+
                        fname[0] = 0;
                        fname2[0] = 0;
 
                        if (i>1 && 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);
                }
        }