Commit 1b4b55a1 authored by Pavel Shilovsky's avatar Pavel Shilovsky Committed by Steve French

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: default avatarPavel Shilovsky <pshilovsky@etersoft.ru>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent b140799a
...@@ -937,7 +937,7 @@ cifs_init_once(void *inode) ...@@ -937,7 +937,7 @@ cifs_init_once(void *inode)
struct cifsInodeInfo *cifsi = inode; struct cifsInodeInfo *cifsi = inode;
inode_init_once(&cifsi->vfs_inode); inode_init_once(&cifsi->vfs_inode);
mutex_init(&cifsi->lock_mutex); init_rwsem(&cifsi->lock_sem);
} }
static int static int
......
...@@ -1000,7 +1000,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file); ...@@ -1000,7 +1000,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
struct cifsInodeInfo { struct cifsInodeInfo {
bool can_cache_brlcks; bool can_cache_brlcks;
struct list_head llist; /* locks helb by this inode */ struct list_head llist; /* locks helb by this inode */
struct mutex lock_mutex; /* protect the fields above */ struct rw_semaphore lock_sem; /* protect the fields above */
/* BB add in lists for dirty pages i.e. write caching info for oplock */ /* BB add in lists for dirty pages i.e. write caching info for oplock */
struct list_head openFileList; struct list_head openFileList;
__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
......
...@@ -260,9 +260,9 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, ...@@ -260,9 +260,9 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
INIT_LIST_HEAD(&fdlocks->locks); INIT_LIST_HEAD(&fdlocks->locks);
fdlocks->cfile = cfile; fdlocks->cfile = cfile;
cfile->llist = fdlocks; cfile->llist = fdlocks;
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
list_add(&fdlocks->llist, &cinode->llist); list_add(&fdlocks->llist, &cinode->llist);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
cfile->count = 1; cfile->count = 1;
cfile->pid = current->tgid; cfile->pid = current->tgid;
...@@ -351,7 +351,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) ...@@ -351,7 +351,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
* Delete any outstanding lock records. We'll lose them when the file * Delete any outstanding lock records. We'll lose them when the file
* is closed anyway. * is closed anyway.
*/ */
mutex_lock(&cifsi->lock_mutex); down_write(&cifsi->lock_sem);
list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) { list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) {
list_del(&li->llist); list_del(&li->llist);
cifs_del_lock_waiters(li); cifs_del_lock_waiters(li);
...@@ -359,7 +359,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) ...@@ -359,7 +359,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
} }
list_del(&cifs_file->llist->llist); list_del(&cifs_file->llist->llist);
kfree(cifs_file->llist); kfree(cifs_file->llist);
mutex_unlock(&cifsi->lock_mutex); up_write(&cifsi->lock_sem);
cifs_put_tlink(cifs_file->tlink); cifs_put_tlink(cifs_file->tlink);
dput(cifs_file->dentry); dput(cifs_file->dentry);
...@@ -762,7 +762,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, ...@@ -762,7 +762,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
bool exist; bool exist;
mutex_lock(&cinode->lock_mutex); down_read(&cinode->lock_sem);
exist = cifs_find_lock_conflict(cfile, offset, length, type, exist = cifs_find_lock_conflict(cfile, offset, length, type,
&conf_lock); &conf_lock);
...@@ -779,7 +779,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, ...@@ -779,7 +779,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
else else
flock->fl_type = F_UNLCK; flock->fl_type = F_UNLCK;
mutex_unlock(&cinode->lock_mutex); up_read(&cinode->lock_sem);
return rc; return rc;
} }
...@@ -787,9 +787,9 @@ static void ...@@ -787,9 +787,9 @@ static void
cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
{ {
struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
list_add_tail(&lock->llist, &cfile->llist->locks); list_add_tail(&lock->llist, &cfile->llist->locks);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
} }
/* /*
...@@ -809,13 +809,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, ...@@ -809,13 +809,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
try_again: try_again:
exist = false; exist = false;
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length, exist = cifs_find_lock_conflict(cfile, lock->offset, lock->length,
lock->type, &conf_lock); lock->type, &conf_lock);
if (!exist && cinode->can_cache_brlcks) { if (!exist && cinode->can_cache_brlcks) {
list_add_tail(&lock->llist, &cfile->llist->locks); list_add_tail(&lock->llist, &cfile->llist->locks);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
return rc; return rc;
} }
...@@ -825,17 +825,17 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, ...@@ -825,17 +825,17 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
rc = -EACCES; rc = -EACCES;
else { else {
list_add_tail(&lock->blist, &conf_lock->blist); list_add_tail(&lock->blist, &conf_lock->blist);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
rc = wait_event_interruptible(lock->block_q, rc = wait_event_interruptible(lock->block_q,
(lock->blist.prev == &lock->blist) && (lock->blist.prev == &lock->blist) &&
(lock->blist.next == &lock->blist)); (lock->blist.next == &lock->blist));
if (!rc) if (!rc)
goto try_again; goto try_again;
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
list_del_init(&lock->blist); list_del_init(&lock->blist);
} }
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
return rc; return rc;
} }
...@@ -856,7 +856,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) ...@@ -856,7 +856,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock)
if ((flock->fl_flags & FL_POSIX) == 0) if ((flock->fl_flags & FL_POSIX) == 0)
return 1; return 1;
mutex_lock(&cinode->lock_mutex); down_read(&cinode->lock_sem);
posix_test_lock(file, flock); posix_test_lock(file, flock);
if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) { if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) {
...@@ -864,7 +864,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) ...@@ -864,7 +864,7 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock)
rc = 1; rc = 1;
} }
mutex_unlock(&cinode->lock_mutex); up_read(&cinode->lock_sem);
return rc; return rc;
} }
...@@ -884,14 +884,14 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock) ...@@ -884,14 +884,14 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
return rc; return rc;
try_again: try_again:
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
if (!cinode->can_cache_brlcks) { if (!cinode->can_cache_brlcks) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
return rc; return rc;
} }
rc = posix_lock_file(file, flock, NULL); rc = posix_lock_file(file, flock, NULL);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
if (rc == FILE_LOCK_DEFERRED) { if (rc == FILE_LOCK_DEFERRED) {
rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next); rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next);
if (!rc) if (!rc)
...@@ -918,9 +918,10 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -918,9 +918,10 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
xid = get_xid(); xid = get_xid();
tcon = tlink_tcon(cfile->tlink); tcon = tlink_tcon(cfile->tlink);
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) { if (!cinode->can_cache_brlcks) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
...@@ -931,7 +932,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -931,7 +932,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
*/ */
max_buf = tcon->ses->server->maxBuf; max_buf = tcon->ses->server->maxBuf;
if (!max_buf) { if (!max_buf) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return -EINVAL; return -EINVAL;
} }
...@@ -940,7 +941,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -940,7 +941,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
sizeof(LOCKING_ANDX_RANGE); sizeof(LOCKING_ANDX_RANGE);
buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL); buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL);
if (!buf) { if (!buf) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return -ENOMEM; return -ENOMEM;
} }
...@@ -978,7 +979,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -978,7 +979,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
} }
cinode->can_cache_brlcks = false; cinode->can_cache_brlcks = false;
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
kfree(buf); kfree(buf);
free_xid(xid); free_xid(xid);
...@@ -1013,9 +1014,10 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1013,9 +1014,10 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
xid = get_xid(); 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) { if (!cinode->can_cache_brlcks) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
...@@ -1031,7 +1033,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1031,7 +1033,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
/* /*
* Allocating count locks is enough because no FL_POSIX locks can be * Allocating count locks is enough because no FL_POSIX locks can be
* added to the list while we are holding cinode->lock_mutex that * added to the list while we are holding cinode->lock_sem that
* protects locking operations of this inode. * protects locking operations of this inode.
*/ */
for (; i < count; i++) { for (; i < count; i++) {
...@@ -1086,7 +1088,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1086,7 +1088,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
out: out:
cinode->can_cache_brlcks = false; cinode->can_cache_brlcks = false;
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return rc; return rc;
...@@ -1278,7 +1280,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1278,7 +1280,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
cur = buf; cur = buf;
num = 0; num = 0;
...@@ -1348,7 +1350,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1348,7 +1350,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
} }
} }
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
kfree(buf); kfree(buf);
return rc; return rc;
} }
......
...@@ -135,7 +135,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -135,7 +135,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
cur = buf; cur = buf;
mutex_lock(&cinode->lock_mutex); down_write(&cinode->lock_sem);
list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) { list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
if (flock->fl_start > li->offset || if (flock->fl_start > li->offset ||
(flock->fl_start + length) < (flock->fl_start + length) <
...@@ -196,7 +196,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -196,7 +196,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
} else } else
cifs_free_llist(&tmp_llist); cifs_free_llist(&tmp_llist);
} }
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
kfree(buf); kfree(buf);
return rc; return rc;
...@@ -253,9 +253,10 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -253,9 +253,10 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
struct cifs_fid_locks *fdlocks; struct cifs_fid_locks *fdlocks;
xid = get_xid(); 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) { if (!cinode->can_cache_brlcks) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
...@@ -266,7 +267,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -266,7 +267,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
*/ */
max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf; max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
if (!max_buf) { if (!max_buf) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return -EINVAL; return -EINVAL;
} }
...@@ -274,7 +275,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -274,7 +275,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
max_num = max_buf / sizeof(struct smb2_lock_element); max_num = max_buf / sizeof(struct smb2_lock_element);
buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL); buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL);
if (!buf) { if (!buf) {
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return -ENOMEM; return -ENOMEM;
} }
...@@ -288,7 +289,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -288,7 +289,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
cinode->can_cache_brlcks = false; cinode->can_cache_brlcks = false;
kfree(buf); kfree(buf);
mutex_unlock(&cinode->lock_mutex); up_write(&cinode->lock_sem);
free_xid(xid); free_xid(xid);
return rc; return rc;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment