1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
Commit Graph

943 Commits

Author SHA1 Message Date
Volker Lendecke
9034cb39d7 smbd: Optimize delay_for_oplock()
get_lease_type() can involve a database access. Do that only if
necessary, and that is at most once in this loop.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-08-19 23:14:38 +00:00
Volker Lendecke
aeb4265ec2 smbd: Remove a misleading comment
open_mode_check() is done before the oplock breaks.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-08-19 23:14:38 +00:00
Volker Lendecke
d09bd5f8fd smbd: Merge two DEBUGs into one
This looks easier to understand to me, less lines in logfiles

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-08-19 23:14:38 +00:00
Volker Lendecke
13fb42ac40 smbd: Avoid casts in share_conflict()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-08-19 23:14:38 +00:00
Volker Lendecke
fe26ff6e91 smbd: Simplify fd_open_atomic()
* Assign *file_created on every exit.

* Directly assign curr_flags without &= / |=

Both of these changes make the routine easier to understand for me,
less jumping around in the code to see where the values came from.

* Do the retry in a "positive" if-clause

Normally I'm a big fan of early returns, but this single retry is so
simple that to me it's easier to understand this way.

Overall, 13 lines less code. YMMV :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Aug 10 00:07:28 UTC 2019 on sn-devel-184
2019-08-10 00:07:28 +00:00
Volker Lendecke
16b56549d2 smbd: FTRUNCATE regular files only
I don't really have a test case, but to me a positive test for a
regular file makes more sense here than just ruling out FIFOs. While
we probably only ever hit regular files (or FIFOs), there might be
more that we catch and don't properly handle.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
c2a779f50e smbd: Make "lease" const in create_file_default()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
665e3f022f smbd: Make "lease" const in create_file_unixpath()
This is the one place where *lease actually got modified. We can
easily make a copy, "struct smb2_lease" is not too large, and this
case is pretty rare anyway.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
bfa604541e smbd: Make "lease_key" const in lease_match()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
91b479fb6c smbd: Make "lease" const in open_file_ntcreate()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
d2aaef2e9c smbd: Make "lease" const in grant_fsp_oplock_type()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
e257224298 smbd: Nobody uses the changed "lease" from grant_fsp_oplock_type
.. except for the DEBUG message

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-09 22:48:46 +00:00
Volker Lendecke
4c08043ee5 smbd: Move handling the 1sec sharing_violation delay into smb1 code
Simplify the flow in open_file_ntcreate, streamline it for SMB2

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:50 +00:00
Volker Lendecke
c7e110e51a smbd: Add defer_sharing_violation_smb1
This is close to what Windows SMB1 does: Instead of waiting for the
share entry causing the SHARING_VIOLATION to disappear, retry every
200msec up to one second. Windows does it a little differently: Retry
up to 5 times. But up to one second should be close enough.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:50 +00:00
Volker Lendecke
305ea37c81 smbd: Get "req->request_time" early in create_file_default()
This is necessary for the following case:

