CIFS: Turn lock mutex into rw semaphore
and allow several processes to walk through the lock list and read
can_cache_brlcks value if they are not going to modify them.
Signed-off-by: Pavel Shilovsky <pshilovsky@etersoft.ru>
Signed-off-by: Steve French <sfrench@us.ibm.com>
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
index 181e13d..0ddd617 100644
--- a/fs/cifs/smb2file.c
+++ b/fs/cifs/smb2file.c
@@ -135,7 +135,7 @@
cur = buf;
- mutex_lock(&cinode->lock_mutex);
+ down_write(&cinode->lock_sem);
list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
if (flock->fl_start > li->offset ||
(flock->fl_start + length) <
@@ -196,7 +196,7 @@
} else
cifs_free_llist(&tmp_llist);
}
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
kfree(buf);
return rc;
@@ -253,9 +253,10 @@
struct cifs_fid_locks *fdlocks;
xid = get_xid();
- mutex_lock(&cinode->lock_mutex);
+ /* we are going to update can_cache_brlcks here - need a write access */
+ down_write(&cinode->lock_sem);
if (!cinode->can_cache_brlcks) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return rc;
}
@@ -266,7 +267,7 @@
*/
max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
if (!max_buf) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return -EINVAL;
}
@@ -274,7 +275,7 @@
max_num = max_buf / sizeof(struct smb2_lock_element);
buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL);
if (!buf) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return -ENOMEM;
}
@@ -288,7 +289,7 @@
cinode->can_cache_brlcks = false;
kfree(buf);
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return rc;
}