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"
31 extern int nbench_line_count;
32 static int nbio_id = -1;
34 static BOOL bypass_io;
35 static struct timeval tv_start, tv_end;
36 static int warmup, timelimit;
37 static int in_cleanup;
40 struct ftable *next, *prev;
41 int fd; /* the fd that we got back from the server */
42 int handle; /* the handle in the load file */
45 static struct ftable *ftable;
48 double bytes, warmup_bytes;
53 double nbio_result(void)
57 for (i=0;i<nprocs;i++) {
58 total += children[i].bytes - children[i].warmup_bytes;
60 return 1.0e-6 * total / timeval_elapsed2(&tv_start, &tv_end);
65 return children[nbio_id].done;
69 void nb_alarm(int sig)
76 if (nbio_id != -1) return;
78 for (i=0;i<nprocs;i++) {
79 if (children[i].bytes == 0) {
82 lines += children[i].line;
85 t = timeval_elapsed(&tv_start);
87 if (!in_warmup && warmup>0 && t > warmup) {
88 tv_start = timeval_current();
90 for (i=0;i<nprocs;i++) {
91 children[i].warmup_bytes = children[i].bytes;
97 } else if (!in_warmup && !in_cleanup && t > timelimit) {
98 for (i=0;i<nprocs;i++) {
101 tv_end = timeval_current();
108 tv_end = timeval_current();
112 printf("%4d %8d %.2f MB/sec warmup %.0f sec \n",
113 nprocs, lines/nprocs,
115 } else if (in_cleanup) {
116 printf("%4d %8d %.2f MB/sec cleanup %.0f sec \n",
117 nprocs, lines/nprocs,
120 printf("%4d %8d %.2f MB/sec execute %.0f sec \n",
121 nprocs, lines/nprocs,
127 signal(SIGALRM, nb_alarm);
131 void nbio_shmem(int n, int t_timelimit, int t_warmup)
134 children = shm_setup(sizeof(*children) * nprocs);
136 printf("Failed to setup shared memory!\n");
139 memset(children, 0, sizeof(*children) * nprocs);
140 timelimit = t_timelimit;
143 tv_start = timeval_current();
146 static struct ftable *find_ftable(int handle)
150 for (f=ftable;f;f=f->next) {
151 if (f->handle == handle) return f;
156 static int find_handle(int handle)
160 children[nbio_id].line = nbench_line_count;
162 f = find_ftable(handle);
166 printf("(%d) ERROR: handle %d was not found\n",
167 nbench_line_count, handle);
170 return -1; /* Not reached */
175 static struct smbcli_state *c;
178 a handler function for oplock break requests
180 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private)
182 struct smbcli_tree *tree = private;
183 return smbcli_oplock_ack(tree, fnum, level);
186 void nb_setup(struct smbcli_state *cli, int id)
191 printf("skipping I/O\n");
194 smbcli_oplock_handler(cli->transport, oplock_handler, cli->tree);
199 static void check_status(const char *op, NTSTATUS status, NTSTATUS ret)
201 if (!NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(ret)) {
202 printf("[%d] Error: %s should have failed with %s\n",
203 nbench_line_count, op, nt_errstr(status));
207 if (NT_STATUS_IS_OK(status) && !NT_STATUS_IS_OK(ret)) {
208 printf("[%d] Error: %s should have succeeded - %s\n",
209 nbench_line_count, op, nt_errstr(ret));
213 if (!NT_STATUS_EQUAL(status, ret)) {
214 printf("[%d] Warning: got status %s but expected %s\n",
215 nbench_line_count, nt_errstr(ret), nt_errstr(status));
220 void nb_unlink(const char *fname, int attr, NTSTATUS status)
222 struct smb_unlink io;
225 io.in.pattern = fname;
227 io.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
228 if (strchr(fname, '*') == 0) {
229 io.in.attrib |= FILE_ATTRIBUTE_DIRECTORY;
232 ret = smb_raw_unlink(c->tree, &io);
234 check_status("Unlink", status, ret);
238 void nb_createx(const char *fname,
239 uint_t create_options, uint_t create_disposition, int handle,
243 uint32_t desired_access;
249 mem_ctx = talloc_init("raw_open");
251 if (create_options & NTCREATEX_OPTIONS_DIRECTORY) {
252 desired_access = SEC_FILE_READ_DATA;
256 SEC_FILE_WRITE_DATA |
257 SEC_FILE_READ_ATTRIBUTE |
258 SEC_FILE_WRITE_ATTRIBUTE;
259 flags = NTCREATEX_FLAGS_EXTENDED |
260 NTCREATEX_FLAGS_REQUEST_OPLOCK |
261 NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
264 io.ntcreatex.level = RAW_OPEN_NTCREATEX;
265 io.ntcreatex.in.flags = flags;
266 io.ntcreatex.in.root_fid = 0;
267 io.ntcreatex.in.access_mask = desired_access;
268 io.ntcreatex.in.file_attr = 0;
269 io.ntcreatex.in.alloc_size = 0;
270 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE;
271 io.ntcreatex.in.open_disposition = create_disposition;
272 io.ntcreatex.in.create_options = create_options;
273 io.ntcreatex.in.impersonation = 0;
274 io.ntcreatex.in.security_flags = 0;
275 io.ntcreatex.in.fname = fname;
277 ret = smb_raw_open(c->tree, mem_ctx, &io);
279 talloc_free(mem_ctx);
281 check_status("NTCreateX", status, ret);
283 if (!NT_STATUS_IS_OK(ret)) return;
285 f = malloc_p(struct ftable);
287 f->fd = io.ntcreatex.out.fnum;
289 DLIST_ADD_END(ftable, f, struct ftable *);
292 void nb_writex(int handle, int offset, int size, int ret_size, NTSTATUS status)
299 i = find_handle(handle);
301 if (bypass_io) return;
304 memset(buf, 0xab, size);
306 io.writex.level = RAW_WRITE_WRITEX;
307 io.writex.in.fnum = i;
308 io.writex.in.wmode = 0;
309 io.writex.in.remaining = 0;
310 io.writex.in.offset = offset;
311 io.writex.in.count = size;
312 io.writex.in.data = buf;
314 ret = smb_raw_write(c->tree, &io);
318 check_status("WriteX", status, ret);
320 if (NT_STATUS_IS_OK(ret) && io.writex.out.nwritten != ret_size) {
321 printf("[%d] Warning: WriteX got count %d expected %d\n",
323 io.writex.out.nwritten, ret_size);
326 children[nbio_id].bytes += ret_size;
329 void nb_write(int handle, int offset, int size, int ret_size, NTSTATUS status)
336 i = find_handle(handle);
338 if (bypass_io) return;
342 memset(buf, 0x12, size);
344 io.write.level = RAW_WRITE_WRITE;
345 io.write.in.fnum = i;
346 io.write.in.remaining = 0;
347 io.write.in.offset = offset;
348 io.write.in.count = size;
349 io.write.in.data = buf;
351 ret = smb_raw_write(c->tree, &io);
355 check_status("Write", status, ret);
357 if (NT_STATUS_IS_OK(ret) && io.write.out.nwritten != ret_size) {
358 printf("[%d] Warning: Write got count %d expected %d\n",
360 io.write.out.nwritten, ret_size);
363 children[nbio_id].bytes += ret_size;
367 void nb_lockx(int handle, uint_t offset, int size, NTSTATUS status)
372 struct smb_lock_entry lck;
374 i = find_handle(handle);
380 io.lockx.level = RAW_LOCK_LOCKX;
381 io.lockx.in.fnum = i;
382 io.lockx.in.mode = 0;
383 io.lockx.in.timeout = 0;
384 io.lockx.in.ulock_cnt = 0;
385 io.lockx.in.lock_cnt = 1;
386 io.lockx.in.locks = &lck;
388 ret = smb_raw_lock(c->tree, &io);
390 check_status("LockX", status, ret);
393 void nb_unlockx(int handle, uint_t offset, int size, NTSTATUS status)
398 struct smb_lock_entry lck;
400 i = find_handle(handle);
406 io.lockx.level = RAW_LOCK_LOCKX;
407 io.lockx.in.fnum = i;
408 io.lockx.in.mode = 0;
409 io.lockx.in.timeout = 0;
410 io.lockx.in.ulock_cnt = 1;
411 io.lockx.in.lock_cnt = 0;
412 io.lockx.in.locks = &lck;
414 ret = smb_raw_lock(c->tree, &io);
416 check_status("UnlockX", status, ret);
419 void nb_readx(int handle, int offset, int size, int ret_size, NTSTATUS status)
426 i = find_handle(handle);
428 if (bypass_io) return;
432 io.readx.level = RAW_READ_READX;
433 io.readx.in.fnum = i;
434 io.readx.in.offset = offset;
435 io.readx.in.mincnt = size;
436 io.readx.in.maxcnt = size;
437 io.readx.in.remaining = 0;
438 io.readx.out.data = buf;
440 ret = smb_raw_read(c->tree, &io);
444 check_status("ReadX", status, ret);
446 if (NT_STATUS_IS_OK(ret) && io.readx.out.nread != ret_size) {
447 printf("[%d] ERROR: ReadX got count %d expected %d\n",
449 io.readx.out.nread, ret_size);
453 children[nbio_id].bytes += ret_size;
456 void nb_close(int handle, NTSTATUS status)
462 i = find_handle(handle);
464 io.close.level = RAW_CLOSE_CLOSE;
465 io.close.in.fnum = i;
466 io.close.in.write_time = 0;
468 ret = smb_raw_close(c->tree, &io);
470 check_status("Close", status, ret);
472 if (NT_STATUS_IS_OK(ret)) {
473 struct ftable *f = find_ftable(handle);
474 DLIST_REMOVE(ftable, f);
479 void nb_rmdir(const char *dname, NTSTATUS status)
486 ret = smb_raw_rmdir(c->tree, &io);
488 check_status("Rmdir", status, ret);
491 void nb_mkdir(const char *dname, NTSTATUS status)
495 io.mkdir.level = RAW_MKDIR_MKDIR;
496 io.mkdir.in.path = dname;
498 /* NOTE! no error checking. Used for base fileset creation */
499 smb_raw_mkdir(c->tree, &io);
502 void nb_rename(const char *old, const char *new, NTSTATUS status)
507 io.generic.level = RAW_RENAME_RENAME;
508 io.rename.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
509 io.rename.in.pattern1 = old;
510 io.rename.in.pattern2 = new;
512 ret = smb_raw_rename(c->tree, &io);
514 check_status("Rename", status, ret);
518 void nb_qpathinfo(const char *fname, int level, NTSTATUS status)
520 union smb_fileinfo io;
524 mem_ctx = talloc_init("nb_qpathinfo");
526 io.generic.level = level;
527 io.generic.in.fname = fname;
529 ret = smb_raw_pathinfo(c->tree, mem_ctx, &io);
531 talloc_free(mem_ctx);
533 check_status("Pathinfo", status, ret);
537 void nb_qfileinfo(int fnum, int level, NTSTATUS status)
539 union smb_fileinfo io;
544 i = find_handle(fnum);
546 mem_ctx = talloc_init("nb_qfileinfo");
548 io.generic.level = level;
549 io.generic.in.fnum = i;
551 ret = smb_raw_fileinfo(c->tree, mem_ctx, &io);
553 talloc_free(mem_ctx);
555 check_status("Fileinfo", status, ret);
558 void nb_sfileinfo(int fnum, int level, NTSTATUS status)
560 union smb_setfileinfo io;
564 if (level != RAW_SFILEINFO_BASIC_INFORMATION) {
565 printf("[%d] Warning: setfileinfo level %d not handled\n", nbench_line_count, level);
571 i = find_handle(fnum);
573 io.generic.level = level;
574 io.generic.file.fnum = i;
575 unix_to_nt_time(&io.basic_info.in.create_time, time(NULL));
576 unix_to_nt_time(&io.basic_info.in.access_time, 0);
577 unix_to_nt_time(&io.basic_info.in.write_time, 0);
578 unix_to_nt_time(&io.basic_info.in.change_time, 0);
579 io.basic_info.in.attrib = 0;
581 ret = smb_raw_setfileinfo(c->tree, &io);
583 check_status("Setfileinfo", status, ret);
586 void nb_qfsinfo(int level, NTSTATUS status)
592 mem_ctx = talloc_init("smbcli_dskattr");
594 io.generic.level = level;
595 ret = smb_raw_fsinfo(c->tree, mem_ctx, &io);
597 talloc_free(mem_ctx);
599 check_status("Fsinfo", status, ret);
602 /* callback function used for trans2 search */
603 static BOOL findfirst_callback(void *private, union smb_search_data *file)
608 void nb_findfirst(const char *mask, int level, int maxcnt, int count, NTSTATUS status)
610 union smb_search_first io;
614 mem_ctx = talloc_init("smbcli_dskattr");
616 io.t2ffirst.level = level;
617 io.t2ffirst.in.max_count = maxcnt;
618 io.t2ffirst.in.search_attrib = FILE_ATTRIBUTE_DIRECTORY;
619 io.t2ffirst.in.pattern = mask;
620 io.t2ffirst.in.flags = FLAG_TRANS2_FIND_CLOSE;
621 io.t2ffirst.in.storage_type = 0;
623 ret = smb_raw_search_first(c->tree, mem_ctx, &io, NULL, findfirst_callback);
625 talloc_free(mem_ctx);
627 check_status("Search", status, ret);
629 if (NT_STATUS_IS_OK(ret) && io.t2ffirst.out.count != count) {
630 printf("[%d] Warning: got count %d expected %d\n",
632 io.t2ffirst.out.count, count);
636 void nb_flush(int fnum, NTSTATUS status)
641 i = find_handle(fnum);
645 ret = smb_raw_flush(c->tree, &io);
647 check_status("Flush", status, ret);
650 void nb_sleep(int usec, NTSTATUS status)
656 void nb_deltree(const char *dname)
660 smb_raw_exit(c->session);
663 struct ftable *f = ftable;
664 DLIST_REMOVE(ftable, f);
668 total_deleted = smbcli_deltree(c->tree, dname);
670 if (total_deleted == -1) {
671 printf("Failed to cleanup tree %s - exiting\n", dname);
675 smbcli_rmdir(c->tree, dname);