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>
struct cifsInodeInfo *cifsi = inode;
inode_init_once(&cifsi->vfs_inode);
struct cifsInodeInfo *cifsi = inode;
inode_init_once(&cifsi->vfs_inode);
- mutex_init(&cifsi->lock_mutex);
+ init_rwsem(&cifsi->lock_sem);
struct cifsInodeInfo {
bool can_cache_brlcks;
struct list_head llist; /* locks helb by this inode */
struct cifsInodeInfo {
bool can_cache_brlcks;
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 */
struct list_head openFileList;
__u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
/* 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 */
INIT_LIST_HEAD(&fdlocks->locks);
fdlocks->cfile = cfile;
cfile->llist = fdlocks;
INIT_LIST_HEAD(&fdlocks->locks);
fdlocks->cfile = cfile;
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->pid = current->tgid;
cfile->count = 1;
cfile->pid = current->tgid;
* Delete any outstanding lock records. We'll lose them when the file
* is closed anyway.
*/
* Delete any outstanding lock records. We'll lose them when the file
* 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_del(&li->llist);
cifs_del_lock_waiters(li);
list_for_each_entry_safe(li, tmp, &cifs_file->llist->locks, llist) {
list_del(&li->llist);
cifs_del_lock_waiters(li);
}
list_del(&cifs_file->llist->llist);
kfree(cifs_file->llist);
}
list_del(&cifs_file->llist->llist);
kfree(cifs_file->llist);
- mutex_unlock(&cifsi->lock_mutex);
+ up_write(&cifsi->lock_sem);
cifs_put_tlink(cifs_file->tlink);
dput(cifs_file->dentry);
cifs_put_tlink(cifs_file->tlink);
dput(cifs_file->dentry);
struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
bool exist;
struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
bool exist;
- mutex_lock(&cinode->lock_mutex);
+ down_read(&cinode->lock_sem);
exist = cifs_find_lock_conflict(cfile, offset, length, type,
&conf_lock);
exist = cifs_find_lock_conflict(cfile, offset, length, type,
&conf_lock);
else
flock->fl_type = F_UNLCK;
else
flock->fl_type = F_UNLCK;
- mutex_unlock(&cinode->lock_mutex);
+ up_read(&cinode->lock_sem);
cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
{
struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
{
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);
try_again:
exist = false;
try_again:
exist = false;
- mutex_lock(&cinode->lock_mutex);
+ down_write(&cinode->lock_sem);
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->locks);
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->locks);
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
rc = -EACCES;
else {
list_add_tail(&lock->blist, &conf_lock->blist);
rc = -EACCES;
else {
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,
(lock->blist.prev == &lock->blist) &&
(lock->blist.next == &lock->blist));
if (!rc)
goto try_again;
rc = wait_event_interruptible(lock->block_q,
(lock->blist.prev == &lock->blist) &&
(lock->blist.next == &lock->blist));
if (!rc)
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);
if ((flock->fl_flags & FL_POSIX) == 0)
return 1;
if ((flock->fl_flags & FL_POSIX) == 0)
return 1;
- mutex_lock(&cinode->lock_mutex);
+ down_read(&cinode->lock_sem);
posix_test_lock(file, flock);
if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) {
posix_test_lock(file, flock);
if (flock->fl_type == F_UNLCK && !cinode->can_cache_brlcks) {
- mutex_unlock(&cinode->lock_mutex);
+ up_read(&cinode->lock_sem);
- 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;
}
rc = posix_lock_file(file, flock, NULL);
return rc;
}
rc = posix_lock_file(file, flock, NULL);
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
if (rc == FILE_LOCK_DEFERRED) {
rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next);
if (!rc)
if (rc == FILE_LOCK_DEFERRED) {
rc = wait_event_interruptible(flock->fl_wait, !flock->fl_next);
if (!rc)
xid = get_xid();
tcon = tlink_tcon(cfile->tlink);
xid = get_xid();
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);
return rc;
}
free_xid(xid);
return rc;
}
*/
max_buf = tcon->ses->server->maxBuf;
if (!max_buf) {
*/
max_buf = tcon->ses->server->maxBuf;
if (!max_buf) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return -EINVAL;
}
free_xid(xid);
return -EINVAL;
}
sizeof(LOCKING_ANDX_RANGE);
buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL);
if (!buf) {
sizeof(LOCKING_ANDX_RANGE);
buf = kzalloc(max_num * sizeof(LOCKING_ANDX_RANGE), GFP_KERNEL);
if (!buf) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return -ENOMEM;
}
free_xid(xid);
return -ENOMEM;
}
}
cinode->can_cache_brlcks = false;
}
cinode->can_cache_brlcks = false;
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
kfree(buf);
free_xid(xid);
kfree(buf);
free_xid(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);
return rc;
}
free_xid(xid);
return rc;
}
/*
* 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.
*/
for (; i < count; i++) {
* protects locking operations of this inode.
*/
for (; i < count; i++) {
out:
cinode->can_cache_brlcks = false;
out:
cinode->can_cache_brlcks = false;
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return rc;
free_xid(xid);
return rc;
if (!buf)
return -ENOMEM;
if (!buf)
return -ENOMEM;
- mutex_lock(&cinode->lock_mutex);
+ down_write(&cinode->lock_sem);
for (i = 0; i < 2; i++) {
cur = buf;
num = 0;
for (i = 0; i < 2; i++) {
cur = buf;
num = 0;
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
- 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) <
list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
if (flock->fl_start > li->offset ||
(flock->fl_start + length) <
} else
cifs_free_llist(&tmp_llist);
}
} else
cifs_free_llist(&tmp_llist);
}
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
struct cifs_fid_locks *fdlocks;
xid = get_xid();
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) {
if (!cinode->can_cache_brlcks) {
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return rc;
}
free_xid(xid);
return rc;
}
*/
max_buf = tlink_tcon(cfile->tlink)->ses->server->maxBuf;
if (!max_buf) {
*/
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;
}
free_xid(xid);
return -EINVAL;
}
max_num = max_buf / sizeof(struct smb2_lock_element);
buf = kzalloc(max_num * sizeof(struct smb2_lock_element), GFP_KERNEL);
if (!buf) {
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;
}
free_xid(xid);
return -ENOMEM;
}
cinode->can_cache_brlcks = false;
kfree(buf);
cinode->can_cache_brlcks = false;
kfree(buf);
- mutex_unlock(&cinode->lock_mutex);
+ up_write(&cinode->lock_sem);
free_xid(xid);
return rc;
}
free_xid(xid);
return rc;
}