Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *   fs/cifs/smb2file.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *   Copyright (C) International Business Machines  Corp., 2002, 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   Author(s): Steve French (sfrench@us.ibm.com),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *              Pavel Shilovsky ((pshilovsky@samba.org) 2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   This library is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   it under the terms of the GNU Lesser General Public License as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   by the Free Software Foundation; either version 2.1 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   This library is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   the GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   You should have received a copy of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   along with this library; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "cifsfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "cifspdu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "cifsglob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "cifsproto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "cifs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "cifs_fs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "cifs_unicode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "fscache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "smb2proto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	       __u32 *oplock, FILE_ALL_INFO *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	__le16 *smb2_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct smb2_file_all_info *smb2_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	__u8 smb2_oplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct cifs_fid *fid = oparms->fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct network_resiliency_req nr_ioctl_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (smb2_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (smb2_data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	oparms->desired_access |= FILE_READ_ATTRIBUTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		       NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (oparms->tcon->use_resilient) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		/* default timeout is 0, servers pick default (120 seconds) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		nr_ioctl_req.Timeout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			cpu_to_le32(oparms->tcon->handle_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		nr_ioctl_req.Reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		rc = SMB2_ioctl(xid, oparms->tcon, fid->persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			fid->volatile_fid, FSCTL_LMR_REQUEST_RESILIENCY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			true /* is_fsctl */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			(char *)&nr_ioctl_req, sizeof(nr_ioctl_req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			CIFSMaxBufSize, NULL, NULL /* no return info */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (rc == -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			cifs_dbg(VFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			     "resiliency not supported by server, disabling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			oparms->tcon->use_resilient = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		} else if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			cifs_dbg(FYI, "error %d setting resiliency\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		/* if open response does not have IndexNumber field - get it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (smb2_data->IndexNumber == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			rc = SMB2_get_srv_num(xid, oparms->tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				      fid->persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				      fid->volatile_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				      &smb2_data->IndexNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				 * let get_inode_info disable server inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				 * numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				smb2_data->IndexNumber = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 				rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		move_smb2_info_to_cifs(buf, smb2_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	*oplock = smb2_oplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	kfree(smb2_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	kfree(smb2_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		  const unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	int rc = 0, stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	unsigned int max_num, num = 0, max_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct smb2_lock_element *buf, *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct cifsLockInfo *li, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	__u64 length = 1 + flock->fl_end - flock->fl_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct list_head tmp_llist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	INIT_LIST_HEAD(&tmp_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * Accessing maxBuf is racy with cifs_reconnect - need to store value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * and check it before using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	max_buf = tcon->ses->server->maxBuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (max_buf < sizeof(struct smb2_lock_element))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	BUILD_BUG_ON(sizeof(struct smb2_lock_element) > PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	max_buf = min_t(unsigned int, max_buf, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	max_num = max_buf / sizeof(struct smb2_lock_element);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	cur = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	cifs_down_write(&cinode->lock_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		if (flock->fl_start > li->offset ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		    (flock->fl_start + length) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		    (li->offset + li->length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (current->tgid != li->pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			 * flock and OFD lock are associated with an open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 * file description, not the process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			if (!(flock->fl_flags & (FL_FLOCK | FL_OFDLCK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (cinode->can_cache_brlcks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			 * We can cache brlock requests - simply remove a lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			 * from the file's list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			list_del(&li->llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			cifs_del_lock_waiters(li);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			kfree(li);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		cur->Length = cpu_to_le64(li->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		cur->Offset = cpu_to_le64(li->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		cur->Flags = cpu_to_le32(SMB2_LOCKFLAG_UNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		 * We need to save a lock here to let us add it again to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		 * file's list if the unlock range request fails on the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		list_move(&li->llist, &tmp_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		if (++num == max_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			stored_rc = smb2_lockv(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					       cfile->fid.persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 					       cfile->fid.volatile_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 					       current->tgid, num, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			if (stored_rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				 * We failed on the unlock range request - add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				 * all locks from the tmp list to the head of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 				 * the file's list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 				cifs_move_llist(&tmp_llist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 						&cfile->llist->locks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				rc = stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 				 * The unlock range request succeed - free the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				 * tmp list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				cifs_free_llist(&tmp_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			cur = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			cur++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		stored_rc = smb2_lockv(xid, tcon, cfile->fid.persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				       cfile->fid.volatile_fid, current->tgid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 				       num, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (stored_rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			cifs_move_llist(&tmp_llist, &cfile->llist->locks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			rc = stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			cifs_free_llist(&tmp_llist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	up_write(&cinode->lock_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) smb2_push_mand_fdlocks(struct cifs_fid_locks *fdlocks, const unsigned int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		       struct smb2_lock_element *buf, unsigned int max_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	int rc = 0, stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct cifsFileInfo *cfile = fdlocks->cfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct cifsLockInfo *li;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	unsigned int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct smb2_lock_element *cur = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	list_for_each_entry(li, &fdlocks->locks, llist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		cur->Length = cpu_to_le64(li->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		cur->Offset = cpu_to_le64(li->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		cur->Flags = cpu_to_le32(li->type |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 						SMB2_LOCKFLAG_FAIL_IMMEDIATELY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (++num == max_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			stored_rc = smb2_lockv(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 					       cfile->fid.persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					       cfile->fid.volatile_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 					       current->tgid, num, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			if (stored_rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				rc = stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			cur = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			cur++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		stored_rc = smb2_lockv(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				       cfile->fid.persistent_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				       cfile->fid.volatile_fid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				       current->tgid, num, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		if (stored_rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			rc = stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int rc = 0, stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	unsigned int max_num, max_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct smb2_lock_element *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct cifs_fid_locks *fdlocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 * Accessing maxBuf is racy with cifs_reconnect - need to store value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * and check it for zero before using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (max_buf < sizeof(struct smb2_lock_element)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	BUILD_BUG_ON(sizeof(struct smb2_lock_element) > PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	max_buf = min_t(unsigned int, max_buf, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	max_num = max_buf / sizeof(struct smb2_lock_element);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	list_for_each_entry(fdlocks, &cinode->llist, llist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		stored_rc = smb2_push_mand_fdlocks(fdlocks, xid, buf, max_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (stored_rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			rc = stored_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }