Skip to contentSkip to conversation

Separate protocol-specific part from locking code

PATCH In review Pavel Shilovsky 2 participants 14 messages May 16, 2012 – May 17, 2012 9 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover Separate protocol-specific part from locking code

The first two patches are remains the same from the previous version. Others have been changed according to the new approach where we have protocol ops structure for every server.

The patches are applied on top of slightly modified Jeff's patches (values were separated from smb_version_operations to smb_version_values structure).

The branch with the patches:
http://git.altlinux.org/people/piastry/public/?p=cifs-2.6.git;a=shortlog;h=refs/heads/cifs-patches-new

All comments are welcome - we need to clarify these ones before I move to SMB2 patches.

Pavel Shilovsky (5):
CIFS: Move locks to cifsFileInfo structure
CIFS: Convert lock type to 32 bit variable
CIFS: Separate protocol specific lock type handling
CIFS: Separate protocol specific part from getlk
CIFS: Separate protocol specific part from setlk

 fs/cifs/cifsfs.c   |    1 -
 fs/cifs/cifsglob.h |   20 +++++-
 fs/cifs/file.c     |  174 ++++++++++++++++++++++++++++++----------------------
 fs/cifs/smb1ops.c  |   12 ++++
 4 files changed, 128 insertions(+), 79 deletions(-)

A message that is not in the archive (sent off-list or not yet received): 1337162254-13121-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

#2 lore raw

PATCH v4 1/5 CIFS: Move locks to cifsFileInfo structure

CIFS brlock cache can be used by several file handles if we have a write-caching lease on the file that is supported by SMB2 protocol. Prepate the code to handle this situation correctly by sorting brlocks by a fid to easily push them in portions when lease break comes.

---
 fs/cifs/cifsfs.c   |    1 -
 fs/cifs/cifsglob.h |   12 +++++--
 fs/cifs/file.c     |   89 ++++++++++++++++++++++++++++-----------------------
 3 files changed, 58 insertions(+), 44 deletions(-)
fs/cifs/cifsfs.c +0 -1
index ada9f07..50c603e 100644
@@ -955,7 +955,6 @@ cifs_init_once(void *inode)
 	struct cifsInodeInfo *cifsi = inode;
 
 	inode_init_once(&cifsi->vfs_inode);
-	INIT_LIST_HEAD(&cifsi->llist);
 	mutex_init(&cifsi->lock_mutex);
 }
 
fs/cifs/cifsglob.h +9 -3
index c41bf6d..03d24a5 100644
@@ -568,7 +568,6 @@ struct cifsLockInfo {
 	__u64 length;
 	__u32 pid;
 	__u8 type;
-	__u16 netfid;
 };
 
 /*
@@ -593,6 +592,10 @@ struct cifs_search_info {
 struct cifsFileInfo {
 	struct list_head tlist;	/* pointer to next fid owned by tcon */
 	struct list_head flist;	/* next fid (file instance) for this inode */
+	struct list_head llist;	/*
+				 * brlocks held by this fid, protected by
+				 * lock_mutex from cifsInodeInfo structure
+				 */
 	unsigned int uid;	/* allows finding which FileInfo structure */
 	__u32 pid;		/* process id who opened file */
 	__u16 netfid;		/* file id from remote */
@@ -635,9 +638,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
  */
 
 struct cifsInodeInfo {
-	struct list_head llist;		/* brlocks for this inode */
 	bool can_cache_brlcks;
-	struct mutex lock_mutex;	/* protect two fields above */
+	struct mutex lock_mutex;	/*
+					 * protect the field above and llist
+					 * from every cifsFileInfo structure
+					 * from openFileList
+					 */
 	/* BB add in lists for dirty pages i.e. write caching info for oplock */
 	struct list_head openFileList;
 	__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
fs/cifs/file.c +49 -40

247 lines not on this page · raw message

Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): 1337162254-13121-2-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

Acked-by
#4 lore raw

Re: [PATCH v4 1/5] CIFS: Move locks to cifsFileInfo structure

Quoted 49 lines · On Wed, 16 May 2012 13:57:30 +0400 Pavel Shilovsky…

CIFS brlock cache can be used by several file handles if we have a write-caching lease on the file that is supported by SMB2 protocol. Prepate the code to handle this situation correctly by sorting brlocks by a fid to easily push them in portions when lease break comes.

---
 fs/cifs/cifsfs.c   |    1 -
 fs/cifs/cifsglob.h |   12 +++++--
 fs/cifs/file.c     |   89 ++++++++++++++++++++++++++++-----------------------
 3 files changed, 58 insertions(+), 44 deletions(-)
fs/cifs/cifsfs.c +0 -1
index ada9f07..50c603e 100644
@@ -955,7 +955,6 @@ cifs_init_once(void *inode)
 	struct cifsInodeInfo *cifsi = inode;
 
 	inode_init_once(&cifsi->vfs_inode);
-	INIT_LIST_HEAD(&cifsi->llist);
 	mutex_init(&cifsi->lock_mutex);
 }
 
fs/cifs/cifsglob.h +4 -1
index c41bf6d..03d24a5 100644
@@ -568,7 +568,6 @@ struct cifsLockInfo {
 	__u64 length;
 	__u32 pid;
 	__u8 type;
-	__u16 netfid;
 };
 
 /*
@@ -593,6 +592,10 @@ struct cifs_search_info {
 struct cifsFileInfo {
 	struct list_head tlist;	/* pointer to next fid owned by tcon */
 	struct list_head flist;	/* next fid (file instance) for this inode */
+	struct list_head llist;	/*
+				 * brlocks held by this fid, protected by
+				 * lock_mutex from cifsInodeInfo structure
+				 */
 	unsigned int uid;	/* allows finding which FileInfo structure */
 	__u32 pid;		/* process id who opened file */
 	__u16 netfid;		/* file id from remote */
@@ -635,9 +638,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
  */

fs/cifs/cifsglob.h void cifsFileInfo_put(struct cifsFileInfo *cifs_file); · line 646

Quoted 10 lines
fs/cifs/cifsglob.h +5 -2
 
 struct cifsInodeInfo {
-	struct list_head llist;		/* brlocks for this inode */
 	bool can_cache_brlcks;
-	struct mutex lock_mutex;	/* protect two fields above */
+	struct mutex lock_mutex;	/*
+					 * protect the field above and llist
+					 * from every cifsFileInfo structure
+					 * from openFileList
+					 */

It seems rather ugly to have this mutex at the inode level. Given that most of what it protects hang off the cifsFileInfo, wouldn't it make more sense (and probably perform better) to have a per cifsFileInfo lock instead?

That does mean that you'd need to reconsider how to handle this can_cache_brlocks flag though -- maybe atomic bitops are a possibility.

Quoted 267 lines
fs/cifs/cifsglob.h +0 -0
 	/* BB add in lists for dirty pages i.e. write caching info for oplock */
 	struct list_head openFileList;
 	__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
fs/cifs/file.c +48 -39
index 4b5fe39..fc45cd9 100644
@@ -264,6 +264,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
 	pCifsFile->tlink = cifs_get_tlink(tlink);
 	mutex_init(&pCifsFile->fh_mutex);
 	INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break);
+	INIT_LIST_HEAD(&pCifsFile->llist);
 
 	spin_lock(&cifs_file_list_lock);
 	list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList));
@@ -334,9 +335,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
 	 * is closed anyway.
 	 */
 	mutex_lock(&cifsi->lock_mutex);
-	list_for_each_entry_safe(li, tmp, &cifsi->llist, llist) {
-		if (li->netfid != cifs_file->netfid)
-			continue;
+	list_for_each_entry_safe(li, tmp, &cifs_file->llist, llist) {
 		list_del(&li->llist);
 		cifs_del_lock_waiters(li);
 		kfree(li);
@@ -645,7 +644,7 @@ int cifs_closedir(struct inode *inode, struct file *file)
 }
 
 static struct cifsLockInfo *
-cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
+cifs_lock_init(__u64 offset, __u64 length, __u8 type)
 {
 	struct cifsLockInfo *lock =
 		kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);
@@ -654,7 +653,6 @@ cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
 	lock->offset = offset;
 	lock->length = length;
 	lock->type = type;
-	lock->netfid = netfid;
 	lock->pid = current->tgid;
 	INIT_LIST_HEAD(&lock->blist);
 	init_waitqueue_head(&lock->block_q);
@@ -672,19 +670,19 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
 }
 
 static bool
-__cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
-			__u64 length, __u8 type, __u16 netfid,
-			struct cifsLockInfo **conf_lock)
+cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
+			    __u64 length, __u8 type, __u16 netfid,
+			    struct cifsLockInfo **conf_lock)
 {
-	struct cifsLockInfo *li, *tmp;
+	struct cifsLockInfo *li;
 
-	list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+	list_for_each_entry(li, &cfile->llist, llist) {
 		if (offset + length <= li->offset ||
 		    offset >= li->offset + li->length)
 			continue;
 		else if ((type & LOCKING_ANDX_SHARED_LOCK) &&
-			 ((netfid == li->netfid && current->tgid == li->pid) ||
-			  type == li->type))
+			 ((netfid == cfile->netfid && current->tgid == li->pid)
+			 || type == li->type))
 			continue;
 		else {
 			*conf_lock = li;
@@ -695,11 +693,23 @@ __cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
 }
 
 static bool
-cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
+			__u64 length, __u8 type, __u16 netfid,
 			struct cifsLockInfo **conf_lock)
 {
-	return __cifs_find_lock_conflict(cinode, lock->offset, lock->length,
-					 lock->type, lock->netfid, conf_lock);
+	bool rc = false;
+	struct cifsFileInfo *fid, *tmp;
+
+	spin_lock(&cifs_file_list_lock);
+	list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) {
+		rc = cifs_find_fid_lock_conflict(fid, offset, length, type,
+						 netfid, conf_lock);
+		if (rc)
+			break;
+	}
+	spin_unlock(&cifs_file_list_lock);
+
+	return rc;
 }
 
 /*
@@ -710,17 +720,18 @@ cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
  * the server or 1 otherwise.
  */
 static int
-cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
-	       __u8 type, __u16 netfid, struct file_lock *flock)
+cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
+	       __u8 type, struct file_lock *flock)
 {
 	int rc = 0;
 	struct cifsLockInfo *conf_lock;
+	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
 	bool exist;
 
 	mutex_lock(&cinode->lock_mutex);
 
-	exist = __cifs_find_lock_conflict(cinode, offset, length, type, netfid,
-					  &conf_lock);
+	exist = cifs_find_lock_conflict(cinode, offset, length, type,
+					cfile->netfid, &conf_lock);
 	if (exist) {
 		flock->fl_start = conf_lock->offset;
 		flock->fl_end = conf_lock->offset + conf_lock->length - 1;
@@ -739,10 +750,11 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
 }
 
 static void
-cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
+cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
 {
+	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
 	mutex_lock(&cinode->lock_mutex);
-	list_add_tail(&lock->llist, &cinode->llist);
+	list_add_tail(&lock->llist, &cfile->llist);
 	mutex_unlock(&cinode->lock_mutex);
 }
 
@@ -753,10 +765,11 @@ cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
  * 3) -EACCESS, if there is a lock that prevents us and wait is false.
  */
 static int
-cifs_lock_add_if(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
 		 bool wait)
 {
 	struct cifsLockInfo *conf_lock;
+	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
 	bool exist;
 	int rc = 0;
 
@@ -764,9 +777,10 @@ try_again:
 	exist = false;
 	mutex_lock(&cinode->lock_mutex);
 
-	exist = cifs_find_lock_conflict(cinode, lock, &conf_lock);
+	exist = cifs_find_lock_conflict(cinode, lock->offset, lock->length,
+					lock->type, cfile->netfid, &conf_lock);
 	if (!exist && cinode->can_cache_brlcks) {
-		list_add_tail(&lock->llist, &cinode->llist);
+		list_add_tail(&lock->llist, &cfile->llist);
 		mutex_unlock(&cinode->lock_mutex);
 		return rc;
 	}
@@ -888,7 +902,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
 	for (i = 0; i < 2; i++) {
 		cur = buf;
 		num = 0;
-		list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+		list_for_each_entry_safe(li, tmp, &cfile->llist, llist) {
 			if (li->type != types[i])
 				continue;
 			cur->Pid = cpu_to_le16(li->pid);
@@ -1104,7 +1118,6 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
-	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1124,8 +1137,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
 		return rc;
 	}
 
-	rc = cifs_lock_test(cinode, flock->fl_start, length, type, netfid,
-			    flock);
+	rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock);
 	if (!rc)
 		return rc;
 
@@ -1212,15 +1224,13 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 	for (i = 0; i < 2; i++) {
 		cur = buf;
 		num = 0;
-		list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+		list_for_each_entry_safe(li, tmp, &cfile->llist, llist) {
 			if (flock->fl_start > li->offset ||
 			    (flock->fl_start + length) <
 			    (li->offset + li->length))
 				continue;
 			if (current->tgid != li->pid)
 				continue;
-			if (cfile->netfid != li->netfid)
-				continue;
 			if (types[i] != li->type)
 				continue;
 			if (!cinode->can_cache_brlcks) {
@@ -1233,7 +1243,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 					cpu_to_le32((u32)(li->offset>>32));
 				/*
 				 * We need to save a lock here to let us add
-				 * it again to the inode list if the unlock
+				 * it again to the file's list if the unlock
 				 * range request fails on the server.
 				 */
 				list_move(&li->llist, &tmp_llist);
@@ -1247,10 +1257,10 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 						 * We failed on the unlock range
 						 * request - add all locks from
 						 * the tmp list to the head of
-						 * the inode list.
+						 * the file's list.
 						 */
 						cifs_move_llist(&tmp_llist,
-								&cinode->llist);
+								&cfile->llist);
 						rc = stored_rc;
 					} else
 						/*
@@ -1265,7 +1275,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 			} else {
 				/*
 				 * We can cache brlock requests - simply remove
-				 * a lock from the inode list.
+				 * a lock from the file's list.
 				 */
 				list_del(&li->llist);
 				cifs_del_lock_waiters(li);
@@ -1276,7 +1286,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 			stored_rc = cifs_lockv(xid, tcon, cfile->netfid,
 					       types[i], num, 0, buf);
 			if (stored_rc) {
-				cifs_move_llist(&tmp_llist, &cinode->llist);
+				cifs_move_llist(&tmp_llist, &cfile->llist);
 				rc = stored_rc;
 			} else
 				cifs_free_llist(&tmp_llist);
@@ -1296,7 +1306,6 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
-	struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1323,11 +1332,11 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
 	if (lock) {
 		struct cifsLockInfo *lock;
 
-		lock = cifs_lock_init(flock->fl_start, length, type, netfid);
+		lock = cifs_lock_init(flock->fl_start, length, type);
 		if (!lock)
 			return -ENOMEM;
 
-		rc = cifs_lock_add_if(cinode, lock, wait_flag);
+		rc = cifs_lock_add_if(cfile, lock, wait_flag);
 		if (rc < 0)
 			kfree(lock);
 		if (rc <= 0)

fs/cifs/file.c cifs_setlk(struct file *file, struct file_lock *flock, __u8 type, · line 1355

Quoted 8 lines
fs/cifs/file.c +1 -1
@@ -1340,7 +1349,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
 			goto out;
 		}
 
-		cifs_lock_add(cinode, lock);
+		cifs_lock_add(cfile, lock);
 	} else if (unlock)
 		rc = cifs_unlock_range(cfile, flock, xid);
 

Regardless, I'm inclined to ACK this just so that we can move this along. Perhaps we can clean up the locking to be more granular later?

A message that is not in the archive (sent off-list or not yet received): 20120516141949.48f9de86-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#6 lore raw

Re: [PATCH v4 1/5] CIFS: Move locks to cifsFileInfo structure

2012/5/16 Jeff Layton <[email protected]>:

Quoted 68 lines
Quoted 49 lines · On Wed, 16 May 2012 13:57:30 +0400 Pavel Shilovsky…

CIFS brlock cache can be used by several file handles if we have a write-caching lease on the file that is supported by SMB2 protocol. Prepate the code to handle this situation correctly by sorting brlocks by a fid to easily push them in portions when lease break comes.

---
 fs/cifs/cifsfs.c   |    1 -
 fs/cifs/cifsglob.h |   12 +++++--
 fs/cifs/file.c     |   89 ++++++++++++++++++++++++++++-----------------------

 3 files changed, 58 insertions(+), 44 deletions(-)
fs/cifs/cifsfs.c +0 -1
index ada9f07..50c603e 100644
@@ -955,7 +955,6 @@ cifs_init_once(void *inode)
       struct cifsInodeInfo *cifsi = inode;
 
       inode_init_once(&cifsi->vfs_inode);
-     INIT_LIST_HEAD(&cifsi->llist);
       mutex_init(&cifsi->lock_mutex);
  }
 
fs/cifs/cifsglob.h +0 -1
index c41bf6d..03d24a5 100644
@@ -568,7 +568,6 @@ struct cifsLockInfo {
       __u64 length;
       __u32 pid;
       __u8 type;
-     __u16 netfid;
  };
 
  /*
@@ -593,6 +592,10 @@ struct cifs_search_info {
  struct cifsFileInfo {

      struct list_head tlist; /* pointer to next fid owned by tcon */ struct list_head flist; /* next fid (file instance) for this inode */
+     struct list_head llist; /*
+                              * brlocks held by this fid, protected by
+                              * lock_mutex from cifsInodeInfo structure
+                              */
      unsigned int uid;       /* allows finding which FileInfo structure */ __u32 pid;              /* process id who opened file */ __u16 netfid;           /* file id from remote */

fs/cifs/cifsglob.h +0 -0
@@ -635,9 +638,12 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
   */

fs/cifs/cifsglob.h void cifsFileInfo_put(struct cifsFileInfo *cifs_file); · line 646

Quoted 10 lines
fs/cifs/cifsglob.h +5 -2
 
  struct cifsInodeInfo {
-     struct list_head llist;         /* brlocks for this inode */
       bool can_cache_brlcks;
-     struct mutex lock_mutex;        /* protect two fields above */
+     struct mutex lock_mutex;        /*
+                                      * protect the field above and llist
+                                      * from every cifsFileInfo structure
+                                      * from openFileList
+                                      */

It seems rather ugly to have this mutex at the inode level. Given that most of what it protects hang off the cifsFileInfo, wouldn't it make more sense (and probably perform better) to have a per cifsFileInfo lock instead?

Quoted 2 lines

That does mean that you'd need to reconsider how to handle this can_cache_brlocks flag though -- maybe atomic bitops are a possibility.

The idea of this lock is to protect locking on the inode. Moving locks from inode structure to file structure only helps us to handle locking easier when SMB2 comes: when lease break comes we need to flush all brlocks to the server and we should flush them in groups to make this process faster; if we have brlocks from one file handle in one place - it's easier to flush them this way.

But there is another thing we should solve before getting it work:
several processes can obtain brlocks on the same file handle - so, we need to group file handle's locks by pid too. That's why we will need to sort locks by pid for every file handle - the work for further patches.

Quoted 280 lines
Quoted 268 lines
fs/cifs/cifsglob.h +0 -0
       /* BB add in lists for dirty pages i.e. write caching info for oplock */
       struct list_head openFileList;

      __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */

fs/cifs/file.c +2 -3
index 4b5fe39..fc45cd9 100644
@@ -264,6 +264,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file,
       pCifsFile->tlink = cifs_get_tlink(tlink);
       mutex_init(&pCifsFile->fh_mutex);
       INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break);
+     INIT_LIST_HEAD(&pCifsFile->llist);
 
       spin_lock(&cifs_file_list_lock);
       list_add(&pCifsFile->tlist, &(tlink_tcon(tlink)->openFileList));
@@ -334,9 +335,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
        * is closed anyway.
        */
       mutex_lock(&cifsi->lock_mutex);
-     list_for_each_entry_safe(li, tmp, &cifsi->llist, llist) {
-             if (li->netfid != cifs_file->netfid)
-                     continue;
+     list_for_each_entry_safe(li, tmp, &cifs_file->llist, llist) {
               list_del(&li->llist);
               cifs_del_lock_waiters(li);
               kfree(li);
@@ -645,7 +644,7 @@ int cifs_closedir(struct inode *inode, struct file *file)
  }
 

 static struct cifsLockInfo *

fs/cifs/file.c +1 -1
-cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
+cifs_lock_init(__u64 offset, __u64 length, __u8 type)

 {
      struct cifsLockInfo *lock = kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);

fs/cifs/file.c +0 -1
@@ -654,7 +653,6 @@ cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
       lock->offset = offset;
       lock->length = length;
       lock->type = type;
-     lock->netfid = netfid;
       lock->pid = current->tgid;
       INIT_LIST_HEAD(&lock->blist);
       init_waitqueue_head(&lock->block_q);
@@ -672,19 +670,19 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
  }
 

 static bool

fs/cifs/file.c +3 -3
-__cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
-                     __u64 length, __u8 type, __u16 netfid,
-                     struct cifsLockInfo **conf_lock)
+cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
+                         __u64 length, __u8 type, __u16 netfid,
+                         struct cifsLockInfo **conf_lock)

 {
-     struct cifsLockInfo *li, *tmp;
+     struct cifsLockInfo *li;

-     list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+     list_for_each_entry(li, &cfile->llist, llist) {
              if (offset + length <= li->offset ||
                  offset >= li->offset + li->length)
                      continue;
              else if ((type & LOCKING_ANDX_SHARED_LOCK) &&
-                      ((netfid == li->netfid && current->tgid == li->pid) ||
-                       type == li->type))
+                      ((netfid == cfile->netfid && current->tgid == li->pid)
+                      || type == li->type))
                      continue;
              else {
                      *conf_lock = li;

fs/cifs/file.c +0 -0
@@ -695,11 +693,23 @@ __cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
  }
 

 static bool

fs/cifs/file.c +2 -1
-cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
+                     __u64 length, __u8 type, __u16 netfid,

                      struct cifsLockInfo **conf_lock)
 {
-     return __cifs_find_lock_conflict(cinode, lock->offset, lock->length,
-                                      lock->type, lock->netfid, conf_lock);
+     bool rc = false;
+     struct cifsFileInfo *fid, *tmp;

fs/cifs/file.c +11 -0
+
+     spin_lock(&cifs_file_list_lock);
+     list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) {
+             rc = cifs_find_fid_lock_conflict(fid, offset, length, type,
+                                              netfid, conf_lock);
+             if (rc)
+                     break;
+     }
+     spin_unlock(&cifs_file_list_lock);
+
+     return rc;

 }

 /*

fs/cifs/file.c +0 -0
@@ -710,17 +720,18 @@ cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
   * the server or 1 otherwise.
   */

 static int

fs/cifs/file.c +2 -2
-cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
-            __u8 type, __u16 netfid, struct file_lock *flock)
+cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
+            __u8 type, struct file_lock *flock)

 {
      int rc = 0;
      struct cifsLockInfo *conf_lock;
+     struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); bool exist;

      mutex_lock(&cinode->lock_mutex);

-     exist = __cifs_find_lock_conflict(cinode, offset, length, type, netfid,
-                                       &conf_lock);
+     exist = cifs_find_lock_conflict(cinode, offset, length, type,
+                                     cfile->netfid, &conf_lock); if (exist) {
              flock->fl_start = conf_lock->offset;
              flock->fl_end = conf_lock->offset + conf_lock->length - 1;

fs/cifs/file.c +0 -0
@@ -739,10 +750,11 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
  }
 

 static void

fs/cifs/file.c +1 -1
-cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
+cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)

 {
+     struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); mutex_lock(&cinode->lock_mutex);
-     list_add_tail(&lock->llist, &cinode->llist);
+     list_add_tail(&lock->llist, &cfile->llist); mutex_unlock(&cinode->lock_mutex);
 }

fs/cifs/file.c +0 -0
@@ -753,10 +765,11 @@ cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
   * 3) -EACCESS, if there is a lock that prevents us and wait is false.
   */

 static int

fs/cifs/file.c +1 -1
-cifs_lock_add_if(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,

               bool wait)
 {
      struct cifsLockInfo *conf_lock;
+     struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); bool exist;
      int rc = 0;

fs/cifs/file.c +6 -7
@@ -764,9 +777,10 @@ try_again:
       exist = false;
       mutex_lock(&cinode->lock_mutex);
 
-     exist = cifs_find_lock_conflict(cinode, lock, &conf_lock);
+     exist = cifs_find_lock_conflict(cinode, lock->offset, lock->length,
+                                     lock->type, cfile->netfid, &conf_lock);
       if (!exist && cinode->can_cache_brlcks) {
-             list_add_tail(&lock->llist, &cinode->llist);
+             list_add_tail(&lock->llist, &cfile->llist);
               mutex_unlock(&cinode->lock_mutex);
               return rc;
       }
@@ -888,7 +902,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
       for (i = 0; i < 2; i++) {
               cur = buf;
               num = 0;
-             list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+             list_for_each_entry_safe(li, tmp, &cfile->llist, llist) {
                       if (li->type != types[i])
                               continue;
                       cur->Pid = cpu_to_le16(li->pid);
@@ -1104,7 +1118,6 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
       __u64 length = 1 + flock->fl_end - flock->fl_start;
       struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
       struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
-     struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
       __u16 netfid = cfile->netfid;
 
       if (posix_lck) {
@@ -1124,8 +1137,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
               return rc;
       }
 
-     rc = cifs_lock_test(cinode, flock->fl_start, length, type, netfid,
-                         flock);
+     rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock);
       if (!rc)
               return rc;
 
@@ -1212,15 +1224,13 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
       for (i = 0; i < 2; i++) {
               cur = buf;
               num = 0;
-             list_for_each_entry_safe(li, tmp, &cinode->llist, llist) {
+             list_for_each_entry_safe(li, tmp, &cfile->llist, llist) {

                      if (flock->fl_start > li->offset || (flock->fl_start + length) < (li->offset + li->length)) continue;
                      if (current->tgid != li->pid) continue;
-                     if (cfile->netfid != li->netfid)
-                             continue;
                      if (types[i] != li->type) continue;
                      if (!cinode->can_cache_brlcks) {

fs/cifs/file.c +7 -8
@@ -1233,7 +1243,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
                                       cpu_to_le32((u32)(li->offset>>32));
                               /*
                                * We need to save a lock here to let us add
-                              * it again to the inode list if the unlock
+                              * it again to the file's list if the unlock
                                * range request fails on the server.
                                */
                               list_move(&li->llist, &tmp_llist);
@@ -1247,10 +1257,10 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
                                                * We failed on the unlock range
                                                * request - add all locks from
                                                * the tmp list to the head of
-                                              * the inode list.
+                                              * the file's list.
                                                */
                                               cifs_move_llist(&tmp_llist,
-                                                             &cinode->llist);
+                                                             &cfile->llist);
                                               rc = stored_rc;
                                       } else
                                               /*
@@ -1265,7 +1275,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
                       } else {
                               /*
                                * We can cache brlock requests - simply remove
-                              * a lock from the inode list.
+                              * a lock from the file's list.
                                */
                               list_del(&li->llist);
                               cifs_del_lock_waiters(li);
@@ -1276,7 +1286,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
                       stored_rc = cifs_lockv(xid, tcon, cfile->netfid,
                                              types[i], num, 0, buf);
                       if (stored_rc) {
-                             cifs_move_llist(&tmp_llist, &cinode->llist);
+                             cifs_move_llist(&tmp_llist, &cfile->llist);
                               rc = stored_rc;
                       } else
                               cifs_free_llist(&tmp_llist);
@@ -1296,7 +1306,6 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
       __u64 length = 1 + flock->fl_end - flock->fl_start;
       struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
       struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
-     struct cifsInodeInfo *cinode = CIFS_I(file->f_path.dentry->d_inode);
       __u16 netfid = cfile->netfid;
 
       if (posix_lck) {
@@ -1323,11 +1332,11 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
       if (lock) {
               struct cifsLockInfo *lock;
 
-             lock = cifs_lock_init(flock->fl_start, length, type, netfid);
+             lock = cifs_lock_init(flock->fl_start, length, type);
               if (!lock)
                       return -ENOMEM;
 
-             rc = cifs_lock_add_if(cinode, lock, wait_flag);
+             rc = cifs_lock_add_if(cfile, lock, wait_flag);
               if (rc < 0)
                       kfree(lock);
               if (rc <= 0)

fs/cifs/file.c cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type, · line 1355

Quoted 8 lines
fs/cifs/file.c +1 -1
@@ -1340,7 +1349,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
                       goto out;
               }
 
-             cifs_lock_add(cinode, lock);
+             cifs_lock_add(cfile, lock);
       } else if (unlock)
               rc = cifs_unlock_range(cfile, flock, xid);
 

Regardless, I'm inclined to ACK this just so that we can move this along. Perhaps we can clean up the locking to be more granular later?

Quoted 1 line

Yes, I think it may be easier and we will try several approaches before getting it clean. Thanks for the review!

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#7 lore raw

PATCH v4 2/5 CIFS: Convert lock type to 32 bit variable

In reply to a message not in the archive

to handle SMB2 lock type field further.

---
 fs/cifs/cifsglob.h |    2 +-
 fs/cifs/file.c     |   13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)
fs/cifs/cifsglob.h +1 -1
index 03d24a5..0e06de1 100644
@@ -567,7 +567,7 @@ struct cifsLockInfo {
 	__u64 offset;
 	__u64 length;
 	__u32 pid;
-	__u8 type;
+	__u32 type;
 };
 
 /*
fs/cifs/file.c +7 -6
index fc45cd9..8d5d9c0 100644
@@ -912,7 +912,8 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
 			cur->OffsetHigh = cpu_to_le32((u32)(li->offset>>32));
 			if (++num == max_num) {
 				stored_rc = cifs_lockv(xid, tcon, cfile->netfid,
-						       li->type, 0, num, buf);
+						       (__u8)li->type, 0, num,
+						       buf);
 				if (stored_rc)
 					rc = stored_rc;
 				cur = buf;
@@ -923,7 +924,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
 
 		if (num) {
 			stored_rc = cifs_lockv(xid, tcon, cfile->netfid,
-					       types[i], 0, num, buf);
+					       (__u8)types[i], 0, num, buf);
 			if (stored_rc)
 				rc = stored_rc;
 		}
@@ -1067,7 +1068,7 @@ cifs_push_locks(struct cifsFileInfo *cfile)
 }
 
 static void
-cifs_read_flock(struct file_lock *flock, __u8 *type, int *lock, int *unlock,
+cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
 		bool *wait_flag)
 {
 	if (flock->fl_flags & FL_POSIX)
@@ -1111,7 +1112,7 @@ cifs_read_flock(struct file_lock *flock, __u8 *type, int *lock, int *unlock,
 }
 
 static int
-cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
+cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 	   bool wait_flag, bool posix_lck, int xid)
 {
 	int rc = 0;
@@ -1299,7 +1300,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, int xid)
 }
 
 static int
-cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
+cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 	   bool wait_flag, bool posix_lck, int lock, int unlock, int xid)
 {
 	int rc = 0;
@@ -1370,7 +1371,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
 	struct cifsInodeInfo *cinode;
 	struct cifsFileInfo *cfile;
 	__u16 netfid;
-	__u8 type;
+	__u32 type;
 
 	rc = -EACCES;
 	xid = GetXid();
Signature · 1 line
1.7.1
#8 lore raw

PATCH v4 3/5 CIFS: Separate protocol specific lock type handling

In reply to a message not in the archive
---
 fs/cifs/cifsglob.h |    4 ++++
 fs/cifs/file.c     |   40 ++++++++++++++++++++++++----------------
 fs/cifs/smb1ops.c  |    5 +++++
 3 files changed, 33 insertions(+), 16 deletions(-)
fs/cifs/cifsglob.h +4 -0
index 0e06de1..6943448 100644
@@ -164,6 +164,10 @@ struct smb_version_operations {
 
 struct smb_version_values {
 	char		*version_string;
+	__u32		large_lock_type;
+	__u32		exclusive_lock_type;
+	__u32		shared_lock_type;
+	__u32		unlock_lock_type;
 };
 
 struct smb_vol {
fs/cifs/file.c +24 -16
index 8d5d9c0..ac71f85 100644
@@ -675,12 +675,13 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
 			    struct cifsLockInfo **conf_lock)
 {
 	struct cifsLockInfo *li;
+	struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
 
 	list_for_each_entry(li, &cfile->llist, llist) {
 		if (offset + length <= li->offset ||
 		    offset >= li->offset + li->length)
 			continue;
-		else if ((type & LOCKING_ANDX_SHARED_LOCK) &&
+		else if ((type & server->vals->shared_lock_type) &&
 			 ((netfid == cfile->netfid && current->tgid == li->pid)
 			 || type == li->type))
 			continue;
@@ -726,6 +727,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 	int rc = 0;
 	struct cifsLockInfo *conf_lock;
 	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
+	struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
 	bool exist;
 
 	mutex_lock(&cinode->lock_mutex);
@@ -736,7 +738,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 		flock->fl_start = conf_lock->offset;
 		flock->fl_end = conf_lock->offset + conf_lock->length - 1;
 		flock->fl_pid = conf_lock->pid;
-		if (conf_lock->type & LOCKING_ANDX_SHARED_LOCK)
+		if (conf_lock->type & server->vals->shared_lock_type)
 			flock->fl_type = F_RDLCK;
 		else
 			flock->fl_type = F_WRLCK;
@@ -1069,7 +1071,7 @@ cifs_push_locks(struct cifsFileInfo *cfile)
 
 static void
 cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
-		bool *wait_flag)
+		bool *wait_flag, struct TCP_Server_Info *server)
 {
 	if (flock->fl_flags & FL_POSIX)
 		cFYI(1, "Posix");
@@ -1088,24 +1090,27 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
 	    (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE)))
 		cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags);
 
-	*type = LOCKING_ANDX_LARGE_FILES;
+	*type = server->vals->large_lock_type;
 	if (flock->fl_type == F_WRLCK) {
 		cFYI(1, "F_WRLCK ");
+		*type |= server->vals->exclusive_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_UNLCK) {
 		cFYI(1, "F_UNLCK");
+		*type |= server->vals->unlock_lock_type;
 		*unlock = 1;
 		/* Check if unlock includes more than one lock range */
 	} else if (flock->fl_type == F_RDLCK) {
 		cFYI(1, "F_RDLCK");
-		*type |= LOCKING_ANDX_SHARED_LOCK;
+		*type |= server->vals->shared_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_EXLCK) {
 		cFYI(1, "F_EXLCK");
+		*type |= server->vals->exclusive_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_SHLCK) {
 		cFYI(1, "F_SHLCK");
-		*type |= LOCKING_ANDX_SHARED_LOCK;
+		*type |= server->vals->shared_lock_type;
 		*lock = 1;
 	} else
 		cFYI(1, "Unknown type of lock");
@@ -1119,6 +1124,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+	struct TCP_Server_Info *server = tcon->ses->server;
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1128,7 +1134,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		if (!rc)
 			return rc;
 
-		if (type & LOCKING_ANDX_SHARED_LOCK)
+		if (type & server->vals->shared_lock_type)
 			posix_lock_type = CIFS_RDLCK;
 		else
 			posix_lock_type = CIFS_WRLCK;
@@ -1152,23 +1158,22 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		flock->fl_type = F_UNLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
-				   "range %d during test of lock", rc);
+				  "range %d during test of lock", rc);
 		return 0;
 	}
 
