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