svn commit: samba r15958 - in branches/SAMBA_3_0/source: include smbd

jra at samba.org jra at samba.org
Tue May 30 18:17:38 GMT 2006


Author: jra
Date: 2006-05-30 18:17:37 +0000 (Tue, 30 May 2006)
New Revision: 15958

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15958

Log:
Make us pass RAW-OPLOCK with kernel oplocks off.
This allows a requestor to set FORCE_OPLOCK_BREAK_TO_NONE
to ensure we don't break to level 2. Fixed a couple
of resource leaks in error paths in open_file_ntcreatex.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/include/smb.h
   branches/SAMBA_3_0/source/smbd/open.c
   branches/SAMBA_3_0/source/smbd/oplock.c
   branches/SAMBA_3_0/source/smbd/trans2.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/smb.h
===================================================================
--- branches/SAMBA_3_0/source/include/smb.h	2006-05-30 17:57:35 UTC (rev 15957)
+++ branches/SAMBA_3_0/source/include/smb.h	2006-05-30 18:17:37 UTC (rev 15958)
@@ -1541,19 +1541,26 @@
 
 /*
  * Bits we test with.
+ * Note these must fit into 16-bits.
  */
-                                                                                                                              
+
 #define NO_OPLOCK 0
 #define EXCLUSIVE_OPLOCK 1
 #define BATCH_OPLOCK 2
 #define LEVEL_II_OPLOCK 4
+
+/* The following are Samba-private. */
 #define INTERNAL_OPEN_ONLY 8
 #define FAKE_LEVEL_II_OPLOCK 16	/* Client requested no_oplock, but we have to
 				 * inform potential level2 holders on
 				 * write. */
 #define DEFERRED_OPEN_ENTRY 32
 #define UNUSED_SHARE_MODE_ENTRY 64
+#define FORCE_OPLOCK_BREAK_TO_NONE 128
 
+/* None of the following should ever appear in fsp->oplock_request. */
+#define SAMBA_PRIVATE_OPLOCK_MASK (INTERNAL_OPEN_ONLY|DEFERRED_OPEN_ENTRY|UNUSED_SHARE_MODE_ENTRY|FORCE_OPLOCK_BREAK_TO_NONE)
+
 #define EXCLUSIVE_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)EXCLUSIVE_OPLOCK|(unsigned int)BATCH_OPLOCK))
 #define BATCH_OPLOCK_TYPE(lck) ((lck) & (unsigned int)BATCH_OPLOCK)
 #define LEVEL_II_OPLOCK_TYPE(lck) ((lck) & ((unsigned int)LEVEL_II_OPLOCK|(unsigned int)FAKE_LEVEL_II_OPLOCK))

Modified: branches/SAMBA_3_0/source/smbd/open.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/open.c	2006-05-30 17:57:35 UTC (rev 15957)
+++ branches/SAMBA_3_0/source/smbd/open.c	2006-05-30 18:17:37 UTC (rev 15958)
@@ -611,7 +611,7 @@
 static BOOL delay_for_oplocks(struct share_mode_lock *lck,
 				files_struct *fsp,
 				int pass_number,
-				BOOL internal_only_open)
+				int oplock_request)
 {
 	int i;
 	struct share_mode_entry *exclusive = NULL;
@@ -619,7 +619,7 @@
 	BOOL delay_it = False;
 	BOOL have_level2 = False;
 
-	if (internal_only_open || is_stat_open(fsp->access_mask)) {
+	if ((oplock_request & INTERNAL_OPEN_ONLY) || is_stat_open(fsp->access_mask)) {
 		fsp->oplock_type = NO_OPLOCK;
 		return False;
 	}
@@ -686,8 +686,16 @@
 			   procid_str_static(&exclusive->pid)));
 		exclusive->op_mid = get_current_mid();
 
+		/* Create the message. */
 		share_mode_entry_to_message(msg, exclusive);
 
+		/* Add in the FORCE_OPLOCK_BREAK_TO_NONE bit in the message if set. We don't
+		   want this set in the share mode struct pointed to by lck. */
+
+		if (oplock_request & FORCE_OPLOCK_BREAK_TO_NONE) {
+			SSVAL(msg,6,exclusive->op_type | FORCE_OPLOCK_BREAK_TO_NONE);
+		}
+
 		become_root();
 		ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
 				       msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
@@ -1090,7 +1098,6 @@
 	int flags2=0;
 	BOOL file_existed = VALID_STAT(*psbuf);
 	BOOL def_acl = False;
-	BOOL internal_only_open = False;
 	SMB_DEV_T dev = 0;
 	SMB_INO_T inode = 0;
 	BOOL fsp_open = False;
