2 Unix SMB/CIFS implementation.
3 byte range locking code
4 Updated to handle range splits/merges.
6 Copyright (C) Andrew Tridgell 1992-2000
7 Copyright (C) Jeremy Allison 1992-2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* This module implements a tdb based byte range locking service,
24 replacing the fcntl() based byte range locking previously
25 used. This allows us to provide the same semantics as NT */
30 #define DBGC_CLASS DBGC_LOCKING
34 /* The open brlock.tdb database. */
36 static struct db_context *brlock_db;
38 /****************************************************************************
39 Debug info at level 10 for lock struct.
40 ****************************************************************************/
42 static void print_lock_struct(unsigned int i, struct lock_struct *pls)
44 DEBUG(10,("[%u]: smbpid = %u, tid = %u, pid = %s, ",
46 (unsigned int)pls->context.smbpid,
47 (unsigned int)pls->context.tid,
48 procid_str_static(&pls->context.pid) ));
50 DEBUG(10,("start = %.0f, size = %.0f, fnum = %d, %s %s\n",
54 lock_type_name(pls->lock_type),
55 lock_flav_name(pls->lock_flav) ));
58 /****************************************************************************
59 See if two locking contexts are equal.
60 ****************************************************************************/
62 bool brl_same_context(const struct lock_context *ctx1,
63 const struct lock_context *ctx2)
65 return (procid_equal(&ctx1->pid, &ctx2->pid) &&
66 (ctx1->smbpid == ctx2->smbpid) &&
67 (ctx1->tid == ctx2->tid));
70 /****************************************************************************
71 See if lck1 and lck2 overlap.
72 ****************************************************************************/
74 static bool brl_overlap(const struct lock_struct *lck1,
75 const struct lock_struct *lck2)
77 /* this extra check is not redundent - it copes with locks
78 that go beyond the end of 64 bit file space */
79 if (lck1->size != 0 &&
80 lck1->start == lck2->start &&
81 lck1->size == lck2->size) {
85 if (lck1->start >= (lck2->start+lck2->size) ||
86 lck2->start >= (lck1->start+lck1->size)) {
92 /****************************************************************************
93 See if lock2 can be added when lock1 is in place.
94 ****************************************************************************/
96 static bool brl_conflict(const struct lock_struct *lck1,
97 const struct lock_struct *lck2)
99 /* Ignore PENDING locks. */
100 if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
103 /* Read locks never conflict. */
104 if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) {
108 if (brl_same_context(&lck1->context, &lck2->context) &&
109 lck2->lock_type == READ_LOCK && lck1->fnum == lck2->fnum) {
113 return brl_overlap(lck1, lck2);
116 /****************************************************************************
117 See if lock2 can be added when lock1 is in place - when both locks are POSIX
118 flavour. POSIX locks ignore fnum - they only care about dev/ino which we
120 ****************************************************************************/
122 static bool brl_conflict_posix(const struct lock_struct *lck1,
123 const struct lock_struct *lck2)
125 #if defined(DEVELOPER)
126 SMB_ASSERT(lck1->lock_flav == POSIX_LOCK);
127 SMB_ASSERT(lck2->lock_flav == POSIX_LOCK);
130 /* Ignore PENDING locks. */
131 if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
134 /* Read locks never conflict. */
135 if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) {
139 /* Locks on the same context con't conflict. Ignore fnum. */
140 if (brl_same_context(&lck1->context, &lck2->context)) {
144 /* One is read, the other write, or the context is different,
146 return brl_overlap(lck1, lck2);
150 static bool brl_conflict1(const struct lock_struct *lck1,
151 const struct lock_struct *lck2)
153 if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
156 if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) {
160 if (brl_same_context(&lck1->context, &lck2->context) &&
161 lck2->lock_type == READ_LOCK && lck1->fnum == lck2->fnum) {
165 if (lck2->start == 0 && lck2->size == 0 && lck1->size != 0) {
169 if (lck1->start >= (lck2->start + lck2->size) ||
170 lck2->start >= (lck1->start + lck1->size)) {
178 /****************************************************************************
179 Check to see if this lock conflicts, but ignore our own locks on the
180 same fnum only. This is the read/write lock check code path.
181 This is never used in the POSIX lock case.
182 ****************************************************************************/
184 static bool brl_conflict_other(const struct lock_struct *lck1, const struct lock_struct *lck2)
186 if (IS_PENDING_LOCK(lck1->lock_type) || IS_PENDING_LOCK(lck2->lock_type))
189 if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK)
192 /* POSIX flavour locks never conflict here - this is only called
193 in the read/write path. */
195 if (lck1->lock_flav == POSIX_LOCK && lck2->lock_flav == POSIX_LOCK)
199 * Incoming WRITE locks conflict with existing READ locks even
200 * if the context is the same. JRA. See LOCKTEST7 in smbtorture.
203 if (!(lck2->lock_type == WRITE_LOCK && lck1->lock_type == READ_LOCK)) {
204 if (brl_same_context(&lck1->context, &lck2->context) &&
205 lck1->fnum == lck2->fnum)
209 return brl_overlap(lck1, lck2);
212 /****************************************************************************
213 Check if an unlock overlaps a pending lock.
214 ****************************************************************************/
216 static bool brl_pending_overlap(const struct lock_struct *lock, const struct lock_struct *pend_lock)
218 if ((lock->start <= pend_lock->start) && (lock->start + lock->size > pend_lock->start))
220 if ((lock->start >= pend_lock->start) && (lock->start <= pend_lock->start + pend_lock->size))
225 /****************************************************************************
226 Amazingly enough, w2k3 "remembers" whether the last lock failure on a fnum
227 is the same as this one and changes its error code. I wonder if any
228 app depends on this ?
229 ****************************************************************************/
231 static NTSTATUS brl_lock_failed(files_struct *fsp, const struct lock_struct *lock, bool blocking_lock)
233 if (lock->start >= 0xEF000000 && (lock->start >> 63) == 0) {
234 /* amazing the little things you learn with a test
235 suite. Locks beyond this offset (as a 64 bit
236 number!) always generate the conflict error code,
237 unless the top bit is set */
238 if (!blocking_lock) {
239 fsp->last_lock_failure = *lock;
241 return NT_STATUS_FILE_LOCK_CONFLICT;
244 if (procid_equal(&lock->context.pid, &fsp->last_lock_failure.context.pid) &&
245 lock->context.tid == fsp->last_lock_failure.context.tid &&
246 lock->fnum == fsp->last_lock_failure.fnum &&
247 lock->start == fsp->last_lock_failure.start) {
248 return NT_STATUS_FILE_LOCK_CONFLICT;
251 if (!blocking_lock) {
252 fsp->last_lock_failure = *lock;
254 return NT_STATUS_LOCK_NOT_GRANTED;
257 /****************************************************************************
258 Open up the brlock.tdb database.
259 ****************************************************************************/
261 void brl_init(bool read_only)
266 brlock_db = db_open(NULL, lock_path("brlock.tdb"), 0,
269 |(read_only?0x0:TDB_CLEAR_IF_FIRST),
270 read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644 );
272 DEBUG(0,("Failed to open byte range locking database %s\n",
273 lock_path("brlock.tdb")));
278 /****************************************************************************
279 Close down the brlock.tdb database.
280 ****************************************************************************/
282 void brl_shutdown(void)
284 TALLOC_FREE(brlock_db);
288 /****************************************************************************
289 Compare two locks for sorting.
290 ****************************************************************************/
292 static int lock_compare(const struct lock_struct *lck1,
293 const struct lock_struct *lck2)
295 if (lck1->start != lck2->start) {
296 return (lck1->start - lck2->start);
298 if (lck2->size != lck1->size) {
299 return ((int)lck1->size - (int)lck2->size);
305 /****************************************************************************
306 Lock a range of bytes - Windows lock semantics.
307 ****************************************************************************/
309 static NTSTATUS brl_lock_windows(struct byte_range_lock *br_lck,
310 struct lock_struct *plock, bool blocking_lock)
313 files_struct *fsp = br_lck->fsp;
314 struct lock_struct *locks = br_lck->lock_data;
316 for (i=0; i < br_lck->num_locks; i++) {
317 /* Do any Windows or POSIX locks conflict ? */
318 if (brl_conflict(&locks[i], plock)) {
319 /* Remember who blocked us. */
320 plock->context.smbpid = locks[i].context.smbpid;
321 return brl_lock_failed(fsp,plock,blocking_lock);
324 if (plock->start == 0 && plock->size == 0 &&
325 locks[i].size == 0) {
331 /* We can get the Windows lock, now see if it needs to
332 be mapped into a lower level POSIX one, and if so can
335 if (!IS_PENDING_LOCK(plock->lock_type) && lp_posix_locking(fsp->conn->params)) {
337 if (!set_posix_lock_windows_flavour(fsp,
346 /* We don't know who blocked us. */
347 plock->context.smbpid = 0xFFFFFFFF;
349 if (errno_ret == EACCES || errno_ret == EAGAIN) {
350 return NT_STATUS_FILE_LOCK_CONFLICT;
352 return map_nt_error_from_unix(errno);
357 /* no conflicts - add it to the list of locks */
358 locks = (struct lock_struct *)SMB_REALLOC(locks, (br_lck->num_locks + 1) * sizeof(*locks));
360 return NT_STATUS_NO_MEMORY;
363 memcpy(&locks[br_lck->num_locks], plock, sizeof(struct lock_struct));
364 br_lck->num_locks += 1;
365 br_lck->lock_data = locks;
366 br_lck->modified = True;
371 /****************************************************************************
372 Cope with POSIX range splits and merges.
373 ****************************************************************************/
375 static unsigned int brlock_posix_split_merge(struct lock_struct *lck_arr, /* Output array. */
376 const struct lock_struct *ex, /* existing lock. */
377 const struct lock_struct *plock, /* proposed lock. */
378 bool *lock_was_added)
380 bool lock_types_differ = (ex->lock_type != plock->lock_type);
382 /* We can't merge non-conflicting locks on different context - ignore fnum. */
384 if (!brl_same_context(&ex->context, &plock->context)) {
386 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
390 /* We now know we have the same context. */
392 /* Did we overlap ? */
394 /*********************************************
405 **********************************************/
407 if ( (ex->start > (plock->start + plock->size)) ||
408 (plock->start > (ex->start + ex->size))) {
409 /* No overlap with this lock - copy existing. */
410 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
414 /*********************************************
415 +---------------------------+
417 +---------------------------+
418 +---------------------------+
419 | plock | -> replace with plock.
420 +---------------------------+
421 **********************************************/
423 if ( (ex->start >= plock->start) &&
424 (ex->start + ex->size <= plock->start + plock->size) ) {
425 memcpy(&lck_arr[0], plock, sizeof(struct lock_struct));
426 *lock_was_added = True;
430 /*********************************************
431 +-----------------------+
433 +-----------------------+
446 +---------------+-------+
447 | plock | ex | - different lock types.
448 +---------------+-------+
450 +-----------------------+
451 | ex | - same lock type.
452 +-----------------------+
453 **********************************************/
455 if ( (ex->start >= plock->start) &&
456 (ex->start <= plock->start + plock->size) &&
457 (ex->start + ex->size > plock->start + plock->size) ) {
459 *lock_was_added = True;
461 /* If the lock types are the same, we merge, if different, we
462 add the new lock before the old. */
464 if (lock_types_differ) {
466 memcpy(&lck_arr[0], plock, sizeof(struct lock_struct));
467 memcpy(&lck_arr[1], ex, sizeof(struct lock_struct));
468 /* Adjust existing start and size. */
469 lck_arr[1].start = plock->start + plock->size;
470 lck_arr[1].size = (ex->start + ex->size) - (plock->start + plock->size);
474 memcpy(&lck_arr[0], plock, sizeof(struct lock_struct));
475 /* Set new start and size. */
476 lck_arr[0].start = plock->start;
477 lck_arr[0].size = (ex->start + ex->size) - plock->start;
482 /*********************************************
483 +-----------------------+
485 +-----------------------+
497 +-------+---------------+
498 | ex | plock | - different lock types
499 +-------+---------------+
502 +-----------------------+
503 | ex | - same lock type.
504 +-----------------------+
506 **********************************************/
508 if ( (ex->start < plock->start) &&
509 (ex->start + ex->size >= plock->start) &&
510 (ex->start + ex->size <= plock->start + plock->size) ) {
512 *lock_was_added = True;
514 /* If the lock types are the same, we merge, if different, we
515 add the new lock after the old. */
517 if (lock_types_differ) {
518 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
519 memcpy(&lck_arr[1], plock, sizeof(struct lock_struct));
520 /* Adjust existing size. */
521 lck_arr[0].size = plock->start - ex->start;
525 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
526 /* Adjust existing size. */
527 lck_arr[0].size = (plock->start + plock->size) - ex->start;
532 /*********************************************
533 +---------------------------+
535 +---------------------------+
540 +-------+---------+---------+
541 | ex | plock | ex | - different lock types.
542 +-------+---------+---------+
544 +---------------------------+
545 | ex | - same lock type.
546 +---------------------------+
547 **********************************************/
549 if ( (ex->start < plock->start) && (ex->start + ex->size > plock->start + plock->size) ) {
550 *lock_was_added = True;
552 if (lock_types_differ) {
554 /* We have to split ex into two locks here. */
556 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
557 memcpy(&lck_arr[1], plock, sizeof(struct lock_struct));
558 memcpy(&lck_arr[2], ex, sizeof(struct lock_struct));
560 /* Adjust first existing size. */
561 lck_arr[0].size = plock->start - ex->start;
563 /* Adjust second existing start and size. */
564 lck_arr[2].start = plock->start + plock->size;
565 lck_arr[2].size = (ex->start + ex->size) - (plock->start + plock->size);
568 /* Just eat plock. */
569 memcpy(&lck_arr[0], ex, sizeof(struct lock_struct));
574 /* Never get here. */
575 smb_panic("brlock_posix_split_merge");
578 /* Keep some compilers happy. */
582 /****************************************************************************
583 Lock a range of bytes - POSIX lock semantics.
584 We must cope with range splits and merges.
585 ****************************************************************************/
587 static NTSTATUS brl_lock_posix(struct messaging_context *msg_ctx,
588 struct byte_range_lock *br_lck,
589 struct lock_struct *plock)
591 unsigned int i, count;
592 struct lock_struct *locks = br_lck->lock_data;
593 struct lock_struct *tp;
594 bool lock_was_added = False;
595 bool signal_pending_read = False;
597 /* No zero-zero locks for POSIX. */
598 if (plock->start == 0 && plock->size == 0) {
599 return NT_STATUS_INVALID_PARAMETER;
602 /* Don't allow 64-bit lock wrap. */
603 if (plock->start + plock->size < plock->start ||
604 plock->start + plock->size < plock->size) {
605 return NT_STATUS_INVALID_PARAMETER;
608 /* The worst case scenario here is we have to split an
609 existing POSIX lock range into two, and add our lock,
610 so we need at most 2 more entries. */
612 tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 2));
614 return NT_STATUS_NO_MEMORY;
618 for (i=0; i < br_lck->num_locks; i++) {
619 struct lock_struct *curr_lock = &locks[i];
621 /* If we have a pending read lock, a lock downgrade should
622 trigger a lock re-evaluation. */
623 if (curr_lock->lock_type == PENDING_READ_LOCK &&
624 brl_pending_overlap(plock, curr_lock)) {
625 signal_pending_read = True;
628 if (curr_lock->lock_flav == WINDOWS_LOCK) {
629 /* Do any Windows flavour locks conflict ? */
630 if (brl_conflict(curr_lock, plock)) {
631 /* No games with error messages. */
633 /* Remember who blocked us. */
634 plock->context.smbpid = curr_lock->context.smbpid;
635 return NT_STATUS_FILE_LOCK_CONFLICT;
637 /* Just copy the Windows lock into the new array. */
638 memcpy(&tp[count], curr_lock, sizeof(struct lock_struct));
641 /* POSIX conflict semantics are different. */
642 if (brl_conflict_posix(curr_lock, plock)) {
643 /* Can't block ourselves with POSIX locks. */
644 /* No games with error messages. */
646 /* Remember who blocked us. */
647 plock->context.smbpid = curr_lock->context.smbpid;
648 return NT_STATUS_FILE_LOCK_CONFLICT;
651 /* Work out overlaps. */
652 count += brlock_posix_split_merge(&tp[count], curr_lock, plock, &lock_was_added);
656 if (!lock_was_added) {
657 memcpy(&tp[count], plock, sizeof(struct lock_struct));
661 /* We can get the POSIX lock, now see if it needs to
662 be mapped into a lower level POSIX one, and if so can
665 if (!IS_PENDING_LOCK(plock->lock_type) && lp_posix_locking(br_lck->fsp->conn->params)) {
668 /* The lower layer just needs to attempt to
669 get the system POSIX lock. We've weeded out
670 any conflicts above. */
672 if (!set_posix_lock_posix_flavour(br_lck->fsp,
678 /* We don't know who blocked us. */
679 plock->context.smbpid = 0xFFFFFFFF;
681 if (errno_ret == EACCES || errno_ret == EAGAIN) {
683 return NT_STATUS_FILE_LOCK_CONFLICT;
686 return map_nt_error_from_unix(errno);
691 /* Realloc so we don't leak entries per lock call. */
692 tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
694 return NT_STATUS_NO_MEMORY;
696 br_lck->num_locks = count;
697 SAFE_FREE(br_lck->lock_data);
698 br_lck->lock_data = tp;
700 br_lck->modified = True;
702 /* A successful downgrade from write to read lock can trigger a lock
703 re-evalutation where waiting readers can now proceed. */
705 if (signal_pending_read) {
706 /* Send unlock messages to any pending read waiters that overlap. */
707 for (i=0; i < br_lck->num_locks; i++) {
708 struct lock_struct *pend_lock = &locks[i];
710 /* Ignore non-pending locks. */
711 if (!IS_PENDING_LOCK(pend_lock->lock_type)) {
715 if (pend_lock->lock_type == PENDING_READ_LOCK &&
716 brl_pending_overlap(plock, pend_lock)) {
717 DEBUG(10,("brl_lock_posix: sending unlock message to pid %s\n",
718 procid_str_static(&pend_lock->context.pid )));
720 messaging_send(msg_ctx, pend_lock->context.pid,
721 MSG_SMB_UNLOCK, &data_blob_null);
729 /****************************************************************************
730 Lock a range of bytes.
731 ****************************************************************************/
733 NTSTATUS brl_lock(struct messaging_context *msg_ctx,
734 struct byte_range_lock *br_lck,
736 struct server_id pid,
739 enum brl_type lock_type,
740 enum brl_flavour lock_flav,
745 struct lock_struct lock;
748 if (start == 0 && size == 0) {
749 DEBUG(0,("client sent 0/0 lock - please report this\n"));
753 lock.context.smbpid = smbpid;
754 lock.context.pid = pid;
755 lock.context.tid = br_lck->fsp->conn->cnum;
758 lock.fnum = br_lck->fsp->fnum;
759 lock.lock_type = lock_type;
760 lock.lock_flav = lock_flav;
762 if (lock_flav == WINDOWS_LOCK) {
763 ret = brl_lock_windows(br_lck, &lock, blocking_lock);
765 ret = brl_lock_posix(msg_ctx, br_lck, &lock);
769 /* sort the lock list */
770 qsort(br_lck->lock_data, (size_t)br_lck->num_locks, sizeof(lock), lock_compare);
773 /* If we're returning an error, return who blocked us. */
774 if (!NT_STATUS_IS_OK(ret) && psmbpid) {
775 *psmbpid = lock.context.smbpid;
780 /****************************************************************************
781 Unlock a range of bytes - Windows semantics.
782 ****************************************************************************/
784 static bool brl_unlock_windows(struct messaging_context *msg_ctx,
785 struct byte_range_lock *br_lck,
786 const struct lock_struct *plock)
789 struct lock_struct *locks = br_lck->lock_data;
790 enum brl_type deleted_lock_type = READ_LOCK; /* shut the compiler up.... */
793 /* Delete write locks by preference... The lock list
794 is sorted in the zero zero case. */
796 for (i = 0; i < br_lck->num_locks; i++) {
797 struct lock_struct *lock = &locks[i];
799 if (lock->lock_type == WRITE_LOCK &&
800 brl_same_context(&lock->context, &plock->context) &&
801 lock->fnum == plock->fnum &&
802 lock->lock_flav == WINDOWS_LOCK &&
803 lock->start == plock->start &&
804 lock->size == plock->size) {
806 /* found it - delete it */
807 deleted_lock_type = lock->lock_type;
812 if (i != br_lck->num_locks) {
813 /* We found it - don't search again. */
814 goto unlock_continue;
818 for (i = 0; i < br_lck->num_locks; i++) {
819 struct lock_struct *lock = &locks[i];
821 /* Only remove our own locks that match in start, size, and flavour. */
822 if (brl_same_context(&lock->context, &plock->context) &&
823 lock->fnum == plock->fnum &&
824 lock->lock_flav == WINDOWS_LOCK &&
825 lock->start == plock->start &&
826 lock->size == plock->size ) {
827 deleted_lock_type = lock->lock_type;
832 if (i == br_lck->num_locks) {
833 /* we didn't find it */
841 /* Actually delete the lock. */
842 if (i < br_lck->num_locks - 1) {
843 memmove(&locks[i], &locks[i+1],
844 sizeof(*locks)*((br_lck->num_locks-1) - i));
847 br_lck->num_locks -= 1;
848 br_lck->modified = True;
850 /* Unlock the underlying POSIX regions. */
851 if(lp_posix_locking(br_lck->fsp->conn->params)) {
852 release_posix_lock_windows_flavour(br_lck->fsp,
861 /* Send unlock messages to any pending waiters that overlap. */
862 for (j=0; j < br_lck->num_locks; j++) {
863 struct lock_struct *pend_lock = &locks[j];
865 /* Ignore non-pending locks. */
866 if (!IS_PENDING_LOCK(pend_lock->lock_type)) {
870 /* We could send specific lock info here... */
871 if (brl_pending_overlap(plock, pend_lock)) {
872 DEBUG(10,("brl_unlock: sending unlock message to pid %s\n",
873 procid_str_static(&pend_lock->context.pid )));
875 messaging_send(msg_ctx, pend_lock->context.pid,
876 MSG_SMB_UNLOCK, &data_blob_null);
883 /****************************************************************************
884 Unlock a range of bytes - POSIX semantics.
885 ****************************************************************************/
887 static bool brl_unlock_posix(struct messaging_context *msg_ctx,
888 struct byte_range_lock *br_lck,
889 const struct lock_struct *plock)
891 unsigned int i, j, count;
892 struct lock_struct *tp;
893 struct lock_struct *locks = br_lck->lock_data;
894 bool overlap_found = False;
896 /* No zero-zero locks for POSIX. */
897 if (plock->start == 0 && plock->size == 0) {
901 /* Don't allow 64-bit lock wrap. */
902 if (plock->start + plock->size < plock->start ||
903 plock->start + plock->size < plock->size) {
904 DEBUG(10,("brl_unlock_posix: lock wrap\n"));
908 /* The worst case scenario here is we have to split an
909 existing POSIX lock range into two, so we need at most
912 tp = SMB_MALLOC_ARRAY(struct lock_struct, (br_lck->num_locks + 1));
914 DEBUG(10,("brl_unlock_posix: malloc fail\n"));
919 for (i = 0; i < br_lck->num_locks; i++) {
920 struct lock_struct *lock = &locks[i];
921 struct lock_struct tmp_lock[3];
922 bool lock_was_added = False;
923 unsigned int tmp_count;
925 /* Only remove our own locks - ignore fnum. */
926 if (IS_PENDING_LOCK(lock->lock_type) ||
927 !brl_same_context(&lock->context, &plock->context)) {
928 memcpy(&tp[count], lock, sizeof(struct lock_struct));
933 /* Work out overlaps. */
934 tmp_count = brlock_posix_split_merge(&tmp_lock[0], &locks[i], plock, &lock_was_added);
936 if (tmp_count == 1) {
937 /* Ether the locks didn't overlap, or the unlock completely
938 overlapped this lock. If it didn't overlap, then there's
939 no change in the locks. */
940 if (tmp_lock[0].lock_type != UNLOCK_LOCK) {
941 SMB_ASSERT(tmp_lock[0].lock_type == locks[i].lock_type);
942 /* No change in this lock. */
943 memcpy(&tp[count], &tmp_lock[0], sizeof(struct lock_struct));
946 SMB_ASSERT(tmp_lock[0].lock_type == UNLOCK_LOCK);
947 overlap_found = True;
950 } else if (tmp_count == 2) {
951 /* The unlock overlapped an existing lock. Copy the truncated
952 lock into the lock array. */
953 if (tmp_lock[0].lock_type != UNLOCK_LOCK) {
954 SMB_ASSERT(tmp_lock[0].lock_type == locks[i].lock_type);
955 SMB_ASSERT(tmp_lock[1].lock_type == UNLOCK_LOCK);
956 memcpy(&tp[count], &tmp_lock[0], sizeof(struct lock_struct));
957 if (tmp_lock[0].size != locks[i].size) {
958 overlap_found = True;
961 SMB_ASSERT(tmp_lock[0].lock_type == UNLOCK_LOCK);
962 SMB_ASSERT(tmp_lock[1].lock_type == locks[i].lock_type);
963 memcpy(&tp[count], &tmp_lock[1], sizeof(struct lock_struct));
964 if (tmp_lock[1].start != locks[i].start) {
965 overlap_found = True;
971 /* tmp_count == 3 - (we split a lock range in two). */
972 SMB_ASSERT(tmp_lock[0].lock_type == locks[i].lock_type);
973 SMB_ASSERT(tmp_lock[1].lock_type == UNLOCK_LOCK);
974 SMB_ASSERT(tmp_lock[2].lock_type == locks[i].lock_type);
976 memcpy(&tp[count], &tmp_lock[0], sizeof(struct lock_struct));
978 memcpy(&tp[count], &tmp_lock[2], sizeof(struct lock_struct));
980 overlap_found = True;
981 /* Optimisation... */
982 /* We know we're finished here as we can't overlap any
983 more POSIX locks. Copy the rest of the lock array. */
984 if (i < br_lck->num_locks - 1) {
985 memcpy(&tp[count], &locks[i+1],
986 sizeof(*locks)*((br_lck->num_locks-1) - i));
987 count += ((br_lck->num_locks-1) - i);
993 if (!overlap_found) {
994 /* Just ignore - no change. */
996 DEBUG(10,("brl_unlock_posix: No overlap - unlocked.\n"));
1000 /* Unlock any POSIX regions. */
1001 if(lp_posix_locking(br_lck->fsp->conn->params)) {
1002 release_posix_lock_posix_flavour(br_lck->fsp,
1010 /* Realloc so we don't leak entries per unlock call. */
1012 tp = (struct lock_struct *)SMB_REALLOC(tp, count * sizeof(*locks));
1014 DEBUG(10,("brl_unlock_posix: realloc fail\n"));
1018 /* We deleted the last lock. */
1023 br_lck->num_locks = count;
1024 SAFE_FREE(br_lck->lock_data);
1026 br_lck->lock_data = tp;
1027 br_lck->modified = True;
1029 /* Send unlock messages to any pending waiters that overlap. */
1031 for (j=0; j < br_lck->num_locks; j++) {
1032 struct lock_struct *pend_lock = &locks[j];
1034 /* Ignore non-pending locks. */
1035 if (!IS_PENDING_LOCK(pend_lock->lock_type)) {
1039 /* We could send specific lock info here... */
1040 if (brl_pending_overlap(plock, pend_lock)) {
1041 DEBUG(10,("brl_unlock: sending unlock message to pid %s\n",
1042 procid_str_static(&pend_lock->context.pid )));
1044 messaging_send(msg_ctx, pend_lock->context.pid,
1045 MSG_SMB_UNLOCK, &data_blob_null);
1052 /****************************************************************************
1053 Unlock a range of bytes.
1054 ****************************************************************************/
1056 bool brl_unlock(struct messaging_context *msg_ctx,
1057 struct byte_range_lock *br_lck,
1059 struct server_id pid,
1062 enum brl_flavour lock_flav)
1064 struct lock_struct lock;
1066 lock.context.smbpid = smbpid;
1067 lock.context.pid = pid;
1068 lock.context.tid = br_lck->fsp->conn->cnum;
1071 lock.fnum = br_lck->fsp->fnum;
1072 lock.lock_type = UNLOCK_LOCK;
1073 lock.lock_flav = lock_flav;
1075 if (lock_flav == WINDOWS_LOCK) {
1076 return brl_unlock_windows(msg_ctx, br_lck, &lock);
1078 return brl_unlock_posix(msg_ctx, br_lck, &lock);
1082 /****************************************************************************
1083 Test if we could add a lock if we wanted to.
1084 Returns True if the region required is currently unlocked, False if locked.
1085 ****************************************************************************/
1087 bool brl_locktest(struct byte_range_lock *br_lck,
1089 struct server_id pid,
1092 enum brl_type lock_type,
1093 enum brl_flavour lock_flav)
1097 struct lock_struct lock;
1098 const struct lock_struct *locks = br_lck->lock_data;
1099 files_struct *fsp = br_lck->fsp;
1101 lock.context.smbpid = smbpid;
1102 lock.context.pid = pid;
1103 lock.context.tid = br_lck->fsp->conn->cnum;
1106 lock.fnum = fsp->fnum;
1107 lock.lock_type = lock_type;
1108 lock.lock_flav = lock_flav;
1110 /* Make sure existing locks don't conflict */
1111 for (i=0; i < br_lck->num_locks; i++) {
1113 * Our own locks don't conflict.
1115 if (brl_conflict_other(&locks[i], &lock)) {
1121 * There is no lock held by an SMB daemon, check to
1122 * see if there is a POSIX lock from a UNIX or NFS process.
1123 * This only conflicts with Windows locks, not POSIX locks.
1126 if(lp_posix_locking(fsp->conn->params) && (lock_flav == WINDOWS_LOCK)) {
1127 ret = is_posix_locked(fsp, &start, &size, &lock_type, WINDOWS_LOCK);
1129 DEBUG(10,("brl_locktest: posix start=%.0f len=%.0f %s for fnum %d file %s\n",
1130 (double)start, (double)size, ret ? "locked" : "unlocked",
1131 fsp->fnum, fsp->fsp_name ));
1133 /* We need to return the inverse of is_posix_locked. */
1137 /* no conflicts - we could have added it */
1141 /****************************************************************************
1142 Query for existing locks.
1143 ****************************************************************************/
1145 NTSTATUS brl_lockquery(struct byte_range_lock *br_lck,
1147 struct server_id pid,
1150 enum brl_type *plock_type,
1151 enum brl_flavour lock_flav)
1154 struct lock_struct lock;
1155 const struct lock_struct *locks = br_lck->lock_data;
1156 files_struct *fsp = br_lck->fsp;
1158 lock.context.smbpid = *psmbpid;
1159 lock.context.pid = pid;
1160 lock.context.tid = br_lck->fsp->conn->cnum;
1161 lock.start = *pstart;
1163 lock.fnum = fsp->fnum;
1164 lock.lock_type = *plock_type;
1165 lock.lock_flav = lock_flav;
1167 /* Make sure existing locks don't conflict */
1168 for (i=0; i < br_lck->num_locks; i++) {
1169 const struct lock_struct *exlock = &locks[i];
1170 bool conflict = False;
1172 if (exlock->lock_flav == WINDOWS_LOCK) {
1173 conflict = brl_conflict(exlock, &lock);
1175 conflict = brl_conflict_posix(exlock, &lock);
1179 *psmbpid = exlock->context.smbpid;
1180 *pstart = exlock->start;
1181 *psize = exlock->size;
1182 *plock_type = exlock->lock_type;
1183 return NT_STATUS_LOCK_NOT_GRANTED;
1188 * There is no lock held by an SMB daemon, check to
1189 * see if there is a POSIX lock from a UNIX or NFS process.
1192 if(lp_posix_locking(fsp->conn->params)) {
1193 bool ret = is_posix_locked(fsp, pstart, psize, plock_type, POSIX_LOCK);
1195 DEBUG(10,("brl_lockquery: posix start=%.0f len=%.0f %s for fnum %d file %s\n",
1196 (double)*pstart, (double)*psize, ret ? "locked" : "unlocked",
1197 fsp->fnum, fsp->fsp_name ));
1200 /* Hmmm. No clue what to set smbpid to - use -1. */
1202 return NT_STATUS_LOCK_NOT_GRANTED;
1206 return NT_STATUS_OK;
1209 /****************************************************************************
1210 Remove a particular pending lock.
1211 ****************************************************************************/
1213 bool brl_lock_cancel(struct byte_range_lock *br_lck,
1215 struct server_id pid,
1218 enum brl_flavour lock_flav)
1221 struct lock_struct *locks = br_lck->lock_data;
1222 struct lock_context context;
1224 context.smbpid = smbpid;
1226 context.tid = br_lck->fsp->conn->cnum;
1228 for (i = 0; i < br_lck->num_locks; i++) {
1229 struct lock_struct *lock = &locks[i];
1231 /* For pending locks we *always* care about the fnum. */
1232 if (brl_same_context(&lock->context, &context) &&
1233 lock->fnum == br_lck->fsp->fnum &&
1234 IS_PENDING_LOCK(lock->lock_type) &&
1235 lock->lock_flav == lock_flav &&
1236 lock->start == start &&
1237 lock->size == size) {
1242 if (i == br_lck->num_locks) {
1243 /* Didn't find it. */
1247 if (i < br_lck->num_locks - 1) {
1248 /* Found this particular pending lock - delete it */
1249 memmove(&locks[i], &locks[i+1],
1250 sizeof(*locks)*((br_lck->num_locks-1) - i));
1253 br_lck->num_locks -= 1;
1254 br_lck->modified = True;
1258 /****************************************************************************
1259 Remove any locks associated with a open file.
1260 We return True if this process owns any other Windows locks on this
1261 fd and so we should not immediately close the fd.
1262 ****************************************************************************/
1264 void brl_close_fnum(struct messaging_context *msg_ctx,
1265 struct byte_range_lock *br_lck)
1267 files_struct *fsp = br_lck->fsp;
1268 uint16 tid = fsp->conn->cnum;
1269 int fnum = fsp->fnum;
1270 unsigned int i, j, dcount=0;
1271 int num_deleted_windows_locks = 0;
1272 struct lock_struct *locks = br_lck->lock_data;
1273 struct server_id pid = procid_self();
1274 bool unlock_individually = False;
1276 if(lp_posix_locking(fsp->conn->params)) {
1278 /* Check if there are any Windows locks associated with this dev/ino
1279 pair that are not this fnum. If so we need to call unlock on each
1280 one in order to release the system POSIX locks correctly. */
1282 for (i=0; i < br_lck->num_locks; i++) {
1283 struct lock_struct *lock = &locks[i];
1285 if (!procid_equal(&lock->context.pid, &pid)) {
1289 if (lock->lock_type != READ_LOCK && lock->lock_type != WRITE_LOCK) {
1290 continue; /* Ignore pending. */
1293 if (lock->context.tid != tid || lock->fnum != fnum) {
1294 unlock_individually = True;
1299 if (unlock_individually) {
1300 struct lock_struct *locks_copy;
1301 unsigned int num_locks_copy;
1303 /* Copy the current lock array. */
1304 if (br_lck->num_locks) {
1305 locks_copy = (struct lock_struct *)TALLOC_MEMDUP(br_lck, locks, br_lck->num_locks * sizeof(struct lock_struct));
1307 smb_panic("brl_close_fnum: talloc failed");
1313 num_locks_copy = br_lck->num_locks;
1315 for (i=0; i < num_locks_copy; i++) {
1316 struct lock_struct *lock = &locks_copy[i];
1318 if (lock->context.tid == tid && procid_equal(&lock->context.pid, &pid) &&
1319 (lock->fnum == fnum)) {
1322 lock->context.smbpid,
1333 /* We can bulk delete - any POSIX locks will be removed when the fd closes. */
1335 /* Remove any existing locks for this fnum (or any fnum if they're POSIX). */
1337 for (i=0; i < br_lck->num_locks; i++) {
1338 struct lock_struct *lock = &locks[i];
1339 bool del_this_lock = False;
1341 if (lock->context.tid == tid && procid_equal(&lock->context.pid, &pid)) {
1342 if ((lock->lock_flav == WINDOWS_LOCK) && (lock->fnum == fnum)) {
1343 del_this_lock = True;
1344 num_deleted_windows_locks++;
1345 } else if (lock->lock_flav == POSIX_LOCK) {
1346 del_this_lock = True;
1350 if (del_this_lock) {
1351 /* Send unlock messages to any pending waiters that overlap. */
1352 for (j=0; j < br_lck->num_locks; j++) {
1353 struct lock_struct *pend_lock = &locks[j];
1355 /* Ignore our own or non-pending locks. */
1356 if (!IS_PENDING_LOCK(pend_lock->lock_type)) {
1360 /* Optimisation - don't send to this fnum as we're
1362 if (pend_lock->context.tid == tid &&
1363 procid_equal(&pend_lock->context.pid, &pid) &&
1364 pend_lock->fnum == fnum) {
1368 /* We could send specific lock info here... */
1369 if (brl_pending_overlap(lock, pend_lock)) {
1370 messaging_send(msg_ctx, pend_lock->context.pid,
1371 MSG_SMB_UNLOCK, &data_blob_null);
1375 /* found it - delete it */
1376 if (br_lck->num_locks > 1 && i < br_lck->num_locks - 1) {
1377 memmove(&locks[i], &locks[i+1],
1378 sizeof(*locks)*((br_lck->num_locks-1) - i));
1380 br_lck->num_locks--;
1381 br_lck->modified = True;
1387 if(lp_posix_locking(fsp->conn->params) && num_deleted_windows_locks) {
1388 /* Reduce the Windows lock POSIX reference count on this dev/ino pair. */
1389 reduce_windows_lock_ref_count(fsp, num_deleted_windows_locks);
1393 /****************************************************************************
1394 Ensure this set of lock entries is valid.
1395 ****************************************************************************/
1397 static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks)
1400 unsigned int num_valid_entries = 0;
1401 struct lock_struct *locks = *pplocks;
1403 for (i = 0; i < *pnum_entries; i++) {
1404 struct lock_struct *lock_data = &locks[i];
1405 if (!process_exists(lock_data->context.pid)) {
1406 /* This process no longer exists - mark this
1407 entry as invalid by zeroing it. */
1408 ZERO_STRUCTP(lock_data);
1410 num_valid_entries++;
1414 if (num_valid_entries != *pnum_entries) {
1415 struct lock_struct *new_lock_data = NULL;
1417 if (num_valid_entries) {
1418 new_lock_data = SMB_MALLOC_ARRAY(struct lock_struct, num_valid_entries);
1419 if (!new_lock_data) {
1420 DEBUG(3, ("malloc fail\n"));
1424 num_valid_entries = 0;
1425 for (i = 0; i < *pnum_entries; i++) {
1426 struct lock_struct *lock_data = &locks[i];
1427 if (lock_data->context.smbpid &&
1428 lock_data->context.tid) {
1429 /* Valid (nonzero) entry - copy it. */
1430 memcpy(&new_lock_data[num_valid_entries],
1431 lock_data, sizeof(struct lock_struct));
1432 num_valid_entries++;
1437 SAFE_FREE(*pplocks);
1438 *pplocks = new_lock_data;
1439 *pnum_entries = num_valid_entries;
1445 struct brl_forall_cb {
1446 void (*fn)(struct file_id id, struct server_id pid,
1447 enum brl_type lock_type,
1448 enum brl_flavour lock_flav,
1449 br_off start, br_off size,
1450 void *private_data);
1454 /****************************************************************************
1455 Traverse the whole database with this function, calling traverse_callback
1457 ****************************************************************************/
1459 static int traverse_fn(struct db_record *rec, void *state)
1461 struct brl_forall_cb *cb = (struct brl_forall_cb *)state;
1462 struct lock_struct *locks;
1463 struct file_id *key;
1465 unsigned int num_locks = 0;
1466 unsigned int orig_num_locks = 0;
1468 /* In a traverse function we must make a copy of
1469 dbuf before modifying it. */
1471 locks = (struct lock_struct *)memdup(rec->value.dptr,
1474 return -1; /* Terminate traversal. */
1477 key = (struct file_id *)rec->key.dptr;
1478 orig_num_locks = num_locks = rec->value.dsize/sizeof(*locks);
1480 /* Ensure the lock db is clean of entries from invalid processes. */
1482 if (!validate_lock_entries(&num_locks, &locks)) {
1484 return -1; /* Terminate traversal */
1487 if (orig_num_locks != num_locks) {
1490 data.dptr = (uint8_t *)locks;
1491 data.dsize = num_locks*sizeof(struct lock_struct);
1492 rec->store(rec, data, TDB_REPLACE);
1494 rec->delete_rec(rec);
1498 for ( i=0; i<num_locks; i++) {
1500 locks[i].context.pid,
1512 /*******************************************************************
1513 Call the specified function on each lock in the database.
1514 ********************************************************************/
1516 int brl_forall(void (*fn)(struct file_id id, struct server_id pid,
1517 enum brl_type lock_type,
1518 enum brl_flavour lock_flav,
1519 br_off start, br_off size,
1520 void *private_data),
1523 struct brl_forall_cb cb;
1529 cb.private_data = private_data;
1530 return brlock_db->traverse(brlock_db, traverse_fn, &cb);
1533 /*******************************************************************
1534 Store a potentially modified set of byte range lock data back into
1537 ********************************************************************/
1539 static int byte_range_lock_destructor(struct byte_range_lock *br_lck)
1543 key.dptr = (uint8 *)&br_lck->key;
1544 key.dsize = sizeof(struct file_id);
1546 if (br_lck->read_only) {
1547 SMB_ASSERT(!br_lck->modified);
1550 if (!br_lck->modified) {
1554 if (br_lck->num_locks == 0) {
1555 /* No locks - delete this entry. */
1556 NTSTATUS status = br_lck->record->delete_rec(br_lck->record);
1557 if (!NT_STATUS_IS_OK(status)) {
1558 DEBUG(0, ("delete_rec returned %s\n",
1559 nt_errstr(status)));
1560 smb_panic("Could not delete byte range lock entry");
1566 data.dptr = (uint8 *)br_lck->lock_data;
1567 data.dsize = br_lck->num_locks * sizeof(struct lock_struct);
1569 status = br_lck->record->store(br_lck->record, data,
1571 if (!NT_STATUS_IS_OK(status)) {
1572 DEBUG(0, ("store returned %s\n", nt_errstr(status)));
1573 smb_panic("Could not store byte range mode entry");
1579 SAFE_FREE(br_lck->lock_data);
1580 TALLOC_FREE(br_lck->record);
1584 /*******************************************************************
1585 Fetch a set of byte range lock data from the database.
1586 Leave the record locked.
1587 TALLOC_FREE(brl) will release the lock in the destructor.
1588 ********************************************************************/
1590 static struct byte_range_lock *brl_get_locks_internal(TALLOC_CTX *mem_ctx,
1591 files_struct *fsp, bool read_only)
1594 struct byte_range_lock *br_lck = TALLOC_P(mem_ctx, struct byte_range_lock);
1596 if (br_lck == NULL) {
1601 br_lck->num_locks = 0;
1602 br_lck->modified = False;
1603 memset(&br_lck->key, '\0', sizeof(struct file_id));
1604 br_lck->key = fsp->file_id;
1606 key.dptr = (uint8 *)&br_lck->key;
1607 key.dsize = sizeof(struct file_id);
1609 if (!fsp->lockdb_clean) {
1610 /* We must be read/write to clean
1611 the dead entries. */
1616 if (brlock_db->fetch(brlock_db, br_lck, key, &data) == -1) {
1617 DEBUG(3, ("Could not fetch byte range lock record\n"));
1618 TALLOC_FREE(br_lck);
1621 br_lck->record = NULL;
1624 br_lck->record = brlock_db->fetch_locked(brlock_db, br_lck, key);
1626 if (br_lck->record == NULL) {
1627 DEBUG(3, ("Could not lock byte range lock entry\n"));
1628 TALLOC_FREE(br_lck);
1632 data = br_lck->record->value;
1635 br_lck->read_only = read_only;
1636 br_lck->lock_data = NULL;
1638 talloc_set_destructor(br_lck, byte_range_lock_destructor);
1640 br_lck->num_locks = data.dsize / sizeof(struct lock_struct);
1642 if (br_lck->num_locks != 0) {
1643 br_lck->lock_data = SMB_MALLOC_ARRAY(struct lock_struct,
1645 if (br_lck->lock_data == NULL) {
1646 DEBUG(0, ("malloc failed\n"));
1647 TALLOC_FREE(br_lck);
1651 memcpy(br_lck->lock_data, data.dptr, data.dsize);
1654 if (!fsp->lockdb_clean) {
1655 int orig_num_locks = br_lck->num_locks;
1657 /* This is the first time we've accessed this. */
1658 /* Go through and ensure all entries exist - remove any that don't. */
1659 /* Makes the lockdb self cleaning at low cost. */
1661 if (!validate_lock_entries(&br_lck->num_locks,
1662 &br_lck->lock_data)) {
1663 SAFE_FREE(br_lck->lock_data);
1664 TALLOC_FREE(br_lck);
1668 /* Ensure invalid locks are cleaned up in the destructor. */
1669 if (orig_num_locks != br_lck->num_locks) {
1670 br_lck->modified = True;
1673 /* Mark the lockdb as "clean" as seen from this open file. */
1674 fsp->lockdb_clean = True;
1677 if (DEBUGLEVEL >= 10) {
1679 struct lock_struct *locks = br_lck->lock_data;
1680 DEBUG(10,("brl_get_locks_internal: %u current locks on file_id %s\n",
1682 file_id_string_tos(&fsp->file_id)));
1683 for( i = 0; i < br_lck->num_locks; i++) {
1684 print_lock_struct(i, &locks[i]);
1690 struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx,
1693 return brl_get_locks_internal(mem_ctx, fsp, False);
1696 struct byte_range_lock *brl_get_locks_readonly(TALLOC_CTX *mem_ctx,
1699 return brl_get_locks_internal(mem_ctx, fsp, True);
1702 struct brl_revalidate_state {
1705 struct server_id *pids;
1709 * Collect PIDs of all processes with pending entries
1712 static void brl_revalidate_collect(struct file_id id, struct server_id pid,
1713 enum brl_type lock_type,
1714 enum brl_flavour lock_flav,
1715 br_off start, br_off size,
1718 struct brl_revalidate_state *state =
1719 (struct brl_revalidate_state *)private_data;
1721 if (!IS_PENDING_LOCK(lock_type)) {
1725 add_to_large_array(state, sizeof(pid), (void *)&pid,
1726 &state->pids, &state->num_pids,
1727 &state->array_size);
1731 * qsort callback to sort the processes
1734 static int compare_procids(const void *p1, const void *p2)
1736 const struct server_id *i1 = (struct server_id *)p1;
1737 const struct server_id *i2 = (struct server_id *)p2;
1739 if (i1->pid < i2->pid) return -1;
1740 if (i2->pid > i2->pid) return 1;
1745 * Send a MSG_SMB_UNLOCK message to all processes with pending byte range
1746 * locks so that they retry. Mainly used in the cluster code after a node has
1749 * Done in two steps to avoid double-sends: First we collect all entries in an
1750 * array, then qsort that array and only send to non-dupes.
1753 static void brl_revalidate(struct messaging_context *msg_ctx,
1756 struct server_id server_id,
1759 struct brl_revalidate_state *state;
1761 struct server_id last_pid;
1763 if (!(state = TALLOC_ZERO_P(NULL, struct brl_revalidate_state))) {
1764 DEBUG(0, ("talloc failed\n"));
1768 brl_forall(brl_revalidate_collect, state);
1770 if (state->array_size == -1) {
1771 DEBUG(0, ("talloc failed\n"));
1775 if (state->num_pids == 0) {
1779 qsort(state->pids, state->num_pids, sizeof(state->pids[0]),
1782 ZERO_STRUCT(last_pid);
1784 for (i=0; i<state->num_pids; i++) {
1785 if (procid_equal(&last_pid, &state->pids[i])) {
1787 * We've seen that one already
1792 messaging_send(msg_ctx, state->pids[i], MSG_SMB_UNLOCK,
1794 last_pid = state->pids[i];
1802 void brl_register_msgs(struct messaging_context *msg_ctx)
1804 messaging_register(msg_ctx, NULL, MSG_SMB_BRL_VALIDATE,