1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
14 */
15
16 /*
17 * Test & debug program for oplocks
18 *
19 * This implements a simple command reader which accepts
20 * commands to simulate oplock events, and prints the
21 * state changes and actions that would happen after
22 * each event.
23 */
24
25 #include <sys/types.h>
26 #include <sys/debug.h>
27 #include <sys/stddef.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <strings.h>
32 #include <unistd.h>
33
148 "read" : "none");
149 }
150 printf("\n");
151 }
152 }
153
154 static void
155 do_open(int fid, char *arg2)
156 {
157 smb_node_t *node = &test_node;
158 smb_ofile_t *ofile = &ofile_array[fid];
159
160 /*
161 * Simulate an open (minimal init)
162 */
163 if (ofile->f_refcnt) {
164 printf("open fid %d already opened\n");
165 return;
166 }
167
168 if (arg2 != NULL)
169 strlcpy((char *)ofile->TargetOplockKey, arg2,
170 SMB_LEASE_KEY_SZ);
171
172 ofile->f_refcnt++;
173 node->n_open_count++;
174 smb_llist_insert_tail(&node->n_ofile_list, ofile);
175 printf(" open %d OK\n", fid);
176 }
177
178 static void
179 do_close(int fid)
180 {
181 smb_node_t *node = &test_node;
182 smb_ofile_t *ofile = &ofile_array[fid];
183
184 /*
185 * Simulate an close
186 */
187 if (ofile->f_refcnt <= 0) {
188 printf(" close fid %d already closed\n");
189 return;
190 }
380 int fid;
381
382 if (isatty(0))
383 prompt = "> ";
384
385 smb_llist_constructor(&node->n_ofile_list, sizeof (smb_ofile_t),
386 offsetof(smb_ofile_t, f_node_lnd));
387
388 for (fid = 0; fid < MAXFID; fid++) {
389 smb_ofile_t *f = &ofile_array[fid];
390
391 f->f_magic = SMB_OFILE_MAGIC;
392 mutex_init(&f->f_mutex, NULL, MUTEX_DEFAULT, NULL);
393 f->f_fid = fid;
394 f->f_ftype = SMB_FTYPE_DISK;
395 f->f_node = &test_node;
396 }
397
398 for (;;) {
399 if (prompt) {
400 fputs(prompt, stdout);
401 fflush(stdout);
402 }
403
404 cmd = fgets(cmdbuf, sizeof (cmdbuf), stdin);
405 if (cmd == NULL)
406 break;
407 if (cmd[0] == '#')
408 continue;
409
410 if (prompt == NULL) {
411 /* Put commands in the output too. */
412 fputs(cmdbuf, stdout);
413 }
414 cmd = strtok_r(cmd, sep, &savep);
415 if (cmd == NULL)
416 continue;
417
418 /*
419 * Commands with no args
420 */
421 if (0 == strcmp(cmd, "help")) {
422 fputs(helpstr, stdout);
423 continue;
424 }
425
426 if (0 == strcmp(cmd, "show")) {
427 do_show();
428 continue;
429 }
430
431 /*
432 * Commands with one arg (the FID)
433 */
434 arg1 = strtok_r(NULL, sep, &savep);
435 if (arg1 == NULL) {
436 fprintf(stderr, "%s missing arg1\n", cmd);
437 continue;
438 }
439 fid = atoi(arg1);
440 if (fid <= 0 || fid >= MAXFID) {
441 fprintf(stderr, "%s bad FID %d\n", cmd, fid);
442 continue;
|
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
14 * Copyright 2019 Joyent, Inc.
15 */
16
17 /*
18 * Test & debug program for oplocks
19 *
20 * This implements a simple command reader which accepts
21 * commands to simulate oplock events, and prints the
22 * state changes and actions that would happen after
23 * each event.
24 */
25
26 #include <sys/types.h>
27 #include <sys/debug.h>
28 #include <sys/stddef.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <unistd.h>
34
149 "read" : "none");
150 }
151 printf("\n");
152 }
153 }
154
155 static void
156 do_open(int fid, char *arg2)
157 {
158 smb_node_t *node = &test_node;
159 smb_ofile_t *ofile = &ofile_array[fid];
160
161 /*
162 * Simulate an open (minimal init)
163 */
164 if (ofile->f_refcnt) {
165 printf("open fid %d already opened\n");
166 return;
167 }
168
169 if (arg2 != NULL) {
170 (void) strlcpy((char *)ofile->TargetOplockKey, arg2,
171 SMB_LEASE_KEY_SZ);
172 }
173
174 ofile->f_refcnt++;
175 node->n_open_count++;
176 smb_llist_insert_tail(&node->n_ofile_list, ofile);
177 printf(" open %d OK\n", fid);
178 }
179
180 static void
181 do_close(int fid)
182 {
183 smb_node_t *node = &test_node;
184 smb_ofile_t *ofile = &ofile_array[fid];
185
186 /*
187 * Simulate an close
188 */
189 if (ofile->f_refcnt <= 0) {
190 printf(" close fid %d already closed\n");
191 return;
192 }
382 int fid;
383
384 if (isatty(0))
385 prompt = "> ";
386
387 smb_llist_constructor(&node->n_ofile_list, sizeof (smb_ofile_t),
388 offsetof(smb_ofile_t, f_node_lnd));
389
390 for (fid = 0; fid < MAXFID; fid++) {
391 smb_ofile_t *f = &ofile_array[fid];
392
393 f->f_magic = SMB_OFILE_MAGIC;
394 mutex_init(&f->f_mutex, NULL, MUTEX_DEFAULT, NULL);
395 f->f_fid = fid;
396 f->f_ftype = SMB_FTYPE_DISK;
397 f->f_node = &test_node;
398 }
399
400 for (;;) {
401 if (prompt) {
402 (void) fputs(prompt, stdout);
403 fflush(stdout);
404 }
405
406 cmd = fgets(cmdbuf, sizeof (cmdbuf), stdin);
407 if (cmd == NULL)
408 break;
409 if (cmd[0] == '#')
410 continue;
411
412 if (prompt == NULL) {
413 /* Put commands in the output too. */
414 (void) fputs(cmdbuf, stdout);
415 }
416 cmd = strtok_r(cmd, sep, &savep);
417 if (cmd == NULL)
418 continue;
419
420 /*
421 * Commands with no args
422 */
423 if (0 == strcmp(cmd, "help")) {
424 (void) fputs(helpstr, stdout);
425 continue;
426 }
427
428 if (0 == strcmp(cmd, "show")) {
429 do_show();
430 continue;
431 }
432
433 /*
434 * Commands with one arg (the FID)
435 */
436 arg1 = strtok_r(NULL, sep, &savep);
437 if (arg1 == NULL) {
438 fprintf(stderr, "%s missing arg1\n", cmd);
439 continue;
440 }
441 fid = atoi(arg1);
442 if (fid <= 0 || fid >= MAXFID) {
443 fprintf(stderr, "%s bad FID %d\n", cmd, fid);
444 continue;
|