[dbench @ cvs-1:tridge-20020204020859-7k0wp7jku0v37qkv]
[amitay/dbench.git] / child.c
1 /* 
2    dbench version 1
3    Copyright (C) Andrew Tridgell 1999
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /* This file links against either fileio.c to do operations against a
21    local filesystem (making dbench), or sockio.c to issue SMB-like
22    command packets over a socket (making tbench).
23
24    So, the pattern of operations and the control structure is the same
25    for both benchmarks, but the operations performed are different.
26 */
27
28 #include "dbench.h"
29
30 char *client_filename = DATADIR "client_oplocks.txt";
31
32
33 FILE * open_client_dump(void)
34 {
35         FILE            *f;
36
37         if ((f = fopen(client_filename, "rt")) != NULL)
38                 return f;
39
40         fprintf(stderr,
41                 "dbench: error opening %s: %s\n", client_filename,
42                 strerror(errno));
43
44         return NULL;
45 }
46
47 #define ival(s) strtol(s, NULL, 0)
48
49 void child_run(struct child_struct *child)
50 {
51         int i;
52         char line[1024];
53         char cname[20];
54         FILE *f;
55         char *params[20];
56
57         child->line = 0;
58
59         sprintf(cname,"client%d", child->id);
60
61         f = open_client_dump();
62
63         if (!f) {
64                 exit(1);
65         }
66
67         while (fgets(line, sizeof(line)-1, f)) {
68                 child->line++;
69
70                 all_string_sub(line,"client1", cname);
71                 all_string_sub(line,"\\", "/");
72                 all_string_sub(line," /", " ");
73                 
74                 /* parse the command parameters */
75                 params[0] = strtok(line," \n");
76                 i = 0;
77                 while (params[i]) params[++i] = strtok(NULL," \n");
78                 params[i] = "";
79
80                 if (i < 2) continue;
81
82                 if (!strcmp(params[0],"NTCreateX")) {
83                         nb_createx(child, params[1], ival(params[2]), ival(params[3]), 
84                                    ival(params[4]));
85                 } else if (!strcmp(params[0],"Close")) {
86                         nb_close(child, ival(params[1]));
87                 } else if (!strcmp(params[0],"Rename")) {
88                         nb_rename(child, params[1], params[2]);
89                 } else if (!strcmp(params[0],"Unlink")) {
90                         nb_unlink(child, params[1]);
91                 } else if (!strcmp(params[0],"Rmdir")) {
92                         nb_rmdir(child, params[1]);
93                 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
94                         nb_qpathinfo(child, params[1]);
95                 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
96                         nb_qfileinfo(child, ival(params[1]));
97                 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
98                         nb_qfsinfo(child, ival(params[1]));
99                 } else if (!strcmp(params[0],"FIND_FIRST")) {
100                         nb_findfirst(child, params[1]);
101                 } else if (!strcmp(params[0],"WriteX")) {
102                         nb_writex(child, ival(params[1]), 
103                                   ival(params[2]), ival(params[3]), ival(params[4]));
104                 } else if (!strcmp(params[0],"ReadX")) {
105                         nb_readx(child, ival(params[1]), 
106                                   ival(params[2]), ival(params[3]), ival(params[4]));
107                 } else if (!strcmp(params[0],"Flush")) {
108                         nb_flush(child, ival(params[1]));
109                 } else {
110                         printf("Unknown operation %s\n", params[0]);
111                         fflush(stdout);
112                         exit(1);
113                 }
114         }
115         fclose(f);
116
117         nb_cleanup(child);
118
119         child->done = 1;
120 }