[dbench @ cvs-1:tridge-20031015155848-mo532i7yg19srujm]
[tridge/dbench.git] / child.c
1 /* 
2    dbench version 2
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 (!strncmp(params[0],"SMB", 3)) {
83                         printf("ERROR: You are using a dbench 1 load file\n");
84                         exit(1);
85                 }
86
87                 if (!strcmp(params[0],"NTCreateX")) {
88                         nb_createx(child, params[1], ival(params[2]), ival(params[3]), 
89                                    ival(params[4]));
90                 } else if (!strcmp(params[0],"Close")) {
91                         nb_close(child, ival(params[1]));
92                 } else if (!strcmp(params[0],"Rename")) {
93                         nb_rename(child, params[1], params[2]);
94                 } else if (!strcmp(params[0],"Unlink")) {
95                         nb_unlink(child, params[1]);
96                 } else if (!strcmp(params[0],"Deltree")) {
97                         nb_deltree(child, params[1]);
98                 } else if (!strcmp(params[0],"Rmdir")) {
99                         nb_rmdir(child, params[1]);
100                 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
101                         nb_qpathinfo(child, params[1]);
102                 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
103                         nb_qfileinfo(child, ival(params[1]));
104                 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
105                         nb_qfsinfo(child, ival(params[1]));
106                 } else if (!strcmp(params[0],"FIND_FIRST")) {
107                         nb_findfirst(child, params[1]);
108                 } else if (!strcmp(params[0],"WriteX")) {
109                         nb_writex(child, ival(params[1]), 
110                                   ival(params[2]), ival(params[3]), ival(params[4]));
111                 } else if (!strcmp(params[0],"ReadX")) {
112                         nb_readx(child, ival(params[1]), 
113                                   ival(params[2]), ival(params[3]), ival(params[4]));
114                 } else if (!strcmp(params[0],"Flush")) {
115                         nb_flush(child, ival(params[1]));
116                 } else {
117                         printf("Unknown operation %s\n", params[0]);
118                         fflush(stdout);
119                         exit(1);
120                 }
121         }
122         fclose(f);
123
124         nb_cleanup(child);
125
126         child->done = 1;
127 }