xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb_srv_oplock.c (revision e86372a01d2d16a5dd4a64e144ed978ba17fe7dd)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2019 Nexenta by DDN, Inc. All rights reserved.
14  */
15 
16 /*
17  * (SMB1/SMB2) Server-level Oplock support.
18  *
19  * Conceptually, this is a separate layer on top of the
20  * file system (FS) layer oplock code in smb_cmn_oplock.c.
21  * If these layers were more distinct, the FS layer would
22  * need to use call-back functions (installed from here)
23  * to "indicate an oplock break to the server" (see below).
24  * As these layers are all in the same kernel module, the
25  * delivery of these break indications just uses a direct
26  * function call to smb_oplock_ind_break() below.
27  *
28  * This layer is responsible for handling the break indication,
29  * which often requires scheduling a taskq job in the server,
30  * and sending an oplock break mesage to the client using
31  * the appropriate protocol for the open handle affected.
32  *
33  * The details of composing an oplock break message, the
34  * protocol-specific details of requesting an oplock, and
35  * returning that oplock to the client are in the files:
36  *  smb_oplock.c, smb2_oplock.c, smb2_lease.c
37  */
38 
39 #include <smbsrv/smb2_kproto.h>
40 #include <smbsrv/smb_oplock.h>
41 
42 /*
43  * Verify relationship between BREAK_TO_... and CACHE bits,
44  * used when setting the BREAK_TO_... below.
45  */
46 #if BREAK_TO_READ_CACHING != (READ_CACHING << BREAK_SHIFT)
47 #error "BREAK_TO_READ_CACHING"
48 #endif
49 #if BREAK_TO_HANDLE_CACHING != (HANDLE_CACHING << BREAK_SHIFT)
50 #error "BREAK_TO_HANDLE_CACHING"
51 #endif
52 #if BREAK_TO_WRITE_CACHING != (WRITE_CACHING << BREAK_SHIFT)
53 #error "BREAK_TO_WRITE_CACHING"
54 #endif
55 #define	CACHE_RWH (READ_CACHING | WRITE_CACHING | HANDLE_CACHING)
56 
57 /*
58  * This is the timeout used in the thread that sends an
59  * oplock break and waits for the client to respond
60  * before it breaks the oplock locally.
61  */
62 int smb_oplock_timeout_ack = 30000; /* mSec. */
63 
64 /*
65  * This is the timeout used in threads that have just
66  * finished some sort of oplock request and now must
67  * wait for (possibly multiple) breaks to complete.
68  * This value must be at least a couple seconds LONGER
69  * than the ack timeout above so that I/O callers won't
70  * give up waiting before the local ack timeout.
71  */
72 int smb_oplock_timeout_def = 45000; /* mSec. */
73 
74 static void smb_oplock_async_break(void *);
75 static void smb_oplock_hdl_clear(smb_ofile_t *);
76 
77 
78 /*
79  * 2.1.5.17.3 Indicating an Oplock Break to the Server
80  *
81  * The inputs for indicating an oplock break to the server are:
82  *
83  *	BreakingOplockOpen: The Open used to request the oplock
84  *	  that is now breaking.
85  *	 NewOplockLevel: The type of oplock the requested oplock
86  *	  has been broken to.  Valid values are as follows:
87  *		LEVEL_NONE (that is, no oplock)
88  *		LEVEL_TWO
89  *		A combination of one or more of the following flags:
90  *			READ_CACHING
91  *			HANDLE_CACHING
92  *			WRITE_CACHING
93  *	AcknowledgeRequired: A Boolean value; TRUE if the server
94  *	  MUST acknowledge the oplock break, FALSE if not,
95  *	  as specified in section 2.1.5.18.
96  *	OplockCompletionStatus: The NTSTATUS code to return to the server.
97  *
98  * This algorithm simply represents the completion of an oplock request,
99  * as specified in section 2.1.5.17.1 or section 2.1.5.17.2. The server
100  * is expected to associate the return status from this algorithm with
101  * BreakingOplockOpen, which is the Open passed in when it requested
102  * the oplock that is now breaking.
103  *
104  * It is important to note that because several oplocks can be outstanding
105  * in parallel, although this algorithm represents the completion of an
106  * oplock request, it might not result in the completion of the algorithm
107  * that called it. In particular, calling this algorithm will result in
108  * completion of the caller only if BreakingOplockOpen is the same as the
109  * Open with which the calling algorithm was itself called. To mitigate
110  * confusion, each algorithm that refers to this section will specify
111  * whether that algorithm's operation terminates at that point or not.
112  *
113  * The object store MUST return OplockCompletionStatus,
114  * AcknowledgeRequired, and NewOplockLevel to the server (the algorithm is
115  * as specified in section 2.1.5.17.1 and section 2.1.5.17.2).
116  *
117  * Implementation:
118  *
119  * We use two versions of this function:
120  *	smb_oplock_ind_break_in_ack
121  *	smb_oplock_ind_break
122  *
123  * The first is used when we're handling an Oplock Break Ack.
124  * The second is used when other operations cause a break,
125  * generally in one of the smb_oplock_break_... functions.
126  *
127  * Note that these are call-back functions that may be called with the
128  * node ofile list rwlock held and the node oplock mutex entered, so
129  * these should ONLY schedule oplock break work, and MUST NOT attempt
130  * any actions that might require either of those locks.
131  */
132 
133 /*
134  * smb_oplock_ind_break_in_ack
135  *
136  * Variant of smb_oplock_ind_break() for the oplock Ack handler.
137  * When we need to indicate another oplock break from within the
138  * Ack handler (during the Ack. of some previous oplock break)
139  * we need to make sure this new break indication goes out only
140  * AFTER the reply to the current break ack. is sent out.
141  *
142  * In this case, we always have an SR (the break ack) so we can
143  * append the "ind break" work to the current SR and let the
144  * request hander thread do this work after the reply is sent.
145  * Note: this is always an SMB2 or later request, because this
146  * only happens for "granular" oplocks, which are SMB2-only.
147  *
148  * This is mostly the same as smb_oplock_ind_break() except:
149  * - The only CompletionStatus possible is STATUS_CANT_GRANT.
150  * - Instead of taskq_dispatch this appends the new SR to
151  *   the "post work" queue on the current SR.
152  *
153  * Note called with the node ofile list rwlock held and
154  * the oplock mutex entered.
155  */
156 void
157 smb_oplock_ind_break_in_ack(smb_request_t *ack_sr, smb_ofile_t *ofile,
158     uint32_t NewLevel, boolean_t AckRequired)
159 {
160 	smb_request_t *new_sr;
161 
162 	/*
163 	 * This should happen only with SMB2 or later,
164 	 * but in case that ever changes...
165 	 */
166 	if (ack_sr->session->dialect < SMB_VERS_2_BASE) {
167 		smb_oplock_ind_break(ofile, NewLevel,
168 		    AckRequired, STATUS_CANT_GRANT);
169 		return;
170 	}
171 
172 	/*
173 	 * We're going to schedule a request that will have a
174 	 * reference to this ofile. Get the hold first.
175 	 */
176 	if (!smb_ofile_hold_olbrk(ofile)) {
177 		/* It's closing (or whatever).  Nothing to do. */
178 		return;
179 	}
180 
181 	/*
182 	 * When called from Ack processing, we want to use a
183 	 * request on the session doing the ack.  If we can't
184 	 * allocate a request on that session (because it's
185 	 * now disconnecting) just fall-back to the normal
186 	 * oplock break code path which deals with that.
187 	 * Once we have a request on the ack session, that
188 	 * session won't go away until the request is done.
189 	 */
190 	new_sr = smb_request_alloc(ack_sr->session, 0);
191 	if (new_sr == NULL) {
192 		smb_oplock_ind_break(ofile, NewLevel,
193 		    AckRequired, STATUS_CANT_GRANT);
194 		smb_ofile_release(ofile);
195 		return;
196 	}
197 
198 	new_sr->sr_state = SMB_REQ_STATE_SUBMITTED;
199 	new_sr->smb2_async = B_TRUE;
200 	new_sr->user_cr = zone_kcred();
201 	new_sr->fid_ofile = ofile;
202 	if (ofile->f_tree != NULL) {
203 		new_sr->tid_tree = ofile->f_tree;
204 		smb_tree_hold_internal(ofile->f_tree);
205 	}
206 	if (ofile->f_user != NULL) {
207 		new_sr->uid_user = ofile->f_user;
208 		smb_user_hold_internal(ofile->f_user);
209 	}
210 	new_sr->arg.olbrk.NewLevel = NewLevel;
211 	new_sr->arg.olbrk.AckRequired = AckRequired;
212 
213 	/*
214 	 * Using smb2_cmd_code to indicate what to call.
215 	 * work func. will call smb_oplock_send_brk
216 	 */
217 	new_sr->smb2_cmd_code = SMB2_OPLOCK_BREAK;
218 	smb2sr_append_postwork(ack_sr, new_sr);
219 }
220 
221 /*
222  * smb_oplock_ind_break
223  *
224  * This is the function described in [MS-FSA] 2.1.5.17.3
225  * which is called many places in the oplock break code.
226  *
227  * Schedule a request & taskq job to do oplock break work
228  * as requested by the FS-level code (smb_cmn_oplock.c).
229  *
230  * Note called with the node ofile list rwlock held and
231  * the oplock mutex entered.
232  */
233 void
234 smb_oplock_ind_break(smb_ofile_t *ofile, uint32_t NewLevel,
235     boolean_t AckRequired, uint32_t CompletionStatus)
236 {
237 	smb_server_t *sv = ofile->f_server;
238 	smb_request_t *sr = NULL;
239 
240 	/*
241 	 * See notes at smb_oplock_async_break re. CompletionStatus
242 	 * Check for any invalid codes here, so assert happens in
243 	 * the thread passing an unexpected value.
244 	 * The real work happens in a taskq job.
245 	 */
246 	switch (CompletionStatus) {
247 
248 	case NT_STATUS_SUCCESS:
249 	case STATUS_CANT_GRANT:
250 		/* Send break via taskq job. */
251 		break;
252 
253 	case STATUS_NEW_HANDLE:
254 	case NT_STATUS_OPLOCK_HANDLE_CLOSED:
255 		smb_oplock_hdl_clear(ofile);
256 		return;
257 
258 	default:
259 		ASSERT(0);
260 		return;
261 	}
262 
263 	/*
264 	 * We're going to schedule a request that will have a
265 	 * reference to this ofile. Get the hold first.
266 	 */
267 	if (!smb_ofile_hold_olbrk(ofile)) {
268 		/* It's closing (or whatever).  Nothing to do. */
269 		return;
270 	}
271 
272 	/*
273 	 * We need a request allocated on the session that owns
274 	 * this ofile in order to safely send on that session.
275 	 *
276 	 * Note that while we hold a ref. on the ofile, it's
277 	 * f_session will not change.  An ofile in state
278 	 * _ORPHANED will have f_session == NULL, but the
279 	 * f_session won't _change_ while we have a ref,
280 	 * and won't be torn down under our feet.
281 	 * Same for f_tree and f_user
282 	 *
283 	 * If f_session is NULL, or it's in a state that doesn't
284 	 * allow new requests, use the special "server" session.
285 	 */
286 	if (ofile->f_session != NULL)
287 		sr = smb_request_alloc(ofile->f_session, 0);
288 	if (sr == NULL)
289 		sr = smb_request_alloc(sv->sv_session, 0);
290 
291 	sr->sr_state = SMB_REQ_STATE_SUBMITTED;
292 	sr->smb2_async = B_TRUE;
293 	sr->user_cr = zone_kcred();
294 	sr->fid_ofile = ofile;
295 	if (ofile->f_tree != NULL) {
296 		sr->tid_tree = ofile->f_tree;
297 		smb_tree_hold_internal(sr->tid_tree);
298 	}
299 	if (ofile->f_user != NULL) {
300 		sr->uid_user = ofile->f_user;
301 		smb_user_hold_internal(sr->uid_user);
302 	}
303 	sr->arg.olbrk.NewLevel = NewLevel;
304 	sr->arg.olbrk.AckRequired = AckRequired;
305 	sr->smb2_status = CompletionStatus;
306 
307 	(void) taskq_dispatch(
308 	    sv->sv_worker_pool,
309 	    smb_oplock_async_break, sr, TQ_SLEEP);
310 }
311 
312 /*
313  * smb_oplock_async_break
314  *
315  * Called via the taskq to handle an asynchronous oplock break.
316  * We have a hold on the ofile, which will be released in
317  * smb_request_free (via sr->fid_ofile)
318  *
319  * Note we have: sr->uid_user == NULL, sr->tid_tree == NULL.
320  * Nothing called here needs those.
321  *
322  * Note that NewLevel as provided by the FS up-call does NOT
323  * include the GRANULAR flag.  The SMB level is expected to
324  * keep track of how each oplock was acquired (by lease or
325  * traditional oplock request) and put the GRANULAR flag
326  * back into the oplock state when calling down to the
327  * FS-level code.  Also note that the lease break message
328  * carries only the cache flags, not the GRANULAR flag.
329  */
330 static void
331 smb_oplock_async_break(void *arg)
332 {
333 	smb_request_t	*sr = arg;
334 	uint32_t	CompletionStatus;
335 
336 	SMB_REQ_VALID(sr);
337 
338 	CompletionStatus = sr->smb2_status;
339 	sr->smb2_status = NT_STATUS_SUCCESS;
340 
341 	mutex_enter(&sr->sr_mutex);
342 	sr->sr_worker = curthread;
343 	sr->sr_state = SMB_REQ_STATE_ACTIVE;
344 	mutex_exit(&sr->sr_mutex);
345 
346 	/*
347 	 * Note that the CompletionStatus from the FS level
348 	 * (smb_cmn_oplock.c) encodes what kind of action we
349 	 * need to take at the SMB level.
350 	 */
351 	switch (CompletionStatus) {
352 
353 	case STATUS_CANT_GRANT:
354 	case NT_STATUS_SUCCESS:
355 		smb_oplock_send_brk(sr);
356 		break;
357 
358 	default:
359 		/* Checked by caller. */
360 		ASSERT(0);
361 		break;
362 	}
363 
364 	if (sr->dh_nvl_dirty) {
365 		sr->dh_nvl_dirty = B_FALSE;
366 		smb2_dh_update_nvfile(sr);
367 	}
368 
369 	sr->sr_state = SMB_REQ_STATE_COMPLETED;
370 	smb_request_free(sr);
371 }
372 
373 #ifdef DEBUG
374 int smb_oplock_debug_wait = 0;
375 #endif
376 
377 /*
378  * Send an oplock break over the wire, or if we can't,
379  * then process the oplock break locally.
380  *
381  * Note that we have sr->fid_ofile here but all the other
382  * normal sr members may be NULL:  uid_user, tid_tree.
383  * Also sr->session may or may not be the same session as
384  * the ofile came from (ofile->f_session) depending on
385  * whether this is a "live" open or an orphaned DH,
386  * where ofile->f_session will be NULL.
387  *
388  * Given that we don't always have a session, we determine
389  * the oplock type (lease etc) from f_oplock.og_dialect.
390  */
391 void
392 smb_oplock_send_brk(smb_request_t *sr)
393 {
394 	smb_ofile_t	*ofile;
395 	smb_lease_t	*lease;
396 	uint32_t	NewLevel;
397 	boolean_t	AckReq;
398 	uint32_t	status;
399 	int		rc;
400 
401 	ofile = sr->fid_ofile;
402 	NewLevel = sr->arg.olbrk.NewLevel;
403 	AckReq = sr->arg.olbrk.AckRequired;
404 	lease = ofile->f_lease;
405 
406 	/*
407 	 * Build the break message in sr->reply.
408 	 * It's free'd in smb_request_free().
409 	 * Also updates the lease and NewLevel.
410 	 */
411 	sr->reply.max_bytes = MLEN;
412 	if (ofile->f_oplock.og_dialect >= SMB_VERS_2_BASE) {
413 		if (lease != NULL) {
414 			/*
415 			 * Oplock state has changed, so
416 			 * update the epoch.
417 			 */
418 			mutex_enter(&lease->ls_mutex);
419 			lease->ls_epoch++;
420 			mutex_exit(&lease->ls_mutex);
421 
422 			/* Note, needs "old" state in og_state */
423 			smb2_lease_break_notification(sr,
424 			    (NewLevel & CACHE_RWH), AckReq);
425 			NewLevel |= OPLOCK_LEVEL_GRANULAR;
426 		} else {
427 			smb2_oplock_break_notification(sr, NewLevel);
428 		}
429 	} else {
430 		/*
431 		 * SMB1 clients should only get Level II oplocks if they
432 		 * set the capability indicating they know about them.
433 		 */
434 		if (NewLevel == OPLOCK_LEVEL_TWO &&
435 		    ofile->f_oplock.og_dialect < NT_LM_0_12)
436 			NewLevel = OPLOCK_LEVEL_NONE;
437 		smb1_oplock_break_notification(sr, NewLevel);
438 	}
439 
440 	/*
441 	 * Keep track of what we last sent to the client,
442 	 * preserving the GRANULAR flag (if a lease).
443 	 * If we're expecting an ACK, set og_breaking
444 	 * (and maybe lease->ls_breaking) so we can
445 	 * later find the ofile with breaks pending.
446 	 */
447 	if (AckReq) {
448 		uint32_t BreakTo;
449 
450 		if (lease != NULL) {
451 			BreakTo = (NewLevel & CACHE_RWH) << BREAK_SHIFT;
452 			if (BreakTo == 0)
453 				BreakTo = BREAK_TO_NO_CACHING;
454 			lease->ls_breaking = BreakTo;
455 		} else {
456 			if ((NewLevel & LEVEL_TWO_OPLOCK) != 0)
457 				BreakTo = BREAK_TO_TWO;
458 			else
459 				BreakTo = BREAK_TO_NONE;
460 		}
461 		/* Will update og_state in ack. */
462 		ofile->f_oplock.og_breaking = BreakTo;
463 	} else {
464 		if (lease != NULL)
465 			lease->ls_state = NewLevel & CACHE_RWH;
466 		ofile->f_oplock.og_state = NewLevel;
467 
468 		if (ofile->dh_persist) {
469 			smb2_dh_update_oplock(sr, ofile);
470 		}
471 	}
472 
473 	/*
474 	 * Try to send the break message to the client.
475 	 * When we get to multi-channel, this is supposed to
476 	 * try to send on every channel before giving up.
477 	 */
478 	if (sr->session == ofile->f_session)
479 		rc = smb_session_send(sr->session, 0, &sr->reply);
480 	else
481 		rc = ENOTCONN;
482 
483 	if (rc == 0) {
484 		/*
485 		 * OK, we were able to send the break message.
486 		 * If no ack. required, we're done.
487 		 */
488 		if (!AckReq)
489 			return;
490 
491 		/*
492 		 * We're expecting an ACK.  Wait in this thread
493 		 * so we can log clients that don't respond.
494 		 *
495 		 * If debugging, may want to break after a
496 		 * short wait to look into why we might be
497 		 * holding up progress.  (i.e. locks?)
498 		 */
499 #ifdef DEBUG
500 		if (smb_oplock_debug_wait > 0) {
501 			status = smb_oplock_wait_break(ofile->f_node,
502 			    smb_oplock_debug_wait);
503 			if (status == 0)
504 				return;
505 			cmn_err(CE_NOTE, "clnt %s oplock break wait debug",
506 			    sr->session->ip_addr_str);
507 			debug_enter("oplock_wait");
508 		}
509 #endif
510 		status = smb_oplock_wait_break(ofile->f_node,
511 		    smb_oplock_timeout_ack);
512 		if (status == 0)
513 			return;
514 
515 		cmn_err(CE_NOTE, "clnt %s oplock break timeout",
516 		    sr->session->ip_addr_str);
517 		DTRACE_PROBE1(break_timeout, smb_ofile_t, ofile);
518 
519 		/*
520 		 * Will do local ack below.  Note, after timeout,
521 		 * do a break to none or "no caching" regardless
522 		 * of what the passed in cache level was.
523 		 * That means: clear all except GRANULAR.
524 		 */
525 		NewLevel &= OPLOCK_LEVEL_GRANULAR;
526 	} else {
527 		/*
528 		 * We were unable to send the oplock break request.
529 		 * Generally, that means we have no connection to this
530 		 * client right now, and this ofile will have state
531 		 * SMB_OFILE_STATE_ORPHANED.  We either close the handle
532 		 * or break the oplock locally, in which case the client
533 		 * gets the updated oplock state when they reconnect.
534 		 * Decide whether to keep or close.
535 		 *
536 		 * Relevant [MS-SMB2] sections:
537 		 *
538 		 * 3.3.4.6 Object Store Indicates an Oplock Break
539 		 * If Open.Connection is NULL, Open.IsResilient is FALSE,
540 		 * Open.IsDurable is FALSE and Open.IsPersistent is FALSE,
541 		 * the server SHOULD close the Open as specified in...
542 		 *
543 		 * 3.3.4.7 Object Store Indicates a Lease Break
544 		 * If Open.Connection is NULL, the server MUST close the
545 		 * Open as specified in ... for the following cases:
546 		 * - Open.IsResilient is FALSE, Open.IsDurable is FALSE,
547 		 *   and Open.IsPersistent is FALSE.
548 		 * - Lease.BreakToLeaseState does not contain
549 		 *   ...HANDLE_CACHING and Open.IsDurable is TRUE.
550 		 * If Lease.LeaseOpens is empty, (... local ack to "none").
551 		 */
552 
553 		/*
554 		 * See similar logic in smb_dh_should_save
555 		 */
556 		switch (ofile->dh_vers) {
557 		case SMB2_RESILIENT:
558 			break;			/* keep DH */
559 
560 		case SMB2_DURABLE_V2:
561 			if (ofile->dh_persist)
562 				break;		/* keep DH */
563 			/* FALLTHROUGH */
564 		case SMB2_DURABLE_V1:
565 			/* IS durable (v1 or v2) */
566 			if ((NewLevel & (OPLOCK_LEVEL_BATCH |
567 			    OPLOCK_LEVEL_CACHE_HANDLE)) != 0)
568 				break;		/* keep DH */
569 			/* FALLTHROUGH */
570 		case SMB2_NOT_DURABLE:
571 		default:
572 			smb_ofile_close(ofile, 0);
573 			return;
574 		}
575 		/* Keep this ofile (durable handle). */
576 
577 		if (!AckReq) {
578 			/* Nothing more to do. */
579 			return;
580 		}
581 	}
582 
583 	/*
584 	 * We get here after either an oplock break ack timeout,
585 	 * or a send failure for a durable handle type that we
586 	 * preserve rather than just close.  Do local ack.
587 	 */
588 	ofile->f_oplock.og_breaking = 0;
589 	if (lease != NULL)
590 		lease->ls_breaking = 0;
591 
592 	status = smb_oplock_ack_break(sr, ofile, &NewLevel);
593 	if (status == NT_STATUS_OPLOCK_BREAK_IN_PROGRESS) {
594 		/* Not expecting this status return. */
595 		cmn_err(CE_NOTE, "clnt local oplock ack wait?");
596 		(void) smb_oplock_wait_break(ofile->f_node,
597 		    smb_oplock_timeout_ack);
598 		status = 0;
599 	}
600 	if (status != 0) {
601 		cmn_err(CE_NOTE, "clnt local oplock ack, "
602 		    "status=0x%x", status);
603 	}
604 
605 	/* Update og_state as if we heard from the client. */
606 	ofile->f_oplock.og_state = NewLevel;
607 	if (lease != NULL) {
608 		lease->ls_state = NewLevel & CACHE_RWH;
609 	}
610 
611 	if (ofile->dh_persist) {
612 		smb2_dh_update_oplock(sr, ofile);
613 	}
614 }
615 
616 /*
617  * See: NT_STATUS_OPLOCK_HANDLE_CLOSED above,
618  * and: STATUS_NEW_HANDLE
619  *
620  * The FS-level oplock layer calls this to update the
621  * SMB-level state when a handle loses its oplock.
622  */
623 static void
624 smb_oplock_hdl_clear(smb_ofile_t *ofile)
625 {
626 	smb_lease_t *lease = ofile->f_lease;
627 
628 	if (lease != NULL) {
629 		if (lease->ls_oplock_ofile == ofile) {
630 			/* Last close on the lease. */
631 			lease->ls_oplock_ofile = NULL;
632 		}
633 	}
634 	ofile->f_oplock.og_state = 0;
635 	ofile->f_oplock.og_breaking = 0;
636 }
637 
638 /*
639  * Wait up to "timeout" mSec. for the current oplock "breaking" flags
640  * to be cleared (by smb_oplock_ack_break or smb_oplock_break_CLOSE).
641  *
642  * Callers of the above public oplock functions:
643  *	smb_oplock_request()
644  *	smb_oplock_ack_break()
645  *	smb_oplock_break_OPEN() ...
646  * check for return status == NT_STATUS_OPLOCK_BREAK_IN_PROGRESS
647  * and call this function to wait for the break to complete.
648  *
649  * Most callers should use this default timeout, which they get
650  * by passing zero as the timeout arg.  This include places where
651  * we're about to do something that invalidates some cache.
652  */
653 uint32_t
654 smb_oplock_wait_break(smb_node_t *node, int timeout)  /* mSec. */
655 {
656 	smb_oplock_t	*ol;
657 	clock_t		time, rv;
658 	uint32_t	status = 0;
659 
660 	if (timeout == 0)
661 		timeout = smb_oplock_timeout_def;
662 
663 	SMB_NODE_VALID(node);
664 	ol = &node->n_oplock;
665 
666 	mutex_enter(&ol->ol_mutex);
667 	time = MSEC_TO_TICK(timeout) + ddi_get_lbolt();
668 
669 	while ((ol->ol_state & BREAK_ANY) != 0) {
670 		ol->waiters++;
671 		rv = cv_timedwait(&ol->WaitingOpenCV,
672 		    &ol->ol_mutex, time);
673 		ol->waiters--;
674 		if (rv < 0) {
675 			status = NT_STATUS_CANNOT_BREAK_OPLOCK;
676 			break;
677 		}
678 	}
679 
680 	mutex_exit(&ol->ol_mutex);
681 
682 	return (status);
683 }
684