Remove horrid goto.
[ira/wip.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    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 /* Oplock ipc UDP socket. */
25 static int oplock_sock = -1;
26 uint16 global_oplock_port = 0;
27
28 /* Current number of oplocks we have outstanding. */
29 static int32 exclusive_oplocks_open = 0;
30 static int32 level_II_oplocks_open = 0;
31 BOOL global_client_failed_oplock_break = False;
32 BOOL global_oplock_break = False;
33
34 extern int smb_read_error;
35
36 static struct kernel_oplocks *koplocks;
37
38 static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id, BOOL local);
39
40 /****************************************************************************
41  Get the number of current exclusive oplocks.
42 ****************************************************************************/
43
44 int32 get_number_of_exclusive_open_oplocks(void)
45 {
46   return exclusive_oplocks_open;
47 }
48
49 /****************************************************************************
50  Return True if an oplock message is pending.
51 ****************************************************************************/
52
53 BOOL oplock_message_waiting(fd_set *fds)
54 {
55         if (koplocks && koplocks->msg_waiting(fds))
56                 return True;
57
58         if (FD_ISSET(oplock_sock, fds))
59                 return True;
60
61         return False;
62 }
63
64 /****************************************************************************
65  Read an oplock break message from either the oplock UDP fd or the
66  kernel (if kernel oplocks are supported).
67
68  If timeout is zero then *fds contains the file descriptors that
69  are ready to be read and acted upon. If timeout is non-zero then
70  *fds contains the file descriptors to be selected on for read.
71  The timeout is in milliseconds
72
73 ****************************************************************************/
74
75 BOOL receive_local_message( char *buffer, int buffer_len, int timeout)
76 {
77         struct sockaddr_in from;
78         socklen_t fromlen = sizeof(from);
79         int32 msg_len = 0;
80         fd_set fds;
81         int selrtn = -1;
82
83         smb_read_error = 0;
84
85         while (timeout > 0) {
86                 struct timeval to;
87                 int maxfd = oplock_sock;
88                 time_t starttime = time(NULL);
89
90                 FD_ZERO(&fds);
91                 maxfd = setup_oplock_select_set(&fds);
92
93                 to.tv_sec = timeout / 1000;
94                 to.tv_usec = (timeout % 1000) * 1000;
95
96                 DEBUG(5,("receive_local_message: doing select with timeout of %d ms\n", timeout));
97
98                 selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to);
99
100                 if (selrtn == -1 && errno == EINTR) {
101                         /* could be a kernel oplock interrupt */
102                         if (koplocks && koplocks->msg_waiting(&fds)) {
103                                 return koplocks->receive_message(&fds, buffer, buffer_len);
104                         }
105                         /* Not a kernel interrupt - could be a SIGUSR1 message. We must restart. */
106                         /* We need to decrement the timeout here. */
107                         timeout -= ((time(NULL) - starttime)*1000);
108                         if (timeout < 0)
109                                 timeout = 1;
110
111                         DEBUG(5,("receive_local_message: EINTR : new timeout %d ms\n", timeout));
112                         continue;
113                 }
114
115                 /* Check if error */
116                 if(selrtn == -1) {
117                         /* something is wrong. Maybe the socket is dead? */
118                         smb_read_error = READ_ERROR;
119                         return False;
120                 }
121
122                 /* Did we timeout ? */
123                 if (selrtn == 0) {
124                         smb_read_error = READ_TIMEOUT;
125                         return False;
126                 }
127         }
128
129         if (koplocks && koplocks->msg_waiting(&fds)) {
130                 return koplocks->receive_message(&fds, buffer, buffer_len);
131         }
132
133         if (!FD_ISSET(oplock_sock, &fds))
134                 return False;
135
136         /*
137          * From here down we deal with the smbd <--> smbd
138          * oplock break protocol only.
139          */
140
141         /*
142          * Read a loopback udp message.
143          */
144         msg_len = sys_recvfrom(oplock_sock, &buffer[OPBRK_CMD_HEADER_LEN],
145                                                 buffer_len - OPBRK_CMD_HEADER_LEN, 0, (struct sockaddr *)&from, &fromlen);
146
147         if(msg_len < 0) {
148                 DEBUG(0,("receive_local_message. Error in recvfrom. (%s).\n",strerror(errno)));
149                 return False;
150         }
151
152         /* Validate message length. */
153         if(msg_len > (buffer_len - OPBRK_CMD_HEADER_LEN)) {
154                 DEBUG(0,("receive_local_message: invalid msg_len (%d) max can be %d\n", msg_len,
155                         buffer_len  - OPBRK_CMD_HEADER_LEN));
156                 return False;
157         }
158
159         /* Validate message from address (must be localhost). */
160         if(from.sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
161                 DEBUG(0,("receive_local_message: invalid 'from' address \
162 (was %lx should be 127.0.0.1)\n", (long)from.sin_addr.s_addr));
163                 return False;
164         }
165
166         /* Setup the message header */
167         SIVAL(buffer,OPBRK_CMD_LEN_OFFSET,msg_len);
168         SSVAL(buffer,OPBRK_CMD_PORT_OFFSET,ntohs(from.sin_port));
169
170         return True;
171 }
172
173 /****************************************************************************
174  Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
175  disabled (just sets flags). Returns True if oplock set.
176 ****************************************************************************/
177
178 BOOL set_file_oplock(files_struct *fsp, int oplock_type)
179 {
180         if (koplocks && !koplocks->set_oplock(fsp, oplock_type))
181                 return False;
182
183         fsp->oplock_type = oplock_type;
184         fsp->sent_oplock_break = NO_BREAK_SENT;
185         if (oplock_type == LEVEL_II_OPLOCK)
186                 level_II_oplocks_open++;
187         else
188                 exclusive_oplocks_open++;
189
190         DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \
191 tv_sec = %x, tv_usec = %x\n",
192                  fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id,
193                  (int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
194
195         return True;
196 }
197
198 /****************************************************************************
199  Attempt to release an oplock on a file. Decrements oplock count.
200 ****************************************************************************/
201
202 void release_file_oplock(files_struct *fsp)
203 {
204         if (koplocks)
205                 koplocks->release_oplock(fsp);
206
207         if (fsp->oplock_type == LEVEL_II_OPLOCK)
208                 level_II_oplocks_open--;
209         else
210                 exclusive_oplocks_open--;
211         
212         fsp->oplock_type = NO_OPLOCK;
213         fsp->sent_oplock_break = NO_BREAK_SENT;
214         
215         flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
216 }
217
218 /****************************************************************************
219  Attempt to downgrade an oplock on a file. Doesn't decrement oplock count.
220 ****************************************************************************/
221
222 static void downgrade_file_oplock(files_struct *fsp)
223 {
224         if (koplocks)
225                 koplocks->release_oplock(fsp);
226         fsp->oplock_type = LEVEL_II_OPLOCK;
227         exclusive_oplocks_open--;
228         level_II_oplocks_open++;
229         fsp->sent_oplock_break = NO_BREAK_SENT;
230 }
231
232 /****************************************************************************
233  Remove a file oplock. Copes with level II and exclusive.
234  Locks then unlocks the share mode lock. Client can decide to go directly
235  to none even if a "break-to-level II" was sent.
236 ****************************************************************************/
237
238 BOOL remove_oplock(files_struct *fsp, BOOL break_to_none)
239 {
240         SMB_DEV_T dev = fsp->dev;
241         SMB_INO_T inode = fsp->inode;
242         BOOL ret = True;
243
244         /* Remove the oplock flag from the sharemode. */
245         if (lock_share_entry_fsp(fsp) == False) {
246                 DEBUG(0,("remove_oplock: failed to lock share entry for file %s\n",
247                          fsp->fsp_name ));
248                 ret = False;
249         }
250
251         if (fsp->sent_oplock_break == EXCLUSIVE_BREAK_SENT || break_to_none) {
252                 /*
253                  * Deal with a reply when a break-to-none was sent.
254                  */
255
256                 if(remove_share_oplock(fsp)==False) {
257                         DEBUG(0,("remove_oplock: failed to remove share oplock for file %s fnum %d, \
258 dev = %x, inode = %.0f\n", fsp->fsp_name, fsp->fnum, (unsigned int)dev, (double)inode));
259                         ret = False;
260                 }
261
262                 release_file_oplock(fsp);
263         } else {
264                 /*
265                  * Deal with a reply when a break-to-level II was sent.
266                  */
267                 if(downgrade_share_oplock(fsp)==False) {
268                         DEBUG(0,("remove_oplock: failed to downgrade share oplock for file %s fnum %d, \
269 dev = %x, inode = %.0f\n", fsp->fsp_name, fsp->fnum, (unsigned int)dev, (double)inode));
270                         ret = False;
271                 }
272                 
273                 downgrade_file_oplock(fsp);
274         }
275
276         unlock_share_entry_fsp(fsp);
277         return ret;
278 }
279
280 /****************************************************************************
281  Setup the listening set of file descriptors for an oplock break
282  message either from the UDP socket or from the kernel. Returns the maximum
283  fd used.
284 ****************************************************************************/
285
286 int setup_oplock_select_set( fd_set *fds)
287 {
288         int maxfd = oplock_sock;
289
290         if(oplock_sock == -1)
291                 return 0;
292
293         FD_SET(oplock_sock,fds);
294
295         if (koplocks && koplocks->notification_fd != -1) {
296                 FD_SET(koplocks->notification_fd, fds);
297                 maxfd = MAX(maxfd, koplocks->notification_fd);
298         }
299
300         return maxfd;
301 }
302
303 /****************************************************************************
304  Process an oplock break message - whether it came from the UDP socket
305  or from the kernel.
306 ****************************************************************************/
307
308 BOOL process_local_message(char *buffer, int buf_size)
309 {
310         int32 msg_len;
311         uint16 from_port;
312         char *msg_start;
313         pid_t remotepid;
314         SMB_DEV_T dev;
315         SMB_INO_T inode;
316         unsigned long file_id;
317         uint16 break_cmd_type;
318
319         msg_len = IVAL(buffer,OPBRK_CMD_LEN_OFFSET);
320         from_port = SVAL(buffer,OPBRK_CMD_PORT_OFFSET);
321
322         msg_start = &buffer[OPBRK_CMD_HEADER_LEN];
323
324         DEBUG(5,("process_local_message: Got a message of length %d from port (%d)\n", 
325                 msg_len, from_port));
326
327         /* 
328          * Pull the info out of the requesting packet.
329          */
330
331         break_cmd_type = SVAL(msg_start,OPBRK_MESSAGE_CMD_OFFSET);
332
333         switch(break_cmd_type) {
334                 case KERNEL_OPLOCK_BREAK_CMD:
335                         if (!koplocks) {
336                                 DEBUG(0,("unexpected kernel oplock break!\n"));
337                                 break;
338                         } 
339                         if (!koplocks->parse_message(msg_start, msg_len, &inode, &dev, &file_id)) {
340                                 DEBUG(0,("kernel oplock break parse failure!\n"));
341                         }
342                         break;
343
344                 case OPLOCK_BREAK_CMD:
345                 case LEVEL_II_OPLOCK_BREAK_CMD:
346
347                         /* Ensure that the msg length is correct. */
348                         if(msg_len != OPLOCK_BREAK_MSG_LEN) {
349                                 DEBUG(0,("process_local_message: incorrect length for OPLOCK_BREAK_CMD (was %d, should be %d).\n",
350                                         (int)msg_len, (int)OPLOCK_BREAK_MSG_LEN));
351                                 return False;
352                         }
353
354                         memcpy((char *)&remotepid, msg_start+OPLOCK_BREAK_PID_OFFSET,sizeof(remotepid));
355                         memcpy((char *)&inode, msg_start+OPLOCK_BREAK_INODE_OFFSET,sizeof(inode));
356                         memcpy((char *)&dev, msg_start+OPLOCK_BREAK_DEV_OFFSET,sizeof(dev));
357                         memcpy((char *)&file_id, msg_start+OPLOCK_BREAK_FILEID_OFFSET,sizeof(file_id));
358
359                         DEBUG(5,("process_local_message: (%s) oplock break request from \
360 pid %d, port %d, dev = %x, inode = %.0f, file_id = %lu\n",
361                                 (break_cmd_type == OPLOCK_BREAK_CMD) ? "exclusive" : "level II",
362                                 (int)remotepid, from_port, (unsigned int)dev, (double)inode, file_id));
363                         break;
364
365                 /* 
366                  * Keep this as a debug case - eventually we can remove it.
367                  */
368                 case 0x8001:
369                         DEBUG(0,("process_local_message: Received unsolicited break \
370 reply - dumping info.\n"));
371
372                         if(msg_len != OPLOCK_BREAK_MSG_LEN) {
373                                 DEBUG(0,("process_local_message: ubr: incorrect length for reply \
374 (was %d, should be %d).\n", (int)msg_len, (int)OPLOCK_BREAK_MSG_LEN));
375                                 return False;
376                         }
377
378                         memcpy((char *)&inode, msg_start+OPLOCK_BREAK_INODE_OFFSET,sizeof(inode));
379                         memcpy((char *)&remotepid, msg_start+OPLOCK_BREAK_PID_OFFSET,sizeof(remotepid));
380                         memcpy((char *)&dev, msg_start+OPLOCK_BREAK_DEV_OFFSET,sizeof(dev));
381                         memcpy((char *)&file_id, msg_start+OPLOCK_BREAK_FILEID_OFFSET,sizeof(file_id));
382
383                         DEBUG(0,("process_local_message: unsolicited oplock break reply from \
384 pid %d, port %d, dev = %x, inode = %.0f, file_id = %lu\n",
385                                 (int)remotepid, from_port, (unsigned int)dev, (double)inode, file_id));
386
387                         return False;
388
389                 default:
390                         DEBUG(0,("process_local_message: unknown UDP message command code (%x) - ignoring.\n",
391                                 (unsigned int)SVAL(msg_start,0)));
392                         return False;
393         }
394
395         /*
396          * Now actually process the break request.
397          */
398
399         if((exclusive_oplocks_open + level_II_oplocks_open) != 0) {
400                 if (oplock_break(dev, inode, file_id, False) == False) {
401                         DEBUG(0,("process_local_message: oplock break failed.\n"));
402                         return False;
403                 }
404         } else {
405                 /*
406                  * If we have no record of any currently open oplocks,
407                  * it's not an error, as a close command may have
408                  * just been issued on the file that was oplocked.
409                  * Just log a message and return success in this case.
410                  */
411                 DEBUG(3,("process_local_message: oplock break requested with no outstanding \
412 oplocks. Returning success.\n"));
413         }
414
415         /* 
416          * Do the appropriate reply - none in the kernel or level II case.
417          */
418
419         if(SVAL(msg_start,OPBRK_MESSAGE_CMD_OFFSET) == OPLOCK_BREAK_CMD) {
420                 struct sockaddr_in toaddr;
421
422                 /* Send the message back after OR'ing in the 'REPLY' bit. */
423                 SSVAL(msg_start,OPBRK_MESSAGE_CMD_OFFSET,OPLOCK_BREAK_CMD | CMD_REPLY);
424
425                 memset((char *)&toaddr,'\0',sizeof(toaddr));
426                 toaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
427                 toaddr.sin_port = htons(from_port);
428                 toaddr.sin_family = AF_INET;
429
430                 if(sys_sendto( oplock_sock, msg_start, OPLOCK_BREAK_MSG_LEN, 0,
431                                 (struct sockaddr *)&toaddr, sizeof(toaddr)) < 0) {
432                         DEBUG(0,("process_local_message: sendto process %d failed. Errno was %s\n",
433                                 (int)remotepid, strerror(errno)));
434                         return False;
435                 }
436
437                 DEBUG(5,("process_local_message: oplock break reply sent to \
438 pid %d, port %d, for file dev = %x, inode = %.0f, file_id = %lu\n",
439                         (int)remotepid, from_port, (unsigned int)dev, (double)inode, file_id));
440         }
441
442         return True;
443 }
444
445 /****************************************************************************
446  Set up an oplock break message.
447 ****************************************************************************/
448
449 static void prepare_break_message(char *outbuf, files_struct *fsp, BOOL level2)
450 {
451         memset(outbuf,'\0',smb_size);
452         set_message(outbuf,8,0,True);
453
454         SCVAL(outbuf,smb_com,SMBlockingX);
455         SSVAL(outbuf,smb_tid,fsp->conn->cnum);
456         SSVAL(outbuf,smb_pid,0xFFFF);
457         SSVAL(outbuf,smb_uid,0);
458         SSVAL(outbuf,smb_mid,0xFFFF);
459         SCVAL(outbuf,smb_vwv0,0xFF);
460         SSVAL(outbuf,smb_vwv2,fsp->fnum);
461         SCVAL(outbuf,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
462         SCVAL(outbuf,smb_vwv3+1,level2 ? OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
463 }
464
465 /****************************************************************************
466  Function to do the waiting before sending a local break.
467 ****************************************************************************/
468
469 static void wait_before_sending_break(BOOL local_request)
470 {
471         extern struct timeval smb_last_time;
472
473         if(local_request) {
474                 struct timeval cur_tv;
475                 long wait_left = (long)lp_oplock_break_wait_time();
476
477                 if (wait_left == 0)
478                         return;
479
480                 GetTimeOfDay(&cur_tv);
481
482                 wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) +
483                 ((cur_tv.tv_usec - smb_last_time.tv_usec)/1000);
484
485                 if(wait_left > 0) {
486                         wait_left = MIN(wait_left, 1000);
487                         sys_usleep(wait_left * 1000);
488                 }
489         }
490 }
491
492 /****************************************************************************
493  Ensure that we have a valid oplock.
494 ****************************************************************************/
495
496 static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id)
497 {
498         files_struct *fsp = NULL;
499
500         if( DEBUGLVL( 3 ) ) {
501                 dbgtext( "initial_break_processing: called for dev = %x, inode = %.0f file_id = %lu\n",
502                         (unsigned int)dev, (double)inode, file_id);
503                 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
504                         exclusive_oplocks_open, level_II_oplocks_open );
505         }
506
507         /*
508          * We need to search the file open table for the
509          * entry containing this dev and inode, and ensure
510          * we have an oplock on it.
511          */
512
513         fsp = file_find_dif(dev, inode, file_id);
514
515         if(fsp == NULL) {
516                 /* The file could have been closed in the meantime - return success. */
517                 if( DEBUGLVL( 3 ) ) {
518                         dbgtext( "initial_break_processing: cannot find open file with " );
519                         dbgtext( "dev = %x, inode = %.0f file_id = %lu", (unsigned int)dev,
520                                 (double)inode, file_id);
521                         dbgtext( "allowing break to succeed.\n" );
522                 }
523                 return NULL;
524         }
525
526         /* Ensure we have an oplock on the file */
527
528         /*
529          * There is a potential race condition in that an oplock could
530          * have been broken due to another udp request, and yet there are
531          * still oplock break messages being sent in the udp message
532          * queue for this file. So return true if we don't have an oplock,
533          * as we may have just freed it.
534          */
535
536         if(fsp->oplock_type == NO_OPLOCK) {
537                 if( DEBUGLVL( 3 ) ) {
538                         dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
539                         dbgtext( "(dev = %x, inode = %.0f, file_id = %lu) has no oplock.\n",
540                                 (unsigned int)dev, (double)inode, fsp->file_id );
541                         dbgtext( "Allowing break to succeed regardless.\n" );
542                 }
543                 return NULL;
544         }
545
546         return fsp;
547 }
548
549 /****************************************************************************
550  Process a level II oplock break directly.
551 ****************************************************************************/
552
553 BOOL oplock_break_level2(files_struct *fsp, BOOL local_request, int token)
554 {
555         extern uint32 global_client_caps;
556         char outbuf[128];
557         BOOL got_lock = False;
558         SMB_DEV_T dev = fsp->dev;
559         SMB_INO_T inode = fsp->inode;
560
561         /*
562          * We can have a level II oplock even if the client is not
563          * level II oplock aware. In this case just remove the
564          * flags and don't send the break-to-none message to
565          * the client.
566          */
567
568         if (global_client_caps & CAP_LEVEL_II_OPLOCKS) {
569                 /*
570                  * If we are sending an oplock break due to an SMB sent
571                  * by our own client we ensure that we wait at leat
572                  * lp_oplock_break_wait_time() milliseconds before sending
573                  * the packet. Sending the packet sooner can break Win9x
574                  * and has reported to cause problems on NT. JRA.
575                  */
576
577                 wait_before_sending_break(local_request);
578
579                 /* Prepare the SMBlockingX message. */
580
581                 prepare_break_message( outbuf, fsp, False);
582                 if (!send_smb(smbd_server_fd(), outbuf))
583                         exit_server("oplock_break_level2: send_smb failed.");
584         }
585
586         /*
587          * Now we must update the shared memory structure to tell
588          * everyone else we no longer have a level II oplock on 
589          * this open file. If local_request is true then token is
590          * the existing lock on the shared memory area.
591          */
592
593         if(!local_request && lock_share_entry_fsp(fsp) == False) {
594                 DEBUG(0,("oplock_break_level2: unable to lock share entry for file %s\n", fsp->fsp_name ));
595         } else {
596                 got_lock = True;
597         }
598
599         if(remove_share_oplock(fsp)==False) {
600                 DEBUG(0,("oplock_break_level2: unable to remove level II oplock for file %s\n", fsp->fsp_name ));
601         }
602
603         if (!local_request && got_lock)
604                 unlock_share_entry_fsp(fsp);
605
606         fsp->oplock_type = NO_OPLOCK;
607         level_II_oplocks_open--;
608
609         if(level_II_oplocks_open < 0) {
610                 DEBUG(0,("oplock_break_level2: level_II_oplocks_open < 0 (%d). PANIC ERROR\n",
611                         level_II_oplocks_open));
612                 abort();
613         }
614
615         if( DEBUGLVL( 3 ) ) {
616                 dbgtext( "oplock_break_level2: returning success for " );
617                 dbgtext( "dev = %x, inode = %.0f, file_id = %lu\n", (unsigned int)dev, (double)inode, fsp->file_id );
618                 dbgtext( "Current level II oplocks_open = %d\n", level_II_oplocks_open );
619         }
620
621         return True;
622 }
623
624 /****************************************************************************
625  Process an oplock break directly.
626 ****************************************************************************/
627
628 static BOOL oplock_break(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id, BOOL local_request)
629 {
630         extern uint32 global_client_caps;
631         extern struct current_user current_user;
632         char *inbuf = NULL;
633         char *outbuf = NULL;
634         files_struct *fsp = NULL;
635         time_t start_time;
636         BOOL shutdown_server = False;
637         BOOL oplock_timeout = False;
638         connection_struct *saved_user_conn;
639         connection_struct *saved_fsp_conn;
640         int saved_vuid;
641         pstring saved_dir; 
642         int timeout = (OPLOCK_BREAK_TIMEOUT * 1000);
643         pstring file_name;
644         BOOL using_levelII;
645
646         if((fsp = initial_break_processing(dev, inode, file_id)) == NULL)
647                 return True;
648
649         /*
650          * Deal with a level II oplock going break to none separately.
651          */
652
653         if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
654                 return oplock_break_level2(fsp, local_request, -1);
655
656         /* Mark the oplock break as sent - we don't want to send twice! */
657         if (fsp->sent_oplock_break) {
658                 if( DEBUGLVL( 0 ) ) {
659                         dbgtext( "oplock_break: ERROR: oplock_break already sent for " );
660                         dbgtext( "file %s ", fsp->fsp_name);
661                         dbgtext( "(dev = %x, inode = %.0f, file_id = %lu)\n", (unsigned int)dev, (double)inode, fsp->file_id );
662                 }
663
664                 /*
665                  * We have to fail the open here as we cannot send another oplock break on
666                  * this file whilst we are awaiting a response from the client - neither
667                  * can we allow another open to succeed while we are waiting for the client.
668                  */
669                 return False;
670         }
671
672         if(global_oplock_break) {
673                 DEBUG(0,("ABORT : ABORT : recursion in oplock_break !!!!!\n"));
674                 abort();
675         }
676
677         /*
678          * Now comes the horrid part. We must send an oplock break to the client,
679          * and then process incoming messages until we get a close or oplock release.
680          * At this point we know we need a new inbuf/outbuf buffer pair.
681          * We cannot use these staticaly as we may recurse into here due to
682          * messages crossing on the wire.
683          */
684
685         if((inbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
686                 DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
687                 return False;
688         }
689
690         if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
691                 DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
692                 SAFE_FREE(inbuf);
693                 return False;
694         }
695
696         /*
697          * If we are sending an oplock break due to an SMB sent
698          * by our own client we ensure that we wait at leat
699          * lp_oplock_break_wait_time() milliseconds before sending
700          * the packet. Sending the packet sooner can break Win9x
701          * and has reported to cause problems on NT. JRA.
702          */
703
704         wait_before_sending_break(local_request);
705
706         /* Prepare the SMBlockingX message. */
707
708         if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) && 
709                         !koplocks && /* NOTE: we force levelII off for kernel oplocks - this will change when it is supported */
710                         lp_level2_oplocks(SNUM(fsp->conn))) {
711                 using_levelII = True;
712         } else {
713                 using_levelII = False;
714         }
715
716         prepare_break_message( outbuf, fsp, using_levelII);
717         /* Remember if we just sent a break to level II on this file. */
718         fsp->sent_oplock_break = using_levelII? LEVEL_II_BREAK_SENT:EXCLUSIVE_BREAK_SENT;
719
720         if (!send_smb(smbd_server_fd(), outbuf))
721                 exit_server("oplock_break: send_smb failed.");
722
723         /* We need this in case a readraw crosses on the wire. */
724         global_oplock_break = True;
725  
726         /* Process incoming messages. */
727
728         /*
729          * JRA - If we don't get a break from the client in OPLOCK_BREAK_TIMEOUT
730          * seconds we should just die....
731          */
732
733         start_time = time(NULL);
734
735         /*
736          * Save the information we need to re-become the
737          * user, then unbecome the user whilst we're doing this.
738          */
739         saved_user_conn = current_user.conn;
740         saved_vuid = current_user.vuid;
741         saved_fsp_conn = fsp->conn;
742         change_to_root_user();
743         vfs_GetWd(saved_fsp_conn,saved_dir);
744         /* Save the chain fnum. */
745         file_chain_save();
746
747         /*
748          * From Charles Hoch <hoch@exemplary.com>. If the break processing
749          * code closes the file (as it often does), then the fsp pointer here
750          * points to free()'d memory. We *must* revalidate fsp each time
751          * around the loop.
752          */
753
754         pstrcpy(file_name, fsp->fsp_name);
755
756         while((fsp = initial_break_processing(dev, inode, file_id)) &&
757                         OPEN_FSP(fsp) && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
758                 if(receive_smb(smbd_server_fd(),inbuf, timeout) == False) {
759                         /*
760                          * Die if we got an error.
761                          */
762
763                         if (smb_read_error == READ_EOF) {
764                                 DEBUG( 0, ( "oplock_break: end of file from client\n" ) );
765                                 shutdown_server = True;
766                         } else if (smb_read_error == READ_ERROR) {
767                                 DEBUG( 0, ("oplock_break: receive_smb error (%s)\n", strerror(errno)) );
768                                 shutdown_server = True;
769                         } else if (smb_read_error == READ_TIMEOUT) {
770                                 DEBUG( 0, ( "oplock_break: receive_smb timed out after %d seconds.\n", OPLOCK_BREAK_TIMEOUT ) );
771                                 oplock_timeout = True;
772                         }
773
774                         DEBUGADD( 0, ( "oplock_break failed for file %s ", file_name ) );
775                         DEBUGADD( 0, ( "(dev = %x, inode = %.0f, file_id = %lu).\n",
776                                 (unsigned int)dev, (double)inode, file_id));
777
778                         break;
779                 }
780
781                 /*
782                  * There are certain SMB requests that we shouldn't allow
783                  * to recurse. opens, renames and deletes are the obvious
784                  * ones. This is handled in the switch_message() function.
785                  * If global_oplock_break is set they will push the packet onto
786                  * the pending smb queue and return -1 (no reply).
787                  * JRA.
788                  */
789
790                 process_smb(inbuf, outbuf);
791
792                 /*
793                  * Die if we go over the time limit.
794                  */
795
796                 if((time(NULL) - start_time) > OPLOCK_BREAK_TIMEOUT) {
797                         if( DEBUGLVL( 0 ) ) {
798                                 dbgtext( "oplock_break: no break received from client " );
799                                 dbgtext( "within %d seconds.\n", OPLOCK_BREAK_TIMEOUT );
800                                 dbgtext( "oplock_break failed for file %s ", fsp->fsp_name );
801                                 dbgtext( "(dev = %x, inode = %.0f, file_id = %lu).\n",  
802                                         (unsigned int)dev, (double)inode, file_id );
803                         }
804                         oplock_timeout = True;
805                         break;
806                 }
807         }
808
809         /*
810          * Go back to being the user who requested the oplock
811          * break.
812          */
813         if((saved_user_conn != NULL) && (saved_vuid != UID_FIELD_INVALID) && !change_to_user(saved_user_conn, saved_vuid)) {
814                 DEBUG( 0, ( "oplock_break: unable to re-become user!" ) );
815                 DEBUGADD( 0, ( "Shutting down server\n" ) );
816                 close(oplock_sock);
817                 exit_server("unable to re-become user");
818         }
819
820         /* Including the directory. */
821         vfs_ChDir(saved_fsp_conn,saved_dir);
822
823         /* Restore the chain fnum. */
824         file_chain_restore();
825
826         /* Free the buffers we've been using to recurse. */
827         SAFE_FREE(inbuf);
828         SAFE_FREE(outbuf);
829
830         /* We need this in case a readraw crossed on the wire. */
831         if(global_oplock_break)
832                 global_oplock_break = False;
833
834         /*
835          * If the client timed out then clear the oplock (or go to level II)
836          * and continue. This seems to be what NT does and is better than dropping
837          * the connection.
838          */
839
840         if(oplock_timeout && (fsp = initial_break_processing(dev, inode, file_id)) &&
841                         OPEN_FSP(fsp) && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
842                 DEBUG(0,("oplock_break: client failure in oplock break in file %s\n", fsp->fsp_name));
843                 remove_oplock(fsp,True);
844 #if FASCIST_OPLOCK_BACKOFF
845                 global_client_failed_oplock_break = True; /* Never grant this client an oplock again. */
846 #endif
847         }
848
849         /*
850          * If the client had an error we must die.
851          */
852
853         if(shutdown_server) {
854                 DEBUG( 0, ( "oplock_break: client failure in break - " ) );
855                 DEBUGADD( 0, ( "shutting down this smbd.\n" ) );
856                 close(oplock_sock);
857                 exit_server("oplock break failure");
858         }
859
860         /* Santity check - remove this later. JRA */
861         if(exclusive_oplocks_open < 0) {
862                 DEBUG(0,("oplock_break: exclusive_oplocks_open < 0 (%d). PANIC ERROR\n", exclusive_oplocks_open));
863                 abort();
864         }
865
866         if( DEBUGLVL( 3 ) ) {
867                 dbgtext( "oplock_break: returning success for " );
868                 dbgtext( "dev = %x, inode = %.0f, file_id = %lu\n", (unsigned int)dev, (double)inode, file_id );
869                 dbgtext( "Current exclusive_oplocks_open = %d\n", exclusive_oplocks_open );
870         }
871
872         return True;
873 }
874
875 /****************************************************************************
876 Send an oplock break message to another smbd process. If the oplock is held 
877 by the local smbd then call the oplock break function directly.
878 ****************************************************************************/
879
880 BOOL request_oplock_break(share_mode_entry *share_entry)
881 {
882         char op_break_msg[OPLOCK_BREAK_MSG_LEN];
883         struct sockaddr_in addr_out;
884         pid_t pid = sys_getpid();
885         time_t start_time;
886         int time_left;
887         SMB_DEV_T dev = share_entry->dev;
888         SMB_INO_T inode = share_entry->inode;
889         unsigned long file_id = share_entry->share_file_id;
890
891         if(pid == share_entry->pid) {
892                 /* We are breaking our own oplock, make sure it's us. */
893                 if(share_entry->op_port != global_oplock_port) {
894                         DEBUG(0,("request_oplock_break: corrupt share mode entry - pid = %d, port = %d \
895 should be %d\n", (int)pid, share_entry->op_port, global_oplock_port));
896                         return False;
897                 }
898
899                 DEBUG(5,("request_oplock_break: breaking our own oplock\n"));
900
901 #if 1 /* JRA PARANOIA TEST.... */
902                 {
903                         files_struct *fsp = file_find_dif(dev, inode, file_id);
904                         if (!fsp) {
905                                 DEBUG(0,("request_oplock_break: PANIC : breaking our own oplock requested for \
906 dev = %x, inode = %.0f, file_id = %lu and no fsp found !\n",
907             (unsigned int)dev, (double)inode, file_id ));
908                                 smb_panic("request_oplock_break: no fsp found for our own oplock\n");
909                         }
910                 }
911 #endif /* END JRA PARANOIA TEST... */
912
913                 /* Call oplock break direct. */
914                 return oplock_break(dev, inode, file_id, True);
915         }
916
917         /* We need to send a OPLOCK_BREAK_CMD message to the port in the share mode entry. */
918
919         if (LEVEL_II_OPLOCK_TYPE(share_entry->op_type)) {
920                 SSVAL(op_break_msg,OPBRK_MESSAGE_CMD_OFFSET,LEVEL_II_OPLOCK_BREAK_CMD);
921         } else {
922                 SSVAL(op_break_msg,OPBRK_MESSAGE_CMD_OFFSET,OPLOCK_BREAK_CMD);
923         }
924
925         memcpy(op_break_msg+OPLOCK_BREAK_PID_OFFSET,(char *)&pid,sizeof(pid));
926         memcpy(op_break_msg+OPLOCK_BREAK_DEV_OFFSET,(char *)&dev,sizeof(dev));
927         memcpy(op_break_msg+OPLOCK_BREAK_INODE_OFFSET,(char *)&inode,sizeof(inode));
928         memcpy(op_break_msg+OPLOCK_BREAK_FILEID_OFFSET,(char *)&file_id,sizeof(file_id));
929
930         /* Set the address and port. */
931         memset((char *)&addr_out,'\0',sizeof(addr_out));
932         addr_out.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
933         addr_out.sin_port = htons( share_entry->op_port );
934         addr_out.sin_family = AF_INET;
935    
936         if( DEBUGLVL( 3 ) ) {
937                 dbgtext( "request_oplock_break: sending a oplock break message to " );
938                 dbgtext( "pid %d on port %d ", (int)share_entry->pid, share_entry->op_port );
939                 dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
940             (unsigned int)dev, (double)inode, file_id );
941         }
942
943         if(sys_sendto(oplock_sock,op_break_msg,OPLOCK_BREAK_MSG_LEN,0,
944                         (struct sockaddr *)&addr_out,sizeof(addr_out)) < 0) {
945                 if( DEBUGLVL( 0 ) ) {
946                         dbgtext( "request_oplock_break: failed when sending a oplock " );
947                         dbgtext( "break message to pid %d ", (int)share_entry->pid );
948                         dbgtext( "on port %d ", share_entry->op_port );
949                         dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
950           (unsigned int)dev, (double)inode, file_id );
951                         dbgtext( "Error was %s\n", strerror(errno) );
952                 }
953                 return False;
954         }
955
956         /*
957          * If we just sent a message to a level II oplock share entry then
958          * we are done and may return.
959          */
960
961         if (LEVEL_II_OPLOCK_TYPE(share_entry->op_type)) {
962                 DEBUG(3,("request_oplock_break: sent break message to level II entry.\n"));
963                 return True;
964         }
965
966         /*
967          * Now we must await the oplock broken message coming back
968          * from the target smbd process. Timeout if it fails to
969          * return in (OPLOCK_BREAK_TIMEOUT + OPLOCK_BREAK_TIMEOUT_FUDGEFACTOR) seconds.
970          * While we get messages that aren't ours, loop.
971          */
972
973         start_time = time(NULL);
974         time_left = OPLOCK_BREAK_TIMEOUT+OPLOCK_BREAK_TIMEOUT_FUDGEFACTOR;
975
976         while(time_left >= 0) {
977                 char op_break_reply[OPBRK_CMD_HEADER_LEN+OPLOCK_BREAK_MSG_LEN];
978                 uint16 reply_from_port;
979                 char *reply_msg_start;
980
981                 if(receive_local_message(op_break_reply, sizeof(op_break_reply),
982                                 time_left ? time_left * 1000 : 1) == False) {
983                         if(smb_read_error == READ_TIMEOUT) {
984                                 if( DEBUGLVL( 0 ) ) {
985                                         dbgtext( "request_oplock_break: no response received to oplock " );
986                                         dbgtext( "break request to pid %d ", (int)share_entry->pid );
987                                         dbgtext( "on port %d ", share_entry->op_port );
988                                         dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
989                                                         (unsigned int)dev, (double)inode, file_id );
990                                 }
991
992                                 /*
993                                  * This is a hack to make handling of failing clients more robust.
994                                  * If a oplock break response message is not received in the timeout
995                                  * period we may assume that the smbd servicing that client holding
996                                  * the oplock has died and the client changes were lost anyway, so
997                                  * we should continue to try and open the file.
998                                  */
999                                 break;
1000                         } else {
1001                                 if( DEBUGLVL( 0 ) ) {
1002                                         dbgtext( "request_oplock_break: error in response received " );
1003                                         dbgtext( "to oplock break request to pid %d ", (int)share_entry->pid );
1004                                         dbgtext( "on port %d ", share_entry->op_port );
1005                                         dbgtext( "for dev = %x, inode = %.0f, file_id = %lu\n",
1006                                                 (unsigned int)dev, (double)inode, file_id );
1007                                         dbgtext( "Error was (%s).\n", strerror(errno) );
1008                                 }
1009                         }
1010                         return False;
1011                 }
1012
1013                 reply_from_port = SVAL(op_break_reply,OPBRK_CMD_PORT_OFFSET);
1014                 reply_msg_start = &op_break_reply[OPBRK_CMD_HEADER_LEN];
1015
1016                 /*
1017                  * Test to see if this is the reply we are awaiting.
1018                  */
1019                 if((SVAL(reply_msg_start,OPBRK_MESSAGE_CMD_OFFSET) & CMD_REPLY) &&
1020                         ((SVAL(reply_msg_start,OPBRK_MESSAGE_CMD_OFFSET) & ~CMD_REPLY) == OPLOCK_BREAK_CMD) &&
1021                         (reply_from_port == share_entry->op_port) && 
1022                         (memcmp(&reply_msg_start[OPLOCK_BREAK_PID_OFFSET], &op_break_msg[OPLOCK_BREAK_PID_OFFSET],
1023                                 OPLOCK_BREAK_MSG_LEN - OPLOCK_BREAK_PID_OFFSET) == 0)) {
1024
1025                         /*
1026                          * This is the reply we've been waiting for.
1027                          */
1028                         break;
1029                 } else {
1030                         /*
1031                          * This is another message - a break request.
1032                          * Note that both kernel oplock break requests
1033                          * and UDP inter-smbd oplock break requests will
1034                          * be processed here.
1035                          *
1036                          * Process it to prevent potential deadlock.
1037                          * Note that the code in switch_message() prevents
1038                          * us from recursing into here as any SMB requests
1039                          * we might process that would cause another oplock
1040                          * break request to be made will be queued.
1041                          * JRA.
1042                          */
1043
1044                         process_local_message(op_break_reply, sizeof(op_break_reply));
1045                 }
1046
1047                 time_left -= (time(NULL) - start_time);
1048         }
1049
1050         DEBUG(3,("request_oplock_break: broke oplock.\n"));
1051
1052         return True;
1053 }
1054
1055 /****************************************************************************
1056   Attempt to break an oplock on a file (if oplocked).
1057   Returns True if the file was closed as a result of
1058   the oplock break, False otherwise.
1059   Used as a last ditch attempt to free a space in the 
1060   file table when we have run out.
1061 ****************************************************************************/
1062
1063 BOOL attempt_close_oplocked_file(files_struct *fsp)
1064 {
1065         DEBUG(5,("attempt_close_oplocked_file: checking file %s.\n", fsp->fsp_name));
1066
1067         if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !fsp->sent_oplock_break && (fsp->fd != -1)) {
1068                 /* Try and break the oplock. */
1069                 if (oplock_break(fsp->dev, fsp->inode, fsp->file_id, True)) {
1070                         if(file_find_fsp(fsp) == NULL) /* Did the oplock break close the file ? */
1071                                 return True;
1072                 }
1073         }
1074
1075         return False;
1076 }
1077
1078 /****************************************************************************
1079  This function is called on any file modification or lock request. If a file
1080  is level 2 oplocked then it must tell all other level 2 holders to break to none.
1081 ****************************************************************************/
1082
1083 void release_level_2_oplocks_on_change(files_struct *fsp)
1084 {
1085         share_mode_entry *share_list = NULL;
1086         pid_t pid = sys_getpid();
1087         int token = -1;
1088         int num_share_modes = 0;
1089         int i;
1090
1091         /*
1092          * If this file is level II oplocked then we need
1093          * to grab the shared memory lock and inform all
1094          * other files with a level II lock that they need
1095          * to flush their read caches. We keep the lock over
1096          * the shared memory area whilst doing this.
1097          */
1098
1099         if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
1100                 return;
1101
1102         if (lock_share_entry_fsp(fsp) == False) {
1103                 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock share mode entry for file %s.\n", fsp->fsp_name ));
1104         }
1105
1106         num_share_modes = get_share_modes(fsp->conn, fsp->dev, fsp->inode, &share_list);
1107
1108         DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n", 
1109                         num_share_modes ));
1110
1111         for(i = 0; i < num_share_modes; i++) {
1112                 share_mode_entry *share_entry = &share_list[i];
1113
1114                 /*
1115                  * As there could have been multiple writes waiting at the lock_share_entry
1116                  * gate we may not be the first to enter. Hence the state of the op_types
1117                  * in the share mode entries may be partly NO_OPLOCK and partly LEVEL_II
1118                  * oplock. It will do no harm to re-send break messages to those smbd's
1119                  * that are still waiting their turn to remove their LEVEL_II state, and
1120                  * also no harm to ignore existing NO_OPLOCK states. JRA.
1121                  */
1122
1123                 DEBUG(10,("release_level_2_oplocks_on_change: share_entry[%i]->op_type == %d\n",
1124                                 i, share_entry->op_type ));
1125
1126                 if (share_entry->op_type == NO_OPLOCK)
1127                         continue;
1128
1129                 /* Paranoia .... */
1130                 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
1131                         DEBUG(0,("release_level_2_oplocks_on_change: PANIC. share mode entry %d is an exlusive oplock !\n", i ));
1132                         unlock_share_entry(fsp->conn, fsp->dev, fsp->inode);
1133                         abort();
1134                 }
1135
1136                 /*
1137                  * Check if this is a file we have open (including the
1138                  * file we've been called to do write_file on. If so
1139                  * then break it directly without releasing the lock.
1140                  */
1141
1142                 if (pid == share_entry->pid) {
1143                         files_struct *new_fsp = file_find_dif(share_entry->dev, share_entry->inode, share_entry->share_file_id);
1144
1145                         /* Paranoia check... */
1146                         if(new_fsp == NULL) {
1147                                 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. share mode entry %d is not a local file !\n", i ));
1148                                 unlock_share_entry(fsp->conn, fsp->dev, fsp->inode);
1149                                 abort();
1150                         }
1151
1152                         DEBUG(10,("release_level_2_oplocks_on_change: breaking our own oplock.\n"));
1153
1154                         oplock_break_level2(new_fsp, True, token);
1155
1156                 } else {
1157
1158                         /*
1159                          * This is a remote file and so we send an asynchronous
1160                          * message.
1161                          */
1162
1163                         DEBUG(10,("release_level_2_oplocks_on_change: breaking remote oplock.\n"));
1164                         request_oplock_break(share_entry);
1165                 }
1166         }
1167
1168         SAFE_FREE(share_list);
1169         unlock_share_entry_fsp(fsp);
1170
1171         /* Paranoia check... */
1172         if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
1173                 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. File %s still has a level II oplock.\n", fsp->fsp_name));
1174                 smb_panic("release_level_2_oplocks_on_change");
1175         }
1176 }
1177
1178 /****************************************************************************
1179 setup oplocks for this process
1180 ****************************************************************************/
1181
1182 BOOL init_oplocks(void)
1183 {
1184         struct sockaddr_in sock_name;
1185         socklen_t len = sizeof(sock_name);
1186
1187         DEBUG(3,("open_oplock_ipc: opening loopback UDP socket.\n"));
1188
1189         /* Open a lookback UDP socket on a random port. */
1190         oplock_sock = open_socket_in(SOCK_DGRAM, 0, 0, htonl(INADDR_LOOPBACK),False);
1191         if (oplock_sock == -1) {
1192                 DEBUG(0,("open_oplock_ipc: Failed to get local UDP socket for \
1193 address %lx. Error was %s\n", (long)htonl(INADDR_LOOPBACK), strerror(errno)));
1194                 global_oplock_port = 0;
1195                 return(False);
1196         }
1197
1198         /* Find out the transient UDP port we have been allocated. */
1199         if(getsockname(oplock_sock, (struct sockaddr *)&sock_name, &len)<0) {
1200                 DEBUG(0,("open_oplock_ipc: Failed to get local UDP port. Error was %s\n",
1201                          strerror(errno)));
1202                 close(oplock_sock);
1203                 oplock_sock = -1;
1204                 global_oplock_port = 0;
1205                 return False;
1206         }
1207         global_oplock_port = ntohs(sock_name.sin_port);
1208
1209         if (lp_kernel_oplocks()) {
1210 #if HAVE_KERNEL_OPLOCKS_IRIX
1211                 koplocks = irix_init_kernel_oplocks();
1212 #elif HAVE_KERNEL_OPLOCKS_LINUX
1213                 koplocks = linux_init_kernel_oplocks();
1214 #endif
1215         }
1216
1217         DEBUG(3,("open_oplock ipc: pid = %d, global_oplock_port = %u\n", 
1218                  (int)sys_getpid(), global_oplock_port));
1219
1220         return True;
1221 }