Skip to content

Commit

Permalink
s3: smbd: Move implicit call to lp_posix_cifsu_locktype() out of init…
Browse files Browse the repository at this point in the history
…_strict_lock_struct().

Make it explicit. When we add POSIX handles to SMB2 we will only
look at the handle type. lp_posix_cifsu_locktype() already does this,
but hidden inside init_strict_lock_struct() makes it hard to see.

No logic change.

Signed-off-by: Jeremy Allison <[email protected]>
Reviewed-by: Noel Power <[email protected]>
  • Loading branch information
jrasamba authored and Noel Power committed Jan 6, 2022
1 parent 9a02128 commit 85e131b
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 36 deletions.
1 change: 1 addition & 0 deletions source3/locking/locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void init_strict_lock_struct(files_struct *fsp,
br_off start,
br_off size,
enum brl_type lock_type,
enum brl_flavour lock_flav,
struct lock_struct *plock)
{
SMB_ASSERT(lock_type == READ_LOCK || lock_type == WRITE_LOCK);
Expand Down
1 change: 1 addition & 0 deletions source3/locking/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void init_strict_lock_struct(files_struct *fsp,
br_off start,
br_off size,
enum brl_type lock_type,
enum brl_flavour lock_flav,
struct lock_struct *plock);
bool strict_lock_check_default(files_struct *fsp,
struct lock_struct *plock);
Expand Down
2 changes: 2 additions & 0 deletions source3/modules/vfs_btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ static struct tevent_req *btrfs_offload_write_send(struct vfs_handle_struct *han
src_off,
num,
READ_LOCK,
lp_posix_cifsu_locktype(src_fsp),
&src_lck);
if (!SMB_VFS_STRICT_LOCK_CHECK(src_fsp->conn, src_fsp, &src_lck)) {
tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand All @@ -360,6 +361,7 @@ static struct tevent_req *btrfs_offload_write_send(struct vfs_handle_struct *han
dest_off,
num,
WRITE_LOCK,
lp_posix_cifsu_locktype(dest_fsp),
&dest_lck);

if (!SMB_VFS_STRICT_LOCK_CHECK(dest_fsp->conn, dest_fsp, &dest_lck)) {
Expand Down
4 changes: 4 additions & 0 deletions source3/modules/vfs_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,7 @@ static NTSTATUS vfswrap_offload_copy_file_range(struct tevent_req *req)
state->src_off,
state->remaining,
READ_LOCK,
lp_posix_cifsu_locktype(state->src_fsp),
&lck);

ok = SMB_VFS_STRICT_LOCK_CHECK(state->src_fsp->conn,
Expand All @@ -2264,6 +2265,7 @@ static NTSTATUS vfswrap_offload_copy_file_range(struct tevent_req *req)
state->dst_off,
state->remaining,
WRITE_LOCK,
lp_posix_cifsu_locktype(state->dst_fsp),
&lck);

ok = SMB_VFS_STRICT_LOCK_CHECK(state->dst_fsp->conn,
Expand Down Expand Up @@ -2358,6 +2360,7 @@ static NTSTATUS vfswrap_offload_write_loop(struct tevent_req *req)
state->src_off,
state->next_io_size,
READ_LOCK,
lp_posix_cifsu_locktype(state->src_fsp),
&read_lck);

ok = SMB_VFS_STRICT_LOCK_CHECK(state->src_fsp->conn,
Expand Down Expand Up @@ -2421,6 +2424,7 @@ static void vfswrap_offload_write_read_done(struct tevent_req *subreq)
state->dst_off,
state->next_io_size,
WRITE_LOCK,
lp_posix_cifsu_locktype(state->dst_fsp),
&write_lck);

ok = SMB_VFS_STRICT_LOCK_CHECK(state->dst_fsp->conn,
Expand Down
40 changes: 28 additions & 12 deletions source3/smbd/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,13 @@ NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
SCVAL(aio_ex->outbuf.data,smb_vwv0,0xFF); /* Never a chained reply. */
SCVAL(smb_buf(aio_ex->outbuf.data), 0, 0); /* padding byte */

init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
&aio_ex->lock);
init_strict_lock_struct(fsp,
(uint64_t)smbreq->smbpid,
(uint64_t)startpos,
(uint64_t)smb_maxcnt,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&aio_ex->lock);

/* Take the lock until the AIO completes. */
if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &aio_ex->lock)) {
Expand Down Expand Up @@ -472,9 +476,13 @@ NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
srv_set_message((char *)aio_ex->outbuf.data, 6, 0, True);
SCVAL(aio_ex->outbuf.data,smb_vwv0,0xFF); /* Never a chained reply. */

init_strict_lock_struct(fsp, (uint64_t)smbreq->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&aio_ex->lock);
init_strict_lock_struct(fsp,
(uint64_t)smbreq->smbpid,
(uint64_t)startpos,
(uint64_t)numtowrite,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&aio_ex->lock);

/* Take the lock until the AIO completes. */
if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &aio_ex->lock)) {
Expand Down Expand Up @@ -720,9 +728,13 @@ NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
return NT_STATUS_NO_MEMORY;
}

