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