s3:smbd: add fsp_lease_type() and get_lease_type() helper functions
authorVolker Lendecke <vl@samba.org>
Tue, 28 Oct 2014 22:31:46 +0000 (15:31 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 4 Dec 2014 04:45:10 +0000 (05:45 +0100)
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>
source3/smbd/files.c
source3/smbd/oplock.c
source3/smbd/proto.h

index 71166288a6595e9c97dc0e2821ab03f255b97913..d866d6337c648f010393b6754d60d11d737bb083 100644 (file)
@@ -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);
+}
index 62858c6593cf088d5614dc3a34d28ea3113da0d3..5a128839a473e2e3637199a4b91cd848fc2a20c7 100644 (file)
@@ -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;
index 0670597e4963e9acee9e77e352c5751deffd5da1..67adbba6f25d7dd254bcb966b1a6f256bdd083f8 100644 (file)
@@ -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);