2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1998 - 2001
6 Copyright (C) Volker Lendecke 2005
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.
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.
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.
25 /* Current number of oplocks we have outstanding. */
26 static int32 exclusive_oplocks_open = 0;
27 static int32 level_II_oplocks_open = 0;
28 BOOL global_client_failed_oplock_break = False;
30 extern struct timeval smb_last_time;
31 extern uint32 global_client_caps;
32 extern int smb_read_error;
34 static struct kernel_oplocks *koplocks;
36 /****************************************************************************
37 Get the number of current exclusive oplocks.
38 ****************************************************************************/
40 int32 get_number_of_exclusive_open_oplocks(void)
42 return exclusive_oplocks_open;
45 /****************************************************************************
46 Return True if an oplock message is pending.
47 ****************************************************************************/
49 BOOL oplock_message_waiting(fd_set *fds)
51 if (koplocks && koplocks->msg_waiting(fds)) {
58 /****************************************************************************
59 Find out if there are any kernel oplock messages waiting and process them
60 if so. pfds is the fd_set from the main select loop (which contains any
61 kernel oplock fd if that's what the system uses (IRIX). If may be NULL if
62 we're calling this in a shutting down state.
63 ****************************************************************************/
65 void process_kernel_oplocks(fd_set *pfds)
68 * We need to check for kernel oplocks before going into the select
69 * here, as the EINTR generated by the linux kernel oplock may have
70 * already been eaten. JRA.
77 while (koplocks->msg_waiting(pfds)) {
79 char msg[MSG_SMB_KERNEL_BREAK_SIZE];
81 fsp = koplocks->receive_message(pfds);
84 DEBUG(3, ("Kernel oplock message announced, but none "
89 /* Put the kernel break info into the message. */
90 SDEV_T_VAL(msg,0,fsp->dev);
91 SINO_T_VAL(msg,8,fsp->inode);
92 SIVAL(msg,16,fsp->file_id);
94 /* Don't need to be root here as we're only ever
95 sending to ourselves. */
97 message_send_pid(pid_to_procid(sys_getpid()),
99 &msg, MSG_SMB_KERNEL_BREAK_SIZE, True);
103 /****************************************************************************
104 Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
105 disabled (just sets flags). Returns True if oplock set.
106 ****************************************************************************/
108 BOOL set_file_oplock(files_struct *fsp, int oplock_type)
110 if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) {
114 fsp->oplock_type = oplock_type;
115 fsp->sent_oplock_break = NO_BREAK_SENT;
116 if (oplock_type == LEVEL_II_OPLOCK) {
117 level_II_oplocks_open++;
119 exclusive_oplocks_open++;
122 DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \
123 tv_sec = %x, tv_usec = %x\n",
124 fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id,
125 (int)fsp->open_time.tv_sec, (int)fsp->open_time.tv_usec ));
130 /****************************************************************************
131 Attempt to release an oplock on a file. Decrements oplock count.
132 ****************************************************************************/
134 void release_file_oplock(files_struct *fsp)
136 if ((fsp->oplock_type != NO_OPLOCK) &&
137 (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
139 koplocks->release_oplock(fsp);
142 if (fsp->oplock_type == LEVEL_II_OPLOCK) {
143 level_II_oplocks_open--;
144 } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
145 exclusive_oplocks_open--;
148 SMB_ASSERT(exclusive_oplocks_open>=0);
149 SMB_ASSERT(level_II_oplocks_open>=0);
151 fsp->oplock_type = NO_OPLOCK;
152 fsp->sent_oplock_break = NO_BREAK_SENT;
154 flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
157 /****************************************************************************
158 Attempt to downgrade an oplock on a file. Doesn't decrement oplock count.
159 ****************************************************************************/
161 static void downgrade_file_oplock(files_struct *fsp)
164 koplocks->release_oplock(fsp);
166 fsp->oplock_type = LEVEL_II_OPLOCK;
167 exclusive_oplocks_open--;
168 level_II_oplocks_open++;
169 fsp->sent_oplock_break = NO_BREAK_SENT;
172 /****************************************************************************
173 Remove a file oplock. Copes with level II and exclusive.
174 Locks then unlocks the share mode lock. Client can decide to go directly
175 to none even if a "break-to-level II" was sent.
176 ****************************************************************************/
178 BOOL remove_oplock(files_struct *fsp)
180 SMB_DEV_T dev = fsp->dev;
181 SMB_INO_T inode = fsp->inode;
183 struct share_mode_lock *lck;
185 /* Remove the oplock flag from the sharemode. */
186 lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL);
188 DEBUG(0,("remove_oplock: failed to lock share entry for "
189 "file %s\n", fsp->fsp_name ));
192 ret = remove_share_oplock(lck, fsp);
194 DEBUG(0,("remove_oplock: failed to remove share oplock for "
195 "file %s fnum %d, dev = %x, inode = %.0f\n",
196 fsp->fsp_name, fsp->fnum, (unsigned int)dev,
199 release_file_oplock(fsp);
205 * Deal with a reply when a break-to-level II was sent.
207 BOOL downgrade_oplock(files_struct *fsp)
209 SMB_DEV_T dev = fsp->dev;
210 SMB_INO_T inode = fsp->inode;
212 struct share_mode_lock *lck;
214 lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL);
216 DEBUG(0,("downgrade_oplock: failed to lock share entry for "
217 "file %s\n", fsp->fsp_name ));
220 ret = downgrade_share_oplock(lck, fsp);
222 DEBUG(0,("downgrade_oplock: failed to downgrade share oplock "
223 "for file %s fnum %d, dev = %x, inode = %.0f\n",
224 fsp->fsp_name, fsp->fnum, (unsigned int)dev,
228 downgrade_file_oplock(fsp);
233 /****************************************************************************
234 Setup the listening set of file descriptors for an oplock break
235 message either from the UDP socket or from the kernel. Returns the maximum
237 ****************************************************************************/
239 int setup_oplock_select_set( fd_set *fds)
243 if (koplocks && koplocks->notification_fd != -1) {
244 FD_SET(koplocks->notification_fd, fds);
245 maxfd = MAX(maxfd, koplocks->notification_fd);
251 /****************************************************************************
252 Set up an oplock break message.
253 ****************************************************************************/
255 static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
256 files_struct *fsp, uint8 cmd)
258 char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
260 if (result == NULL) {
261 DEBUG(0, ("talloc failed\n"));
265 memset(result,'\0',smb_size);
266 set_message(result,8,0,True);
267 SCVAL(result,smb_com,SMBlockingX);
268 SSVAL(result,smb_tid,fsp->conn->cnum);
269 SSVAL(result,smb_pid,0xFFFF);
270 SSVAL(result,smb_uid,0);
271 SSVAL(result,smb_mid,0xFFFF);
272 SCVAL(result,smb_vwv0,0xFF);
273 SSVAL(result,smb_vwv2,fsp->fnum);
274 SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
275 SCVAL(result,smb_vwv3+1,cmd);
279 /****************************************************************************
280 Function to do the waiting before sending a local break.
281 ****************************************************************************/
283 static void wait_before_sending_break(void)
285 struct timeval cur_tv;
286 long wait_left = (long)lp_oplock_break_wait_time();
288 if (wait_left == 0) {
292 GetTimeOfDay(&cur_tv);
294 wait_left -= ((cur_tv.tv_sec - smb_last_time.tv_sec)*1000) +
295 ((cur_tv.tv_usec - smb_last_time.tv_usec)/1000);
298 wait_left = MIN(wait_left, 1000);
299 sys_usleep(wait_left * 1000);
303 /****************************************************************************
304 Ensure that we have a valid oplock.
305 ****************************************************************************/
307 static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, unsigned long file_id)
309 files_struct *fsp = NULL;
311 if( DEBUGLVL( 3 ) ) {
312 dbgtext( "initial_break_processing: called for dev = 0x%x, inode = %.0f file_id = %lu\n",
313 (unsigned int)dev, (double)inode, file_id);
314 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
315 exclusive_oplocks_open, level_II_oplocks_open );
319 * We need to search the file open table for the
320 * entry containing this dev and inode, and ensure
321 * we have an oplock on it.
324 fsp = file_find_dif(dev, inode, file_id);
327 /* The file could have been closed in the meantime - return success. */
328 if( DEBUGLVL( 3 ) ) {
329 dbgtext( "initial_break_processing: cannot find open file with " );
330 dbgtext( "dev = 0x%x, inode = %.0f file_id = %lu", (unsigned int)dev,
331 (double)inode, file_id);
332 dbgtext( "allowing break to succeed.\n" );
337 /* Ensure we have an oplock on the file */
340 * There is a potential race condition in that an oplock could
341 * have been broken due to another udp request, and yet there are
342 * still oplock break messages being sent in the udp message
343 * queue for this file. So return true if we don't have an oplock,
344 * as we may have just freed it.
347 if(fsp->oplock_type == NO_OPLOCK) {
348 if( DEBUGLVL( 3 ) ) {
349 dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
350 dbgtext( "(dev = %x, inode = %.0f, file_id = %lu) has no oplock.\n",
351 (unsigned int)dev, (double)inode, fsp->file_id );
352 dbgtext( "Allowing break to succeed regardless.\n" );
360 static void oplock_timeout_handler(struct timed_event *te,
361 const struct timeval *now,
364 files_struct *fsp = private_data;
366 DEBUG(0, ("Oplock break failed for file %s -- replying anyway\n", fsp->fsp_name));
367 global_client_failed_oplock_break = True;
369 reply_to_oplock_break_requests(fsp);
372 /*******************************************************************
373 Add a timeout handler waiting for the client reply.
374 *******************************************************************/
376 static void add_oplock_timeout_handler(files_struct *fsp)
378 if (fsp->oplock_timeout != NULL) {
379 DEBUG(0, ("Logic problem -- have an oplock event hanging "
383 fsp->oplock_timeout =
384 add_timed_event(NULL,
385 timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
386 "oplock_timeout_handler",
387 oplock_timeout_handler, fsp);
389 if (fsp->oplock_timeout == NULL) {
390 DEBUG(0, ("Could not add oplock timeout handler\n"));
394 /*******************************************************************
395 This handles the case of a write triggering a break to none
396 message on a level2 oplock.
397 When we get this message we may be in any of three states :
398 NO_OPLOCK, LEVEL_II, FAKE_LEVEL2. We only send a message to
399 the client for LEVEL2.
400 *******************************************************************/
402 static void process_oplock_async_level2_break_message(int msg_type, struct process_id src,
403 void *buf, size_t len)
405 struct share_mode_entry msg;
411 DEBUG(0, ("Got NULL buffer\n"));
415 if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
416 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
420 /* De-linearize incoming message. */
421 message_to_share_mode_entry(&msg, buf);
423 DEBUG(10, ("Got oplock async level 2 break message from pid %d: 0x%x/%.0f/%d\n",
424 (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
425 (int)msg.share_file_id));
427 fsp = initial_break_processing(msg.dev, msg.inode,
431 /* We hit a race here. Break messages are sent, and before we
432 * get to process this message, we have closed the file.
433 * No need to reply as this is an async message. */
434 DEBUG(3, ("process_oplock_async_level2_break_message: Did not find fsp, ignoring\n"));
438 if (fsp->oplock_type == NO_OPLOCK) {
439 /* We already got a "break to none" message and we've handled it.
441 DEBUG(3, ("process_oplock_async_level2_break_message: already broken to none, ignoring.\n"));
445 if (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
446 /* Don't tell the client, just downgrade. */
447 DEBUG(3, ("process_oplock_async_level2_break_message: downgrading fake level 2 oplock.\n"));
452 /* Ensure we're really at level2 state. */
453 SMB_ASSERT(fsp->oplock_type == LEVEL_II_OPLOCK);
455 /* Now send a break to none message to our client. */
457 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
458 if (break_msg == NULL) {
459 exit_server("Could not talloc break_msg\n");
462 /* Need to wait before sending a break message if we sent ourselves this message. */
463 if (procid_to_pid(&src) == sys_getpid()) {
464 wait_before_sending_break();
467 /* Save the server smb signing state. */
468 sign_state = srv_oplock_set_signing(False);
471 if (!send_smb(smbd_server_fd(), break_msg)) {
472 exit_server("oplock_break: send_smb failed.");
475 /* Restore the sign state to what it was. */
476 srv_oplock_set_signing(sign_state);
478 talloc_free(break_msg);
480 /* Async level2 request, don't send a reply, just remove the oplock. */
484 /*******************************************************************
485 This handles the generic oplock break message from another smbd.
486 *******************************************************************/
488 static void process_oplock_break_message(int msg_type, struct process_id src,
489 void *buf, size_t len)
491 struct share_mode_entry msg;
494 BOOL break_to_level2 = False;
498 DEBUG(0, ("Got NULL buffer\n"));
502 if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
503 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
507 /* De-linearize incoming message. */
508 message_to_share_mode_entry(&msg, buf);
510 DEBUG(10, ("Got oplock break message from pid %d: 0x%x/%.0f/%d\n",
511 (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
512 (int)msg.share_file_id));
514 fsp = initial_break_processing(msg.dev, msg.inode,
518 /* a We hit race here. Break messages are sent, and before we
519 * get to process this message, we have closed the file. Reply
520 * with 'ok, oplock broken' */
521 DEBUG(3, ("Did not find fsp\n"));
524 /* We just send the same message back. */
525 message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
526 buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
532 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
533 /* Remember we have to inform the requesting PID when the
536 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
537 &fsp->pending_break_messages,
538 &fsp->num_pending_break_messages);
542 if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
543 !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
544 DEBUG(3, ("Already downgraded oplock on 0x%x/%.0f: %s\n",
545 (unsigned int)fsp->dev, (double)fsp->inode,
549 /* We just send the same message back. */
550 message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
551 buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
557 if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
558 !koplocks && /* NOTE: we force levelII off for kernel oplocks -
559 * this will change when it is supported */
560 lp_level2_oplocks(SNUM(fsp->conn))) {
561 break_to_level2 = True;
564 break_msg = new_break_smb_message(NULL, fsp, break_to_level2 ?
565 OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
566 if (break_msg == NULL) {
567 exit_server("Could not talloc break_msg\n");
570 /* Need to wait before sending a break message if we sent ourselves this message. */
571 if (procid_to_pid(&src) == sys_getpid()) {
572 wait_before_sending_break();
575 /* Save the server smb signing state. */
576 sign_state = srv_oplock_set_signing(False);
579 if (!send_smb(smbd_server_fd(), break_msg)) {
580 exit_server("oplock_break: send_smb failed.");
583 /* Restore the sign state to what it was. */
584 srv_oplock_set_signing(sign_state);
586 talloc_free(break_msg);
588 fsp->sent_oplock_break = break_to_level2 ? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
591 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
592 &fsp->pending_break_messages,
593 &fsp->num_pending_break_messages);
595 add_oplock_timeout_handler(fsp);
598 /*******************************************************************
599 This handles the kernel oplock break message.
600 *******************************************************************/
602 static void process_kernel_oplock_break(int msg_type, struct process_id src,
603 void *buf, size_t len)
607 unsigned long file_id;
613 DEBUG(0, ("Got NULL buffer\n"));
617 if (len != MSG_SMB_KERNEL_BREAK_SIZE) {
618 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
622 /* Pull the data from the message. */
623 dev = DEV_T_VAL(buf, 0);
624 inode = INO_T_VAL(buf, 8);
625 file_id = (unsigned long)IVAL(buf, 16);
627 DEBUG(10, ("Got kernel oplock break message from pid %d: 0x%x/%.0f/%u\n",
628 (int)procid_to_pid(&src), (unsigned int)dev, (double)inode,
629 (unsigned int)file_id));
631 fsp = initial_break_processing(dev, inode, file_id);
634 DEBUG(3, ("Got a kernel oplock break message for a file "
635 "I don't know about\n"));
639 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
640 /* This is ok, kernel oplocks come in completely async */
641 DEBUG(3, ("Got a kernel oplock request while waiting for a "
646 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
647 if (break_msg == NULL) {
648 exit_server("Could not talloc break_msg\n");
651 /* Save the server smb signing state. */
652 sign_state = srv_oplock_set_signing(False);
655 if (!send_smb(smbd_server_fd(), break_msg)) {
656 exit_server("oplock_break: send_smb failed.");
659 /* Restore the sign state to what it was. */
660 srv_oplock_set_signing(sign_state);
662 talloc_free(break_msg);
664 fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
666 add_oplock_timeout_handler(fsp);
669 void reply_to_oplock_break_requests(files_struct *fsp)
674 for (i=0; i<fsp->num_pending_break_messages; i++) {
675 struct share_mode_entry *e = &fsp->pending_break_messages[i];
676 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
678 share_mode_entry_to_message(msg, e);
680 message_send_pid(e->pid, MSG_SMB_BREAK_RESPONSE,
681 msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
685 SAFE_FREE(fsp->pending_break_messages);
686 fsp->num_pending_break_messages = 0;
687 if (fsp->oplock_timeout != NULL) {
688 /* Remove the timed event handler. */
689 talloc_free(fsp->oplock_timeout);
690 fsp->oplock_timeout = NULL;
695 static void process_oplock_break_response(int msg_type, struct process_id src,
696 void *buf, size_t len)
698 struct share_mode_entry msg;
701 DEBUG(0, ("Got NULL buffer\n"));
705 if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
706 DEBUG(0, ("Got invalid msg len %u\n", (unsigned int)len));
710 /* De-linearize incoming message. */
711 message_to_share_mode_entry(&msg, buf);
713 DEBUG(10, ("Got oplock break response from pid %d: 0x%x/%.0f/%u mid %u\n",
714 (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
715 (unsigned int)msg.share_file_id, (unsigned int)msg.op_mid));
717 /* Here's the hack from open.c, store the mid in the 'port' field */
718 schedule_deferred_open_smb_message(msg.op_mid);
721 static void process_open_retry_message(int msg_type, struct process_id src,
722 void *buf, size_t len)
724 struct share_mode_entry msg;
727 DEBUG(0, ("Got NULL buffer\n"));
731 if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
732 DEBUG(0, ("Got invalid msg len %d\n", (int)len));
736 /* De-linearize incoming message. */
737 message_to_share_mode_entry(&msg, buf);
739 DEBUG(10, ("Got open retry msg from pid %d: 0x%x/%.0f mid %u\n",
740 (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
741 (unsigned int)msg.op_mid));
743 schedule_deferred_open_smb_message(msg.op_mid);
746 /****************************************************************************
747 This function is called on any file modification or lock request. If a file
748 is level 2 oplocked then it must tell all other level 2 holders to break to
750 ****************************************************************************/
752 void release_level_2_oplocks_on_change(files_struct *fsp)
755 struct share_mode_lock *lck;
758 * If this file is level II oplocked then we need
759 * to grab the shared memory lock and inform all
760 * other files with a level II lock that they need
761 * to flush their read caches. We keep the lock over
762 * the shared memory area whilst doing this.
765 if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
768 lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL);
770 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
771 "share mode entry for file %s.\n", fsp->fsp_name ));
774 DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n",
775 lck->num_share_modes ));
777 for(i = 0; i < lck->num_share_modes; i++) {
778 struct share_mode_entry *share_entry = &lck->share_modes[i];
779 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
781 if (!is_valid_share_mode_entry(share_entry)) {
786 * As there could have been multiple writes waiting at the
787 * lock_share_entry gate we may not be the first to
788 * enter. Hence the state of the op_types in the share mode
789 * entries may be partly NO_OPLOCK and partly LEVEL_II or FAKE_LEVEL_II
790 * oplock. It will do no harm to re-send break messages to
791 * those smbd's that are still waiting their turn to remove
792 * their LEVEL_II state, and also no harm to ignore existing
793 * NO_OPLOCK states. JRA.
796 DEBUG(10,("release_level_2_oplocks_on_change: "
797 "share_entry[%i]->op_type == %d\n",
798 i, share_entry->op_type ));
800 if (share_entry->op_type == NO_OPLOCK) {
805 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
806 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
807 "share mode entry %d is an exlusive "
813 share_mode_entry_to_message(msg, share_entry);
816 message_send_pid(share_entry->pid, MSG_SMB_ASYNC_LEVEL2_BREAK,
817 msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
821 /* We let the message receivers handle removing the oplock state
822 in the share mode lock db. */
827 /****************************************************************************
828 Linearize a share mode entry struct to an internal oplock break message.
829 ****************************************************************************/
831 void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
833 SIVAL(msg,0,(uint32)e->pid.pid);
834 SSVAL(msg,4,e->op_mid);
835 SSVAL(msg,6,e->op_type);
836 SIVAL(msg,8,e->access_mask);
837 SIVAL(msg,12,e->share_access);
838 SIVAL(msg,16,e->private_options);
839 SIVAL(msg,20,(uint32)e->time.tv_sec);
840 SIVAL(msg,24,(uint32)e->time.tv_usec);
841 SDEV_T_VAL(msg,28,e->dev);
842 SINO_T_VAL(msg,36,e->inode);
843 SIVAL(msg,44,e->share_file_id);
846 /****************************************************************************
847 De-linearize an internal oplock break message to a share mode entry struct.
848 ****************************************************************************/
850 void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
852 e->pid.pid = (pid_t)IVAL(msg,0);
853 e->op_mid = SVAL(msg,4);
854 e->op_type = SVAL(msg,6);
855 e->access_mask = IVAL(msg,8);
856 e->share_access = IVAL(msg,12);
857 e->private_options = IVAL(msg,16);
858 e->time.tv_sec = (time_t)IVAL(msg,20);
859 e->time.tv_usec = (int)IVAL(msg,24);
860 e->dev = DEV_T_VAL(msg,28);
861 e->inode = INO_T_VAL(msg,36);
862 e->share_file_id = (unsigned long)IVAL(msg,44);
865 /****************************************************************************
866 Setup oplocks for this process.
867 ****************************************************************************/
869 BOOL init_oplocks(void)
871 DEBUG(3,("open_oplock_ipc: initializing messages.\n"));
873 message_register(MSG_SMB_BREAK_REQUEST,
874 process_oplock_break_message);
875 message_register(MSG_SMB_ASYNC_LEVEL2_BREAK,
876 process_oplock_async_level2_break_message);
877 message_register(MSG_SMB_BREAK_RESPONSE,
878 process_oplock_break_response);
879 message_register(MSG_SMB_KERNEL_BREAK,
880 process_kernel_oplock_break);
881 message_register(MSG_SMB_OPEN_RETRY,
882 process_open_retry_message);
884 if (lp_kernel_oplocks()) {
885 #if HAVE_KERNEL_OPLOCKS_IRIX
886 koplocks = irix_init_kernel_oplocks();
887 #elif HAVE_KERNEL_OPLOCKS_LINUX
888 koplocks = linux_init_kernel_oplocks();