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, see <http://www.gnu.org/licenses/>.
22 #define DBGC_CLASS DBGC_LOCKING
24 #include "smbd/globals.h"
26 /****************************************************************************
27 Get the number of current exclusive oplocks.
28 ****************************************************************************/
30 int32 get_number_of_exclusive_open_oplocks(void)
32 return exclusive_oplocks_open;
36 * helper function used by the kernel oplock backends to post the break message
38 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp)
40 uint8_t msg[MSG_SMB_KERNEL_BREAK_SIZE];
42 /* Put the kernel break info into the message. */
43 push_file_id_16((char *)msg, &fsp->file_id);
44 SIVAL(msg,16,fsp->fh->gen_id);
46 /* Don't need to be root here as we're only ever
47 sending to ourselves. */
49 messaging_send_buf(msg_ctx, procid_self(),
51 msg, MSG_SMB_KERNEL_BREAK_SIZE);
54 /****************************************************************************
55 Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
56 disabled (just sets flags). Returns True if oplock set.
57 ****************************************************************************/
59 bool set_file_oplock(files_struct *fsp, int oplock_type)
61 if ((fsp->oplock_type != NO_OPLOCK) &&
62 (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
64 !koplocks->ops->set_oplock(koplocks, fsp, oplock_type)) {
68 fsp->oplock_type = oplock_type;
69 fsp->sent_oplock_break = NO_BREAK_SENT;
70 if (oplock_type == LEVEL_II_OPLOCK) {
71 level_II_oplocks_open++;
72 } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
73 exclusive_oplocks_open++;
76 DEBUG(5,("set_file_oplock: granted oplock on file %s, %s/%lu, "
77 "tv_sec = %x, tv_usec = %x\n",
78 fsp->fsp_name, file_id_string_tos(&fsp->file_id),
79 fsp->fh->gen_id, (int)fsp->open_time.tv_sec,
80 (int)fsp->open_time.tv_usec ));
85 /****************************************************************************
86 Attempt to release an oplock on a file. Decrements oplock count.
87 ****************************************************************************/
89 void release_file_oplock(files_struct *fsp)
91 if ((fsp->oplock_type != NO_OPLOCK) &&
92 (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
94 koplocks->ops->release_oplock(koplocks, fsp);
97 if (fsp->oplock_type == LEVEL_II_OPLOCK) {
98 level_II_oplocks_open--;
99 } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
100 exclusive_oplocks_open--;
103 SMB_ASSERT(exclusive_oplocks_open>=0);
104 SMB_ASSERT(level_II_oplocks_open>=0);
106 if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
107 /* This doesn't matter for close. */
108 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
110 fsp->oplock_type = NO_OPLOCK;
112 fsp->sent_oplock_break = NO_BREAK_SENT;
114 flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
116 TALLOC_FREE(fsp->oplock_timeout);
119 /****************************************************************************
120 Attempt to downgrade an oplock on a file. Doesn't decrement oplock count.
121 ****************************************************************************/
123 static void downgrade_file_oplock(files_struct *fsp)
126 koplocks->ops->release_oplock(koplocks, fsp);
128 fsp->oplock_type = LEVEL_II_OPLOCK;
129 exclusive_oplocks_open--;
130 level_II_oplocks_open++;
131 fsp->sent_oplock_break = NO_BREAK_SENT;
134 /****************************************************************************
135 Remove a file oplock. Copes with level II and exclusive.
136 Locks then unlocks the share mode lock. Client can decide to go directly
137 to none even if a "break-to-level II" was sent.
138 ****************************************************************************/
140 bool remove_oplock(files_struct *fsp)
143 struct share_mode_lock *lck;
145 /* Remove the oplock flag from the sharemode. */
146 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
149 DEBUG(0,("remove_oplock: failed to lock share entry for "
150 "file %s\n", fsp->fsp_name ));
153 ret = remove_share_oplock(lck, fsp);
155 DEBUG(0,("remove_oplock: failed to remove share oplock for "
156 "file %s fnum %d, %s\n",
157 fsp->fsp_name, fsp->fnum, file_id_string_tos(&fsp->file_id)));
159 release_file_oplock(fsp);
165 * Deal with a reply when a break-to-level II was sent.
167 bool downgrade_oplock(files_struct *fsp)
170 struct share_mode_lock *lck;
172 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
175 DEBUG(0,("downgrade_oplock: failed to lock share entry for "
176 "file %s\n", fsp->fsp_name ));
179 ret = downgrade_share_oplock(lck, fsp);
181 DEBUG(0,("downgrade_oplock: failed to downgrade share oplock "
182 "for file %s fnum %d, file_id %s\n",
183 fsp->fsp_name, fsp->fnum, file_id_string_tos(&fsp->file_id)));
186 downgrade_file_oplock(fsp);
191 /****************************************************************************
192 Set up an oplock break message.
193 ****************************************************************************/
195 static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
196 files_struct *fsp, uint8 cmd)
198 char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
200 if (result == NULL) {
201 DEBUG(0, ("talloc failed\n"));
205 memset(result,'\0',smb_size);
206 srv_set_message(result,8,0,true);
207 SCVAL(result,smb_com,SMBlockingX);
208 SSVAL(result,smb_tid,fsp->conn->cnum);
209 SSVAL(result,smb_pid,0xFFFF);
210 SSVAL(result,smb_uid,0);
211 SSVAL(result,smb_mid,0xFFFF);
212 SCVAL(result,smb_vwv0,0xFF);
213 SSVAL(result,smb_vwv2,fsp->fnum);
214 SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
215 SCVAL(result,smb_vwv3+1,cmd);
219 /****************************************************************************
220 Function to do the waiting before sending a local break.
221 ****************************************************************************/
223 static void wait_before_sending_break(void)
225 long wait_time = (long)lp_oplock_break_wait_time();
228 smb_msleep(wait_time);
232 /****************************************************************************
233 Ensure that we have a valid oplock.
234 ****************************************************************************/
236 static files_struct *initial_break_processing(struct file_id id, unsigned long file_id)
238 files_struct *fsp = NULL;
240 if( DEBUGLVL( 3 ) ) {
241 dbgtext( "initial_break_processing: called for %s/%u\n",
242 file_id_string_tos(&id), (int)file_id);
243 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
244 exclusive_oplocks_open, level_II_oplocks_open );
248 * We need to search the file open table for the
249 * entry containing this dev and inode, and ensure
250 * we have an oplock on it.
253 fsp = file_find_dif(id, file_id);
256 /* The file could have been closed in the meantime - return success. */
257 if( DEBUGLVL( 3 ) ) {
258 dbgtext( "initial_break_processing: cannot find open file with " );
259 dbgtext( "file_id %s gen_id = %lu", file_id_string_tos(&id), file_id);
260 dbgtext( "allowing break to succeed.\n" );
265 /* Ensure we have an oplock on the file */
268 * There is a potential race condition in that an oplock could
269 * have been broken due to another udp request, and yet there are
270 * still oplock break messages being sent in the udp message
271 * queue for this file. So return true if we don't have an oplock,
272 * as we may have just freed it.
275 if(fsp->oplock_type == NO_OPLOCK) {
276 if( DEBUGLVL( 3 ) ) {
277 dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
278 dbgtext( "(file_id = %s gen_id = %lu) has no oplock.\n",
279 file_id_string_tos(&id), fsp->fh->gen_id );
280 dbgtext( "Allowing break to succeed regardless.\n" );
288 static void oplock_timeout_handler(struct event_context *ctx,
289 struct timed_event *te,
293 files_struct *fsp = (files_struct *)private_data;
295 /* Remove the timed event handler. */
296 TALLOC_FREE(fsp->oplock_timeout);
297 DEBUG(0, ("Oplock break failed for file %s -- replying anyway\n", fsp->fsp_name));
298 global_client_failed_oplock_break = True;
300 reply_to_oplock_break_requests(fsp);
303 /*******************************************************************
304 Add a timeout handler waiting for the client reply.
305 *******************************************************************/
307 static void add_oplock_timeout_handler(files_struct *fsp)
309 if (fsp->oplock_timeout != NULL) {
310 DEBUG(0, ("Logic problem -- have an oplock event hanging "
314 fsp->oplock_timeout =
315 event_add_timed(smbd_event_context(), NULL,
316 timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
317 oplock_timeout_handler, fsp);
319 if (fsp->oplock_timeout == NULL) {
320 DEBUG(0, ("Could not add oplock timeout handler\n"));
324 /*******************************************************************
325 This handles the case of a write triggering a break to none
326 message on a level2 oplock.
327 When we get this message we may be in any of three states :
328 NO_OPLOCK, LEVEL_II, FAKE_LEVEL2. We only send a message to
329 the client for LEVEL2.
330 *******************************************************************/
332 static void process_oplock_async_level2_break_message(struct messaging_context *msg_ctx,
335 struct server_id src,
338 struct share_mode_entry msg;
343 if (data->data == NULL) {
344 DEBUG(0, ("Got NULL buffer\n"));
348 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
349 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
353 /* De-linearize incoming message. */
354 message_to_share_mode_entry(&msg, (char *)data->data);
356 DEBUG(10, ("Got oplock async level 2 break message from pid %d: %s/%lu\n",
357 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
359 fsp = initial_break_processing(msg.id, msg.share_file_id);
362 /* We hit a race here. Break messages are sent, and before we
363 * get to process this message, we have closed the file.
364 * No need to reply as this is an async message. */
365 DEBUG(3, ("process_oplock_async_level2_break_message: Did not find fsp, ignoring\n"));
369 if (fsp->oplock_type == NO_OPLOCK) {
370 /* We already got a "break to none" message and we've handled it.
372 DEBUG(3, ("process_oplock_async_level2_break_message: already broken to none, ignoring.\n"));
376 if (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
377 /* Don't tell the client, just downgrade. */
378 DEBUG(3, ("process_oplock_async_level2_break_message: downgrading fake level 2 oplock.\n"));
383 /* Ensure we're really at level2 state. */
384 SMB_ASSERT(fsp->oplock_type == LEVEL_II_OPLOCK);
386 DEBUG(10,("process_oplock_async_level2_break_message: sending break to "
387 "none message for fid %d, file %s\n",
391 /* Now send a break to none message to our client. */
393 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
394 if (break_msg == NULL) {
395 exit_server("Could not talloc break_msg\n");
398 /* Need to wait before sending a break message if we sent ourselves this message. */
399 if (procid_to_pid(&src) == sys_getpid()) {
400 wait_before_sending_break();
403 /* Save the server smb signing state. */
404 sign_state = srv_oplock_set_signing(False);
407 if (!srv_send_smb(smbd_server_fd(),
409 IS_CONN_ENCRYPTED(fsp->conn))) {
410 exit_server_cleanly("oplock_break: srv_send_smb failed.");
413 /* Restore the sign state to what it was. */
414 srv_oplock_set_signing(sign_state);
416 TALLOC_FREE(break_msg);
418 /* Async level2 request, don't send a reply, just remove the oplock. */
422 /*******************************************************************
423 This handles the generic oplock break message from another smbd.
424 *******************************************************************/
426 static void process_oplock_break_message(struct messaging_context *msg_ctx,
429 struct server_id src,
432 struct share_mode_entry msg;
435 bool break_to_level2 = False;
438 if (data->data == NULL) {
439 DEBUG(0, ("Got NULL buffer\n"));
443 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
444 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
448 /* De-linearize incoming message. */
449 message_to_share_mode_entry(&msg, (char *)data->data);
451 DEBUG(10, ("Got oplock break message from pid %d: %s/%lu\n",
452 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
454 fsp = initial_break_processing(msg.id, msg.share_file_id);
457 /* a We hit race here. Break messages are sent, and before we
458 * get to process this message, we have closed the file. Reply
459 * with 'ok, oplock broken' */
460 DEBUG(3, ("Did not find fsp\n"));
462 /* We just send the same message back. */
463 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
465 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
469 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
470 /* Remember we have to inform the requesting PID when the
473 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
474 &fsp->pending_break_messages,
475 &fsp->num_pending_break_messages);
479 if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
480 !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
481 DEBUG(3, ("Already downgraded oplock on %s: %s\n",
482 file_id_string_tos(&fsp->file_id),
484 /* We just send the same message back. */
485 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
487 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
491 if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
492 !(msg.op_type & FORCE_OPLOCK_BREAK_TO_NONE) &&
493 !koplocks && /* NOTE: we force levelII off for kernel oplocks -
494 * this will change when it is supported */
495 lp_level2_oplocks(SNUM(fsp->conn))) {
496 break_to_level2 = True;
499 break_msg = new_break_smb_message(NULL, fsp, break_to_level2 ?
500 OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
501 if (break_msg == NULL) {
502 exit_server("Could not talloc break_msg\n");
505 /* Need to wait before sending a break message if we sent ourselves this message. */
506 if (procid_to_pid(&src) == sys_getpid()) {
507 wait_before_sending_break();
510 /* Save the server smb signing state. */
511 sign_state = srv_oplock_set_signing(False);
514 if (!srv_send_smb(smbd_server_fd(),
516 IS_CONN_ENCRYPTED(fsp->conn))) {
517 exit_server_cleanly("oplock_break: srv_send_smb failed.");
520 /* Restore the sign state to what it was. */
521 srv_oplock_set_signing(sign_state);
523 TALLOC_FREE(break_msg);
525 fsp->sent_oplock_break = break_to_level2 ? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
528 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
529 &fsp->pending_break_messages,
530 &fsp->num_pending_break_messages);
532 add_oplock_timeout_handler(fsp);
535 /*******************************************************************
536 This handles the kernel oplock break message.
537 *******************************************************************/
539 static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
542 struct server_id src,
546 unsigned long file_id;
551 if (data->data == NULL) {
552 DEBUG(0, ("Got NULL buffer\n"));
556 if (data->length != MSG_SMB_KERNEL_BREAK_SIZE) {
557 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
561 /* Pull the data from the message. */
562 pull_file_id_16((char *)data->data, &id);
563 file_id = (unsigned long)IVAL(data->data, 16);
565 DEBUG(10, ("Got kernel oplock break message from pid %d: %s/%u\n",
566 (int)procid_to_pid(&src), file_id_string_tos(&id),
567 (unsigned int)file_id));
569 fsp = initial_break_processing(id, file_id);
572 DEBUG(3, ("Got a kernel oplock break message for a file "
573 "I don't know about\n"));
577 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
578 /* This is ok, kernel oplocks come in completely async */
579 DEBUG(3, ("Got a kernel oplock request while waiting for a "
584 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
585 if (break_msg == NULL) {
586 exit_server("Could not talloc break_msg\n");
589 /* Save the server smb signing state. */
590 sign_state = srv_oplock_set_signing(False);
593 if (!srv_send_smb(smbd_server_fd(),
595 IS_CONN_ENCRYPTED(fsp->conn))) {
596 exit_server_cleanly("oplock_break: srv_send_smb failed.");
599 /* Restore the sign state to what it was. */
600 srv_oplock_set_signing(sign_state);
602 TALLOC_FREE(break_msg);
604 fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
606 add_oplock_timeout_handler(fsp);
609 void reply_to_oplock_break_requests(files_struct *fsp)
613 for (i=0; i<fsp->num_pending_break_messages; i++) {
614 struct share_mode_entry *e = &fsp->pending_break_messages[i];
615 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
617 share_mode_entry_to_message(msg, e);
619 messaging_send_buf(smbd_messaging_context(), e->pid,
620 MSG_SMB_BREAK_RESPONSE,
622 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
625 SAFE_FREE(fsp->pending_break_messages);
626 fsp->num_pending_break_messages = 0;
627 if (fsp->oplock_timeout != NULL) {
628 /* Remove the timed event handler. */
629 TALLOC_FREE(fsp->oplock_timeout);
630 fsp->oplock_timeout = NULL;
635 static void process_oplock_break_response(struct messaging_context *msg_ctx,
638 struct server_id src,
641 struct share_mode_entry msg;
643 if (data->data == NULL) {
644 DEBUG(0, ("Got NULL buffer\n"));
648 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
649 DEBUG(0, ("Got invalid msg len %u\n",
650 (unsigned int)data->length));
654 /* De-linearize incoming message. */
655 message_to_share_mode_entry(&msg, (char *)data->data);
657 DEBUG(10, ("Got oplock break response from pid %d: %s/%lu mid %u\n",
658 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id,
659 (unsigned int)msg.op_mid));
661 /* Here's the hack from open.c, store the mid in the 'port' field */
662 schedule_deferred_open_smb_message(msg.op_mid);
665 static void process_open_retry_message(struct messaging_context *msg_ctx,
668 struct server_id src,
671 struct share_mode_entry msg;
673 if (data->data == NULL) {
674 DEBUG(0, ("Got NULL buffer\n"));
678 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
679 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
683 /* De-linearize incoming message. */
684 message_to_share_mode_entry(&msg, (char *)data->data);
686 DEBUG(10, ("Got open retry msg from pid %d: %s mid %u\n",
687 (int)procid_to_pid(&src), file_id_string_tos(&msg.id),
688 (unsigned int)msg.op_mid));
690 schedule_deferred_open_smb_message(msg.op_mid);
693 /****************************************************************************
694 This function is called on any file modification or lock request. If a file
695 is level 2 oplocked then it must tell all other level 2 holders to break to
697 ****************************************************************************/
699 void release_level_2_oplocks_on_change(files_struct *fsp)
702 struct share_mode_lock *lck;
705 * If this file is level II oplocked then we need
706 * to grab the shared memory lock and inform all
707 * other files with a level II lock that they need
708 * to flush their read caches. We keep the lock over
709 * the shared memory area whilst doing this.
712 if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
715 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
718 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
719 "share mode entry for file %s.\n", fsp->fsp_name ));
723 DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n",
724 lck->num_share_modes ));
726 for(i = 0; i < lck->num_share_modes; i++) {
727 struct share_mode_entry *share_entry = &lck->share_modes[i];
728 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
730 if (!is_valid_share_mode_entry(share_entry)) {
735 * As there could have been multiple writes waiting at the
736 * lock_share_entry gate we may not be the first to
737 * enter. Hence the state of the op_types in the share mode
738 * entries may be partly NO_OPLOCK and partly LEVEL_II or FAKE_LEVEL_II
739 * oplock. It will do no harm to re-send break messages to
740 * those smbd's that are still waiting their turn to remove
741 * their LEVEL_II state, and also no harm to ignore existing
742 * NO_OPLOCK states. JRA.
745 DEBUG(10,("release_level_2_oplocks_on_change: "
746 "share_entry[%i]->op_type == %d\n",
747 i, share_entry->op_type ));
749 if (share_entry->op_type == NO_OPLOCK) {
754 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
755 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
756 "share mode entry %d is an exlusive "
762 share_mode_entry_to_message(msg, share_entry);
765 * Deal with a race condition when breaking level2
766 * oplocks. Don't send all the messages and release
767 * the lock, this allows someone else to come in and
768 * get a level2 lock before any of the messages are
769 * processed, and thus miss getting a break message.
770 * Ensure at least one entry (the one we're breaking)
771 * is processed immediately under the lock and becomes
772 * set as NO_OPLOCK to stop any waiter getting a level2.
776 if (procid_is_me(&share_entry->pid)) {
777 DATA_BLOB blob = data_blob_const(msg,
778 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
779 process_oplock_async_level2_break_message(smbd_messaging_context(),
781 MSG_SMB_ASYNC_LEVEL2_BREAK,
785 messaging_send_buf(smbd_messaging_context(),
787 MSG_SMB_ASYNC_LEVEL2_BREAK,
789 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
793 /* We let the message receivers handle removing the oplock state
794 in the share mode lock db. */
799 /****************************************************************************
800 Linearize a share mode entry struct to an internal oplock break message.
801 ****************************************************************************/
803 void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
805 SIVAL(msg,0,(uint32)e->pid.pid);
806 SSVAL(msg,4,e->op_mid);
807 SSVAL(msg,6,e->op_type);
808 SIVAL(msg,8,e->access_mask);
809 SIVAL(msg,12,e->share_access);
810 SIVAL(msg,16,e->private_options);
811 SIVAL(msg,20,(uint32)e->time.tv_sec);
812 SIVAL(msg,24,(uint32)e->time.tv_usec);
813 push_file_id_16(msg+28, &e->id);
814 SIVAL(msg,44,e->share_file_id);
815 SIVAL(msg,48,e->uid);
816 SSVAL(msg,52,e->flags);
817 #ifdef CLUSTER_SUPPORT
818 SIVAL(msg,54,e->pid.vnn);
822 /****************************************************************************
823 De-linearize an internal oplock break message to a share mode entry struct.
824 ****************************************************************************/
826 void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
828 e->pid.pid = (pid_t)IVAL(msg,0);
829 e->op_mid = SVAL(msg,4);
830 e->op_type = SVAL(msg,6);
831 e->access_mask = IVAL(msg,8);
832 e->share_access = IVAL(msg,12);
833 e->private_options = IVAL(msg,16);
834 e->time.tv_sec = (time_t)IVAL(msg,20);
835 e->time.tv_usec = (int)IVAL(msg,24);
836 pull_file_id_16(msg+28, &e->id);
837 e->share_file_id = (unsigned long)IVAL(msg,44);
838 e->uid = (uint32)IVAL(msg,48);
839 e->flags = (uint16)SVAL(msg,52);
840 #ifdef CLUSTER_SUPPORT
841 e->pid.vnn = IVAL(msg,54);
845 /****************************************************************************
846 Setup oplocks for this process.
847 ****************************************************************************/
849 bool init_oplocks(struct messaging_context *msg_ctx)
851 DEBUG(3,("init_oplocks: initializing messages.\n"));
853 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_REQUEST,
854 process_oplock_break_message);
855 messaging_register(msg_ctx, NULL, MSG_SMB_ASYNC_LEVEL2_BREAK,
856 process_oplock_async_level2_break_message);
857 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_RESPONSE,
858 process_oplock_break_response);
859 messaging_register(msg_ctx, NULL, MSG_SMB_KERNEL_BREAK,
860 process_kernel_oplock_break);
861 messaging_register(msg_ctx, NULL, MSG_SMB_OPEN_RETRY,
862 process_open_retry_message);
864 if (lp_kernel_oplocks()) {
865 #if HAVE_KERNEL_OPLOCKS_IRIX
866 koplocks = irix_init_kernel_oplocks(talloc_autofree_context());
867 #elif HAVE_KERNEL_OPLOCKS_LINUX
868 koplocks = linux_init_kernel_oplocks(talloc_autofree_context());