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