r24765: added a RAW-HOLD-OPLOCK test. This is a manual test, meant to be used
authorAndrew Tridgell <tridge@samba.org>
Wed, 29 Aug 2007 04:33:26 +0000 (04:33 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:03:06 +0000 (15:03 -0500)
to test the interaction of oplocks with local filesystem or NFS
access. You start it, then manually access the 4 files via another
mechanism (such as a shell) and see what oplock breaks you get
(This used to be commit 4c3e4564260e55434a54a013051db609c92cabe8)

source4/torture/raw/oplock.c
source4/torture/raw/raw.c

index f1779ad9cf650348e2a8b30a78e63158885a2a2e..7a921af422e1c301fb71ba7f187930d7b9ca5af4 100644 (file)
@@ -1388,3 +1388,112 @@ done:
        talloc_free(mem_ctx);
        return ret;
 }
+
+
+static struct hold_oplock_info {
+       const char *fname;
+       bool close_on_break;
+       uint32_t share_access;
+       uint16_t fnum;
+} hold_info[] = {
+       { BASEDIR "\\notshared_close", True,  
+         NTCREATEX_SHARE_ACCESS_NONE, },
+       { BASEDIR "\\notshared_noclose", False, 
+         NTCREATEX_SHARE_ACCESS_NONE, },
+       { BASEDIR "\\shared_close", True,  
+         NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, },
+       { BASEDIR "\\shared_noclose", False,  
+         NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, },
+};
+
+static BOOL oplock_handler_hold(struct smbcli_transport *transport, uint16_t tid, 
+                               uint16_t fnum, uint8_t level, void *private)
+{
+       struct smbcli_tree *tree = private;
+       struct hold_oplock_info *info;
+       int i;
+
+       for (i=0;i<ARRAY_SIZE(hold_info);i++) {
+               if (hold_info[i].fnum == fnum) break;
+       }
+
+       if (i == ARRAY_SIZE(hold_info)) {
+               printf("oplock break for unknown fnum %u\n", fnum);
+               return False;
+       }
+
+       info = &hold_info[i];
+
+       if (info->close_on_break) {
+               printf("oplock break on %s - closing\n",
+                      info->fname);
+               oplock_handler_close(transport, tid, fnum, level, private);
+               return True;
+       }
+
+       printf("oplock break on %s - acking break\n", info->fname);
+
+       return smbcli_oplock_ack(tree, fnum, OPLOCK_BREAK_TO_NONE);
+}
+
+
+/* 
+   used for manual testing of oplocks - especially interaction with
+   other filesystems (such as NFS and local access)
+*/
+BOOL torture_hold_oplock(struct torture_context *torture, 
+                        struct smbcli_state *cli)
+{
+       struct event_context *ev = cli->transport->socket->event.ctx;
+       int i;
+
+       printf("Setting up open files with oplocks in %s\n", BASEDIR);
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       smbcli_oplock_handler(cli->transport, oplock_handler_hold, cli->tree);
+
+       /* setup the files */
+       for (i=0;i<ARRAY_SIZE(hold_info);i++) {
+               union smb_open io;
+               NTSTATUS status;
+
+               io.generic.level = RAW_OPEN_NTCREATEX;
+               io.ntcreatex.in.root_fid = 0;
+               io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+               io.ntcreatex.in.alloc_size = 0;
+               io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+               io.ntcreatex.in.share_access = hold_info[i].share_access;
+               io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+               io.ntcreatex.in.create_options = 0;
+               io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+               io.ntcreatex.in.security_flags = 0;
+               io.ntcreatex.in.fname = hold_info[i].fname;
+               io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED | 
+                       NTCREATEX_FLAGS_REQUEST_OPLOCK |
+                       NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK;
+               printf("opening %s\n", hold_info[i].fname);
+
+               status = smb_raw_open(cli->tree, cli, &io);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("Failed to open %s - %s\n", 
+                              hold_info[i].fname, nt_errstr(status));
+                       return False;
+               }
+
+               if (io.ntcreatex.out.oplock_level != BATCH_OPLOCK_RETURN) {
+                       printf("Oplock not granted for %s - expected %d but got %d\n", 
+                              hold_info[i].fname, BATCH_OPLOCK_RETURN, 
+                               io.ntcreatex.out.oplock_level);
+                       return False;
+               }
+               hold_info[i].fnum = io.ntcreatex.out.file.fnum;
+       }
+
+       printf("Waiting for oplock events\n");
+       event_loop_wait(ev);
+
+       return True;
+}
index 85db92661b20d20e84533d156e272dadfce75567..d85f26703501d1672fffebb6ec20b6809d054117 100644 (file)
@@ -44,6 +44,7 @@ NTSTATUS torture_raw_init(void)
        torture_suite_add_1smb_test(suite, "OPEN", torture_raw_open);
        torture_suite_add_1smb_test(suite, "MKDIR", torture_raw_mkdir);
        torture_suite_add_suite(suite, torture_raw_oplock(suite));
+       torture_suite_add_1smb_test(suite, "HOLD-OPLOCK", torture_hold_oplock);
        torture_suite_add_2smb_test(suite, "NOTIFY", torture_raw_notify);
        torture_suite_add_1smb_test(suite, "MUX", torture_raw_mux);
        torture_suite_add_1smb_test(suite, "IOCTL", torture_raw_ioctl);