-	if (type & LOCKING_ANDX_SHARED_LOCK) {
+	if (type & server->vals->shared_lock_type) {
 		flock->fl_type = F_WRLCK;
 		return 0;
 	}
 
 	rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
 			 flock->fl_start, 0, 1,
-			 type | LOCKING_ANDX_SHARED_LOCK, 0, 0);
+			 type | server->vals->shared_lock_type, 0, 0);
 	if (rc == 0) {
 		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
 				 length, flock->fl_start, 1, 0,
-				 type | LOCKING_ANDX_SHARED_LOCK,
-				 0, 0);
+				 type | server->vals->shared_lock_type, 0, 0);
 		flock->fl_type = F_RDLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
@@ -1307,6 +1312,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+	struct TCP_Server_Info *server = tcon->ses->server;
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1316,7 +1322,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 		if (!rc || rc < 0)
 			return rc;
 
-		if (type & LOCKING_ANDX_SHARED_LOCK)
+		if (type & server->vals->shared_lock_type)
 			posix_lock_type = CIFS_RDLCK;
 		else
 			posix_lock_type = CIFS_WRLCK;
@@ -1380,11 +1386,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
 		"end: %lld", cmd, flock->fl_flags, flock->fl_type,
 		flock->fl_start, flock->fl_end);
 
-	cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag);
-
-	cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
 	cfile = (struct cifsFileInfo *)file->private_data;
 	tcon = tlink_tcon(cfile->tlink);
+
+	cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag,
+			tcon->ses->server);
+
+	cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
 	netfid = cfile->netfid;
 	cinode = CIFS_I(file->f_path.dentry->d_inode);
 
fs/cifs/smb1ops.c +5 -0
index fa486f0..af48a8b 100644
@@ -20,6 +20,7 @@
 #include "cifsglob.h"
 #include "cifsproto.h"
 #include "cifs_debug.h"
