1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r24765: added a RAW-HOLD-OPLOCK test. This is a manual test, meant to be used

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 4c3e456426)
This commit is contained in:
Andrew Tridgell 2007-08-29 04:33:26 +00:00 committed by Gerald (Jerry) Carter
parent 64e98b0324
commit aaf7df0597
2 changed files with 110 additions and 0 deletions

View 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;
}

View 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);