s3:smbd: split out smbd_do_qfsinfo() from call_trans2qfsinfo()
[Samba/fernandojvsilva.git] / source3 / smbd / blocking.c
blob4c61428692dc48d45ca76600d2e5cddd140f73b8
1 /*
2 Unix SMB/CIFS implementation.
3 Blocking Locking functions
4 Copyright (C) Jeremy Allison 1998-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "smbd/globals.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_LOCKING
26 /****************************************************************************
27 Determine if this is a secondary element of a chained SMB.
28 **************************************************************************/
30 static void received_unlock_msg(struct messaging_context *msg,
31 void *private_data,
32 uint32_t msg_type,
33 struct server_id server_id,
34 DATA_BLOB *data);
36 static void brl_timeout_fn(struct event_context *event_ctx,
37 struct timed_event *te,
38 struct timeval now,
39 void *private_data)
41 SMB_ASSERT(brl_timeout == te);
42 TALLOC_FREE(brl_timeout);
44 change_to_root_user(); /* TODO: Possibly run all timed events as
45 * root */
47 process_blocking_lock_queue();
50 /****************************************************************************
51 After a change to blocking_lock_queue, recalculate the timed_event for the
52 next processing.
53 ****************************************************************************/
55 static bool recalc_brl_timeout(void)
57 struct blocking_lock_record *blr;
58 struct timeval next_timeout;
60 TALLOC_FREE(brl_timeout);
62 next_timeout = timeval_zero();
64 for (blr = blocking_lock_queue; blr; blr = blr->next) {
65 if (timeval_is_zero(&blr->expire_time)) {
67 * If we're blocked on pid 0xFFFFFFFF this is
68 * a POSIX lock, so calculate a timeout of
69 * 10 seconds into the future.
71 if (blr->blocking_pid == 0xFFFFFFFF) {
72 struct timeval psx_to = timeval_current_ofs(10, 0);
73 next_timeout = timeval_min(&next_timeout, &psx_to);
76 continue;
79 if (timeval_is_zero(&next_timeout)) {
80 next_timeout = blr->expire_time;
82 else {
83 next_timeout = timeval_min(&next_timeout,
84 &blr->expire_time);
88 if (timeval_is_zero(&next_timeout)) {
89 DEBUG(10, ("Next timeout = Infinite.\n"));
90 return True;
93 if (DEBUGLVL(10)) {
94 struct timeval cur, from_now;
96 cur = timeval_current();
97 from_now = timeval_until(&cur, &next_timeout);
98 DEBUG(10, ("Next timeout = %d.%d seconds from now.\n",
99 (int)from_now.tv_sec, (int)from_now.tv_usec));
102 if (!(brl_timeout = event_add_timed(smbd_event_context(), NULL,
103 next_timeout,
104 brl_timeout_fn, NULL))) {
105 return False;
108 return True;
112 /****************************************************************************
113 Function to push a blocking lock request onto the lock queue.
114 ****************************************************************************/
116 bool push_blocking_lock_request( struct byte_range_lock *br_lck,
117 struct smb_request *req,
118 files_struct *fsp,
119 int lock_timeout,
120 int lock_num,
121 uint32_t lock_pid,
122 enum brl_type lock_type,
123 enum brl_flavour lock_flav,
124 uint64_t offset,
125 uint64_t count,
126 uint32_t blocking_pid)
128 struct blocking_lock_record *blr;
129 NTSTATUS status;
131 if(req_is_in_chain(req)) {
132 DEBUG(0,("push_blocking_lock_request: cannot queue a chained request (currently).\n"));
133 return False;
137 * Now queue an entry on the blocking lock queue. We setup
138 * the expiration time here.
141 blr = talloc(NULL, struct blocking_lock_record);
142 if (blr == NULL) {
143 DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
144 return False;
147 blr->next = NULL;
148 blr->prev = NULL;
150 blr->fsp = fsp;
151 if (lock_timeout == -1) {
152 blr->expire_time.tv_sec = 0;
153 blr->expire_time.tv_usec = 0; /* Never expire. */
154 } else {
155 blr->expire_time = timeval_current_ofs(lock_timeout/1000,
156 (lock_timeout % 1000) * 1000);
158 blr->lock_num = lock_num;
159 blr->lock_pid = lock_pid;
160 blr->blocking_pid = blocking_pid;
161 blr->lock_flav = lock_flav;
162 blr->lock_type = lock_type;
163 blr->offset = offset;
164 blr->count = count;
166 /* Specific brl_lock() implementations can fill this in. */
167 blr->blr_private = NULL;
169 /* Add a pending lock record for this. */
170 status = brl_lock(smbd_messaging_context(),
171 br_lck,
172 lock_pid,
173 procid_self(),
174 offset,
175 count,
176 lock_type == READ_LOCK ? PENDING_READ_LOCK : PENDING_WRITE_LOCK,
177 blr->lock_flav,
178 lock_timeout ? True : False, /* blocking_lock. */
179 NULL,
180 blr);
182 if (!NT_STATUS_IS_OK(status)) {
183 DEBUG(0,("push_blocking_lock_request: failed to add PENDING_LOCK record.\n"));
184 TALLOC_FREE(blr);
185 return False;
188 SMB_PERFCOUNT_DEFER_OP(&req->pcd, &req->pcd);
189 blr->req = talloc_move(blr, &req);
191 DLIST_ADD_END(blocking_lock_queue, blr, struct blocking_lock_record *);
192 recalc_brl_timeout();
194 /* Ensure we'll receive messages when this is unlocked. */
195 if (!blocking_lock_unlock_state) {
196 messaging_register(smbd_messaging_context(), NULL,
197 MSG_SMB_UNLOCK, received_unlock_msg);
198 blocking_lock_unlock_state = true;
201 DEBUG(3,("push_blocking_lock_request: lock request blocked with "
202 "expiry time (%u sec. %u usec) (+%d msec) for fnum = %d, name = %s\n",
203 (unsigned int)blr->expire_time.tv_sec,
204 (unsigned int)blr->expire_time.tv_usec, lock_timeout,
205 blr->fsp->fnum, blr->fsp->fsp_name ));
207 return True;
210 /****************************************************************************
211 Return a lockingX success SMB.
212 *****************************************************************************/
214 static void reply_lockingX_success(struct blocking_lock_record *blr)
216 reply_outbuf(blr->req, 2, 0);
219 * As this message is a lockingX call we must handle
220 * any following chained message correctly.
221 * This is normally handled in construct_reply(),
222 * but as that calls switch_message, we can't use
223 * that here and must set up the chain info manually.
226 chain_reply(blr->req);
227 TALLOC_FREE(blr->req->outbuf);
230 /****************************************************************************
231 Return a generic lock fail error blocking call.
232 *****************************************************************************/
234 static void generic_blocking_lock_error(struct blocking_lock_record *blr, NTSTATUS status)
236 /* whenever a timeout is given w2k maps LOCK_NOT_GRANTED to
237 FILE_LOCK_CONFLICT! (tridge) */
238 if (NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED)) {
239 status = NT_STATUS_FILE_LOCK_CONFLICT;
242 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
243 /* Store the last lock error. */
244 files_struct *fsp = blr->fsp;
246 if (fsp) {
247 fsp->last_lock_failure.context.smbpid = blr->lock_pid;
248 fsp->last_lock_failure.context.tid = fsp->conn->cnum;
249 fsp->last_lock_failure.context.pid = procid_self();
250 fsp->last_lock_failure.start = blr->offset;
251 fsp->last_lock_failure.size = blr->count;
252 fsp->last_lock_failure.fnum = fsp->fnum;
253 fsp->last_lock_failure.lock_type = READ_LOCK; /* Don't care. */
254 fsp->last_lock_failure.lock_flav = blr->lock_flav;
258 reply_nterror(blr->req, status);
259 if (!srv_send_smb(smbd_server_fd(), (char *)blr->req->outbuf,
260 true, blr->req->seqnum+1,
261 blr->req->encrypted, NULL)) {
262 exit_server_cleanly("generic_blocking_lock_error: srv_send_smb failed.");
264 TALLOC_FREE(blr->req->outbuf);
267 /****************************************************************************
268 Return a lock fail error for a lockingX call. Undo all the locks we have
269 obtained first.
270 *****************************************************************************/
272 static void reply_lockingX_error(struct blocking_lock_record *blr, NTSTATUS status)
274 files_struct *fsp = blr->fsp;
275 uint16 num_ulocks = SVAL(blr->req->vwv+6, 0);
276 uint64_t count = (uint64_t)0, offset = (uint64_t) 0;
277 uint32 lock_pid;
278 unsigned char locktype = CVAL(blr->req->vwv+3, 0);
279 bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
280 uint8_t *data;
281 int i;
283 data = (uint8_t *)blr->req->buf
284 + ((large_file_format ? 20 : 10)*num_ulocks);
287 * Data now points at the beginning of the list
288 * of smb_lkrng structs.
292 * Ensure we don't do a remove on the lock that just failed,
293 * as under POSIX rules, if we have a lock already there, we
294 * will delete it (and we shouldn't) .....
297 for(i = blr->lock_num - 1; i >= 0; i--) {
298 bool err;
300 lock_pid = get_lock_pid( data, i, large_file_format);
301 count = get_lock_count( data, i, large_file_format);
302 offset = get_lock_offset( data, i, large_file_format, &err);
305 * We know err cannot be set as if it was the lock
306 * request would never have been queued. JRA.
309 do_unlock(smbd_messaging_context(),
310 fsp,
311 lock_pid,
312 count,
313 offset,
314 WINDOWS_LOCK);
317 generic_blocking_lock_error(blr, status);
320 /****************************************************************************
321 Return a lock fail error.
322 *****************************************************************************/
324 static void blocking_lock_reply_error(struct blocking_lock_record *blr, NTSTATUS status)
326 DEBUG(10, ("Replying with error=%s. BLR = %p\n", nt_errstr(status), blr));
328 switch(blr->req->cmd) {
329 case SMBlockingX:
330 reply_lockingX_error(blr, status);
331 break;
332 case SMBtrans2:
333 case SMBtranss2:
334 reply_nterror(blr->req, status);
337 * construct_reply_common has done us the favor to pre-fill
338 * the command field with SMBtranss2 which is wrong :-)
340 SCVAL(blr->req->outbuf,smb_com,SMBtrans2);
342 if (!srv_send_smb(smbd_server_fd(),
343 (char *)blr->req->outbuf,
344 true, blr->req->seqnum+1,
345 IS_CONN_ENCRYPTED(blr->fsp->conn),
346 NULL)) {
347 exit_server_cleanly("blocking_lock_reply_error: "
348 "srv_send_smb failed.");
350 TALLOC_FREE(blr->req->outbuf);
351 break;
352 default:
353 DEBUG(0,("blocking_lock_reply_error: PANIC - unknown type on blocking lock queue - exiting.!\n"));
354 exit_server("PANIC - unknown type on blocking lock queue");
358 /****************************************************************************
359 Attempt to finish off getting all pending blocking locks for a lockingX call.
360 Returns True if we want to be removed from the list.
361 *****************************************************************************/
363 static bool process_lockingX(struct blocking_lock_record *blr)
365 unsigned char locktype = CVAL(blr->req->vwv+3, 0);
366 files_struct *fsp = blr->fsp;
367 uint16 num_ulocks = SVAL(blr->req->vwv+6, 0);
368 uint16 num_locks = SVAL(blr->req->vwv+7, 0);
369 uint64_t count = (uint64_t)0, offset = (uint64_t)0;
370 uint32 lock_pid;
371 bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
372 uint8_t *data;
373 NTSTATUS status = NT_STATUS_OK;
375 data = (uint8_t *)blr->req->buf
376 + ((large_file_format ? 20 : 10)*num_ulocks);
379 * Data now points at the beginning of the list
380 * of smb_lkrng structs.
383 for(; blr->lock_num < num_locks; blr->lock_num++) {
384 struct byte_range_lock *br_lck = NULL;
385 bool err;
387 lock_pid = get_lock_pid( data, blr->lock_num, large_file_format);
388 count = get_lock_count( data, blr->lock_num, large_file_format);
389 offset = get_lock_offset( data, blr->lock_num, large_file_format, &err);
392 * We know err cannot be set as if it was the lock
393 * request would never have been queued. JRA.
395 errno = 0;
396 br_lck = do_lock(smbd_messaging_context(),
397 fsp,
398 lock_pid,
399 count,
400 offset,
401 ((locktype & LOCKING_ANDX_SHARED_LOCK) ?
402 READ_LOCK : WRITE_LOCK),
403 WINDOWS_LOCK,
404 True,
405 &status,
406 &blr->blocking_pid,
407 blr);
409 TALLOC_FREE(br_lck);
411 if (NT_STATUS_IS_ERR(status)) {
412 break;
416 if(blr->lock_num == num_locks) {
418 * Success - we got all the locks.
421 DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n",
422 fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) );
424 reply_lockingX_success(blr);
425 return True;
428 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
429 !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
431 * We have other than a "can't get lock"
432 * error. Free any locks we had and return an error.
433 * Return True so we get dequeued.
435 blocking_lock_reply_error(blr, status);
436 return True;
440 * Still can't get all the locks - keep waiting.
443 DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \
444 Waiting....\n",
445 blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum));
447 return False;
450 /****************************************************************************
451 Attempt to get the posix lock request from a SMBtrans2 call.
452 Returns True if we want to be removed from the list.
453 *****************************************************************************/
455 static bool process_trans2(struct blocking_lock_record *blr)
457 char params[2];
458 NTSTATUS status;
459 struct byte_range_lock *br_lck = do_lock(smbd_messaging_context(),
460 blr->fsp,
461 blr->lock_pid,
462 blr->count,
463 blr->offset,
464 blr->lock_type,
465 blr->lock_flav,
466 True,
467 &status,
468 &blr->blocking_pid,
469 blr);
470 TALLOC_FREE(br_lck);
472 if (!NT_STATUS_IS_OK(status)) {
473 if (ERROR_WAS_LOCK_DENIED(status)) {
474 /* Still can't get the lock, just keep waiting. */
475 return False;
478 * We have other than a "can't get lock"
479 * error. Send an error and return True so we get dequeued.
481 blocking_lock_reply_error(blr, status);
482 return True;
485 /* We finally got the lock, return success. */
487 SSVAL(params,0,0);
488 /* Fake up max_data_bytes here - we know it fits. */
489 send_trans2_replies(blr->fsp->conn, blr->req, params, 2, NULL, 0, 0xffff);
490 return True;
494 /****************************************************************************
495 Process a blocking lock SMB.
496 Returns True if we want to be removed from the list.
497 *****************************************************************************/
499 static bool blocking_lock_record_process(struct blocking_lock_record *blr)
501 switch(blr->req->cmd) {
502 case SMBlockingX:
503 return process_lockingX(blr);
504 case SMBtrans2:
505 case SMBtranss2:
506 return process_trans2(blr);
507 default:
508 DEBUG(0,("blocking_lock_record_process: PANIC - unknown type on blocking lock queue - exiting.!\n"));
509 exit_server("PANIC - unknown type on blocking lock queue");
511 return False; /* Keep compiler happy. */
514 /****************************************************************************
515 Cancel entries by fnum from the blocking lock pending queue.
516 *****************************************************************************/
518 void cancel_pending_lock_requests_by_fid(files_struct *fsp, struct byte_range_lock *br_lck)
520 struct blocking_lock_record *blr, *blr_cancelled, *next = NULL;
522 for(blr = blocking_lock_queue; blr; blr = next) {
523 unsigned char locktype = 0;
525 next = blr->next;
526 if (blr->fsp->fnum != fsp->fnum) {
527 continue;
530 if (blr->req->cmd == SMBlockingX) {
531 locktype = CVAL(blr->req->vwv+3, 0);
534 DEBUG(10, ("remove_pending_lock_requests_by_fid - removing "
535 "request type %d for file %s fnum = %d\n",
536 blr->req->cmd, fsp->fsp_name, fsp->fnum));
538 blr_cancelled = blocking_lock_cancel(fsp,
539 blr->lock_pid,
540 blr->offset,
541 blr->count,
542 blr->lock_flav,
543 locktype,
544 NT_STATUS_RANGE_NOT_LOCKED);
546 SMB_ASSERT(blr_cancelled == blr);
548 brl_lock_cancel(br_lck,
549 blr->lock_pid,
550 procid_self(),
551 blr->offset,
552 blr->count,
553 blr->lock_flav,
554 blr);
556 /* We're closing the file fsp here, so ensure
557 * we don't have a dangling pointer. */
558 blr->fsp = NULL;
562 /****************************************************************************
563 Delete entries by mid from the blocking lock pending queue. Always send reply.
564 *****************************************************************************/
566 void remove_pending_lock_requests_by_mid(int mid)
568 struct blocking_lock_record *blr, *next = NULL;
570 for(blr = blocking_lock_queue; blr; blr = next) {
571 files_struct *fsp;
572 struct byte_range_lock *br_lck;
574 next = blr->next;
576 if (blr->req->mid != mid) {
577 continue;
580 fsp = blr->fsp;
581 br_lck = brl_get_locks(talloc_tos(), fsp);
583 if (br_lck) {
584 DEBUG(10, ("remove_pending_lock_requests_by_mid - "
585 "removing request type %d for file %s fnum "
586 "= %d\n", blr->req->cmd, fsp->fsp_name,
587 fsp->fnum ));
589 brl_lock_cancel(br_lck,
590 blr->lock_pid,
591 procid_self(),
592 blr->offset,
593 blr->count,
594 blr->lock_flav,
595 blr);
596 TALLOC_FREE(br_lck);
599 blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
600 DLIST_REMOVE(blocking_lock_queue, blr);
601 TALLOC_FREE(blr);
605 /****************************************************************************
606 Is this mid a blocking lock request on the queue ?
607 *****************************************************************************/
609 bool blocking_lock_was_deferred(int mid)
611 struct blocking_lock_record *blr, *next = NULL;
613 for(blr = blocking_lock_queue; blr; blr = next) {
614 next = blr->next;
615 if(blr->req->mid == mid) {
616 return True;
619 return False;
622 /****************************************************************************
623 Set a flag as an unlock request affects one of our pending locks.
624 *****************************************************************************/
626 static void received_unlock_msg(struct messaging_context *msg,
627 void *private_data,
628 uint32_t msg_type,
629 struct server_id server_id,
630 DATA_BLOB *data)
632 DEBUG(10,("received_unlock_msg\n"));
633 process_blocking_lock_queue();
636 /****************************************************************************
637 Process the blocking lock queue. Note that this is only called as root.
638 *****************************************************************************/
640 void process_blocking_lock_queue(void)
642 struct timeval tv_curr = timeval_current();
643 struct blocking_lock_record *blr, *next = NULL;
644 bool recalc_timeout = False;
647 * Go through the queue and see if we can get any of the locks.
650 for (blr = blocking_lock_queue; blr; blr = next) {
652 next = blr->next;
655 * Go through the remaining locks and try and obtain them.
656 * The call returns True if all locks were obtained successfully
657 * and False if we still need to wait.
660 DEBUG(10, ("Processing BLR = %p\n", blr));
662 if(blocking_lock_record_process(blr)) {
663 struct byte_range_lock *br_lck = brl_get_locks(
664 talloc_tos(), blr->fsp);
666 DEBUG(10, ("BLR_process returned true: cancelling and "
667 "removing lock. BLR = %p\n", blr));
669 if (br_lck) {
670 brl_lock_cancel(br_lck,
671 blr->lock_pid,
672 procid_self(),
673 blr->offset,
674 blr->count,
675 blr->lock_flav,
676 blr);
677 TALLOC_FREE(br_lck);
680 DLIST_REMOVE(blocking_lock_queue, blr);
681 TALLOC_FREE(blr);
682 recalc_timeout = True;
683 continue;
687 * We couldn't get the locks for this record on the list.
688 * If the time has expired, return a lock error.
691 if (!timeval_is_zero(&blr->expire_time) && timeval_compare(&blr->expire_time, &tv_curr) <= 0) {
692 struct byte_range_lock *br_lck = brl_get_locks(
693 talloc_tos(), blr->fsp);
695 DEBUG(10, ("Lock timed out! BLR = %p\n", blr));
698 * Lock expired - throw away all previously
699 * obtained locks and return lock error.
702 if (br_lck) {
703 DEBUG(5,("process_blocking_lock_queue: "
704 "pending lock fnum = %d for file %s "
705 "timed out.\n", blr->fsp->fnum,
706 blr->fsp->fsp_name ));
708 brl_lock_cancel(br_lck,
709 blr->lock_pid,
710 procid_self(),
711 blr->offset,
712 blr->count,
713 blr->lock_flav,
714 blr);
715 TALLOC_FREE(br_lck);
718 blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
719 DLIST_REMOVE(blocking_lock_queue, blr);
720 TALLOC_FREE(blr);
721 recalc_timeout = True;
725 if (recalc_timeout) {
726 recalc_brl_timeout();
730 /****************************************************************************
731 Handle a cancel message. Lock already moved onto the cancel queue.
732 *****************************************************************************/
734 #define MSG_BLOCKING_LOCK_CANCEL_SIZE (sizeof(struct blocking_lock_record *) + sizeof(NTSTATUS))
736 static void process_blocking_lock_cancel_message(struct messaging_context *ctx,
737 void *private_data,
738 uint32_t msg_type,
739 struct server_id server_id,
740 DATA_BLOB *data)
742 NTSTATUS err;
743 const char *msg = (const char *)data->data;
744 struct blocking_lock_record *blr;
746 if (data->data == NULL) {
747 smb_panic("process_blocking_lock_cancel_message: null msg");
750 if (data->length != MSG_BLOCKING_LOCK_CANCEL_SIZE) {
751 DEBUG(0, ("process_blocking_lock_cancel_message: "
752 "Got invalid msg len %d\n", (int)data->length));
753 smb_panic("process_blocking_lock_cancel_message: bad msg");
756 memcpy(&blr, msg, sizeof(blr));
757 memcpy(&err, &msg[sizeof(blr)], sizeof(NTSTATUS));
759 DEBUG(10,("process_blocking_lock_cancel_message: returning error %s\n",
760 nt_errstr(err) ));
762 blocking_lock_reply_error(blr, err);
763 DLIST_REMOVE(blocking_lock_cancelled_queue, blr);
764 TALLOC_FREE(blr);
767 /****************************************************************************
768 Send ourselves a blocking lock cancelled message. Handled asynchronously above.
769 Returns the blocking_lock_record that is being cancelled.
770 *****************************************************************************/
772 struct blocking_lock_record *blocking_lock_cancel(files_struct *fsp,
773 uint32 lock_pid,
774 uint64_t offset,
775 uint64_t count,
776 enum brl_flavour lock_flav,
777 unsigned char locktype,
778 NTSTATUS err)
780 char msg[MSG_BLOCKING_LOCK_CANCEL_SIZE];
781 struct blocking_lock_record *blr;
783 if (!blocking_lock_cancel_state) {
784 /* Register our message. */
785 messaging_register(smbd_messaging_context(), NULL,
786 MSG_SMB_BLOCKING_LOCK_CANCEL,
787 process_blocking_lock_cancel_message);
789 blocking_lock_cancel_state = True;
792 for (blr = blocking_lock_queue; blr; blr = blr->next) {
793 if (fsp == blr->fsp &&
794 lock_pid == blr->lock_pid &&
795 offset == blr->offset &&
796 count == blr->count &&
797 lock_flav == blr->lock_flav) {
798 break;
802 if (!blr) {
803 return NULL;
806 /* Check the flags are right. */
807 if (blr->req->cmd == SMBlockingX &&
808 (locktype & LOCKING_ANDX_LARGE_FILES) !=
809 (CVAL(blr->req->vwv+3, 0) & LOCKING_ANDX_LARGE_FILES)) {
810 return NULL;
813 /* Move to cancelled queue. */
814 DLIST_REMOVE(blocking_lock_queue, blr);
815 DLIST_ADD(blocking_lock_cancelled_queue, blr);
817 /* Create the message. */
818 memcpy(msg, &blr, sizeof(blr));
819 memcpy(&msg[sizeof(blr)], &err, sizeof(NTSTATUS));
821 messaging_send_buf(smbd_messaging_context(), procid_self(),
822 MSG_SMB_BLOCKING_LOCK_CANCEL,
823 (uint8 *)&msg, sizeof(msg));
825 return blr;