+#include "cifspdu.h"
 
 /*
  * An NT cancel request header looks just like the original request except:
@@ -65,4 +66,8 @@ struct smb_version_operations smb1_operations = {
 
 struct smb_version_values smb1_values = {
 	.version_string = SMB1_VERSION_STRING,
+	.large_lock_type = LOCKING_ANDX_LARGE_FILES,
+	.exclusive_lock_type = 0,
+	.shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
+	.unlock_lock_type = 0,
 };
Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): 1337162254-13121-4-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

Acked-by
#10 lore raw

Re: [PATCH v4 3/5] CIFS: Separate protocol specific lock type handling

Quoted 12 lines · On Wed, 16 May 2012 13:57:32 +0400 Pavel Shilovsky…
---
 fs/cifs/cifsglob.h |    4 ++++
 fs/cifs/file.c     |   40 ++++++++++++++++++++++++----------------
 fs/cifs/smb1ops.c  |    5 +++++
 3 files changed, 33 insertions(+), 16 deletions(-)
fs/cifs/cifsglob.h +0 -0
index 0e06de1..6943448 100644

fs/cifs/cifsglob.h struct smb_version_operations { · line 172

Quoted 9 lines
fs/cifs/cifsglob.h +4 -0
@@ -164,6 +164,10 @@ struct smb_version_operations {
 
 struct smb_version_values {
 	char		*version_string;
+	__u32		large_lock_type;
+	__u32		exclusive_lock_type;
+	__u32		shared_lock_type;
+	__u32		unlock_lock_type;
 };
 

It would probably be good to send your respin of my patchset so that we can see what this one is based on...

Quoted 169 lines
fs/cifs/cifsglob.h +0 -0
 struct smb_vol {
fs/cifs/file.c +24 -16
index 8d5d9c0..ac71f85 100644
@@ -675,12 +675,13 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
 			    struct cifsLockInfo **conf_lock)
 {
 	struct cifsLockInfo *li;
+	struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
 
 	list_for_each_entry(li, &cfile->llist, llist) {
 		if (offset + length <= li->offset ||
 		    offset >= li->offset + li->length)
 			continue;
-		else if ((type & LOCKING_ANDX_SHARED_LOCK) &&
+		else if ((type & server->vals->shared_lock_type) &&
 			 ((netfid == cfile->netfid && current->tgid == li->pid)
 			 || type == li->type))
 			continue;
@@ -726,6 +727,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 	int rc = 0;
 	struct cifsLockInfo *conf_lock;
 	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
+	struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
 	bool exist;
 
 	mutex_lock(&cinode->lock_mutex);
@@ -736,7 +738,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 		flock->fl_start = conf_lock->offset;
 		flock->fl_end = conf_lock->offset + conf_lock->length - 1;
 		flock->fl_pid = conf_lock->pid;
-		if (conf_lock->type & LOCKING_ANDX_SHARED_LOCK)
+		if (conf_lock->type & server->vals->shared_lock_type)
 			flock->fl_type = F_RDLCK;
 		else
 			flock->fl_type = F_WRLCK;
@@ -1069,7 +1071,7 @@ cifs_push_locks(struct cifsFileInfo *cfile)
 
 static void
 cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
-		bool *wait_flag)
+		bool *wait_flag, struct TCP_Server_Info *server)
 {
 	if (flock->fl_flags & FL_POSIX)
 		cFYI(1, "Posix");
@@ -1088,24 +1090,27 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
 	    (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE)))
 		cFYI(1, "Unknown lock flags 0x%x", flock->fl_flags);
 
-	*type = LOCKING_ANDX_LARGE_FILES;
+	*type = server->vals->large_lock_type;
 	if (flock->fl_type == F_WRLCK) {
 		cFYI(1, "F_WRLCK ");
+		*type |= server->vals->exclusive_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_UNLCK) {
 		cFYI(1, "F_UNLCK");
+		*type |= server->vals->unlock_lock_type;
 		*unlock = 1;
 		/* Check if unlock includes more than one lock range */
 	} else if (flock->fl_type == F_RDLCK) {
 		cFYI(1, "F_RDLCK");
-		*type |= LOCKING_ANDX_SHARED_LOCK;
+		*type |= server->vals->shared_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_EXLCK) {
 		cFYI(1, "F_EXLCK");
+		*type |= server->vals->exclusive_lock_type;
 		*lock = 1;
 	} else if (flock->fl_type == F_SHLCK) {
 		cFYI(1, "F_SHLCK");
-		*type |= LOCKING_ANDX_SHARED_LOCK;
+		*type |= server->vals->shared_lock_type;
 		*lock = 1;
 	} else
 		cFYI(1, "Unknown type of lock");
@@ -1119,6 +1124,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+	struct TCP_Server_Info *server = tcon->ses->server;
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1128,7 +1134,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		if (!rc)
 			return rc;
 
-		if (type & LOCKING_ANDX_SHARED_LOCK)
+		if (type & server->vals->shared_lock_type)
 			posix_lock_type = CIFS_RDLCK;
 		else
 			posix_lock_type = CIFS_WRLCK;
@@ -1152,23 +1158,22 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		flock->fl_type = F_UNLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
-				   "range %d during test of lock", rc);
+				  "range %d during test of lock", rc);
 		return 0;
 	}
 
-	if (type & LOCKING_ANDX_SHARED_LOCK) {
+	if (type & server->vals->shared_lock_type) {
 		flock->fl_type = F_WRLCK;
 		return 0;
 	}
 
 	rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
 			 flock->fl_start, 0, 1,
-			 type | LOCKING_ANDX_SHARED_LOCK, 0, 0);
+			 type | server->vals->shared_lock_type, 0, 0);
 	if (rc == 0) {
 		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
 				 length, flock->fl_start, 1, 0,
-				 type | LOCKING_ANDX_SHARED_LOCK,
-				 0, 0);
+				 type | server->vals->shared_lock_type, 0, 0);
 		flock->fl_type = F_RDLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
@@ -1307,6 +1312,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 	__u64 length = 1 + flock->fl_end - flock->fl_start;
 	struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+	struct TCP_Server_Info *server = tcon->ses->server;
 	__u16 netfid = cfile->netfid;
 
 	if (posix_lck) {
@@ -1316,7 +1322,7 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 		if (!rc || rc < 0)
 			return rc;
 
-		if (type & LOCKING_ANDX_SHARED_LOCK)
+		if (type & server->vals->shared_lock_type)
 			posix_lock_type = CIFS_RDLCK;
 		else
 			posix_lock_type = CIFS_WRLCK;
@@ -1380,11 +1386,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
 		"end: %lld", cmd, flock->fl_flags, flock->fl_type,
 		flock->fl_start, flock->fl_end);
 
-	cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag);
-
-	cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
 	cfile = (struct cifsFileInfo *)file->private_data;
 	tcon = tlink_tcon(cfile->tlink);
+
+	cifs_read_flock(flock, &type, &lock, &unlock, &wait_flag,
+			tcon->ses->server);
+
+	cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
 	netfid = cfile->netfid;
 	cinode = CIFS_I(file->f_path.dentry->d_inode);
 
fs/cifs/smb1ops.c +1 -0
index fa486f0..af48a8b 100644
@@ -20,6 +20,7 @@
 #include "cifsglob.h"
 #include "cifsproto.h"
 #include "cifs_debug.h"
