Merge remote-tracking branch 'c6x/for-linux-next' into uapi-prep
[cascardo/linux.git] / fs / cifs / smb2ops.c
index 0808b23..4d9dbe0 100644 (file)
@@ -374,11 +374,11 @@ smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
        cinode->can_cache_brlcks = cinode->clientCanCacheAll;
 }
 
-static int
+static void
 smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
                struct cifs_fid *fid)
 {
-       return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
+       SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
 }
 
 static int
@@ -496,7 +496,7 @@ smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
 {
        struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
 
-       if (le32_to_cpu(hdr->Status) != STATUS_PENDING)
+       if (hdr->Status != STATUS_PENDING)
                return false;
 
        if (!length) {
@@ -513,6 +513,10 @@ static int
 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
                     struct cifsInodeInfo *cinode)
 {
+       if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
+               return SMB2_lease_break(0, tcon, cinode->lease_key,
+                                       smb2_get_lease_state(cinode));
+
        return SMB2_oplock_break(0, tcon, fid->persistent_fid,
                                 fid->volatile_fid,
                                 cinode->clientCanCacheRead ? 1 : 0);
@@ -555,6 +559,24 @@ smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
                         current->tgid, length, offset, type, wait);
 }
 
+static void
+smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
+{
+       memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
+}
+
+static void
+smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
+{
+       memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
+}
+
+static void
+smb2_new_lease_key(struct cifs_fid *fid)
+{
+       get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
+}
+
 struct smb_version_operations smb21_operations = {
        .compare_fids = smb2_compare_fids,
        .setup_request = smb2_setup_request,
@@ -616,10 +638,32 @@ struct smb_version_operations smb21_operations = {
        .mand_lock = smb2_mand_lock,
        .mand_unlock_range = smb2_unlock_range,
        .push_mand_locks = smb2_push_mandatory_locks,
+       .get_lease_key = smb2_get_lease_key,
+       .set_lease_key = smb2_set_lease_key,
+       .new_lease_key = smb2_new_lease_key,
 };
 
 struct smb_version_values smb21_values = {
        .version_string = SMB21_VERSION_STRING,
+       .protocol_id = SMB21_PROT_ID,
+       .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
+       .large_lock_type = 0,
+       .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
+       .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
+       .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
+       .header_size = sizeof(struct smb2_hdr),
+       .max_header_size = MAX_SMB2_HDR_SIZE,
+       .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
+       .lock_cmd = SMB2_LOCK,
+       .cap_unix = 0,
+       .cap_nt_find = SMB2_NT_FIND,
+       .cap_large_files = SMB2_LARGE_FILES,
+};
+
+struct smb_version_values smb30_values = {
+       .version_string = SMB30_VERSION_STRING,
+       .protocol_id = SMB30_PROT_ID,
+       .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
        .large_lock_type = 0,
        .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
        .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,