提交 f45d3416 编写于 作者: P Pavel Shilovsky 提交者: Steve French

CIFS: Remove spinlock dependence in brlock processing

Now we need to lock/unlock a spinlock while processing brlock ops
on the inode. Move brlocks of a fid to a separate list and attach
all such lists to the inode. This let us not hold a spinlock.
Signed-off-by: NPavel Shilovsky <pshilovsky@samba.org>
上级 1c0bd60b
...@@ -233,6 +233,7 @@ cifs_alloc_inode(struct super_block *sb) ...@@ -233,6 +233,7 @@ cifs_alloc_inode(struct super_block *sb)
to zero by the VFS */ to zero by the VFS */
/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
INIT_LIST_HEAD(&cifs_inode->openFileList); INIT_LIST_HEAD(&cifs_inode->openFileList);
INIT_LIST_HEAD(&cifs_inode->llist);
return &cifs_inode->vfs_inode; return &cifs_inode->vfs_inode;
} }
......
...@@ -890,13 +890,16 @@ struct cifs_fid { ...@@ -890,13 +890,16 @@ struct cifs_fid {
#endif #endif
}; };
struct cifs_fid_locks {
struct list_head llist;
struct cifsFileInfo *cfile; /* fid that owns locks */
struct list_head locks; /* locks held by fid above */
};
struct cifsFileInfo { struct cifsFileInfo {
struct list_head tlist; /* pointer to next fid owned by tcon */ 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 flist; /* next fid (file instance) for this inode */
struct list_head llist; /* struct cifs_fid_locks *llist; /* brlocks held by this fid */
* brlocks held by this fid, protected by
* lock_mutex from cifsInodeInfo structure
*/
unsigned int uid; /* allows finding which FileInfo structure */ unsigned int uid; /* allows finding which FileInfo structure */
__u32 pid; /* process id who opened file */ __u32 pid; /* process id who opened file */
struct cifs_fid fid; /* file id from remote */ struct cifs_fid fid; /* file id from remote */
...@@ -988,11 +991,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file); ...@@ -988,11 +991,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
struct cifsInodeInfo { struct cifsInodeInfo {
bool can_cache_brlcks; bool can_cache_brlcks;
struct mutex lock_mutex; /* struct list_head llist; /* locks helb by this inode */
* protect the field above and llist struct mutex lock_mutex; /* protect the fields above */
* from every cifsFileInfo structure
* from openFileList
*/
/* 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 */
......
...@@ -245,11 +245,25 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, ...@@ -245,11 +245,25 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
struct cifsInodeInfo *cinode = CIFS_I(inode); struct cifsInodeInfo *cinode = CIFS_I(inode);
struct cifsFileInfo *cfile; struct cifsFileInfo *cfile;
struct cifs_fid_locks *fdlocks;
cfile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); cfile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
if (cfile == NULL) if (cfile == NULL)
return cfile; return cfile;
fdlocks = kzalloc(sizeof(struct cifs_fid_locks), GFP_KERNEL);
if (!fdlocks) {
kfree(cfile);
return NULL;
}
INIT_LIST_HEAD(&fdlocks->locks);
fdlocks->cfile = cfile;
cfile->llist = fdlocks;
mutex_lock(&cinode->lock_mutex);
list_add(&fdlocks->llist, &cinode->llist);
mutex_unlock(&cinode->lock_mutex);
cfile->count = 1; cfile->count = 1;
cfile->pid = current->tgid; cfile->pid = current->tgid;
cfile->uid = current_fsuid(); cfile->uid = current_fsuid();
...@@ -257,9 +271,8 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, ...@@ -257,9 +271,8 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
cfile->f_flags = file->f_flags; cfile->f_flags = file->f_flags;
cfile->invalidHandle = false; cfile->invalidHandle = false;
cfile->tlink = cifs_get_tlink(tlink); cfile->tlink = cifs_get_tlink(tlink);
mutex_init(&cfile->fh_mutex);
INIT_WORK(&cfile->oplock_break, cifs_oplock_break); INIT_WORK(&cfile->oplock_break, cifs_oplock_break);
INIT_LIST_HEAD(&cfile->llist); mutex_init(&cfile->fh_mutex);
tlink_tcon(tlink)->ses->server->ops->set_fid(cfile, fid, oplock); tlink_tcon(tlink)->ses->server->ops->set_fid(cfile, fid, oplock);
spin_lock(&cifs_file_list_lock); spin_lock(&cifs_file_list_lock);
...@@ -336,15 +349,18 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) ...@@ -336,15 +349,18 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
free_xid(xid); free_xid(xid);
} }
/* 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); mutex_lock(&cifsi->lock_mutex);
list_for_each_entry_safe(li, tmp, &cifs_file->llist, 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);
kfree(li); kfree(li);
} }
list_del(&cifs_file->llist->llist);
kfree(cifs_file->llist);
mutex_unlock(&cifsi->lock_mutex); mutex_unlock(&cifsi->lock_mutex);
cifs_put_tlink(cifs_file->tlink); cifs_put_tlink(cifs_file->tlink);
...@@ -691,25 +707,24 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock) ...@@ -691,25 +707,24 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
} }
static bool static bool
cifs_find_fid_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
__u64 length, __u8 type, struct cifsFileInfo *cur, __u64 length, __u8 type, struct cifsFileInfo *cfile,
struct cifsLockInfo **conf_lock) struct cifsLockInfo **conf_lock)
{ {
struct cifsLockInfo *li; struct cifsLockInfo *li;
struct cifsFileInfo *cur_cfile = fdlocks->cfile;
struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
list_for_each_entry(li, &cfile->llist, llist) { list_for_each_entry(li, &fdlocks->locks, llist) {
if (offset + length <= li->offset || if (offset + length <= li->offset ||
offset >= li->offset + li->length) offset >= li->offset + li->length)
continue; continue;
else if ((type & server->vals->shared_lock_type) && if ((type & server->vals->shared_lock_type) &&
((server->ops->compare_fids(cur, cfile) && ((server->ops->compare_fids(cfile, cur_cfile) &&
current->tgid == li->pid) || type == li->type)) current->tgid == li->pid) || type == li->type))
continue; continue;
else { *conf_lock = li;
*conf_lock = li; return true;
return true;
}
} }
return false; return false;
} }
...@@ -719,17 +734,15 @@ cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length, ...@@ -719,17 +734,15 @@ cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
__u8 type, struct cifsLockInfo **conf_lock) __u8 type, struct cifsLockInfo **conf_lock)
{ {
bool rc = false; bool rc = false;
struct cifsFileInfo *fid, *tmp; struct cifs_fid_locks *cur;
struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode); struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
spin_lock(&cifs_file_list_lock); list_for_each_entry(cur, &cinode->llist, llist) {
list_for_each_entry_safe(fid, tmp, &cinode->openFileList, flist) { rc = cifs_find_fid_lock_conflict(cur, offset, length, type,
rc = cifs_find_fid_lock_conflict(fid, offset, length, type,
cfile, conf_lock); cfile, conf_lock);
if (rc) if (rc)
break; break;
} }
spin_unlock(&cifs_file_list_lock);
return rc; return rc;
} }
...@@ -777,7 +790,7 @@ cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock) ...@@ -777,7 +790,7 @@ 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); mutex_lock(&cinode->lock_mutex);
list_add_tail(&lock->llist, &cfile->llist); list_add_tail(&lock->llist, &cfile->llist->locks);
mutex_unlock(&cinode->lock_mutex); mutex_unlock(&cinode->lock_mutex);
} }
...@@ -803,7 +816,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock, ...@@ -803,7 +816,7 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
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); list_add_tail(&lock->llist, &cfile->llist->locks);
mutex_unlock(&cinode->lock_mutex); mutex_unlock(&cinode->lock_mutex);
return rc; return rc;
} }
...@@ -937,7 +950,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile) ...@@ -937,7 +950,7 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
cur = buf; cur = buf;
num = 0; num = 0;
list_for_each_entry_safe(li, tmp, &cfile->llist, llist) { list_for_each_entry_safe(li, tmp, &cfile->llist->locks, llist) {
if (li->type != types[i]) if (li->type != types[i])
continue; continue;
cur->Pid = cpu_to_le16(li->pid); cur->Pid = cpu_to_le16(li->pid);
...@@ -1279,7 +1292,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1279,7 +1292,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
cur = buf; cur = buf;
num = 0; num = 0;
list_for_each_entry_safe(li, tmp, &cfile->llist, 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) <
(li->offset + li->length)) (li->offset + li->length))
...@@ -1320,7 +1333,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1320,7 +1333,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
* list to the head of the file's list. * list to the head of the file's list.
*/ */
cifs_move_llist(&tmp_llist, cifs_move_llist(&tmp_llist,
&cfile->llist); &cfile->llist->locks);
rc = stored_rc; rc = stored_rc;
} else } else
/* /*
...@@ -1337,7 +1350,8 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1337,7 +1350,8 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid, stored_rc = cifs_lockv(xid, tcon, cfile->fid.netfid,
types[i], num, 0, buf); types[i], num, 0, buf);
if (stored_rc) { if (stored_rc) {
cifs_move_llist(&tmp_llist, &cfile->llist); cifs_move_llist(&tmp_llist,
&cfile->llist->locks);
rc = stored_rc; rc = stored_rc;
} else } else
cifs_free_llist(&tmp_llist); cifs_free_llist(&tmp_llist);
...@@ -1350,7 +1364,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -1350,7 +1364,7 @@ cifs_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
} }
static int static int
cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
bool wait_flag, bool posix_lck, int lock, int unlock, bool wait_flag, bool posix_lck, int lock, int unlock,
unsigned int xid) unsigned int xid)
{ {
...@@ -1359,7 +1373,6 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1359,7 +1373,6 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data; struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
struct TCP_Server_Info *server = tcon->ses->server; struct TCP_Server_Info *server = tcon->ses->server;
__u16 netfid = cfile->fid.netfid;
if (posix_lck) { if (posix_lck) {
int posix_lock_type; int posix_lock_type;
...@@ -1376,9 +1389,9 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1376,9 +1389,9 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
if (unlock == 1) if (unlock == 1)
posix_lock_type = CIFS_UNLCK; posix_lock_type = CIFS_UNLCK;
rc = CIFSSMBPosixLock(xid, tcon, netfid, current->tgid, rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid,
flock->fl_start, length, NULL, current->tgid, flock->fl_start, length,
posix_lock_type, wait_flag); NULL, posix_lock_type, wait_flag);
goto out; goto out;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册