| 1 | #define NBDEBUG 0
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | Unix SMB/CIFS implementation.
|
|---|
| 5 | SMB torture tester
|
|---|
| 6 | Copyright (C) Andrew Tridgell 1997-1998
|
|---|
| 7 |
|
|---|
| 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.
|
|---|
| 12 |
|
|---|
| 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.
|
|---|
| 17 |
|
|---|
| 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.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | #include "includes.h"
|
|---|
| 24 |
|
|---|
| 25 | #define MAX_FILES 1000
|
|---|
| 26 |
|
|---|
| 27 | static char buf[70000];
|
|---|
| 28 | extern int line_count;
|
|---|
| 29 | extern int nbio_id;
|
|---|
| 30 | static int nprocs;
|
|---|
| 31 |
|
|---|
| 32 | static struct {
|
|---|
| 33 | int fd;
|
|---|
| 34 | int handle;
|
|---|
| 35 | } ftable[MAX_FILES];
|
|---|
| 36 |
|
|---|
| 37 | static struct children {
|
|---|
| 38 | double bytes_in, bytes_out;
|
|---|
| 39 | int line;
|
|---|
| 40 | int done;
|
|---|
| 41 | } *children;
|
|---|
| 42 |
|
|---|
| 43 | double nbio_total(void)
|
|---|
| 44 | {
|
|---|
| 45 | int i;
|
|---|
| 46 | double total = 0;
|
|---|
| 47 | for (i=0;i<nprocs;i++) {
|
|---|
| 48 | total += children[i].bytes_out + children[i].bytes_in;
|
|---|
| 49 | }
|
|---|
| 50 | return total;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | void nb_alarm(int ignore)
|
|---|
| 54 | {
|
|---|
| 55 | int i;
|
|---|
| 56 | int lines=0, num_clients=0;
|
|---|
| 57 | if (nbio_id != -1) return;
|
|---|
| 58 |
|
|---|
| 59 | for (i=0;i<nprocs;i++) {
|
|---|
| 60 | lines += children[i].line;
|
|---|
| 61 | if (!children[i].done) num_clients++;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | printf("%4d %8d %.2f MB/sec\r", num_clients, lines/nprocs, 1.0e-6 * nbio_total() / end_timer());
|
|---|
| 65 |
|
|---|
| 66 | signal(SIGALRM, nb_alarm);
|
|---|
| 67 | alarm(1);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void nbio_shmem(int n)
|
|---|
| 71 | {
|
|---|
| 72 | nprocs = n;
|
|---|
| 73 | children = (struct children *)shm_setup(sizeof(*children) * nprocs);
|
|---|
| 74 | if (!children) {
|
|---|
| 75 | printf("Failed to setup shared memory!\n");
|
|---|
| 76 | exit(1);
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | #if 0
|
|---|
| 81 | static int ne_find_handle(int handle)
|
|---|
| 82 | {
|
|---|
| 83 | int i;
|
|---|
| 84 | children[nbio_id].line = line_count;
|
|---|
| 85 | for (i=0;i<MAX_FILES;i++) {
|
|---|
| 86 | if (ftable[i].handle == handle) return i;
|
|---|
| 87 | }
|
|---|
| 88 | return -1;
|
|---|
| 89 | }
|
|---|
| 90 | #endif
|
|---|
| 91 |
|
|---|
| 92 | static int find_handle(int handle)
|
|---|
| 93 | {
|
|---|
| 94 | int i;
|
|---|
| 95 | children[nbio_id].line = line_count;
|
|---|
| 96 | for (i=0;i<MAX_FILES;i++) {
|
|---|
| 97 | if (ftable[i].handle == handle) return i;
|
|---|
| 98 | }
|
|---|
| 99 | printf("(%d) ERROR: handle %d was not found\n",
|
|---|
| 100 | line_count, handle);
|
|---|
| 101 | exit(1);
|
|---|
| 102 |
|
|---|
| 103 | return -1; /* Not reached */
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | static struct cli_state *c;
|
|---|
| 108 |
|
|---|
| 109 | static void sigsegv(int sig)
|
|---|
| 110 | {
|
|---|
| 111 | char line[200];
|
|---|
| 112 | printf("segv at line %d\n", line_count);
|
|---|
| 113 | slprintf(line, sizeof(line), "/usr/X11R6/bin/xterm -e gdb /proc/%d/exe %d",
|
|---|
| 114 | (int)getpid(), (int)getpid());
|
|---|
| 115 | system(line);
|
|---|
| 116 | exit(1);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | void nb_setup(struct cli_state *cli)
|
|---|
| 120 | {
|
|---|
| 121 | signal(SIGSEGV, sigsegv);
|
|---|
| 122 | c = cli;
|
|---|
| 123 | start_timer();
|
|---|
| 124 | children[nbio_id].done = 0;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | void nb_unlink(const char *fname)
|
|---|
| 129 | {
|
|---|
| 130 | if (!cli_unlink(c, fname)) {
|
|---|
| 131 | #if NBDEBUG
|
|---|
| 132 | printf("(%d) unlink %s failed (%s)\n",
|
|---|
| 133 | line_count, fname, cli_errstr(c));
|
|---|
| 134 | #endif
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | void nb_createx(const char *fname,
|
|---|
| 140 | unsigned create_options, unsigned create_disposition, int handle)
|
|---|
| 141 | {
|
|---|
| 142 | int fd, i;
|
|---|
| 143 | uint32 desired_access;
|
|---|
| 144 |
|
|---|
| 145 | if (create_options & FILE_DIRECTORY_FILE) {
|
|---|
| 146 | desired_access = FILE_READ_DATA;
|
|---|
| 147 | } else {
|
|---|
| 148 | desired_access = FILE_READ_DATA | FILE_WRITE_DATA;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | fd = cli_nt_create_full(c, fname, 0,
|
|---|
| 152 | desired_access,
|
|---|
| 153 | 0x0,
|
|---|
| 154 | FILE_SHARE_READ|FILE_SHARE_WRITE,
|
|---|
| 155 | create_disposition,
|
|---|
| 156 | create_options, 0);
|
|---|
| 157 | if (fd == -1 && handle != -1) {
|
|---|
|
|---|