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