We want to delete a file with an open stream that is not open with
FILE_SHARE_DELETE. In SMB1, we need to defer the sharing violation
reply (we don't do that right now, test to follow). However, when we
move that sharing violation delay to where it belongs, into the outer
layers, only very deep in the nested open_streams_for_delete smb1
sharing violation delay handling call we will hit the sharing
violation in the 1-second retry case. However, that
open_streams_for_delete itself is INTERNAL_OPEN_ONLY and thus not
deferred itself. This means that it will not overwrite
req->request_time at all.

Exec summary: We only have one request_time now, set it properly as
early as possible.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:50 +00:00
Volker Lendecke
1bc7d18b5f smbd: Do not exceed the req's max timeout in setup_poll_open()
This will become important in the next commits when the SMB1 sharing
violation delay will use this. We want to be able to reduce the
timeout to less than 200msec, see the next commits.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:50 +00:00
Volker Lendecke
50a3d08673 smbd: Make setup_poll_open() return bool
This is for callers who don't want to call open_was_deferred()
afterwards

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:49 +00:00
Volker Lendecke
832b9eb6df smbd: Make setup_kernel_oplock_poll_open() more general
This is a generic "open retry without locking.tdb waiter" loop: Take
the specific timeouts as parameters.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:49 +00:00
Volker Lendecke
939a109750 smbd: Avoid exit_server() in setup_kernel_oplock_poll_open()
Failure to postpone a request is not really fatal: We just don't retry
as wanted but return an error to the client that might have resolved
itself after a few seconds. From my point of view such a spurious and
rare error, which is highly unlikely anyway does not justify to kill
that client's connection.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:49 +00:00
Volker Lendecke
2c653515f3 smbd: Remove access check on SHARING_VIOLATION
This piece of code predates our user-space access checks, which we
nowadays always do in open_file()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-07 23:45:49 +00:00
Volker Lendecke
aab1712478 smbd: Assert that INTERNAL_OPEN_ONLY never gets real oplocks
Slightly simplify assumptions in the code

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Aug  6 23:06:41 UTC 2019 on sn-devel-184
2019-08-06 23:06:41 +00:00
Volker Lendecke
5e05686e39 smbd: Remove deferred_open_record_create()
This hides a talloc off the NULL context: The caller needs to make sure
this is put on a real talloc context later. Make that more
obvious. Also, it passes down a boolean flag, making its purpose a bit
opaque to the caller sites.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
718c4e27cd smbd: Remove "delayed_for_oplocks" from deferred_open_record_create()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
fc09be5b51 smbd: Remove "deferred_open_record->delayed_for_oplocks"
Nobody used this

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
61765c7e15 smbd: Remove "id" from deferred_open_record_create()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
67c5034531 smbd: Remove "deferred_open_record->id"
Nobody used this

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
fbc3675954 smbd: Clean up leases.tdb if set_share_mode() fails
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:30 +00:00
Volker Lendecke
e4d5c53e80 smbd: Slightly simplify set_share_mode()
The fsp carries all required information also for leases. There's no
need to pass that as additional parameters

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
13921645c4 smbd: Remove "share_access" from files_struct
Nobody used this (except vfs_gpfs, which did not need it really). If
you *really* need this, you can always look in locking.tdb, but this
should never happen in any hot code path, as no runtime decisions are
made on the share access after the open is done.

Bump VFS interface number to 42.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
71c6da46ee smbd: Pass share_access/access_mask explicitly to grant_fsp_oplock_type()
Why? While restructuring open_file_ntcreate() I found the data flow for
these values confusing: grant_fsp_oplock_type() depends on
fsp->access_mask, which changes its value inside
open_file_ntcreate(). I find the data flow easier to follow if it
happens in explicit variables.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
41ab2b8ec5 smbd: Pass share_access/access_mask explicitly to set_share_mode()
Makes the interface more obvious to me. Also, I want to remove
fsp->share_access, which is not really used anywhere after the fsp has
been fully established.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
1d9970735c smbd: Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
a7d4d5effa smbd: Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
88768fdecd smbd: Use timeval_str_buf() in defer_open()
Also make this a hires timestamp for better debugging.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:29 +00:00
Volker Lendecke
aedfee8f49 smbd: Fix a signed/unsigned warning
For whatever reason, "st_size" in "struct stat" is an off_t, which is a
signed integer. Negative sizes don't really make sense, so this cast
should be safe.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:28 +00:00
Volker Lendecke
2181221d6f smbd: Fix a signed/unsigned comparison
In the 2nd for-loop we need a signed int as we are comparing to >=0.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:28 +00:00
Volker Lendecke
4c6f12c323 smbd: Remove a false comment
Looking at the code we do respect the kernel_flock failure.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:28 +00:00
Volker Lendecke
3ca52f11dc smbd: Pass in "struct smb_request" to request_timed_out()
It seems more natural to pass in a request to a routine called
request_timed_out(), and it's a few bytes less .text

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:28 +00:00
Volker Lendecke
bb81b9a75a smbd: Use "req->request_time" in schedule_async_open()
All callers passed that in

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:28 +00:00
Volker Lendecke
af97381b11 smbd: Use "req->request_time" in schedule_async_open()
The one caller passed that in.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:27 +00:00
Volker Lendecke
2d05524e84 smbd: Use "req->request_time" in setup_kernel_oplock_poll_open()
Both callers passed that in.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:27 +00:00
Volker Lendecke
d5b5ef3e2f smbd: Use "req->request_time" in defer_open()
Both callers passed that in.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:27 +00:00
Volker Lendecke
e5ad2d3720 smbd: Use "req->request_time" in schedule_defer_open()
Both callers passed that in.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:27 +00:00
Volker Lendecke
2ef382fa76 smbd: Avoid a separate "request_time" variable in open_file_ntcreate
We have "smb_request->request_time" that is already set up by
init_smb_request().

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 21:49:27 +00:00
Ralph Boehme
37bb6229ad s3: smbd: fix a comment in fd_close()
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-08-06 14:23:36 +00:00
Volker Lendecke
2b590e16bc smbd: Fix retry for kernel-oplocked files
This now removed comment describes the bug correctly:
/*
 * As this timer event is owned by req, it will
 * disappear if req it talloc_freed.
 */

In smb1, "req" disappears once the reply_whatever routine is done. Thus
the timer goes away and we never look at "req" again.

This change moves the valid data (xconn and mid) to
deferred_open_record, and changes the talloc hierarchy such that the
timer is now a child of open_rec, which is a child of the deferred
message.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14060
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Jul 31 00:12:34 UTC 2019 on sn-devel-184
2019-07-31 00:12:34 +00:00
Volker Lendecke
ef582ffcf3 smbd: Always open files with O_NONBLOCK
It's perfectly possible that someone else takes a kernel oplock and
makes us block, independent of our own kernel oplock setting.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14060
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-07-30 22:37:26 +00:00
Volker Lendecke
32766db210 smbd: Move fcb_or_dos_open() out of open_file_ntcreate()
This is SMB1-only and pre-ntcreate with only 3 callers that look at
NTCREATEX_OPTIONS_PRIVATE_DENY_[DOS|FCB]. It is a bit less efficient
if it kicks in (we have to recreate the fsp), but SMB1 is less and
less popular, and this particular share mode combination from the
open&x family of calls might not be worth optimizing for.

This adds smb1_utils.[ch] as a kitchen sink for functions that can go
away once we drop SMB1.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-07-08 16:22:37 +00:00
Volker Lendecke
b16f7113eb smbd: Slightly simplify open_mode_check()
If there are no share modes, we'll just not enter the loop.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-07-08 16:22:37 +00:00
Volker Lendecke
81011f5ea1 smbd: Make get_relative_fid_filename() static to open.c
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-07-08 16:22:37 +00:00