+#include "cifspdu.h"
 
 /*
  * An NT cancel request header looks just like the original request except:

fs/cifs/smb1ops.c struct smb_version_operations smb1_operations = { · line 73

Quoted 8 lines
fs/cifs/smb1ops.c +4 -0
@@ -65,4 +66,8 @@ struct smb_version_operations smb1_operations = {
 
 struct smb_version_values smb1_values = {
 	.version_string = SMB1_VERSION_STRING,
+	.large_lock_type = LOCKING_ANDX_LARGE_FILES,
+	.exclusive_lock_type = 0,
+	.shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
+	.unlock_lock_type = 0,
 };

Much cleaner than having a bunch of is_smb2 checks all over the place.

A message that is not in the archive (sent off-list or not yet received): 20120516142500.531aca81-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#12 lore raw

Re: [PATCH v4 3/5] CIFS: Separate protocol specific lock type handling

2012/5/16 Jeff Layton <[email protected]>:

Quoted 16 lines
Quoted 13 lines · On Wed, 16 May 2012 13:57:32 +0400 Pavel Shilovsky…

---
 fs/cifs/cifsglob.h |    4 ++++
 fs/cifs/file.c     |   40 ++++++++++++++++++++++++---------------- fs/cifs/smb1ops.c  |    5 +++++

 3 files changed, 33 insertions(+), 16 deletions(-)
fs/cifs/cifsglob.h +0 -0
index 0e06de1..6943448 100644
@@ -164,6 +164,10 @@ struct smb_version_operations {
 
Quoted 12 lines

fs/cifs/cifsglob.h struct smb_version_operations { · line 172

Quoted 8 lines
fs/cifs/cifsglob.h +4 -0
  struct smb_version_values {
       char            *version_string;
+     __u32           large_lock_type;
+     __u32           exclusive_lock_type;
+     __u32           shared_lock_type;
+     __u32           unlock_lock_type;
  };
 

It would probably be good to send your respin of my patchset so that we can see what this one is based on...

Yes - posted.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#13 lore raw

PATCH v4 4/5 CIFS: Separate protocol specific part from getlk

In reply to a message not in the archive
---
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/file.c     |   52 ++++++++++++++++++++++++++++++----------------------
 fs/cifs/smb1ops.c  |    7 +++++++
 3 files changed, 39 insertions(+), 22 deletions(-)
fs/cifs/cifsglob.h +2 -0
index 6943448..b6e97f8 100644
@@ -156,10 +156,12 @@ enum smb_version {
 
 struct mid_q_entry;
 struct TCP_Server_Info;
+struct cifsFileInfo;
 
 struct smb_version_operations {
 	int (*send_cancel)(struct TCP_Server_Info *, void *,
 			   struct mid_q_entry *);
+	bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
 };
 
 struct smb_version_values {
fs/cifs/file.c +30 -22

109 lines not on this page · raw message

fs/cifs/smb1ops.c +7 -0
index af48a8b..7565587 100644
@@ -60,8 +60,15 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf,
 	return rc;
 }
 
+static inline bool
+cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
+{
+	return ob1->netfid == ob2->netfid;
+}
+
 struct smb_version_operations smb1_operations = {
 	.send_cancel = send_nt_cancel,
+	.compare_fids = cifs_compare_fids,
 };
 
 struct smb_version_values smb1_values = {
Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): 1337162254-13121-5-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

#15 lore raw

Re: [PATCH v4 4/5] CIFS: Separate protocol specific part from getlk

Quoted 154 lines · On Wed, 16 May 2012 13:57:33 +0400 Pavel Shilovsky…
---
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/file.c     |   52 ++++++++++++++++++++++++++++++----------------------
 fs/cifs/smb1ops.c  |    7 +++++++
 3 files changed, 39 insertions(+), 22 deletions(-)
fs/cifs/cifsglob.h +2 -0
index 6943448..b6e97f8 100644
@@ -156,10 +156,12 @@ enum smb_version {
 
 struct mid_q_entry;
 struct TCP_Server_Info;
+struct cifsFileInfo;
 
 struct smb_version_operations {
 	int (*send_cancel)(struct TCP_Server_Info *, void *,
 			   struct mid_q_entry *);
+	bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
 };
 
 struct smb_version_values {
fs/cifs/file.c +30 -22
index ac71f85..9c2d85d 100644
@@ -671,7 +671,7 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
 
 static bool
 cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
-			    __u64 length, __u8 type, __u16 netfid,
+			    __u64 length, __u8 type, struct cifsFileInfo *cur,
 			    struct cifsLockInfo **conf_lock)
 {
 	struct cifsLockInfo *li;
@@ -682,8 +682,8 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
 		    offset >= li->offset + li->length)
 			continue;
 		else if ((type & server->vals->shared_lock_type) &&
-			 ((netfid == cfile->netfid && current->tgid == li->pid)
-			 || type == li->type))
+			 ((server->ops->compare_fids(cur, cfile) &&
+			   current->tgid == li->pid) || type == li->type))
 			continue;
 		else {
 			*conf_lock = li;
@@ -694,17 +694,17 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
 }
 
 static bool
-cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
-			__u64 length, __u8 type, __u16 netfid,
-			struct cifsLockInfo **conf_lock)
+cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
+			__u8 type, struct cifsLockInfo **conf_lock)
 {
 	bool rc = false;
 	struct cifsFileInfo *fid, *tmp;
+	struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
 
 	spin_lock(&cifs_file_list_lock);
 	list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) {
 		rc = cifs_find_fid_lock_conflict(fid, offset, length, type,
-						 netfid, conf_lock);
+						 cfile, conf_lock);
 		if (rc)
 			break;
 	}
@@ -732,8 +732,8 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 
 	mutex_lock(&cinode->lock_mutex);
 
-	exist = cifs_find_lock_conflict(cinode, offset, length, type,
-					cfile->netfid, &conf_lock);
+	exist = cifs_find_lock_conflict(cfile, offset, length, type,
+					&conf_lock);
 	if (exist) {
 		flock->fl_start = conf_lock->offset;
 		flock->fl_end = conf_lock->offset + conf_lock->length - 1;
@@ -779,8 +779,8 @@ try_again:
 	exist = false;
 	mutex_lock(&cinode->lock_mutex);
 
-	exist = cifs_find_lock_conflict(cinode, lock->offset, lock->length,
-					lock->type, cfile->netfid, &conf_lock);
+	exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
+					lock->type, &conf_lock);
 	if (!exist && cinode->can_cache_brlcks) {
 		list_add_tail(&lock->llist, &cfile->llist);
 		mutex_unlock(&cinode->lock_mutex);
@@ -1117,6 +1117,15 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
 }
 
 static int
+cifs_mandatory_lock(int xid, struct cifsFileInfo *cfile, __u64 offset,
+		    __u64 length, __u32 type, int lock, int unlock, bool wait)
+{
+	return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->netfid,
+			   current->tgid, length, offset, unlock, lock,
+			   (__u8)type, wait, 0);
+}
+
+static int
 cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 	   bool wait_flag, bool posix_lck, int xid)
 {
@@ -1149,12 +1158,11 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		return rc;
 
 	/* BB we could chain these into one lock request BB */
-	rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-			 flock->fl_start, 0, 1, type, 0, 0);
+	rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, type,
+				 1, 0, false);
 	if (rc == 0) {
-		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
-				 length, flock->fl_start, 1, 0,
-				 type, 0, 0);
+		rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+					 type, 0, 1, false);
 		flock->fl_type = F_UNLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
@@ -1167,13 +1175,13 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
 		return 0;
 	}
 
-	rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-			 flock->fl_start, 0, 1,
-			 type | server->vals->shared_lock_type, 0, 0);
+	rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+				 type | server->vals->shared_lock_type, 1, 0,
+				 false);
 	if (rc == 0) {
-		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
-				 length, flock->fl_start, 1, 0,
-				 type | server->vals->shared_lock_type, 0, 0);
+		rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+					 type | server->vals->shared_lock_type,
+					 0, 1, false);
 		flock->fl_type = F_RDLCK;
 		if (rc != 0)
 			cERROR(1, "Error unlocking previously locked "
fs/cifs/smb1ops.c +1 -0
index af48a8b..7565587 100644
@@ -60,8 +60,15 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf,
 	return rc;
 }
 
+static inline bool

fs/cifs/smb1ops.c send_nt_cancel(struct TCP_Server_Info *server, void *buf, · line 73

Quoted 10 lines
fs/cifs/smb1ops.c +6 -0
+cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
+{
+	return ob1->netfid == ob2->netfid;
+}
+
 struct smb_version_operations smb1_operations = {
 	.send_cancel = send_nt_cancel,
+	.compare_fids = cifs_compare_fids,
 };
 

I don't think this will work. You can't get a pointer to a static inline, can you? Did this actually build?

fs/cifs/smb1ops.c send_nt_cancel(struct TCP_Server_Info *server, void *buf, · line 74

Quoted 1 line
fs/cifs/smb1ops.c +0 -0
 struct smb_version_values smb1_values = {

Otherwise, the basic concept of the patch looks fine to me.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20120516142901.559ac0c6-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#17 lore raw

Re: [PATCH v4 4/5] CIFS: Separate protocol specific part from getlk

2012/5/16 Jeff Layton <[email protected]>:

Quoted 156 lines
Quoted 153 lines · On Wed, 16 May 2012 13:57:33 +0400 Pavel Shilovsky…

---
 fs/cifs/cifsglob.h |    2 ++
 fs/cifs/file.c     |   52 ++++++++++++++++++++++++++++++---------------------- fs/cifs/smb1ops.c  |    7 +++++++

 3 files changed, 39 insertions(+), 22 deletions(-)
fs/cifs/cifsglob.h +2 -0
index 6943448..b6e97f8 100644
@@ -156,10 +156,12 @@ enum smb_version {
 
  struct mid_q_entry;
  struct TCP_Server_Info;
+struct cifsFileInfo;
 
  struct smb_version_operations {
       int (*send_cancel)(struct TCP_Server_Info *, void *,
                          struct mid_q_entry *);
+     bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
  };
 
  struct smb_version_values {
fs/cifs/file.c +0 -0
index ac71f85..9c2d85d 100644
@@ -671,7 +671,7 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
 

 static bool
 cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
-                         __u64 length, __u8 type, __u16 netfid,
+                         __u64 length, __u8 type, struct cifsFileInfo *cur, struct cifsLockInfo **conf_lock)
 {
      struct cifsLockInfo *li;

fs/cifs/file.c +0 -0
@@ -682,8 +682,8 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
                   offset >= li->offset + li->length)
                       continue;

              else if ((type & server->vals->shared_lock_type) &&
-                      ((netfid == cfile->netfid && current->tgid == li->pid)
-                      || type == li->type))
+                      ((server->ops->compare_fids(cur, cfile) &&
+                        current->tgid == li->pid) || type == li->type)) continue;
              else {
                      *conf_lock = li;

fs/cifs/file.c +0 -0
@@ -694,17 +694,17 @@ cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
  }
 

 static bool

fs/cifs/file.c +2 -3
-cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
-                     __u64 length, __u8 type, __u16 netfid,
-                     struct cifsLockInfo **conf_lock)
+cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
+                     __u8 type, struct cifsLockInfo **conf_lock)

 {
      bool rc = false;
      struct cifsFileInfo *fid, *tmp;
+     struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);

      spin_lock(&cifs_file_list_lock); list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) { rc = cifs_find_fid_lock_conflict(fid, offset, length, type,
-                                              netfid, conf_lock);
+                                              cfile, conf_lock); if (rc)
                      break;
      }

