1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3:smb2_lock: iterate over all sconn->client->connections

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Stefan Metzmacher 2014-09-16 09:03:39 +02:00 committed by Michael Adam
parent 1d53557df5
commit 0944797fef

View File

@ -468,34 +468,48 @@ struct blocking_lock_record *get_pending_smb2req_blr(struct smbd_smb2_request *s
static bool recalc_smb2_brl_timeout(struct smbd_server_connection *sconn) static bool recalc_smb2_brl_timeout(struct smbd_server_connection *sconn)
{ {
struct smbXsrv_connection *xconn = sconn->conn; struct smbXsrv_connection *xconn = NULL;
struct smbd_smb2_request *smb2req;
struct timeval next_timeout = timeval_zero(); struct timeval next_timeout = timeval_zero();
int max_brl_timeout = lp_parm_int(-1, "brl", "recalctime", 5); int max_brl_timeout = lp_parm_int(-1, "brl", "recalctime", 5);
TALLOC_FREE(sconn->smb2.locks.brl_timeout); TALLOC_FREE(sconn->smb2.locks.brl_timeout);
for (smb2req = xconn->smb2.requests; smb2req; smb2req = smb2req->next) { if (sconn != NULL && sconn->client != NULL) {
struct blocking_lock_record *blr = xconn = sconn->client->connections;
get_pending_smb2req_blr(smb2req); }
if (!blr) {
continue; for (; xconn != NULL; xconn = xconn->next) {
} struct smbd_smb2_request *smb2req, *nextreq;
if (timeval_is_zero(&blr->expire_time)) {
for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
struct blocking_lock_record *blr =
get_pending_smb2req_blr(smb2req);
nextreq = smb2req->next;
if (blr == NULL) {
continue;
}
if (!timeval_is_zero(&blr->expire_time)) {
next_timeout = timeval_brl_min(&next_timeout,
&blr->expire_time);
continue;
}
/* /*
* If we're blocked on pid 0xFFFFFFFFFFFFFFFFLL this is * If we're blocked on pid 0xFFFFFFFFFFFFFFFFLL this is
* a POSIX lock, so calculate a timeout of * a POSIX lock, so calculate a timeout of
* 10 seconds into the future. * 10 seconds into the future.
*/ */
if (blr->blocking_smblctx == 0xFFFFFFFFFFFFFFFFLL) { if (blr->blocking_smblctx == 0xFFFFFFFFFFFFFFFFLL) {
struct timeval psx_to = timeval_current_ofs(10, 0); struct timeval psx_to;
next_timeout = timeval_brl_min(&next_timeout, &psx_to);
psx_to = timeval_current_ofs(10, 0);
next_timeout = timeval_brl_min(&next_timeout,
&psx_to);
} }
continue;
} }
next_timeout = timeval_brl_min(&next_timeout, &blr->expire_time);
} }
if (timeval_is_zero(&next_timeout)) { if (timeval_is_zero(&next_timeout)) {
@ -775,26 +789,33 @@ static void reprocess_blocked_smb2_lock(struct smbd_smb2_request *smb2req,
void process_blocking_lock_queue_smb2( void process_blocking_lock_queue_smb2(
struct smbd_server_connection *sconn, struct timeval tv_curr) struct smbd_server_connection *sconn, struct timeval tv_curr)
{ {
struct smbXsrv_connection *xconn = sconn->conn; struct smbXsrv_connection *xconn = NULL;
struct smbd_smb2_request *smb2req, *nextreq;
for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) { if (sconn != NULL && sconn->client != NULL) {
const uint8_t *inhdr; xconn = sconn->client->connections;
}
nextreq = smb2req->next; for (; xconn != NULL; xconn = xconn->next) {
struct smbd_smb2_request *smb2req, *nextreq;
if (smb2req->subreq == NULL) { for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
/* This message has been processed. */ const uint8_t *inhdr;
continue;
}
if (!tevent_req_is_in_progress(smb2req->subreq)) {
/* This message has been processed. */
continue;
}
inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req); nextreq = smb2req->next;
if (SVAL(inhdr, SMB2_HDR_OPCODE) == SMB2_OP_LOCK) {
reprocess_blocked_smb2_lock(smb2req, tv_curr); if (smb2req->subreq == NULL) {
/* This message has been processed. */
continue;
}
if (!tevent_req_is_in_progress(smb2req->subreq)) {
/* This message has been processed. */
continue;
}
inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req);
if (SVAL(inhdr, SMB2_HDR_OPCODE) == SMB2_OP_LOCK) {
reprocess_blocked_smb2_lock(smb2req, tv_curr);
}
} }
} }
@ -810,66 +831,73 @@ void cancel_pending_lock_requests_by_fid_smb2(files_struct *fsp,
enum file_close_type close_type) enum file_close_type close_type)
{ {
struct smbd_server_connection *sconn = fsp->conn->sconn; struct smbd_server_connection *sconn = fsp->conn->sconn;
struct smbXsrv_connection *xconn = sconn->conn; struct smbXsrv_connection *xconn = NULL;
struct smbd_smb2_request *smb2req, *nextreq;
for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) { if (sconn != NULL && sconn->client != NULL) {
struct smbd_smb2_lock_state *state = NULL; xconn = sconn->client->connections;
files_struct *fsp_curr = NULL; }
struct blocking_lock_record *blr = NULL;
const uint8_t *inhdr;
nextreq = smb2req->next; for (; xconn != NULL; xconn = xconn->next) {
struct smbd_smb2_request *smb2req, *nextreq;
if (smb2req->subreq == NULL) { for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
/* This message has been processed. */ struct smbd_smb2_lock_state *state = NULL;
continue; files_struct *fsp_curr = NULL;
} struct blocking_lock_record *blr = NULL;
if (!tevent_req_is_in_progress(smb2req->subreq)) { const uint8_t *inhdr;
/* This message has been processed. */
continue;
}
inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req); nextreq = smb2req->next;
if (SVAL(inhdr, SMB2_HDR_OPCODE) != SMB2_OP_LOCK) {
/* Not a lock call. */
continue;
}
state = tevent_req_data(smb2req->subreq, if (smb2req->subreq == NULL) {
struct smbd_smb2_lock_state); /* This message has been processed. */
if (!state) { continue;
/* Strange - is this even possible ? */ }
continue; if (!tevent_req_is_in_progress(smb2req->subreq)) {
} /* This message has been processed. */
continue;
}
fsp_curr = smb2req->compat_chain_fsp; inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req);
if (fsp_curr == NULL) { if (SVAL(inhdr, SMB2_HDR_OPCODE) != SMB2_OP_LOCK) {
/* Strange - is this even possible ? */ /* Not a lock call. */
continue; continue;
} }
if (fsp_curr != fsp) { state = tevent_req_data(smb2req->subreq,
/* It's not our fid */ struct smbd_smb2_lock_state);
continue; if (!state) {
} /* Strange - is this even possible ? */
continue;
}
blr = state->blr; fsp_curr = smb2req->compat_chain_fsp;
if (fsp_curr == NULL) {
/* Strange - is this even possible ? */
continue;
}
/* Remove the entries from the lock db. */ if (fsp_curr != fsp) {
brl_lock_cancel(br_lck, /* It's not our fid */
blr->smblctx, continue;
messaging_server_id(sconn->msg_ctx), }
blr->offset,
blr->count,
blr->lock_flav);
/* Finally end the request. */ blr = state->blr;
if (close_type == SHUTDOWN_CLOSE) {
tevent_req_done(smb2req->subreq); /* Remove the entries from the lock db. */
} else { brl_lock_cancel(br_lck,
tevent_req_nterror(smb2req->subreq, blr->smblctx,
NT_STATUS_RANGE_NOT_LOCKED); messaging_server_id(sconn->msg_ctx),
blr->offset,
blr->count,
blr->lock_flav);
/* Finally end the request. */
if (close_type == SHUTDOWN_CLOSE) {
tevent_req_done(smb2req->subreq);
} else {
tevent_req_nterror(smb2req->subreq,
NT_STATUS_RANGE_NOT_LOCKED);
}
} }
} }
} }