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 3 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.
23 #define DBGC_CLASS DBGC_LOCKING
26 /* Current number of oplocks we have outstanding. */
27 static int32 exclusive_oplocks_open = 0;
28 static int32 level_II_oplocks_open = 0;
29 BOOL global_client_failed_oplock_break = False;
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(struct messaging_context *msg_ctx, 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 push_file_id_16(msg, &fsp->file_id);
91 SIVAL(msg,16,fsp->fh->gen_id);
93 /* Don't need to be root here as we're only ever
94 sending to ourselves. */
96 messaging_send_buf(msg_ctx, procid_self(),
98 (uint8 *)&msg, MSG_SMB_KERNEL_BREAK_SIZE);
102 /****************************************************************************
103 Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
104 disabled (just sets flags). Returns True if oplock set.
105 ****************************************************************************/
107 BOOL set_file_oplock(files_struct *fsp, int oplock_type)
109 if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) {
113 fsp->oplock_type = oplock_type;
114 fsp->sent_oplock_break = NO_BREAK_SENT;
115 if (oplock_type == LEVEL_II_OPLOCK) {
116 level_II_oplocks_open++;
118 exclusive_oplocks_open++;
121 DEBUG(5,("set_file_oplock: granted oplock on file %s, %s/%lu, "
122 "tv_sec = %x, tv_usec = %x\n",
123 fsp->fsp_name, file_id_static_string(&fsp->file_id),
124 fsp->fh->gen_id, (int)fsp->open_time.tv_sec,
125 (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);
156 TALLOC_FREE(fsp->oplock_timeout);
159 /****************************************************************************
160 Attempt to downgrade an oplock on a file. Doesn't decrement oplock count.
161 ****************************************************************************/
163 static void downgrade_file_oplock(files_struct *fsp)
166 koplocks->release_oplock(fsp);
168 fsp->oplock_type = LEVEL_II_OPLOCK;
169 exclusive_oplocks_open--;
170 level_II_oplocks_open++;
171 fsp->sent_oplock_break = NO_BREAK_SENT;
174 /****************************************************************************
175 Remove a file oplock. Copes with level II and exclusive.
176 Locks then unlocks the share mode lock. Client can decide to go directly
177 to none even if a "break-to-level II" was sent.
178 ****************************************************************************/
180 BOOL remove_oplock(files_struct *fsp)
183 struct share_mode_lock *lck;
185 /* Remove the oplock flag from the sharemode. */
186 lck = get_share_mode_lock(NULL, fsp->file_id, 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, %s\n",
196 fsp->fsp_name, fsp->fnum, file_id_static_string(&fsp->file_id)));
198 release_file_oplock(fsp);
204 * Deal with a reply when a break-to-level II was sent.
206 BOOL downgrade_oplock(files_struct *fsp)
209 struct share_mode_lock *lck;
211 lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
213 DEBUG(0,("downgrade_oplock: failed to lock share entry for "
214 "file %s\n", fsp->fsp_name ));
217 ret = downgrade_share_oplock(lck, fsp);
219 DEBUG(0,("downgrade_oplock: failed to downgrade share oplock "
220 "for file %s fnum %d, file_id %s\n",
221 fsp->fsp_name, fsp->fnum, file_id_static_string(&fsp->file_id)));
224 downgrade_file_oplock(fsp);
229 /****************************************************************************
230 Return the fd (if any) used for receiving oplock notifications.
231 ****************************************************************************/
233 int oplock_notify_fd(void)
236 return koplocks->notification_fd;
242 /****************************************************************************
243 Set up an oplock break message.
244 ****************************************************************************/
246 static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
247 files_struct *fsp, uint8 cmd)
249 char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
251 if (result == NULL) {
252 DEBUG(0, ("talloc failed\n"));
256 memset(result,'\0',smb_size);
257 set_message(NULL,result,8,0,True);
258 SCVAL(result,smb_com,SMBlockingX);
259 SSVAL(result,smb_tid,fsp->conn->cnum);
260 SSVAL(result,smb_pid,0xFFFF);
261 SSVAL(result,smb_uid,0);
262 SSVAL(result,smb_mid,0xFFFF);
263 SCVAL(result,smb_vwv0,0xFF);
264 SSVAL(result,smb_vwv2,fsp->fnum);
265 SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
266 SCVAL(result,smb_vwv3+1,cmd);
270 /****************************************************************************
271 Function to do the waiting before sending a local break.
272 ****************************************************************************/
274 static void wait_before_sending_break(void)
276 long wait_time = (long)lp_oplock_break_wait_time();
279 smb_msleep(wait_time);
283 /****************************************************************************
284 Ensure that we have a valid oplock.
285 ****************************************************************************/
287 static files_struct *initial_break_processing(struct file_id id, unsigned long file_id)
289 files_struct *fsp = NULL;
291 if( DEBUGLVL( 3 ) ) {
292 dbgtext( "initial_break_processing: called for %s/%u\n",
293 file_id_static_string(&id), (int)file_id);
294 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
295 exclusive_oplocks_open, level_II_oplocks_open );
299 * We need to search the file open table for the
300 * entry containing this dev and inode, and ensure
301 * we have an oplock on it.
304 fsp = file_find_dif(id, file_id);
307 /* The file could have been closed in the meantime - return success. */
308 if( DEBUGLVL( 3 ) ) {
309 dbgtext( "initial_break_processing: cannot find open file with " );
310 dbgtext( "file_id %s gen_id = %lu", file_id_static_string(&id), file_id);
311 dbgtext( "allowing break to succeed.\n" );
316 /* Ensure we have an oplock on the file */
319 * There is a potential race condition in that an oplock could
320 * have been broken due to another udp request, and yet there are
321 * still oplock break messages being sent in the udp message
322 * queue for this file. So return true if we don't have an oplock,
323 * as we may have just freed it.
326 if(fsp->oplock_type == NO_OPLOCK) {
327 if( DEBUGLVL( 3 ) ) {
328 dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
329 dbgtext( "(file_id = %s gen_id = %lu) has no oplock.\n",
330 file_id_static_string(&id), fsp->fh->gen_id );
331 dbgtext( "Allowing break to succeed regardless.\n" );
339 static void oplock_timeout_handler(struct event_context *ctx,
340 struct timed_event *te,
341 const struct timeval *now,
344 files_struct *fsp = (files_struct *)private_data;
346 /* Remove the timed event handler. */
347 TALLOC_FREE(fsp->oplock_timeout);
348 DEBUG(0, ("Oplock break failed for file %s -- replying anyway\n", fsp->fsp_name));
349 global_client_failed_oplock_break = True;
351 reply_to_oplock_break_requests(fsp);
354 /*******************************************************************
355 Add a timeout handler waiting for the client reply.
356 *******************************************************************/
358 static void add_oplock_timeout_handler(files_struct *fsp)
360 if (fsp->oplock_timeout != NULL) {
361 DEBUG(0, ("Logic problem -- have an oplock event hanging "
365 fsp->oplock_timeout =
366 event_add_timed(smbd_event_context(), NULL,
367 timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
368 "oplock_timeout_handler",
369 oplock_timeout_handler, fsp);
371 if (fsp->oplock_timeout == NULL) {
372 DEBUG(0, ("Could not add oplock timeout handler\n"));
376 /*******************************************************************
377 This handles the case of a write triggering a break to none
378 message on a level2 oplock.
379 When we get this message we may be in any of three states :
380 NO_OPLOCK, LEVEL_II, FAKE_LEVEL2. We only send a message to
381 the client for LEVEL2.
382 *******************************************************************/
384 static void process_oplock_async_level2_break_message(struct messaging_context *msg_ctx,
387 struct server_id src,
390 struct share_mode_entry msg;
395 if (data->data == NULL) {
396 DEBUG(0, ("Got NULL buffer\n"));
400 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
401 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
405 /* De-linearize incoming message. */
406 message_to_share_mode_entry(&msg, (char *)data->data);
408 DEBUG(10, ("Got oplock async level 2 break message from pid %d: %s/%lu\n",
409 (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id));
411 fsp = initial_break_processing(msg.id, msg.share_file_id);
414 /* We hit a race here. Break messages are sent, and before we
415 * get to process this message, we have closed the file.
416 * No need to reply as this is an async message. */
417 DEBUG(3, ("process_oplock_async_level2_break_message: Did not find fsp, ignoring\n"));
421 if (fsp->oplock_type == NO_OPLOCK) {
422 /* We already got a "break to none" message and we've handled it.
424 DEBUG(3, ("process_oplock_async_level2_break_message: already broken to none, ignoring.\n"));
428 if (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
429 /* Don't tell the client, just downgrade. */
430 DEBUG(3, ("process_oplock_async_level2_break_message: downgrading fake level 2 oplock.\n"));
435 /* Ensure we're really at level2 state. */
436 SMB_ASSERT(fsp->oplock_type == LEVEL_II_OPLOCK);
438 /* Now send a break to none message to our client. */
440 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
441 if (break_msg == NULL) {
442 exit_server("Could not talloc break_msg\n");
445 /* Need to wait before sending a break message if we sent ourselves this message. */
446 if (procid_to_pid(&src) == sys_getpid()) {
447 wait_before_sending_break();
450 /* Save the server smb signing state. */
451 sign_state = srv_oplock_set_signing(False);
454 if (!send_smb(smbd_server_fd(), break_msg)) {
455 exit_server_cleanly("oplock_break: send_smb failed.");
458 /* Restore the sign state to what it was. */
459 srv_oplock_set_signing(sign_state);
461 TALLOC_FREE(break_msg);
463 /* Async level2 request, don't send a reply, just remove the oplock. */
467 /*******************************************************************
468 This handles the generic oplock break message from another smbd.
469 *******************************************************************/
471 static void process_oplock_break_message(struct messaging_context *msg_ctx,
474 struct server_id src,
477 struct share_mode_entry msg;
480 BOOL break_to_level2 = False;
483 if (data->data == NULL) {
484 DEBUG(0, ("Got NULL buffer\n"));
488 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
489 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
493 /* De-linearize incoming message. */
494 message_to_share_mode_entry(&msg, (char *)data->data);
496 DEBUG(10, ("Got oplock break message from pid %d: %s/%lu\n",
497 (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id));
499 fsp = initial_break_processing(msg.id, msg.share_file_id);
502 /* a We hit race here. Break messages are sent, and before we
503 * get to process this message, we have closed the file. Reply
504 * with 'ok, oplock broken' */
505 DEBUG(3, ("Did not find fsp\n"));
507 /* We just send the same message back. */
508 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
510 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
514 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
515 /* Remember we have to inform the requesting PID when the
518 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
519 &fsp->pending_break_messages,
520 &fsp->num_pending_break_messages);
524 if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
525 !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
526 DEBUG(3, ("Already downgraded oplock on %s: %s\n",
527 file_id_static_string(&fsp->file_id),
529 /* We just send the same message back. */
530 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
532 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
536 if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
537 !(msg.op_type & FORCE_OPLOCK_BREAK_TO_NONE) &&
538 !koplocks && /* NOTE: we force levelII off for kernel oplocks -
539 * this will change when it is supported */
540 lp_level2_oplocks(SNUM(fsp->conn))) {
541 break_to_level2 = True;
544 break_msg = new_break_smb_message(NULL, fsp, break_to_level2 ?
545 OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
546 if (break_msg == NULL) {
547 exit_server("Could not talloc break_msg\n");
550 /* Need to wait before sending a break message if we sent ourselves this message. */
551 if (procid_to_pid(&src) == sys_getpid()) {
552 wait_before_sending_break();
555 /* Save the server smb signing state. */
556 sign_state = srv_oplock_set_signing(False);
559 if (!send_smb(smbd_server_fd(), break_msg)) {
560 exit_server_cleanly("oplock_break: send_smb failed.");
563 /* Restore the sign state to what it was. */
564 srv_oplock_set_signing(sign_state);
566 TALLOC_FREE(break_msg);
568 fsp->sent_oplock_break = break_to_level2 ? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
571 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
572 &fsp->pending_break_messages,
573 &fsp->num_pending_break_messages);
575 add_oplock_timeout_handler(fsp);
578 /*******************************************************************
579 This handles the kernel oplock break message.
580 *******************************************************************/
582 static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
585 struct server_id src,
589 unsigned long file_id;
594 if (data->data == NULL) {
595 DEBUG(0, ("Got NULL buffer\n"));
599 if (data->length != MSG_SMB_KERNEL_BREAK_SIZE) {
600 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
604 /* Pull the data from the message. */
605 pull_file_id_16((char *)data->data, &id);
606 file_id = (unsigned long)IVAL(data->data, 16);
608 DEBUG(10, ("Got kernel oplock break message from pid %d: %s/%u\n",
609 (int)procid_to_pid(&src), file_id_static_string(&id),
610 (unsigned int)file_id));
612 fsp = initial_break_processing(id, file_id);
615 DEBUG(3, ("Got a kernel oplock break message for a file "
616 "I don't know about\n"));
620 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
621 /* This is ok, kernel oplocks come in completely async */
622 DEBUG(3, ("Got a kernel oplock request while waiting for a "
627 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
628 if (break_msg == NULL) {
629 exit_server("Could not talloc break_msg\n");
632 /* Save the server smb signing state. */
633 sign_state = srv_oplock_set_signing(False);
636 if (!send_smb(smbd_server_fd(), break_msg)) {
637 exit_server_cleanly("oplock_break: send_smb failed.");
640 /* Restore the sign state to what it was. */
641 srv_oplock_set_signing(sign_state);
643 TALLOC_FREE(break_msg);
645 fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
647 add_oplock_timeout_handler(fsp);
650 void reply_to_oplock_break_requests(files_struct *fsp)
654 for (i=0; i<fsp->num_pending_break_messages; i++) {
655 struct share_mode_entry *e = &fsp->pending_break_messages[i];
656 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
658 share_mode_entry_to_message(msg, e);
660 messaging_send_buf(smbd_messaging_context(), e->pid,
661 MSG_SMB_BREAK_RESPONSE,
663 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
666 SAFE_FREE(fsp->pending_break_messages);
667 fsp->num_pending_break_messages = 0;
668 if (fsp->oplock_timeout != NULL) {
669 /* Remove the timed event handler. */
670 TALLOC_FREE(fsp->oplock_timeout);
671 fsp->oplock_timeout = NULL;
676 static void process_oplock_break_response(struct messaging_context *msg_ctx,
679 struct server_id src,
682 struct share_mode_entry msg;
684 if (data->data == NULL) {
685 DEBUG(0, ("Got NULL buffer\n"));
689 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
690 DEBUG(0, ("Got invalid msg len %u\n",
691 (unsigned int)data->length));
695 /* De-linearize incoming message. */
696 message_to_share_mode_entry(&msg, (char *)data->data);
698 DEBUG(10, ("Got oplock break response from pid %d: %s/%lu mid %u\n",
699 (int)procid_to_pid(&src), file_id_static_string(&msg.id), msg.share_file_id,
700 (unsigned int)msg.op_mid));
702 /* Here's the hack from open.c, store the mid in the 'port' field */
703 schedule_deferred_open_smb_message(msg.op_mid);
706 static void process_open_retry_message(struct messaging_context *msg_ctx,
709 struct server_id src,
712 struct share_mode_entry msg;
714 if (data->data == NULL) {
715 DEBUG(0, ("Got NULL buffer\n"));
719 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
720 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
724 /* De-linearize incoming message. */
725 message_to_share_mode_entry(&msg, (char *)data->data);
727 DEBUG(10, ("Got open retry msg from pid %d: %s mid %u\n",
728 (int)procid_to_pid(&src), file_id_static_string(&msg.id),
729 (unsigned int)msg.op_mid));
731 schedule_deferred_open_smb_message(msg.op_mid);
734 /****************************************************************************
735 This function is called on any file modification or lock request. If a file
736 is level 2 oplocked then it must tell all other level 2 holders to break to
738 ****************************************************************************/
740 void release_level_2_oplocks_on_change(files_struct *fsp)
743 struct share_mode_lock *lck;
746 * If this file is level II oplocked then we need
747 * to grab the shared memory lock and inform all
748 * other files with a level II lock that they need
749 * to flush their read caches. We keep the lock over
750 * the shared memory area whilst doing this.
753 if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
756 lck = get_share_mode_lock(NULL, fsp->file_id, NULL, NULL);
758 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
759 "share mode entry for file %s.\n", fsp->fsp_name ));
763 DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n",
764 lck->num_share_modes ));
766 for(i = 0; i < lck->num_share_modes; i++) {
767 struct share_mode_entry *share_entry = &lck->share_modes[i];
768 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
770 if (!is_valid_share_mode_entry(share_entry)) {
775 * As there could have been multiple writes waiting at the
776 * lock_share_entry gate we may not be the first to
777 * enter. Hence the state of the op_types in the share mode
778 * entries may be partly NO_OPLOCK and partly LEVEL_II or FAKE_LEVEL_II
779 * oplock. It will do no harm to re-send break messages to
780 * those smbd's that are still waiting their turn to remove
781 * their LEVEL_II state, and also no harm to ignore existing
782 * NO_OPLOCK states. JRA.
785 DEBUG(10,("release_level_2_oplocks_on_change: "
786 "share_entry[%i]->op_type == %d\n",
787 i, share_entry->op_type ));
789 if (share_entry->op_type == NO_OPLOCK) {
794 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
795 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
796 "share mode entry %d is an exlusive "
802 share_mode_entry_to_message(msg, share_entry);
804 messaging_send_buf(smbd_messaging_context(), share_entry->pid,
805 MSG_SMB_ASYNC_LEVEL2_BREAK,
807 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
810 /* We let the message receivers handle removing the oplock state
811 in the share mode lock db. */
816 /****************************************************************************
817 Linearize a share mode entry struct to an internal oplock break message.
818 ****************************************************************************/
820 void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
822 SIVAL(msg,0,(uint32)e->pid.pid);
823 SSVAL(msg,4,e->op_mid);
824 SSVAL(msg,6,e->op_type);
825 SIVAL(msg,8,e->access_mask);
826 SIVAL(msg,12,e->share_access);
827 SIVAL(msg,16,e->private_options);
828 SIVAL(msg,20,(uint32)e->time.tv_sec);
829 SIVAL(msg,24,(uint32)e->time.tv_usec);
830 push_file_id_16(msg+28, &e->id);
831 SIVAL(msg,44,e->share_file_id);
832 SIVAL(msg,48,e->uid);
833 SSVAL(msg,52,e->flags);
834 #ifdef CLUSTER_SUPPORT
835 SIVAL(msg,54,e->pid.vnn);
839 /****************************************************************************
840 De-linearize an internal oplock break message to a share mode entry struct.
841 ****************************************************************************/
843 void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
845 e->pid.pid = (pid_t)IVAL(msg,0);
846 e->op_mid = SVAL(msg,4);
847 e->op_type = SVAL(msg,6);
848 e->access_mask = IVAL(msg,8);
849 e->share_access = IVAL(msg,12);
850 e->private_options = IVAL(msg,16);
851 e->time.tv_sec = (time_t)IVAL(msg,20);
852 e->time.tv_usec = (int)IVAL(msg,24);
853 pull_file_id_16(msg+28, &e->id);
854 e->share_file_id = (unsigned long)IVAL(msg,44);
855 e->uid = (uint32)IVAL(msg,48);
856 e->flags = (uint16)SVAL(msg,52);
857 #ifdef CLUSTER_SUPPORT
858 e->pid.vnn = IVAL(msg,54);
862 /****************************************************************************
863 Setup oplocks for this process.
864 ****************************************************************************/
866 BOOL init_oplocks(struct messaging_context *msg_ctx)
868 DEBUG(3,("init_oplocks: initializing messages.\n"));
870 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_REQUEST,
871 process_oplock_break_message);
872 messaging_register(msg_ctx, NULL, MSG_SMB_ASYNC_LEVEL2_BREAK,
873 process_oplock_async_level2_break_message);
874 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_RESPONSE,
875 process_oplock_break_response);
876 messaging_register(msg_ctx, NULL, MSG_SMB_KERNEL_BREAK,
877 process_kernel_oplock_break);
878 messaging_register(msg_ctx, NULL, MSG_SMB_OPEN_RETRY,
879 process_open_retry_message);
881 if (lp_kernel_oplocks()) {
882 #if HAVE_KERNEL_OPLOCKS_IRIX
883 koplocks = irix_init_kernel_oplocks();
884 #elif HAVE_KERNEL_OPLOCKS_LINUX
885 koplocks = linux_init_kernel_oplocks();