init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
&aio_ex->lock);
init_strict_lock_struct(fsp,
fsp->op->global->open_persistent_id,
(uint64_t)startpos,
(uint64_t)smb_maxcnt,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&aio_ex->lock);

/* Take the lock until the AIO completes. */
if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &aio_ex->lock)) {
Expand Down Expand Up @@ -857,9 +869,13 @@ NTSTATUS schedule_aio_smb2_write(connection_struct *conn,

aio_ex->write_through = write_through;

init_strict_lock_struct(fsp, fsp->op->global->open_persistent_id,
in_offset, (uint64_t)in_data.length, WRITE_LOCK,
&aio_ex->lock);
init_strict_lock_struct(fsp,
fsp->op->global->open_persistent_id,
in_offset,
(uint64_t)in_data.length,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&aio_ex->lock);

/* Take the lock until the AIO completes. */
if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &aio_ex->lock)) {
Expand Down
80 changes: 56 additions & 24 deletions source3/smbd/reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3697,9 +3697,13 @@ void reply_readbraw(struct smb_request *req)
/* ensure we don't overrun the packet size */
maxcount = MIN(65535,maxcount);

init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)maxcount, READ_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)maxcount,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_readbraw_error(xconn);
Expand Down Expand Up @@ -3965,9 +3969,13 @@ Returning short read of maximum allowed for compatibility with Windows 2000.\n",

data = smb_buf(req->outbuf) + 3;

init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)numtoread, READ_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)numtoread,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -4042,9 +4050,13 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req,
int saved_errno = 0;
NTSTATUS status;

init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)smb_maxcnt, READ_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)smb_maxcnt,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -4565,9 +4577,13 @@ void reply_writebraw(struct smb_request *req)
}

if (!fsp->print_file) {
init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)tcount, WRITE_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)tcount,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -4780,9 +4796,13 @@ void reply_writeunlock(struct smb_request *req)
}

if (!fsp->print_file && numtowrite > 0) {
init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)numtowrite,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -4911,9 +4931,13 @@ void reply_write(struct smb_request *req)
}

if (!fsp->print_file) {
init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)numtowrite,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -5207,9 +5231,13 @@ void reply_write_and_X(struct smb_request *req)
/* NT_STATUS_RETRY - fall through to sync write. */
}

init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)numtowrite,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down Expand Up @@ -5909,9 +5937,13 @@ void reply_writeclose(struct smb_request *req)
}

if (fsp->print_file == NULL) {
init_strict_lock_struct(fsp, (uint64_t)req->smbpid,
(uint64_t)startpos, (uint64_t)numtowrite, WRITE_LOCK,
&lock);
init_strict_lock_struct(fsp,
(uint64_t)req->smbpid,
(uint64_t)startpos,
(uint64_t)numtowrite,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
reply_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
Expand Down
1 change: 1 addition & 0 deletions source3/smbd/smb2_ioctl_filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ static NTSTATUS fsctl_zero_data(TALLOC_CTX *mem_ctx,
zdata_info.file_off,
len,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lck);

if (!SMB_VFS_STRICT_LOCK_CHECK(fsp->conn, fsp, &lck)) {
Expand Down
2 changes: 2 additions & 0 deletions source3/smbd/smb2_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ static int smb2_sendfile_send_data(struct smbd_smb2_read_state *state)
in_offset,
in_length,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

*pstatus = NT_STATUS_OK;
Expand Down Expand Up @@ -553,6 +554,7 @@ static struct tevent_req *smbd_smb2_read_send(TALLOC_CTX *mem_ctx,
in_offset,
in_length,
READ_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
Expand Down
1 change: 1 addition & 0 deletions source3/smbd/smb2_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ static struct tevent_req *smbd_smb2_write_send(TALLOC_CTX *mem_ctx,
in_offset,
in_data.length,
WRITE_LOCK,
lp_posix_cifsu_locktype(fsp),
&lock);

if (!SMB_VFS_STRICT_LOCK_CHECK(conn, fsp, &lock)) {
Expand Down

0 comments on commit 85e131b

Please sign in to comment.