r10656: BIG merge from trunk. Features not copied over
[samba.git] / source3 / smbd / oplock.c
1 /* 
2    Unix SMB/CIFS implementation.
3    oplock processing
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Jeremy Allison 1998 - 2001
6    Copyright (C) Volker Lendecke 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 /* Current number of oplocks we have outstanding. */
26 static int32 exclusive_oplocks_open = 0;
27 static int32 level_II_oplocks_open = 0;
28 BOOL global_client_failed_oplock_break = False;
29
30 extern struct timeval smb_last_time;
31 extern uint32 global_client_caps;
32 extern int smb_read_error;
33
34 static struct kernel_oplocks *koplocks;
35
36 /****************************************************************************
37  Get the number of current exclusive oplocks.
38 ****************************************************************************/
39
40 int32 get_number_of_exclusive_open_oplocks(void)
41 {
42   return exclusive_oplocks_open;
43 }
44
45 /****************************************************************************
46  Return True if an oplock message is pending.
47 ****************************************************************************/
48
49 BOOL oplock_message_waiting(fd_set *fds)
50 {
51         if (koplocks && koplocks->msg_waiting(fds))
52                 return True;
53
54         return False;
55 }
56
57 /****************************************************************************
58  Read an oplock break message from either the oplock UDP fd or the
59  kernel (if kernel oplocks are supported).
60
61  If timeout is zero then *fds contains the file descriptors that
62  are ready to be read and acted upon. If timeout is non-zero then
63  *fds contains the file descriptors to be selected on for read.
64  The timeout is in milliseconds
65
66 ****************************************************************************/
67
68 void process_kernel_oplocks(void)
69 {
70         fd_set fds;
71
72         FD_ZERO(&fds);
73         smb_read_error = 0;
74
75         /*
76          * We need to check for kernel oplocks before going into the select
77          * here, as the EINTR generated by the linux kernel oplock may have
78          * already been eaten. JRA.
79          */
80
81         if (!koplocks) {
82                 return;
83         }
84
85         while (koplocks->msg_waiting(&fds)) { 
86                 files_struct *fsp;
87                 struct kernel_oplock_message msg;
88
89                 fsp = koplocks->receive_message(&fds);
90
91                 if (fsp == NULL) {
92                         DEBUG(3, ("Kernel oplock message announced, but none "
93                                   "received\n"));
94                         return;
95                 }
96
97                 msg.dev = fsp->dev;
98                 msg.inode = fsp->inode;
99                 msg.file_id = fsp->file_id;
100                 message_send_pid(pid_to_procid(sys_getpid()),
101                                  MSG_SMB_KERNEL_BREAK,
102                                  &msg, sizeof(msg), True);
103         }
104 }
105
106 /****************************************************************************
107  Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
108  disabled (just sets flags). Returns True if oplock set.
109 ****************************************************************************/
110
111 BOOL set_file_oplock(files_struct *fsp, int oplock_type)
112 {
113         if (koplocks && !koplocks->set_oplock(fsp, oplock_type))
114                 return False;
115
116         fsp->oplock_type = oplock_type;
117         fsp->sent_oplock_break = NO_BREAK_SENT;
118         if (oplock_type == LEVEL_II_OPLOCK)
119                 level_II_oplocks_open++;
120         else
121                 exclusive_oplocks_open++;
122
123         DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \
124 tv_sec = %x, tv_usec = %x\n",
125                  fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id,
126                  (int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
127
128         return True;
129 }
130
131 /****************************************************************************
132  Attempt to release an oplock on a file. Decrements oplock count.
133 ****************************************************************************/
134
135 void release_file_oplock(files_struct *fsp)
136 {
137         if ((fsp->oplock_type != NO_OPLOCK) &&
138             (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
139             koplocks) {
140                 koplocks->release_oplock(fsp);
141         }
142
143         if (fsp->oplock_type == LEVEL_II_OPLOCK)
144                 level_II_oplocks_open--;
145         else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
146                 exclusive_oplocks_open--;
147
148         SMB_ASSERT(exclusive_oplocks_open>=0);
149         SMB_ASSERT(level_II_oplocks_open>=0);
150         
151         fsp->oplock_type = NO_OPLOCK;
152         fsp->sent_oplock_break = NO_BREAK_SENT;
153         
154         flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
155 }
156
157 /****************************************************************************
158  Attempt to downgrade an oplock on a file. Doesn't decrement oplock count.
159 ****************************************************************************/
160
161 static void downgrade_file_oplock(files_struct *fsp)
162 {
163         if (koplocks)
164                 koplocks->release_oplock(fsp);
165         fsp->oplock_type = LEVEL_II_OPLOCK;
166         exclusive_oplocks_open--;
167         level_II_oplocks_open++;
168         fsp->sent_oplock_break = NO_BREAK_SENT;
169 }
170
171 /****************************************************************************
172  Remove a file oplock. Copes with level II and exclusive.
173  Locks then unlocks the share mode lock. Client can decide to go directly
174  to none even if a "break-to-level II" was sent.
175 ****************************************************************************/
176
177 BOOL remove_oplock(files_struct *fsp)
178 {
179         SMB_DEV_T dev = fsp->dev;
180         SMB_INO_T inode = fsp->inode;
181         BOOL ret;
182         struct share_mode_lock *lck;
183
184         /* Remove the oplock flag from the sharemode. */
185         lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL);
186         if (lck == NULL) {
187                 DEBUG(0,("remove_oplock: failed to lock share entry for "
188                          "file %s\n", fsp->fsp_name ));
189                 return False;
190         }
191         ret = remove_share_oplock(lck, fsp);
192         if (!ret) {
193                 DEBUG(0,("remove_oplock: failed to remove share oplock for "
194                          "file %s fnum %d, dev = %x, inode = %.0f\n",
195                          fsp->fsp_name, fsp->fnum, (unsigned int)dev,
196                          (double)inode));
197         }
198         release_file_oplock(fsp);
199         talloc_free(lck);
200         return ret;
201 }
202
203 /*
204  * Deal with a reply when a break-to-level II was sent.
205  */
206 BOOL downgrade_oplock(files_struct *fsp)
207 {
208         SMB_DEV_T dev = fsp->dev;
209         SMB_INO_T inode = fsp->inode;
210         BOOL ret;
211         struct share_mode_lock *lck;
212
213         lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL);
214         if (lck == NULL) {
215                 DEBUG(0,("downgrade_oplock: failed to lock share entry for "
216                          "file %s\n", fsp->fsp_name ));
217                 return False;
218         }
219         ret = downgrade_share_oplock(lck, fsp);
220         if (!ret) {
221                 DEBUG(0,("downgrade_oplock: failed to downgrade share oplock "
222                          "for file %s fnum %d, dev = %x, inode = %.0f\n",
223                          fsp->fsp_name, fsp->fnum, (unsigned int)dev,
224                          (double)inode));
225         }
226                 
227         downgrade_file_oplock(fsp);
228         talloc_free(lck);
229         return ret;
230 }
231
232 /****************************************************************************
233  Setup the listening set of file descriptors for an oplock break
234  message either from the UDP socket or from the kernel. Returns the maximum
235  fd used.
236 ****************************************************************************/
237
238 int setup_oplock_select_set( fd_set *fds)
239 {
240         int maxfd = 0;
241
242         if (koplocks && koplocks->notification_fd != -1) {
243                 FD_SET(koplocks->notification_fd, fds);
244                 maxfd = MAX(maxfd, koplocks->notification_fd);
245         }
246
247         return maxfd;
248 }
249
250 /****************************************************************************
251  Set up an oplock break message.
252 ****************************************************************************/
253
254 static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
255                                    files_struct *fsp, uint8_t cmd)
256 {
257         char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
258
259         if (result == NULL) {
260                 DEBUG(0, ("talloc failed\n"));
261                 return NULL;
262         }
263
264         memset(result,'\0',smb_size);
265         set_message(result,8,0,True);
266         SCVAL(result,smb_com,SMBlockingX);
267         SSVAL(result,smb_tid,fsp->conn->cnum);
268         SSVAL(result,smb_pid,0xFFFF);
269         SSVAL(result,smb_uid,0);
270         SSVAL(result,smb_mid,0xFFFF);
271         SCVAL(result,smb_vwv0,0xFF);
272         SSVAL(result,smb_vwv2,fsp->fnum);
273         SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
274         SCVAL(result,smb_vwv3+1,cmd);
275         return result;
276 }
277
278 /****************************************************************************
279  Function to do the waiting before sending a local break.
280 ****************************************************************************/
281
282 static void wait_before_sending_break(void)
283 {
284         struct timeval cur_tv;
285         long wait_left = (long)lp_oplock_break_wait_time();
286
287         if (wait_left == 0)
288                 return;
289
290         GetTimeOfDay(&cur_tv);
291
292         wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) +
293                 ((cur_tv.tv_usec - smb_last_time.tv_usec)/1000);
294
295         if(wait_left > 0) {
296                 wait_left = MIN(wait_left, 1000);
297                 sys_usleep(wait_left * 1000);
298         }
299 }
300
301 /****************************************************************************
302  Ensure that we have a valid oplock.
303 ****************************************************************************/
304
305 static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id)
306 {
307         files_struct *fsp = NULL;
308
309         if( DEBUGLVL( 3 ) ) {
310                 dbgtext( "initial_break_processing: called for dev = %x, inode = %.0f file_id = %lu\n",
311                         (unsigned int)dev, (double)inode, file_id);
312                 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
313                         exclusive_oplocks_open, level_II_oplocks_open );
314         }
315
316         /*
317          * We need to search the file open table for the
318          * entry containing this dev and inode, and ensure
319          * we have an oplock on it.
320          */
321
322         fsp = file_find_dif(dev, inode, file_id);
323
324         if(fsp == NULL) {
325                 /* The file could have been closed in the meantime - return success. */
326                 if( DEBUGLVL( 3 ) ) {
327                         dbgtext( "initial_break_processing: cannot find open file with " );
328                         dbgtext( "dev = %x, inode = %.0f file_id = %lu", (unsigned int)dev,
329                                 (double)inode, file_id);
330                         dbgtext( "allowing break to succeed.\n" );
331                 }
332                 return NULL;
333         }
334
335         /* Ensure we have an oplock on the file */
336
337         /*
338          * There is a potential race condition in that an oplock could
339          * have been broken due to another udp request, and yet there are
340          * still oplock break messages being sent in the udp message
341          * queue for this file. So return true if we don't have an oplock,
342          * as we may have just freed it.
343          */
344
345         if(fsp->oplock_type == NO_OPLOCK) {
346                 if( DEBUGLVL( 3 ) ) {
347                         dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
348                         dbgtext( "(dev = %x, inode = %.0f, file_id = %lu) has no oplock.\n",
349                                 (unsigned int)dev, (double)inode, fsp->file_id );
350                         dbgtext( "Allowing break to succeed regardless.\n" );
351                 }
352                 return NULL;
353         }
354
355         return fsp;
356 }
357
358 static void oplock_timeout_handler(struct timed_event *te,
359                                    const struct timeval *now,
360                                    void *private_data)
361 {
362         files_struct *fsp = private_data;
363
364         DEBUG(0, ("Oplock break failed -- replying anyway\n"));
365         global_client_failed_oplock_break = True;
366         remove_oplock(fsp);
367         reply_to_oplock_break_requests(fsp);
368 }
369
370 static void process_oplock_break_message(int msg_type, struct process_id src,
371                                          void *buf, size_t len)
372 {
373         struct share_mode_entry *msg = buf;
374         files_struct *fsp;
375         char *break_msg;
376         BOOL break_to_level2 = False;
377         BOOL sign_state;
378
379         if (buf == NULL) {
380                 DEBUG(0, ("Got NULL buffer\n"));
381                 return;
382         }
383
384         if (len != sizeof(*msg)) {
385                 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
386                 return;
387         }
388
389         DEBUG(10, ("Got oplock break message from pid %d: %d/%d/%d\n",
390                    (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
391                    (int)msg->share_file_id));
392
393         fsp = initial_break_processing(msg->dev, msg->inode,
394                                        msg->share_file_id);
395
396         if (fsp == NULL) {
397                 /* We hit race here. Break messages are sent, and before we
398                  * get to process this message, we have closed the file. Reply
399                  * with 'ok, oplock broken' */
400                 DEBUG(3, ("Did not find fsp\n"));
401                 message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
402                                  msg, sizeof(*msg), True);
403                 return;
404         }
405
406         if (fsp->sent_oplock_break != NO_BREAK_SENT) {
407                 /* Remember we have to inform the requesting PID when the
408                  * client replies */
409                 msg->pid = src;
410                 ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg,
411                              &fsp->pending_break_messages,
412                              &fsp->num_pending_break_messages);
413                 return;
414         }
415
416         if (EXCLUSIVE_OPLOCK_TYPE(msg->op_type) &&
417             !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
418                 DEBUG(3, ("Already downgraded oplock on %.0f/%.0f: %s\n",
419                           (double)fsp->dev, (double)fsp->inode,
420                           fsp->fsp_name));
421                 message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
422                                  msg, sizeof(*msg), True);
423                 return;
424         }
425
426         if ((msg_type == MSG_SMB_BREAK_REQUEST) &&
427             (global_client_caps & CAP_LEVEL_II_OPLOCKS) && 
428             !koplocks && /* NOTE: we force levelII off for kernel oplocks -
429                           * this will change when it is supported */
430             lp_level2_oplocks(SNUM(fsp->conn))) {
431                 break_to_level2 = True;
432         }
433
434         break_msg = new_break_smb_message(NULL, fsp, break_to_level2 ?
435                                           OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
436         if (break_msg == NULL) {
437                 exit_server("Could not talloc break_msg\n");
438         }
439
440         /* Need to wait before sending a break message to a file of our own */
441         if (procid_to_pid(&src) == sys_getpid()) {
442                 wait_before_sending_break();
443         }
444
445         /* Save the server smb signing state. */
446         sign_state = srv_oplock_set_signing(False);
447
448         show_msg(break_msg);
449         if (!send_smb(smbd_server_fd(), break_msg)) {
450                 exit_server("oplock_break: send_smb failed.");
451         }
452
453         /* Restore the sign state to what it was. */
454         srv_oplock_set_signing(sign_state);
455
456         talloc_free(break_msg);
457
458         if (msg_type == MSG_SMB_BREAK_REQUEST) {
459                 fsp->sent_oplock_break = break_to_level2 ?
460                         LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
461         } else {
462                 /* Async level2 request, don't send a reply */
463                 fsp->sent_oplock_break = ASYNC_LEVEL_II_BREAK_SENT;
464         }
465         msg->pid = src;
466         ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg,
467                      &fsp->pending_break_messages,
468                      &fsp->num_pending_break_messages);
469
470         if (fsp->oplock_timeout != NULL) {
471                 DEBUG(0, ("Logic problem -- have an oplock event hanging "
472                           "around\n"));
473         }
474
475         fsp->oplock_timeout =
476                 add_timed_event(NULL,
477                                 timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
478                                 "oplock_timeout_handler",
479                                 oplock_timeout_handler, fsp);
480
481         if (fsp->oplock_timeout == NULL) {
482                 DEBUG(0, ("Could not add oplock timeout handler\n"));
483         }
484 }
485
486 static void process_kernel_oplock_break(int msg_type, struct process_id src,
487                                         void *buf, size_t len)
488 {
489         struct kernel_oplock_message *msg = buf;
490         files_struct *fsp;
491         char *break_msg;
492         BOOL sign_state;
493
494         if (buf == NULL) {
495                 DEBUG(0, ("Got NULL buffer\n"));
496                 return;
497         }
498
499         if (len != sizeof(*msg)) {
500                 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
501                 return;
502         }
503
504         DEBUG(10, ("Got kernel oplock break message from pid %d: %d/%d/%d\n",
505                    (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
506                    (int)msg->file_id));
507
508         fsp = initial_break_processing(msg->dev, msg->inode, msg->file_id);
509
510         if (fsp == NULL) {
511                 DEBUG(3, ("Got a kernel oplock break message for a file "
512                           "I don't know about\n"));
513                 return;
514         }
515
516         if (fsp->sent_oplock_break != NO_BREAK_SENT) {
517                 /* This is ok, kernel oplocks come in completely async */
518                 DEBUG(3, ("Got a kernel oplock request while waiting for a "
519                           "break reply\n"));
520                 return;
521         }
522
523         break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
524         if (break_msg == NULL) {
525                 exit_server("Could not talloc break_msg\n");
526         }
527
528         /* Save the server smb signing state. */
529         sign_state = srv_oplock_set_signing(False);
530
531         show_msg(break_msg);
532         if (!send_smb(smbd_server_fd(), break_msg)) {
533                 exit_server("oplock_break: send_smb failed.");
534         }
535
536         /* Restore the sign state to what it was. */
537         srv_oplock_set_signing(sign_state);
538
539         talloc_free(break_msg);
540
541         fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
542 }
543
544 void reply_to_oplock_break_requests(files_struct *fsp)
545 {
546         int i;
547
548         for (i=0; i<fsp->num_pending_break_messages; i++) {
549                 struct share_mode_entry *msg = &fsp->pending_break_messages[i];
550                 message_send_pid(msg->pid, MSG_SMB_BREAK_RESPONSE,
551                                  msg, sizeof(*msg), True);
552         }
553
554         SAFE_FREE(fsp->pending_break_messages);
555         fsp->num_pending_break_messages = 0;
556         if (fsp->oplock_timeout != NULL) {
557                 talloc_free(fsp->oplock_timeout);
558                 fsp->oplock_timeout = NULL;
559         }
560         return;
561 }
562
563 static void process_oplock_break_response(int msg_type, struct process_id src,
564                                           void *buf, size_t len)
565 {
566         struct share_mode_entry *msg = buf;
567
568         if (buf == NULL) {
569                 DEBUG(0, ("Got NULL buffer\n"));
570                 return;
571         }
572
573         if (len != sizeof(*msg)) {
574                 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
575                 return;
576         }
577
578         DEBUG(10, ("Got oplock break response from pid %d: %d/%d/%d mid %d\n",
579                    (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
580                    (int)msg->share_file_id, (int)msg->op_mid));
581
582         /* Here's the hack from open.c, store the mid in the 'port' field */
583         schedule_deferred_open_smb_message(msg->op_mid);
584 }
585
586 static void process_open_retry_message(int msg_type, struct process_id src,
587                                        void *buf, size_t len)
588 {
589         struct share_mode_entry *msg = buf;
590         
591         if (buf == NULL) {
592                 DEBUG(0, ("Got NULL buffer\n"));
593                 return;
594         }
595
596         if (len != sizeof(*msg)) {
597                 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
598                 return;
599         }
600
601         DEBUG(10, ("Got open retry msg from pid %d: %d/%d mid %d\n",
602                    (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
603                    (int)msg->op_mid));
604
605         schedule_deferred_open_smb_message(msg->op_mid);
606 }
607
608 /****************************************************************************
609  This function is called on any file modification or lock request. If a file
610  is level 2 oplocked then it must tell all other level 2 holders to break to
611  none.
612 ****************************************************************************/
613
614 void release_level_2_oplocks_on_change(files_struct *fsp)
615 {
616         int i;
617         struct share_mode_lock *lck;
618
619         /*
620          * If this file is level II oplocked then we need
621          * to grab the shared memory lock and inform all
622          * other files with a level II lock that they need
623          * to flush their read caches. We keep the lock over
624          * the shared memory area whilst doing this.
625          */
626
627         if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
628                 return;
629
630         lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL);
631         if (lck == NULL) {
632                 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
633                          "share mode entry for file %s.\n", fsp->fsp_name ));
634         }
635
636         DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n", 
637                   lck->num_share_modes ));
638
639         if (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
640                 /* See if someone else has already downgraded us, then we
641                    don't have to do anything */
642                 for (i=0; i<lck->num_share_modes; i++) {
643                         struct share_mode_entry *e = &lck->share_modes[i];
644                         if ((e->op_type == NO_OPLOCK) &&
645                             (e->share_file_id == fsp->file_id) &&
646                             (e->dev == fsp->dev) &&
647                             (e->inode == fsp->inode) &&
648                             (procid_is_me(&e->pid))) {
649                                 /* We're done */
650                                 fsp->oplock_type = NO_OPLOCK;
651                                 talloc_free(lck);
652                                 return;
653                         }
654                 }
655         }
656
657         for(i = 0; i < lck->num_share_modes; i++) {
658                 struct share_mode_entry *share_entry = &lck->share_modes[i];
659
660                 /*
661                  * As there could have been multiple writes waiting at the
662                  * lock_share_entry gate we may not be the first to
663                  * enter. Hence the state of the op_types in the share mode
664                  * entries may be partly NO_OPLOCK and partly LEVEL_II
665                  * oplock. It will do no harm to re-send break messages to
666                  * those smbd's that are still waiting their turn to remove
667                  * their LEVEL_II state, and also no harm to ignore existing
668                  * NO_OPLOCK states. JRA.
669                  */
670
671                 DEBUG(10,("release_level_2_oplocks_on_change: "
672                           "share_entry[%i]->op_type == %d\n",
673                           i, share_entry->op_type ));
674
675                 if ((share_entry->op_type == NO_OPLOCK) ||
676                     (share_entry->op_type == FAKE_LEVEL_II_OPLOCK)) {
677                         continue;
678                 }
679
680                 /* Paranoia .... */
681                 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
682                         DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
683                                  "share mode entry %d is an exlusive "
684                                  "oplock !\n", i ));
685                         talloc_free(lck);
686                         abort();
687                 }
688
689                 message_send_pid(share_entry->pid, MSG_SMB_ASYNC_LEVEL2_BREAK,
690                                  share_entry, sizeof(*share_entry), True);
691         }
692
693         remove_all_share_oplocks(lck, fsp);
694         talloc_free(lck);
695 }
696
697 /****************************************************************************
698  Setup oplocks for this process.
699 ****************************************************************************/
700
701 BOOL init_oplocks(void)
702 {
703         DEBUG(3,("open_oplock_ipc: opening loopback UDP socket.\n"));
704
705         message_register(MSG_SMB_BREAK_REQUEST,
706                          process_oplock_break_message);
707         message_register(MSG_SMB_ASYNC_LEVEL2_BREAK,
708                          process_oplock_break_message);
709         message_register(MSG_SMB_BREAK_RESPONSE,
710                          process_oplock_break_response);
711         message_register(MSG_SMB_KERNEL_BREAK,
712                          process_kernel_oplock_break);
713         message_register(MSG_SMB_OPEN_RETRY,
714                          process_open_retry_message);
715
716         if (lp_kernel_oplocks()) {
717 #if HAVE_KERNEL_OPLOCKS_IRIX
718                 koplocks = irix_init_kernel_oplocks();
719 #elif HAVE_KERNEL_OPLOCKS_LINUX
720                 koplocks = linux_init_kernel_oplocks();
721 #endif
722         }
723
724         return True;
725 }