fs/cifs/file.c +4 -4
@@ -732,8 +732,8 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
 
       mutex_lock(&cinode->lock_mutex);
 
-     exist = cifs_find_lock_conflict(cinode, offset, length, type,
-                                     cfile->netfid, &conf_lock);
+     exist = cifs_find_lock_conflict(cfile, offset, length, type,
+                                     &conf_lock);
       if (exist) {
               flock->fl_start = conf_lock->offset;
               flock->fl_end = conf_lock->offset + conf_lock->length - 1;
@@ -779,8 +779,8 @@ try_again:
       exist = false;
       mutex_lock(&cinode->lock_mutex);
 
-     exist = cifs_find_lock_conflict(cinode, lock->offset, lock->length,
-                                     lock->type, cfile->netfid, &conf_lock);
+     exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
+                                     lock->type, &conf_lock);
       if (!exist && cinode->can_cache_brlcks) {
               list_add_tail(&lock->llist, &cfile->llist);
               mutex_unlock(&cinode->lock_mutex);
@@ -1117,6 +1117,15 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
  }
 

 static int

fs/cifs/file.c +9 -0
+cifs_mandatory_lock(int xid, struct cifsFileInfo *cfile, __u64 offset,
+                 __u64 length, __u32 type, int lock, int unlock, bool wait)
+{
+     return CIFSSMBLock(xid, tlink_tcon(cfile->tlink), cfile->netfid,
+                        current->tgid, length, offset, unlock, lock,
+                        (__u8)type, wait, 0);
+}
+
+static int

 cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, bool wait_flag, bool posix_lck, int xid)
 {

fs/cifs/file.c +4 -5
@@ -1149,12 +1158,11 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
               return rc;
 
       /* BB we could chain these into one lock request BB */
-     rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-                      flock->fl_start, 0, 1, type, 0, 0);
+     rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length, type,
+                              1, 0, false);
       if (rc == 0) {
-             rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
-                              length, flock->fl_start, 1, 0,
-                              type, 0, 0);
+             rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+                                      type, 0, 1, false);
               flock->fl_type = F_UNLCK;
               if (rc != 0)

                      cERROR(1, "Error unlocking previously locked "

fs/cifs/file.c +6 -6
@@ -1167,13 +1175,13 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
               return 0;
       }
 
-     rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-                      flock->fl_start, 0, 1,
-                      type | server->vals->shared_lock_type, 0, 0);
+     rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+                              type | server->vals->shared_lock_type, 1, 0,
+                              false);
       if (rc == 0) {
-             rc = CIFSSMBLock(xid, tcon, netfid, current->tgid,
-                              length, flock->fl_start, 1, 0,
-                              type | server->vals->shared_lock_type, 0, 0);
+             rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+                                      type | server->vals->shared_lock_type,
+                                      0, 1, false);
               flock->fl_type = F_RDLCK;
               if (rc != 0)

                      cERROR(1, "Error unlocking previously locked "

fs/cifs/smb1ops.c +0 -0
index af48a8b..7565587 100644
@@ -60,8 +60,15 @@ send_nt_cancel(struct TCP_Server_Info *server, void *buf,
       return rc;
  }
 
Quoted 15 lines

fs/cifs/smb1ops.c send_nt_cancel(struct TCP_Server_Info *server, void *buf, · line 73

Quoted 11 lines
fs/cifs/smb1ops.c +7 -0
+static inline bool
+cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
+{
+     return ob1->netfid == ob2->netfid;
+}
+
  struct smb_version_operations smb1_operations = {
       .send_cancel = send_nt_cancel,
+     .compare_fids = cifs_compare_fids,
  };
 

I don't think this will work. You can't get a pointer to a static inline, can you? Did this actually build?

But you are right - the compiler will just drop 'inline' in this case
- while we don't get this patch in the mainline I think it should be respin.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#18 lore raw

PATCH v4 5/5 CIFS: Separate protocol specific part from setlk

In reply to a message not in the archive
---
 fs/cifs/file.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/cifs/file.c +2 -2
index 9c2d85d..ed9b5a8 100644
@@ -1357,8 +1357,8 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 		if (rc <= 0)
 			goto out;
 
-		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-				 flock->fl_start, 0, 1, type, wait_flag, 0);
+		rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+					 type, 1, 0, wait_flag);
 		if (rc) {
 			kfree(lock);
 			goto out;
Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): 1337162254-13121-6-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

#20 lore raw

Re: [PATCH v4 5/5] CIFS: Separate protocol specific part from setlk

Quoted 10 lines · On Wed, 16 May 2012 13:57:34 +0400 Pavel Shilovsky…
---
 fs/cifs/file.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/cifs/file.c +0 -0
index 9c2d85d..ed9b5a8 100644

fs/cifs/file.c cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, · line 1364

Quoted 10 lines
fs/cifs/file.c +2 -2
@@ -1357,8 +1357,8 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
 		if (rc <= 0)
 			goto out;
 
-		rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-				 flock->fl_start, 0, 1, type, wait_flag, 0);
+		rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+					 type, 1, 0, wait_flag);
 		if (rc) {
 			kfree(lock);
 			goto out;

You can probably roll this in with patch #4 since it's a very similar change and so small...

Looks fine though. I guess at some point you'll need to add a ops->mandatory_lock or something?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20120516143134.7871db3f-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#22 lore raw

Re: [PATCH v4 5/5] CIFS: Separate protocol specific part from setlk

2012/5/16 Jeff Layton <[email protected]>:

Quoted 27 lines
Quoted 10 lines · On Wed, 16 May 2012 13:57:34 +0400 Pavel Shilovsky…

---
 fs/cifs/file.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
fs/cifs/file.c +0 -0
index 9c2d85d..ed9b5a8 100644

fs/cifs/file.c cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type, · line 1364

Quoted 10 lines
fs/cifs/file.c +2 -2
@@ -1357,8 +1357,8 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u32 type,
               if (rc <= 0)
                       goto out;
 
-             rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
-                              flock->fl_start, 0, 1, type, wait_flag, 0);
+             rc = cifs_mandatory_lock(xid, cfile, flock->fl_start, length,
+                                      type, 1, 0, wait_flag);
               if (rc) {
                       kfree(lock);
                       goto out;

You can probably roll this in with patch #4 since it's a very similar change and so small...

Quoted 2 lines

Looks fine though. I guess at some point you'll need to add a ops->mandatory_lock or something?

Yes - it will be the next step.

Signature · 2 lines
Best regards,
Pavel Shilovsky.