summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2017-03-14 13:23:13 -0700
committerRalph Boehme <slow@samba.org>2017-03-15 16:14:08 +0100
commit125c78ad0b8f9caaef1ba2f1aeb5ec593375fccd (patch)
treed56dbd331fee864d279821c4df48d2a632413d16 /source3/locking
parentb59f5b15b27c0ca93817de4c8de910c9d7d895af (diff)
downloadsamba-125c78ad0b8f9caaef1ba2f1aeb5ec593375fccd.tar.gz
s3: locking: Move two leases functions into a new file.
map_oplock_to_lease_type(), fsp_lease_type(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=12628 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/leases_util.c55
-rw-r--r--source3/locking/proto.h4
2 files changed, 59 insertions, 0 deletions
diff --git a/source3/locking/leases_util.c b/source3/locking/leases_util.c
new file mode 100644
index 00000000000..cb307c88d36
--- /dev/null
+++ b/source3/locking/leases_util.c
@@ -0,0 +1,55 @@
+/*
+ Unix SMB/CIFS implementation.
+ Lease utility functions
+
+ Copyright (C) Jeremy Allison 2017.
+ Copyright (C) Stefan (metze) Metzmacher 2017.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#define DBGC_CLASS DBGC_LOCKING
+#include "includes.h"
+#include "../librpc/gen_ndr/open_files.h"
+#include "locking/proto.h"
+
+uint32_t map_oplock_to_lease_type(uint16_t op_type)
+{
+ uint32_t ret;
+
+ switch(op_type) {
+ case BATCH_OPLOCK:
+ case BATCH_OPLOCK|EXCLUSIVE_OPLOCK:
+ ret = SMB2_LEASE_READ|SMB2_LEASE_WRITE|SMB2_LEASE_HANDLE;
+ break;
+ case EXCLUSIVE_OPLOCK:
+ ret = SMB2_LEASE_READ|SMB2_LEASE_WRITE;
+ break;
+ case LEVEL_II_OPLOCK:
+ ret = SMB2_LEASE_READ;
+ break;
+ default:
+ ret = SMB2_LEASE_NONE;
+ break;
+ }
+ return ret;
+}
+
+uint32_t fsp_lease_type(struct files_struct *fsp)
+{
+ if (fsp->oplock_type == LEASE_OPLOCK) {
+ return fsp->lease->lease.lease_state;
+ }
+ return map_oplock_to_lease_type(fsp->oplock_type);
+}
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index 13499cfbf41..17cb1cdf86b 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -248,4 +248,8 @@ bool release_posix_lock_posix_flavour(files_struct *fsp,
const struct lock_struct *plocks,
int num_locks);
+/* The following definitions come from locking/leases_util.c */
+uint32_t map_oplock_to_lease_type(uint16_t op_type);
+uint32_t fsp_lease_type(struct files_struct *fsp);
+
#endif /* _LOCKING_PROTO_H_ */