@@ -1133,11 +1140,6 @@
 		   create_disposition, create_options, unx_mode,
 		   oplock_request));
 
-	if (oplock_request == INTERNAL_OPEN_ONLY) {
-		internal_only_open = True;
-		oplock_request = 0;
-	}
-
 	if ((pml = get_open_deferred_message(mid)) != NULL) {
 		struct deferred_open_record *state =
 			(struct deferred_open_record *)pml->private_data.data;
@@ -1174,7 +1176,8 @@
 	/* ignore any oplock requests if oplocks are disabled */
 	if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break ||
 	    IS_VETO_OPLOCK_PATH(conn, fname)) {
-		oplock_request = 0;
+		/* Mask off everything except the private Samba bits. */
+		oplock_request &= SAMBA_PRIVATE_OPLOCK_MASK;
 	}
 
 	/* this is for OS/2 long file names - say we don't support them */
@@ -1349,7 +1352,8 @@
 	fsp->share_access = share_access;
 	fsp->fh->private_options = create_options;
 	fsp->access_mask = access_mask;
-	fsp->oplock_type = oplock_request;
+	/* Ensure no SAMBA_PRIVATE bits can be set. */
+	fsp->oplock_type = (oplock_request & ~SAMBA_PRIVATE_OPLOCK_MASK);
 
 	if (timeval_is_zero(&request_time)) {
 		request_time = fsp->open_time;
@@ -1364,15 +1368,17 @@
 					fname);
 
 		if (lck == NULL) {
+			file_free_fsp(fsp);
 			DEBUG(0, ("Could not get share mode lock\n"));
 			set_saved_ntstatus(NT_STATUS_SHARING_VIOLATION);
 			return NULL;
 		}
 
 		/* First pass - send break only on batch oplocks. */
-		if (delay_for_oplocks(lck, fsp, 1, internal_only_open)) {
+		if (delay_for_oplocks(lck, fsp, 1, oplock_request)) {
 			schedule_defer_open(lck, request_time);
 			TALLOC_FREE(lck);
+			file_free_fsp(fsp);
 			return NULL;
 		}
 
@@ -1383,9 +1389,10 @@
 		if (NT_STATUS_IS_OK(status)) {
 			/* We might be going to allow this open. Check oplock status again. */
 			/* Second pass - send break for both batch or exclusive oplocks. */
-			if (delay_for_oplocks(lck, fsp, 2, internal_only_open)) {
+			if (delay_for_oplocks(lck, fsp, 2, oplock_request)) {
 				schedule_defer_open(lck, request_time);
 				TALLOC_FREE(lck);
+				file_free_fsp(fsp);
 				return NULL;
 			}
 		}
@@ -1459,7 +1466,7 @@
 			 * cope with the braindead 1 second delay.
 			 */
 
-			if (!internal_only_open &&
+			if (!(oplock_request & INTERNAL_OPEN_ONLY) &&
 			    lp_defer_sharing_violations()) {
 				struct timeval timeout;
 				struct deferred_open_record state;

Modified: branches/SAMBA_3_0/source/smbd/oplock.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/oplock.c	2006-05-30 17:57:35 UTC (rev 15957)
+++ branches/SAMBA_3_0/source/smbd/oplock.c	2006-05-30 18:17:37 UTC (rev 15958)
@@ -540,6 +540,7 @@
 	}
 
 	if ((global_client_caps & CAP_LEVEL_II_OPLOCKS) && 
+	    !(msg.op_type & FORCE_OPLOCK_BREAK_TO_NONE) &&
 	    !koplocks && /* NOTE: we force levelII off for kernel oplocks -
 			  * this will change when it is supported */
 	    lp_level2_oplocks(SNUM(fsp->conn))) {

Modified: branches/SAMBA_3_0/source/smbd/trans2.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/trans2.c	2006-05-30 17:57:35 UTC (rev 15957)
+++ branches/SAMBA_3_0/source/smbd/trans2.c	2006-05-30 18:17:37 UTC (rev 15958)
@@ -4024,7 +4024,7 @@
 									FILE_OPEN,
 									0,
 									FILE_ATTRIBUTE_NORMAL,
-									NO_OPLOCK,
+									FORCE_OPLOCK_BREAK_TO_NONE,
 									NULL);
  
 					if (new_fsp == NULL) {
@@ -4667,7 +4667,7 @@
 						FILE_OPEN,
 						0,
 						FILE_ATTRIBUTE_NORMAL,
-						NO_OPLOCK,
+						FORCE_OPLOCK_BREAK_TO_NONE,
 						NULL);
 	
 			if (new_fsp == NULL) {



More information about the samba-cvs mailing list