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;
35 /****************************************************************************
36 Return True if an oplock message is pending.
37 ****************************************************************************/
39 bool oplock_message_waiting(void)
41 if (koplocks && koplocks->ops->msg_waiting(koplocks)) {
48 /****************************************************************************
49 Find out if there are any kernel oplock messages waiting and process them
50 if so. pfds is the fd_set from the main select loop (which contains any
51 kernel oplock fd if that's what the system uses (IRIX). If may be NULL if
52 we're calling this in a shutting down state.
53 ****************************************************************************/
55 void process_kernel_oplocks(struct messaging_context *msg_ctx)
58 * We need to check for kernel oplocks before going into the select
59 * here, as the EINTR generated by the linux kernel oplock may have
60 * already been eaten. JRA.
67 while (koplocks->ops->msg_waiting(koplocks)) {
69 char msg[MSG_SMB_KERNEL_BREAK_SIZE];
71 fsp = koplocks->ops->receive_message(koplocks);
74 DEBUG(3, ("Kernel oplock message announced, but none "
79 /* Put the kernel break info into the message. */
80 push_file_id_16(msg, &fsp->file_id);
81 SIVAL(msg,16,fsp->fh->gen_id);
83 /* Don't need to be root here as we're only ever
84 sending to ourselves. */
86 messaging_send_buf(msg_ctx, procid_self(),
88 (uint8 *)&msg, MSG_SMB_KERNEL_BREAK_SIZE);
92 /****************************************************************************
93 Attempt to set an oplock on a file. Always succeeds if kernel oplocks are
94 disabled (just sets flags). Returns True if oplock set.
95 ****************************************************************************/
97 bool set_file_oplock(files_struct *fsp, int oplock_type)
99 if ((fsp->oplock_type != NO_OPLOCK) &&
100 (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
102 !koplocks->ops->set_oplock(koplocks, fsp, oplock_type)) {
106 fsp->oplock_type = oplock_type;
107 fsp->sent_oplock_break = NO_BREAK_SENT;
108 if (oplock_type == LEVEL_II_OPLOCK) {
109 level_II_oplocks_open++;
110 } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
111 exclusive_oplocks_open++;
114 DEBUG(5,("set_file_oplock: granted oplock on file %s, %s/%lu, "
115 "tv_sec = %x, tv_usec = %x\n",
116 fsp->fsp_name, file_id_string_tos(&fsp->file_id),
117 fsp->fh->gen_id, (int)fsp->open_time.tv_sec,
118 (int)fsp->open_time.tv_usec ));
123 /****************************************************************************
124 Attempt to release an oplock on a file. Decrements oplock count.
125 ****************************************************************************/
127 void release_file_oplock(files_struct *fsp)
129 if ((fsp->oplock_type != NO_OPLOCK) &&
130 (fsp->oplock_type != FAKE_LEVEL_II_OPLOCK) &&
132 koplocks->ops->release_oplock(koplocks, fsp);
135 if (fsp->oplock_type == LEVEL_II_OPLOCK) {
136 level_II_oplocks_open--;
137 } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
138 exclusive_oplocks_open--;
141 SMB_ASSERT(exclusive_oplocks_open>=0);
142 SMB_ASSERT(level_II_oplocks_open>=0);
144 if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
145 /* This doesn't matter for close. */
146 fsp->oplock_type = FAKE_LEVEL_II_OPLOCK;
148 fsp->oplock_type = NO_OPLOCK;
150 fsp->sent_oplock_break = NO_BREAK_SENT;
152 flush_write_cache(fsp, OPLOCK_RELEASE_FLUSH);
154 TALLOC_FREE(fsp->oplock_timeout);
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->ops->release_oplock(koplocks, 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)
181 struct share_mode_lock *lck;
183 /* Remove the oplock flag from the sharemode. */
184 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
187 DEBUG(0,("remove_oplock: failed to lock share entry for "
188 "file %s\n", fsp->fsp_name ));
191 ret = remove_share_oplock(lck, fsp);
193 DEBUG(0,("remove_oplock: failed to remove share oplock for "
194 "file %s fnum %d, %s\n",
195 fsp->fsp_name, fsp->fnum, file_id_string_tos(&fsp->file_id)));
197 release_file_oplock(fsp);
203 * Deal with a reply when a break-to-level II was sent.
205 bool downgrade_oplock(files_struct *fsp)
208 struct share_mode_lock *lck;
210 lck = get_share_mode_lock(talloc_tos(), 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_string_tos(&fsp->file_id)));
224 downgrade_file_oplock(fsp);
229 /****************************************************************************
230 Set up an oplock break message.
231 ****************************************************************************/
233 static char *new_break_smb_message(TALLOC_CTX *mem_ctx,
234 files_struct *fsp, uint8 cmd)
236 char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0);
238 if (result == NULL) {
239 DEBUG(0, ("talloc failed\n"));
243 memset(result,'\0',smb_size);
244 srv_set_message(result,8,0,true);
245 SCVAL(result,smb_com,SMBlockingX);
246 SSVAL(result,smb_tid,fsp->conn->cnum);
247 SSVAL(result,smb_pid,0xFFFF);
248 SSVAL(result,smb_uid,0);
249 SSVAL(result,smb_mid,0xFFFF);
250 SCVAL(result,smb_vwv0,0xFF);
251 SSVAL(result,smb_vwv2,fsp->fnum);
252 SCVAL(result,smb_vwv3,LOCKING_ANDX_OPLOCK_RELEASE);
253 SCVAL(result,smb_vwv3+1,cmd);
257 /****************************************************************************
258 Function to do the waiting before sending a local break.
259 ****************************************************************************/
261 static void wait_before_sending_break(void)
263 long wait_time = (long)lp_oplock_break_wait_time();
266 smb_msleep(wait_time);
270 /****************************************************************************
271 Ensure that we have a valid oplock.
272 ****************************************************************************/
274 static files_struct *initial_break_processing(struct file_id id, unsigned long file_id)
276 files_struct *fsp = NULL;
278 if( DEBUGLVL( 3 ) ) {
279 dbgtext( "initial_break_processing: called for %s/%u\n",
280 file_id_string_tos(&id), (int)file_id);
281 dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
282 exclusive_oplocks_open, level_II_oplocks_open );
286 * We need to search the file open table for the
287 * entry containing this dev and inode, and ensure
288 * we have an oplock on it.
291 fsp = file_find_dif(id, file_id);
294 /* The file could have been closed in the meantime - return success. */
295 if( DEBUGLVL( 3 ) ) {
296 dbgtext( "initial_break_processing: cannot find open file with " );
297 dbgtext( "file_id %s gen_id = %lu", file_id_string_tos(&id), file_id);
298 dbgtext( "allowing break to succeed.\n" );
303 /* Ensure we have an oplock on the file */
306 * There is a potential race condition in that an oplock could
307 * have been broken due to another udp request, and yet there are
308 * still oplock break messages being sent in the udp message
309 * queue for this file. So return true if we don't have an oplock,
310 * as we may have just freed it.
313 if(fsp->oplock_type == NO_OPLOCK) {
314 if( DEBUGLVL( 3 ) ) {
315 dbgtext( "initial_break_processing: file %s ", fsp->fsp_name );
316 dbgtext( "(file_id = %s gen_id = %lu) has no oplock.\n",
317 file_id_string_tos(&id), fsp->fh->gen_id );
318 dbgtext( "Allowing break to succeed regardless.\n" );
326 static void oplock_timeout_handler(struct event_context *ctx,
327 struct timed_event *te,
331 files_struct *fsp = (files_struct *)private_data;
333 /* Remove the timed event handler. */
334 TALLOC_FREE(fsp->oplock_timeout);
335 DEBUG(0, ("Oplock break failed for file %s -- replying anyway\n", fsp->fsp_name));
336 global_client_failed_oplock_break = True;
338 reply_to_oplock_break_requests(fsp);
341 /*******************************************************************
342 Add a timeout handler waiting for the client reply.
343 *******************************************************************/
345 static void add_oplock_timeout_handler(files_struct *fsp)
347 if (fsp->oplock_timeout != NULL) {
348 DEBUG(0, ("Logic problem -- have an oplock event hanging "
352 fsp->oplock_timeout =
353 event_add_timed(smbd_event_context(), NULL,
354 timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
355 oplock_timeout_handler, fsp);
357 if (fsp->oplock_timeout == NULL) {
358 DEBUG(0, ("Could not add oplock timeout handler\n"));
362 /*******************************************************************
363 This handles the case of a write triggering a break to none
364 message on a level2 oplock.
365 When we get this message we may be in any of three states :
366 NO_OPLOCK, LEVEL_II, FAKE_LEVEL2. We only send a message to
367 the client for LEVEL2.
368 *******************************************************************/
370 static void process_oplock_async_level2_break_message(struct messaging_context *msg_ctx,
373 struct server_id src,
376 struct share_mode_entry msg;
381 if (data->data == NULL) {
382 DEBUG(0, ("Got NULL buffer\n"));
386 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
387 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
391 /* De-linearize incoming message. */
392 message_to_share_mode_entry(&msg, (char *)data->data);
394 DEBUG(10, ("Got oplock async level 2 break message from pid %d: %s/%lu\n",
395 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
397 fsp = initial_break_processing(msg.id, msg.share_file_id);
400 /* We hit a race here. Break messages are sent, and before we
401 * get to process this message, we have closed the file.
402 * No need to reply as this is an async message. */
403 DEBUG(3, ("process_oplock_async_level2_break_message: Did not find fsp, ignoring\n"));
407 if (fsp->oplock_type == NO_OPLOCK) {
408 /* We already got a "break to none" message and we've handled it.
410 DEBUG(3, ("process_oplock_async_level2_break_message: already broken to none, ignoring.\n"));
414 if (fsp->oplock_type == FAKE_LEVEL_II_OPLOCK) {
415 /* Don't tell the client, just downgrade. */
416 DEBUG(3, ("process_oplock_async_level2_break_message: downgrading fake level 2 oplock.\n"));
421 /* Ensure we're really at level2 state. */
422 SMB_ASSERT(fsp->oplock_type == LEVEL_II_OPLOCK);
424 DEBUG(10,("process_oplock_async_level2_break_message: sending break to "
425 "none message for fid %d, file %s\n",
429 /* Now send a break to none message to our client. */
431 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
432 if (break_msg == NULL) {
433 exit_server("Could not talloc break_msg\n");
436 /* Need to wait before sending a break message if we sent ourselves this message. */
437 if (procid_to_pid(&src) == sys_getpid()) {
438 wait_before_sending_break();
441 /* Save the server smb signing state. */
442 sign_state = srv_oplock_set_signing(False);
445 if (!srv_send_smb(smbd_server_fd(),
447 IS_CONN_ENCRYPTED(fsp->conn))) {
448 exit_server_cleanly("oplock_break: srv_send_smb failed.");
451 /* Restore the sign state to what it was. */
452 srv_oplock_set_signing(sign_state);
454 TALLOC_FREE(break_msg);
456 /* Async level2 request, don't send a reply, just remove the oplock. */
460 /*******************************************************************
461 This handles the generic oplock break message from another smbd.
462 *******************************************************************/
464 static void process_oplock_break_message(struct messaging_context *msg_ctx,
467 struct server_id src,
470 struct share_mode_entry msg;
473 bool break_to_level2 = False;
476 if (data->data == NULL) {
477 DEBUG(0, ("Got NULL buffer\n"));
481 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
482 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
486 /* De-linearize incoming message. */
487 message_to_share_mode_entry(&msg, (char *)data->data);
489 DEBUG(10, ("Got oplock break message from pid %d: %s/%lu\n",
490 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id));
492 fsp = initial_break_processing(msg.id, msg.share_file_id);
495 /* a We hit race here. Break messages are sent, and before we
496 * get to process this message, we have closed the file. Reply
497 * with 'ok, oplock broken' */
498 DEBUG(3, ("Did not find fsp\n"));
500 /* We just send the same message back. */
501 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
503 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
507 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
508 /* Remember we have to inform the requesting PID when the
511 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
512 &fsp->pending_break_messages,
513 &fsp->num_pending_break_messages);
517 if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
518 !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
519 DEBUG(3, ("Already downgraded oplock on %s: %s\n",
520 file_id_string_tos(&fsp->file_id),
522 /* We just send the same message back. */
523 messaging_send_buf(msg_ctx, src, MSG_SMB_BREAK_RESPONSE,
525 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
529 if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) &&
530 !(msg.op_type & FORCE_OPLOCK_BREAK_TO_NONE) &&
531 !koplocks && /* NOTE: we force levelII off for kernel oplocks -
532 * this will change when it is supported */
533 lp_level2_oplocks(SNUM(fsp->conn))) {
534 break_to_level2 = True;
537 break_msg = new_break_smb_message(NULL, fsp, break_to_level2 ?
538 OPLOCKLEVEL_II : OPLOCKLEVEL_NONE);
539 if (break_msg == NULL) {
540 exit_server("Could not talloc break_msg\n");
543 /* Need to wait before sending a break message if we sent ourselves this message. */
544 if (procid_to_pid(&src) == sys_getpid()) {
545 wait_before_sending_break();
548 /* Save the server smb signing state. */
549 sign_state = srv_oplock_set_signing(False);
552 if (!srv_send_smb(smbd_server_fd(),
554 IS_CONN_ENCRYPTED(fsp->conn))) {
555 exit_server_cleanly("oplock_break: srv_send_smb failed.");
558 /* Restore the sign state to what it was. */
559 srv_oplock_set_signing(sign_state);
561 TALLOC_FREE(break_msg);
563 fsp->sent_oplock_break = break_to_level2 ? LEVEL_II_BREAK_SENT:BREAK_TO_NONE_SENT;
566 ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
567 &fsp->pending_break_messages,
568 &fsp->num_pending_break_messages);
570 add_oplock_timeout_handler(fsp);
573 /*******************************************************************
574 This handles the kernel oplock break message.
575 *******************************************************************/
577 static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
580 struct server_id src,
584 unsigned long file_id;
589 if (data->data == NULL) {
590 DEBUG(0, ("Got NULL buffer\n"));
594 if (data->length != MSG_SMB_KERNEL_BREAK_SIZE) {
595 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
599 /* Pull the data from the message. */
600 pull_file_id_16((char *)data->data, &id);
601 file_id = (unsigned long)IVAL(data->data, 16);
603 DEBUG(10, ("Got kernel oplock break message from pid %d: %s/%u\n",
604 (int)procid_to_pid(&src), file_id_string_tos(&id),
605 (unsigned int)file_id));
607 fsp = initial_break_processing(id, file_id);
610 DEBUG(3, ("Got a kernel oplock break message for a file "
611 "I don't know about\n"));
615 if (fsp->sent_oplock_break != NO_BREAK_SENT) {
616 /* This is ok, kernel oplocks come in completely async */
617 DEBUG(3, ("Got a kernel oplock request while waiting for a "
622 break_msg = new_break_smb_message(NULL, fsp, OPLOCKLEVEL_NONE);
623 if (break_msg == NULL) {
624 exit_server("Could not talloc break_msg\n");
627 /* Save the server smb signing state. */
628 sign_state = srv_oplock_set_signing(False);
631 if (!srv_send_smb(smbd_server_fd(),
633 IS_CONN_ENCRYPTED(fsp->conn))) {
634 exit_server_cleanly("oplock_break: srv_send_smb failed.");
637 /* Restore the sign state to what it was. */
638 srv_oplock_set_signing(sign_state);
640 TALLOC_FREE(break_msg);
642 fsp->sent_oplock_break = BREAK_TO_NONE_SENT;
644 add_oplock_timeout_handler(fsp);
647 void reply_to_oplock_break_requests(files_struct *fsp)
651 for (i=0; i<fsp->num_pending_break_messages; i++) {
652 struct share_mode_entry *e = &fsp->pending_break_messages[i];
653 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
655 share_mode_entry_to_message(msg, e);
657 messaging_send_buf(smbd_messaging_context(), e->pid,
658 MSG_SMB_BREAK_RESPONSE,
660 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
663 SAFE_FREE(fsp->pending_break_messages);
664 fsp->num_pending_break_messages = 0;
665 if (fsp->oplock_timeout != NULL) {
666 /* Remove the timed event handler. */
667 TALLOC_FREE(fsp->oplock_timeout);
668 fsp->oplock_timeout = NULL;
673 static void process_oplock_break_response(struct messaging_context *msg_ctx,
676 struct server_id src,
679 struct share_mode_entry msg;
681 if (data->data == NULL) {
682 DEBUG(0, ("Got NULL buffer\n"));
686 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
687 DEBUG(0, ("Got invalid msg len %u\n",
688 (unsigned int)data->length));
692 /* De-linearize incoming message. */
693 message_to_share_mode_entry(&msg, (char *)data->data);
695 DEBUG(10, ("Got oplock break response from pid %d: %s/%lu mid %u\n",
696 (int)procid_to_pid(&src), file_id_string_tos(&msg.id), msg.share_file_id,
697 (unsigned int)msg.op_mid));
699 /* Here's the hack from open.c, store the mid in the 'port' field */
700 schedule_deferred_open_smb_message(msg.op_mid);
703 static void process_open_retry_message(struct messaging_context *msg_ctx,
706 struct server_id src,
709 struct share_mode_entry msg;
711 if (data->data == NULL) {
712 DEBUG(0, ("Got NULL buffer\n"));
716 if (data->length != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
717 DEBUG(0, ("Got invalid msg len %d\n", (int)data->length));
721 /* De-linearize incoming message. */
722 message_to_share_mode_entry(&msg, (char *)data->data);
724 DEBUG(10, ("Got open retry msg from pid %d: %s mid %u\n",
725 (int)procid_to_pid(&src), file_id_string_tos(&msg.id),
726 (unsigned int)msg.op_mid));
728 schedule_deferred_open_smb_message(msg.op_mid);
731 /****************************************************************************
732 This function is called on any file modification or lock request. If a file
733 is level 2 oplocked then it must tell all other level 2 holders to break to
735 ****************************************************************************/
737 void release_level_2_oplocks_on_change(files_struct *fsp)
740 struct share_mode_lock *lck;
743 * If this file is level II oplocked then we need
744 * to grab the shared memory lock and inform all
745 * other files with a level II lock that they need
746 * to flush their read caches. We keep the lock over
747 * the shared memory area whilst doing this.
750 if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
753 lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
756 DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
757 "share mode entry for file %s.\n", fsp->fsp_name ));
761 DEBUG(10,("release_level_2_oplocks_on_change: num_share_modes = %d\n",
762 lck->num_share_modes ));
764 for(i = 0; i < lck->num_share_modes; i++) {
765 struct share_mode_entry *share_entry = &lck->share_modes[i];
766 char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
768 if (!is_valid_share_mode_entry(share_entry)) {
773 * As there could have been multiple writes waiting at the
774 * lock_share_entry gate we may not be the first to
775 * enter. Hence the state of the op_types in the share mode
776 * entries may be partly NO_OPLOCK and partly LEVEL_II or FAKE_LEVEL_II
777 * oplock. It will do no harm to re-send break messages to
778 * those smbd's that are still waiting their turn to remove
779 * their LEVEL_II state, and also no harm to ignore existing
780 * NO_OPLOCK states. JRA.
783 DEBUG(10,("release_level_2_oplocks_on_change: "
784 "share_entry[%i]->op_type == %d\n",
785 i, share_entry->op_type ));
787 if (share_entry->op_type == NO_OPLOCK) {
792 if (EXCLUSIVE_OPLOCK_TYPE(share_entry->op_type)) {
793 DEBUG(0,("release_level_2_oplocks_on_change: PANIC. "
794 "share mode entry %d is an exlusive "
800 share_mode_entry_to_message(msg, share_entry);
803 * Deal with a race condition when breaking level2
804 * oplocks. Don't send all the messages and release
805 * the lock, this allows someone else to come in and
806 * get a level2 lock before any of the messages are
807 * processed, and thus miss getting a break message.
808 * Ensure at least one entry (the one we're breaking)
809 * is processed immediately under the lock and becomes
810 * set as NO_OPLOCK to stop any waiter getting a level2.
814 if (procid_is_me(&share_entry->pid)) {
815 DATA_BLOB blob = data_blob_const(msg,
816 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
817 process_oplock_async_level2_break_message(smbd_messaging_context(),
819 MSG_SMB_ASYNC_LEVEL2_BREAK,
823 messaging_send_buf(smbd_messaging_context(),
825 MSG_SMB_ASYNC_LEVEL2_BREAK,
827 MSG_SMB_SHARE_MODE_ENTRY_SIZE);
831 /* We let the message receivers handle removing the oplock state
832 in the share mode lock db. */
837 /****************************************************************************
838 Linearize a share mode entry struct to an internal oplock break message.
839 ****************************************************************************/
841 void share_mode_entry_to_message(char *msg, const struct share_mode_entry *e)
843 SIVAL(msg,0,(uint32)e->pid.pid);
844 SSVAL(msg,4,e->op_mid);
845 SSVAL(msg,6,e->op_type);
846 SIVAL(msg,8,e->access_mask);
847 SIVAL(msg,12,e->share_access);
848 SIVAL(msg,16,e->private_options);
849 SIVAL(msg,20,(uint32)e->time.tv_sec);
850 SIVAL(msg,24,(uint32)e->time.tv_usec);
851 push_file_id_16(msg+28, &e->id);
852 SIVAL(msg,44,e->share_file_id);
853 SIVAL(msg,48,e->uid);
854 SSVAL(msg,52,e->flags);
855 #ifdef CLUSTER_SUPPORT
856 SIVAL(msg,54,e->pid.vnn);
860 /****************************************************************************
861 De-linearize an internal oplock break message to a share mode entry struct.
862 ****************************************************************************/
864 void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
866 e->pid.pid = (pid_t)IVAL(msg,0);
867 e->op_mid = SVAL(msg,4);
868 e->op_type = SVAL(msg,6);
869 e->access_mask = IVAL(msg,8);
870 e->share_access = IVAL(msg,12);
871 e->private_options = IVAL(msg,16);
872 e->time.tv_sec = (time_t)IVAL(msg,20);
873 e->time.tv_usec = (int)IVAL(msg,24);
874 pull_file_id_16(msg+28, &e->id);
875 e->share_file_id = (unsigned long)IVAL(msg,44);
876 e->uid = (uint32)IVAL(msg,48);
877 e->flags = (uint16)SVAL(msg,52);
878 #ifdef CLUSTER_SUPPORT
879 e->pid.vnn = IVAL(msg,54);
883 /****************************************************************************
884 Setup oplocks for this process.
885 ****************************************************************************/
887 bool init_oplocks(struct messaging_context *msg_ctx)
889 DEBUG(3,("init_oplocks: initializing messages.\n"));
891 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_REQUEST,
892 process_oplock_break_message);
893 messaging_register(msg_ctx, NULL, MSG_SMB_ASYNC_LEVEL2_BREAK,
894 process_oplock_async_level2_break_message);
895 messaging_register(msg_ctx, NULL, MSG_SMB_BREAK_RESPONSE,
896 process_oplock_break_response);
897 messaging_register(msg_ctx, NULL, MSG_SMB_KERNEL_BREAK,
898 process_kernel_oplock_break);
899 messaging_register(msg_ctx, NULL, MSG_SMB_OPEN_RETRY,
900 process_open_retry_message);
902 if (lp_kernel_oplocks()) {
903 #if HAVE_KERNEL_OPLOCKS_IRIX
904 koplocks = irix_init_kernel_oplocks(talloc_autofree_context());
905 #elif HAVE_KERNEL_OPLOCKS_LINUX
906 koplocks = linux_init_kernel_oplocks(talloc_autofree_context());