4 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 1997-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "system/time.h"
25 #include "system/filesys.h"
26 #include "dlinklist.h"
27 #include "librpc/gen_ndr/ndr_security.h"
28 #include "libcli/raw/libcliraw.h"
32 extern int nbench_line_count;
33 static int nbio_id = -1;
35 static BOOL bypass_io;
36 static struct timeval tv_start, tv_end;
37 static int warmup, timelimit;
38 static int in_cleanup;
41 struct ftable *next, *prev;
42 int fd; /* the fd that we got back from the server */
43 int handle; /* the handle in the load file */
46 static struct ftable *ftable;
49 double bytes, warmup_bytes;
54 double nbio_result(void)
58 for (i=0;i<nprocs;i++) {
59 total += children[i].bytes - children[i].warmup_bytes;
61 return 1.0e-6 * total / timeval_elapsed2(&tv_start, &tv_end);
66 return children[nbio_id].done;
70 void nb_alarm(int sig)
77 if (nbio_id != -1) return;
79 for (i=0;i<nprocs;i++) {
80 if (children[i].bytes == 0) {
83 lines += children[i].line;
86 t = timeval_elapsed(&tv_start);
88 if (!in_warmup && warmup>0 && t > warmup) {
89 tv_start = timeval_current();
91 for (i=0;i<nprocs;i++) {
92 children[i].warmup_bytes = children[i].bytes;
98 } else if (!in_warmup && !in_cleanup && t > timelimit) {
99 for (i=0;i<nprocs;i++) {
100 children[i].done = 1;
102 tv_end = timeval_current();
109 tv_end = timeval_current();
113 printf("%4d %8d %.2f MB/sec warmup %.0f sec \n",
114 nprocs, lines/nprocs,
116 } else if (in_cleanup) {
117 printf("%4d %8d %.2f MB/sec cleanup %.0f sec \n",
118 nprocs, lines/nprocs,
121 printf("%4d %8d %.2f MB/sec execute %.0f sec \n",
122 nprocs, lines/nprocs,
128 signal(SIGALRM, nb_alarm);
132 void nbio_shmem(int n, int t_timelimit, int t_warmup)
135 children = shm_setup(sizeof(*children) * nprocs);
137 printf("Failed to setup shared memory!\n");
140 memset(children, 0, sizeof(*children) * nprocs);
141 timelimit = t_timelimit;
144 tv_start = timeval_current();
147 static struct ftable *find_ftable(int handle)
151 for (f=ftable;f;f=f->next) {
152 if (f->handle == handle) return f;
157 static int find_handle(int handle)
161 children[nbio_id].line = nbench_line_count;
163 f = find_ftable(handle);
167 printf("(%d) ERROR: handle %d was not found\n",
168 nbench_line_count, handle);
171 return -1; /* Not reached */
176 static struct smbcli_state *c;
179 a handler function for oplock break requests
181 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
183 struct smbcli_tree *tree = private;
184 return smbcli_oplock_ack(tree, fnum, level);
187 void nb_setup(struct smbcli_state *cli, int id)
192 printf("skipping I/O\n");
195 smbcli_oplock_handler(cli->transport, oplock_handler, cli->tree);
200 static void check_status(const char *op, NTSTATUS status, NTSTATUS ret)
202 if (!NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(ret)) {
203 printf("[%d] Error: %s should have failed with %s\n",
204 nbench_line_count, op, nt_errstr(status));
208 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(ret)) {
209 printf("[%d] Error: %s should have succeeded - %s\n",
210 nbench_line_count, op, nt_errstr(ret));
214 if (!NT_STATUS_EQUAL(status, ret)) {
215 printf("[%d] Warning: got status %s but expected %s\n",
216 nbench_line_count, nt_errstr(ret), nt_errstr(status));
221 void nb_unlink(const char *fname, int attr, NTSTATUS status)
223 struct smb_unlink io;
226 io.in.pattern = fname;
228 io.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
229 if (strchr(fname, '*') == 0) {
230 io.in.attrib |= FILE_ATTRIBUTE_DIRECTORY;
233 ret = smb_raw_unlink(c->tree, &io);
235 check_status("Unlink", status, ret);
239 void nb_createx(const char *fname,
240 uint_t create_options, uint_t create_disposition, int handle,
244 uint32_t desired_access;
250 mem_ctx = talloc_init("raw_open");
252 if (create_options & NTCREATEX_OPTIONS_DIRECTORY) {
253 desired_access = SEC_FILE_READ_DATA;
257 SEC_FILE_WRITE_DATA |
258 SEC_FILE_READ_ATTRIBUTE |
259 SEC_FILE_WRITE_ATTRIBUTE;
260 flags = NTCREATEX_FLAGS_EXTENDED |
261 NTCREATEX_FLAGS_REQUEST_OPLOCK |
262 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
265 io.ntcreatex.level = RAW_OPEN_NTCREATEX;
266 io.ntcreatex.in.flags = flags;
267 io.ntcreatex.in.root_fid = 0;
268 io.ntcreatex.in.access_mask = desired_access;
269 io.ntcreatex.in.file_attr = 0;
270 io.ntcreatex.in.alloc_size = 0;
271 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE;
272 io.ntcreatex.in.open_disposition = create_disposition;
273 io.ntcreatex.in.create_options = create_options;
274 io.ntcreatex.in.impersonation = 0;
275 io.ntcreatex.in.security_flags = 0;
276 io.ntcreatex.in.fname = fname;
278 ret = smb_raw_open(c->tree, mem_ctx, &io);
280 talloc_free(mem_ctx);
282 check_status("NTCreateX", status, ret);
284 if (!NT_STATUS_IS_OK(ret)) return;
286 f = malloc_p(struct ftable);
288 f->fd = io.ntcreatex.out.fnum;
290 DLIST_ADD_END(ftable, f, struct ftable *);
293 void nb_writex(int handle, int offset, int size, int ret_size, NTSTATUS status)
300 i = find_handle(handle);
302 if (bypass_io) return;
305 memset(buf, 0xab, size);
307 io.writex.level = RAW_WRITE_WRITEX;
308 io.writex.in.fnum = i;
309 io.writex.in.wmode = 0;
310 io.writex.in.remaining = 0;
311 io.writex.in.offset = offset;
312 io.writex.in.count = size;
313 io.writex.in.data = buf;
315 ret = smb_raw_write(c->tree, &io);
319 check_status("WriteX", status, ret);
321 if (NT_STATUS_IS_OK(ret) && io.writex.out.nwritten != ret_size) {
322 printf("[%d] Warning: WriteX got count %d expected %d\n",
324 io.writex.out.nwritten, ret_size);
327 children[nbio_id].bytes += ret_size;
330 void nb_write(int handle, int offset, int size, int ret_size, NTSTATUS status)
337 i = find_handle(handle);
339 if (bypass_io) return;
343 memset(buf, 0x12, size);
345 io.write.level = RAW_WRITE_WRITE;
346 io.write.in.fnum = i;
347 io.write.in.remaining = 0;
348 io.write.in.offset = offset;
349 io.write.in.count = size;
350 io.write.in.data = buf;
352 ret = smb_raw_write(c->tree, &io);
356 check_status("Write", status, ret);
358 if (NT_STATUS_IS_OK(ret) && io.write.out.nwritten != ret_size) {
359 printf("[%d] Warning: Write got count %d expected %d\n",
361 io.write.out.nwritten, ret_size);
364 children[nbio_id].bytes += ret_size;
368 void nb_lockx(int handle, uint_t offset, int size, NTSTATUS status)
373 struct smb_lock_entry lck;
375 i = find_handle(handle);
381 io.lockx.level = RAW_LOCK_LOCKX;
382 io.lockx.in.fnum = i;
383 io.lockx.in.mode = 0;
384 io.lockx.in.timeout = 0;
385 io.lockx.in.ulock_cnt = 0;
386 io.lockx.in.lock_cnt = 1;
387 io.lockx.in.locks = &lck;
389 ret = smb_raw_lock(c->tree, &io);
391 check_status("LockX", status, ret);
394 void nb_unlockx(int handle, uint_t offset, int size, NTSTATUS status)
399 struct smb_lock_entry lck;
401 i = find_handle(handle);
407 io.lockx.level = RAW_LOCK_LOCKX;
408 io.lockx.in.fnum = i;
409 io.lockx.in.mode = 0;
410 io.lockx.in.timeout = 0;
411 io.lockx.in.ulock_cnt = 1;
412 io.lockx.in.lock_cnt = 0;
413 io.lockx.in.locks = &lck;
415 ret = smb_raw_lock(c->tree, &io);
417 check_status("UnlockX", status, ret);
420 void nb_readx(int handle, int offset, int size, int ret_size, NTSTATUS status)
427 i = find_handle(handle);
429 if (bypass_io) return;
433 io.readx.level = RAW_READ_READX;
434 io.readx.in.fnum = i;
435 io.readx.in.offset = offset;
436 io.readx.in.mincnt = size;
437 io.readx.in.maxcnt = size;
438 io.readx.in.remaining = 0;
439 io.readx.out.data = buf;
441 ret = smb_raw_read(c->tree, &io);
445 check_status("ReadX", status, ret);
447 if (NT_STATUS_IS_OK(ret) && io.readx.out.nread != ret_size) {
448 printf("[%d] ERROR: ReadX got count %d expected %d\n",
450 io.readx.out.nread, ret_size);
454 children[nbio_id].bytes += ret_size;
457 void nb_close(int handle, NTSTATUS status)
463 i = find_handle(handle);
465 io.close.level = RAW_CLOSE_CLOSE;
466 io.close.in.fnum = i;
467 io.close.in.write_time = 0;
469 ret = smb_raw_close(c->tree, &io);
471 check_status("Close", status, ret);
473 if (NT_STATUS_IS_OK(ret)) {
474 struct ftable *f = find_ftable(handle);
475 DLIST_REMOVE(ftable, f);
480 void nb_rmdir(const char *dname, NTSTATUS status)
487 ret = smb_raw_rmdir(c->tree, &io);
489 check_status("Rmdir", status, ret);
492 void nb_mkdir(const char *dname, NTSTATUS status)
496 io.mkdir.level = RAW_MKDIR_MKDIR;
497 io.mkdir.in.path = dname;
499 /* NOTE! no error checking. Used for base fileset creation */
500 smb_raw_mkdir(c->tree, &io);
503 void nb_rename(const char *old, const char *new, NTSTATUS status)
508 io.generic.level = RAW_RENAME_RENAME;
509 io.rename.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
510 io.rename.in.pattern1 = old;
511 io.rename.in.pattern2 = new;
513 ret = smb_raw_rename(c->tree, &io);
515 check_status("Rename", status, ret);
519 void nb_qpathinfo(const char *fname, int level, NTSTATUS status)
521 union smb_fileinfo io;
525 mem_ctx = talloc_init("nb_qpathinfo");
527 io.generic.level = level;
528 io.generic.in.fname = fname;
530 ret = smb_raw_pathinfo(c->tree, mem_ctx, &io);
532 talloc_free(mem_ctx);
534 check_status("Pathinfo", status, ret);
538 void nb_qfileinfo(int fnum, int level, NTSTATUS status)
540 union smb_fileinfo io;
545 i = find_handle(fnum);
547 mem_ctx = talloc_init("nb_qfileinfo");
549 io.generic.level = level;
550 io.generic.in.fnum = i;
552 ret = smb_raw_fileinfo(c->tree, mem_ctx, &io);
554 talloc_free(mem_ctx);
556 check_status("Fileinfo", status, ret);
559 void nb_sfileinfo(int fnum, int level, NTSTATUS status)
561 union smb_setfileinfo io;
565 if (level != RAW_SFILEINFO_BASIC_INFORMATION) {
566 printf("[%d] Warning: setfileinfo level %d not handled\n", nbench_line_count, level);
572 i = find_handle(fnum);
574 io.generic.level = level;
575 io.generic.file.fnum = i;
576 unix_to_nt_time(&io.basic_info.in.create_time, time(NULL));
577 unix_to_nt_time(&io.basic_info.in.access_time, 0);
578 unix_to_nt_time(&io.basic_info.in.write_time, 0);
579 unix_to_nt_time(&io.basic_info.in.change_time, 0);
580 io.basic_info.in.attrib = 0;
582 ret = smb_raw_setfileinfo(c->tree, &io);
584 check_status("Setfileinfo", status, ret);
587 void nb_qfsinfo(int level, NTSTATUS status)
593 mem_ctx = talloc_init("smbcli_dskattr");
595 io.generic.level = level;
596 ret = smb_raw_fsinfo(c->tree, mem_ctx, &io);
598 talloc_free(mem_ctx);
600 check_status("Fsinfo", status, ret);
603 /* callback function used for trans2 search */
604 static BOOL findfirst_callback(void *private, union smb_search_data *file)
609 void nb_findfirst(const char *mask, int level, int maxcnt, int count, NTSTATUS status)
611 union smb_search_first io;
615 mem_ctx = talloc_init("smbcli_dskattr");
617 io.t2ffirst.level = level;
618 io.t2ffirst.in.max_count = maxcnt;
619 io.t2ffirst.in.search_attrib = FILE_ATTRIBUTE_DIRECTORY;
620 io.t2ffirst.in.pattern = mask;
621 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
622 io.t2ffirst.in.storage_type = 0;
624 ret = smb_raw_search_first(c->tree, mem_ctx, &io, NULL, findfirst_callback);
626 talloc_free(mem_ctx);
628 check_status("Search", status, ret);
630 if (NT_STATUS_IS_OK(ret) && io.t2ffirst.out.count != count) {
631 printf("[%d] Warning: got count %d expected %d\n",
633 io.t2ffirst.out.count, count);
637 void nb_flush(int fnum, NTSTATUS status)
642 i = find_handle(fnum);
646 ret = smb_raw_flush(c->tree, &io);
648 check_status("Flush", status, ret);
651 void nb_sleep(int usec, NTSTATUS status)
657 void nb_deltree(const char *dname)
661 smb_raw_exit(c->session);
664 struct ftable *f = ftable;
665 DLIST_REMOVE(ftable, f);
669 total_deleted = smbcli_deltree(c->tree, dname);
671 if (total_deleted == -1) {
672 printf("Failed to cleanup tree %s - exiting\n", dname);
676 smbcli_rmdir(c->tree, dname);