mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
smbd: Reduce the complexity of open_file_ntcreate
This removes two variables in open_file_ntcreate based on the observation that for exclusive and batch oplocks there can only be one entry. So in these cases we don't need to keep pointers from find_oplock_types to delay_for_oplocks. We can just reference the only share mode entry around. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
parent
c938a1065f
commit
00d84ad192
@ -1212,16 +1212,16 @@ static NTSTATUS send_break_message(files_struct *fsp,
|
|||||||
static bool find_oplock_types(files_struct *fsp,
|
static bool find_oplock_types(files_struct *fsp,
|
||||||
int oplock_request,
|
int oplock_request,
|
||||||
const struct share_mode_lock *lck,
|
const struct share_mode_lock *lck,
|
||||||
struct share_mode_entry **pp_batch,
|
|
||||||
struct share_mode_entry **pp_ex_or_batch,
|
|
||||||
bool *got_level2,
|
bool *got_level2,
|
||||||
bool *got_no_oplock)
|
bool *got_no_oplock)
|
||||||
{
|
{
|
||||||
struct share_mode_data *d = lck->data;
|
struct share_mode_data *d = lck->data;
|
||||||
|
bool batch = false;
|
||||||
|
bool ex_or_batch = false;
|
||||||
|
bool level2 = false;
|
||||||
|
bool no_oplock = false;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
*pp_batch = NULL;
|
|
||||||
*pp_ex_or_batch = NULL;
|
|
||||||
*got_level2 = false;
|
*got_level2 = false;
|
||||||
*got_no_oplock = false;
|
*got_no_oplock = false;
|
||||||
|
|
||||||
@ -1253,12 +1253,12 @@ static bool find_oplock_types(files_struct *fsp,
|
|||||||
DEBUG(10, ("Found stale batch oplock\n"));
|
DEBUG(10, ("Found stale batch oplock\n"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*pp_ex_or_batch || *pp_batch || *got_level2 || *got_no_oplock) {
|
if (ex_or_batch || batch || level2 || no_oplock) {
|
||||||
DEBUG(0, ("Bad batch oplock entry %u.",
|
DEBUG(0, ("Bad batch oplock entry %u.",
|
||||||
(unsigned)i));
|
(unsigned)i));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*pp_batch = e;
|
batch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EXCLUSIVE_OPLOCK_TYPE(e->op_type)) {
|
if (EXCLUSIVE_OPLOCK_TYPE(e->op_type)) {
|
||||||
@ -1267,16 +1267,16 @@ static bool find_oplock_types(files_struct *fsp,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Exclusive or batch - can only be one. */
|
/* Exclusive or batch - can only be one. */
|
||||||
if (*pp_ex_or_batch || *got_level2 || *got_no_oplock) {
|
if (ex_or_batch || level2 || no_oplock) {
|
||||||
DEBUG(0, ("Bad exclusive or batch oplock "
|
DEBUG(0, ("Bad exclusive or batch oplock "
|
||||||
"entry %u.", (unsigned)i));
|
"entry %u.", (unsigned)i));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*pp_ex_or_batch = e;
|
ex_or_batch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LEVEL_II_OPLOCK_TYPE(e->op_type)) {
|
if (LEVEL_II_OPLOCK_TYPE(e->op_type)) {
|
||||||
if (*pp_batch || *pp_ex_or_batch) {
|
if (batch || ex_or_batch) {
|
||||||
if (share_mode_stale_pid(d, i)) {
|
if (share_mode_stale_pid(d, i)) {
|
||||||
DEBUG(10, ("Found stale LevelII "
|
DEBUG(10, ("Found stale LevelII "
|
||||||
"oplock\n"));
|
"oplock\n"));
|
||||||
@ -1286,11 +1286,11 @@ static bool find_oplock_types(files_struct *fsp,
|
|||||||
(unsigned)i));
|
(unsigned)i));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*got_level2 = true;
|
level2 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->op_type == NO_OPLOCK) {
|
if (e->op_type == NO_OPLOCK) {
|
||||||
if (*pp_batch || *pp_ex_or_batch) {
|
if (batch || ex_or_batch) {
|
||||||
if (share_mode_stale_pid(d, i)) {
|
if (share_mode_stale_pid(d, i)) {
|
||||||
DEBUG(10, ("Found stale NO_OPLOCK "
|
DEBUG(10, ("Found stale NO_OPLOCK "
|
||||||
"entry\n"));
|
"entry\n"));
|
||||||
@ -1300,21 +1300,41 @@ static bool find_oplock_types(files_struct *fsp,
|
|||||||
(unsigned)i));
|
(unsigned)i));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*got_no_oplock = true;
|
no_oplock = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_stale_share_mode_entries(d);
|
||||||
|
|
||||||
|
if ((batch || ex_or_batch) && (d->num_share_modes != 1)) {
|
||||||
|
DEBUG(1, ("got batch (%d) or ex (%d) non-exclusively (%d)\n",
|
||||||
|
(int)batch, (int)ex_or_batch,
|
||||||
|
(int)d->num_share_modes));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*got_level2 = level2;
|
||||||
|
*got_no_oplock = no_oplock;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool delay_for_oplock(files_struct *fsp,
|
static bool delay_for_oplock(files_struct *fsp,
|
||||||
uint64_t mid,
|
uint64_t mid,
|
||||||
int oplock_request,
|
int oplock_request,
|
||||||
struct share_mode_entry *entry)
|
struct share_mode_lock *lck,
|
||||||
|
int delay_for_type)
|
||||||
{
|
{
|
||||||
|
struct share_mode_entry *entry;
|
||||||
|
|
||||||
if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
|
if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (entry == NULL) {
|
if (lck->data->num_share_modes != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
entry = &lck->data->share_modes[0];
|
||||||
|
|
||||||
|
if (!(entry->op_type & delay_for_type)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1949,8 +1969,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
|
|||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
char *parent_dir;
|
char *parent_dir;
|
||||||
SMB_STRUCT_STAT saved_stat = smb_fname->st;
|
SMB_STRUCT_STAT saved_stat = smb_fname->st;
|
||||||
struct share_mode_entry *batch_entry = NULL;
|
|
||||||
struct share_mode_entry *exclusive_entry = NULL;
|
|
||||||
bool got_level2_oplock = false;
|
bool got_level2_oplock = false;
|
||||||
bool got_a_none_oplock = false;
|
bool got_a_none_oplock = false;
|
||||||
struct timespec old_write_time;
|
struct timespec old_write_time;
|
||||||
@ -2294,14 +2312,13 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!find_oplock_types(fsp, 0, lck,
|
if (!find_oplock_types(fsp, 0, lck,
|
||||||
&batch_entry, &exclusive_entry,
|
|
||||||
&got_level2_oplock,
|
&got_level2_oplock,
|
||||||
&got_a_none_oplock)) {
|
&got_a_none_oplock)) {
|
||||||
smb_panic("find_oplock_types failed");
|
smb_panic("find_oplock_types failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delay_for_oplock(fsp, req->mid, 0, batch_entry) ||
|
if (delay_for_oplock(fsp, req->mid, 0, lck,
|
||||||
delay_for_oplock(fsp, req->mid, 0, exclusive_entry)) {
|
BATCH_OPLOCK|EXCLUSIVE_OPLOCK)) {
|
||||||
schedule_defer_open(lck, request_time, req);
|
schedule_defer_open(lck, request_time, req);
|
||||||
TALLOC_FREE(lck);
|
TALLOC_FREE(lck);
|
||||||
DEBUG(10, ("Sent oplock break request to kernel "
|
DEBUG(10, ("Sent oplock break request to kernel "
|
||||||
@ -2386,7 +2403,6 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
|
|||||||
|
|
||||||
/* Get the types we need to examine. */
|
/* Get the types we need to examine. */
|
||||||
if (!find_oplock_types(fsp, oplock_request, lck,
|
if (!find_oplock_types(fsp, oplock_request, lck,
|
||||||
&batch_entry, &exclusive_entry,
|
|
||||||
&got_level2_oplock,
|
&got_level2_oplock,
|
||||||
&got_a_none_oplock)) {
|
&got_a_none_oplock)) {
|
||||||
smb_panic("find_oplock_types failed");
|
smb_panic("find_oplock_types failed");
|
||||||
@ -2400,8 +2416,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
|
|||||||
|
|
||||||
/* First pass - send break only on batch oplocks. */
|
/* First pass - send break only on batch oplocks. */
|
||||||
if ((req != NULL) &&
|
if ((req != NULL) &&
|
||||||
delay_for_oplock(fsp, req->mid, oplock_request,
|
delay_for_oplock(fsp, req->mid, oplock_request, lck,
|
||||||
batch_entry)) {
|
BATCH_OPLOCK)) {
|
||||||
schedule_defer_open(lck, request_time, req);
|
schedule_defer_open(lck, request_time, req);
|
||||||
TALLOC_FREE(lck);
|
TALLOC_FREE(lck);
|
||||||
fd_close(fsp);
|
fd_close(fsp);
|
||||||
@ -2418,8 +2434,8 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
|
|||||||
/* Second pass - send break for both batch or
|
/* Second pass - send break for both batch or
|
||||||
* exclusive oplocks. */
|
* exclusive oplocks. */
|
||||||
if ((req != NULL) &&
|
if ((req != NULL) &&
|
||||||
delay_for_oplock(fsp, req->mid, oplock_request,
|
delay_for_oplock(fsp, req->mid, oplock_request, lck,
|
||||||
exclusive_entry)) {
|
BATCH_OPLOCK|EXCLUSIVE_OPLOCK)) {
|
||||||
schedule_defer_open(lck, request_time, req);
|
schedule_defer_open(lck, request_time, req);
|
||||||
TALLOC_FREE(lck);
|
TALLOC_FREE(lck);
|
||||||
fd_close(fsp);
|
fd_close(fsp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user