summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-10-28 15:31:46 -0700
committerJeremy Allison <jra@samba.org>2014-12-04 05:45:10 +0100
commitb72fca52defa1fd0f7d10f2811d86bbc7c661f50 (patch)
treec2da897552f5ae95d221f36d26f14fc1b1f899bd
parent7ca8785cae6529fe9b8f5546aaf3c15cca9458cd (diff)
downloadsamba-b72fca52defa1fd0f7d10f2811d86bbc7c661f50.tar.gz
samba-b72fca52defa1fd0f7d10f2811d86bbc7c661f50.tar.xz
samba-b72fca52defa1fd0f7d10f2811d86bbc7c661f50.zip
s3:smbd: add fsp_lease_type() and get_lease_type() helper functions
These convert the oplock state into SMB2_LEASE_ flags. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--source3/smbd/files.c8
-rw-r--r--source3/smbd/oplock.c30
-rw-r--r--source3/smbd/proto.h3
3 files changed, 41 insertions, 0 deletions
diff --git a/source3/smbd/files.c b/source3/smbd/files.c
index 71166288a6..d866d6337c 100644
--- a/source3/smbd/files.c
+++ b/source3/smbd/files.c
@@ -745,3 +745,11 @@ const struct GUID *fsp_client_guid(const files_struct *fsp)
{
return &fsp->conn->sconn->client->connections->smb2.client.guid;
}
+
+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/smbd/oplock.c b/source3/smbd/oplock.c
index 62858c6593..5a128839a4 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -148,6 +148,36 @@ static void downgrade_file_oplock(files_struct *fsp)
TALLOC_FREE(fsp->oplock_timeout);
}
+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 get_lease_type(struct share_mode_data *d, struct share_mode_entry *e)
+{
+ if (e->op_type == LEASE_OPLOCK) {
+ return d->leases[e->lease_idx].current_state;
+ }
+ return map_oplock_to_lease_type(e->op_type);
+}
+
bool update_num_read_oplocks(files_struct *fsp, struct share_mode_lock *lck)
{
struct share_mode_data *d = lck->data;
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 0670597e49..67adbba6f2 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -388,6 +388,7 @@ NTSTATUS file_name_hash(connection_struct *conn,
NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
const struct smb_filename *smb_fname_in);
const struct GUID *fsp_client_guid(const files_struct *fsp);
+uint32_t fsp_lease_type(struct files_struct *fsp);
/* The following definitions come from smbd/ipc.c */
@@ -648,6 +649,8 @@ NTSTATUS get_relative_fid_filename(connection_struct *conn,
/* The following definitions come from smbd/oplock.c */
+uint32_t map_oplock_to_lease_type(uint16_t op_type);
+uint32_t get_lease_type(struct share_mode_data *d, struct share_mode_entry *e);
bool update_num_read_oplocks(files_struct *fsp, struct share_mode_lock *lck);
void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);