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