CIFS: Fix tcon and file locking
Subsystems (2)
PATCH 1/3 CIFS: Fix tcon and file locking
From: Pavel Shilovsky <[email protected]>
This fix is supposed to be squashed into
"Clarify locking of cifs file and tcon structures and make more granular".
--- fs/cifs/file.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
fs/cifs/file.c +12 -9
@@ -318,14 +318,14 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, oplock =0 ; } +spin_lock (&tcon->open_file_lock);if (fid->pending_open->oplock !=CIFS_OPLOCK_NO_CHANGE && oplock) oplock = fid->pending_open->oplock; -cifs_del_pending_open (fid->pending_open); +list_del (&fid->pending_open->olist); fid->purge_cache = false; server->ops->set_fid (cfile, fid, oplock); -spin_lock (&tcon->open_file_lock);list_add (&cfile->tlist, &tcon->openFileList);/* if readable file instance put first in list*/
@@ -354,7 +354,7 @@ cifsFileInfo_get(struct cifsFileInfo *cifs_file)/* * Release a reference on the file private data. This may involve closing * the filehandle out on the server. Must be called without holding -* cifs_file->file_info_lock. +* tcon->open_file_lock and cifs_file->file_info_lock. */ void cifsFileInfo_put (struct cifsFileInfo *cifs_file) {
@@ -369,11 +369,15 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)struct cifs_pending_open open;bool oplock_break_cancelled; +spin_lock (&tcon->open_file_lock); +spin_lock (&cifs_file->file_info_lock);if (--cifs_file->count >0 ) {spin_unlock (&cifs_file->file_info_lock); +spin_unlock (&tcon->open_file_lock);return ; } +spin_unlock (&cifs_file->file_info_lock);if (server->ops->get_lease_key) server->ops->get_lease_key (inode, &fid);
@@ -397,7 +401,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)set_bit (CIFS_INO_INVALID_MAPPING , &cifsi->flags);cifs_set_oplock_level (cifsi,0 ); } -spin_unlock (&cifs_file->file_info_lock); + +spin_unlock (&tcon->open_file_lock); oplock_break_cancelled =cancel_work_sync (&cifs_file->oplock_break);
@@ -1765,7 +1770,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,if (!open_file->invalidHandle) {/* found a good file */ /* lock it so it will not be closed on us */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }/* else might as well continue, and look for
@@ -1819,7 +1824,7 @@ refind_writable:if (OPEN_FMODE (open_file->f_flags) &FMODE_WRITE ) {if (!open_file->invalidHandle) {/* found a good writable file */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }else {
@@ -1836,9 +1841,7 @@ refind_writable:if (inv_file) { any_available = false; -spin_lock (&inv_file->file_info_lock); -cifsFileInfo_get_locked (inv_file); -spin_unlock (&inv_file->file_info_lock); +cifsFileInfo_get (inv_file); }spin_unlock (&tcon->open_file_lock);
Signature · 1 line
2.7.4
A message that is not in the archive (sent off-list or not yet received): 1476225247-30177-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/3 CIFS: Fix persistent handles re-opening on reconnect
From: Pavel Shilovsky <[email protected]>
openFileList of tcon can be changed while cifs_reopen_file() is called that can lead to an unexpected behavior when we return to the loop. Fix this by introducing a temp list for keeping all file handles that need to be reopen.
--- fs/cifs/cifsglob.h | 1 + fs/cifs/file.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
fs/cifs/cifsglob.h +1 -0
@@ -1067,6 +1067,7 @@ struct cifsFileInfo {kuid_t uid;/* allows finding which FileInfo structure */ __u32 pid;/* process id who opened file */ struct cifs_fid fid;/* file id from remote */ +struct list_head rlist;/* reconnect list */ /* BB add lock scope info here if needed */ ;/* lock scope id (0 if none) */ struct dentry *dentry;
fs/cifs/file.c +17 -5
@@ -763,19 +763,31 @@ int cifs_close(struct inode *inode, struct file *file)void cifs_reopen_persistent_handles (struct cifs_tcon *tcon) { -struct cifsFileInfo *open_file =NULL ; +struct cifsFileInfo *open_file;struct list_head *tmp;struct list_head *tmp1; +struct list_head tmp_list; + +cifs_dbg (FYI ,"Reopen persistent handles" ); +INIT_LIST_HEAD (&tmp_list);/* list all files open on tree connection, reopen resilient handles */ spin_lock (&tcon->open_file_lock); -list_for_each_safe (tmp, tmp1, &tcon->openFileList) { +list_for_each (tmp, &tcon->openFileList) { open_file = list_entry(tmp, struct cifsFileInfo, tlist); -spin_unlock (&tcon->open_file_lock); -cifs_reopen_file (open_file, false/* do not flush */ ); -spin_lock (&tcon->open_file_lock); +if (!open_file->invalidHandle) +continue ; +cifsFileInfo_get (open_file); +list_add_tail (&open_file->rlist, &tmp_list); }spin_unlock (&tcon->open_file_lock); + +list_for_each_safe (tmp, tmp1, &tmp_list) { + open_file = list_entry(tmp, struct cifsFileInfo, rlist); +cifs_reopen_file (open_file, false/* do not flush */ ); +list_del_init (&open_file->rlist); +cifsFileInfo_put (open_file); + } }int cifs_closedir (struct inode *inode,struct file *file)
Signature · 1 line
2.7.4
PATCH 3/3 CIFS: Reset read oplock to NONE if we have mandatory locks after reopen
In reply to a message not in the archiveFrom: Pavel Shilovsky <[email protected]>
We are already doing the same thing for an ordinary open case:
we can't keep read oplock on a file if we have mandatory byte-range locks because pagereading can conflict with these locks on a server. Fix it by setting oplock level to NONE.
--- fs/cifs/file.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/cifs/file.c +9 -0
@@ -739,6 +739,15 @@ reopen_success:* to the server to get the new inode info. */ +/* +* If the server returned a read oplock and we have mandatory brlocks, +* set oplock level to None. +*/ +if (server->ops->is_read_op (oplock) &&cifs_has_mand_locks (cinode)) { +cifs_dbg (FYI ,"Reset oplock val from read to None due to mand locks\n" ); + oplock =0 ; + } + server->ops->set_fid (cfile, &cfile->fid, oplock);if (oparms.reconnect)cifs_relock_file (cfile);
Signature · 1 line
2.7.4
patch merged in with the patch noted above (and the other two patches from Pavel also merged) into cifs-2.6.git for-next
Quoted 102 lines · Pavel Shilovsky
From: Pavel Shilovsky <[email protected]>
This fix is supposed to be squashed into
"Clarify locking of cifs file and tcon structures and make more granular".Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/file.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)fs/cifs/file.c +12
-10@@ -318,14 +318,14 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, oplock =0 ; } +spin_lock (&tcon->open_file_lock);if (fid->pending_open->oplock !=CIFS_OPLOCK_NO_CHANGE && oplock) oplock = fid->pending_open->oplock; -cifs_del_pending_open (fid->pending_open); +list_del (&fid->pending_open->olist); fid->purge_cache = false; server->ops->set_fid (cfile, fid, oplock); -spin_lock (&tcon->open_file_lock);list_add (&cfile->tlist, &tcon->openFileList);/* if readable file instance put first in list*/ @@ -354,7 +354,7 @@ cifsFileInfo_get(struct cifsFileInfo *cifs_file)/* * Release a reference on the file private data. This may involve closing * the filehandle out on the server. Must be called without holding -* cifs_file->file_info_lock. +* tcon->open_file_lock and cifs_file->file_info_lock. */ void cifsFileInfo_put (struct cifsFileInfo *cifs_file) {@@ -369,11 +369,15 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)struct cifs_pending_open open;bool oplock_break_cancelled; +spin_lock (&tcon->open_file_lock); +spin_lock (&cifs_file->file_info_lock);if (--cifs_file->count >0 ) {spin_unlock (&cifs_file->file_info_lock); +spin_unlock (&tcon->open_file_lock);return ; } +spin_unlock (&cifs_file->file_info_lock);if (server->ops->get_lease_key) server->ops->get_lease_key (inode, &fid);@@ -397,7 +401,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)set_bit (CIFS_INO_INVALID_MAPPING , &cifsi->flags);cifs_set_oplock_level (cifsi,0 ); } -spin_unlock (&cifs_file->file_info_lock); + +spin_unlock (&tcon->open_file_lock); oplock_break_cancelled =cancel_work_sync (&cifs_file->oplock_break);@@ -1765,7 +1770,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,if (!open_file->invalidHandle) {/* found a good file */ /* lock it so it will not be closed on us */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }/* else might as well continue, and look for @@ -1819,7 +1824,7 @@ refind_writable:if (OPEN_FMODE (open_file->f_flags) &FMODE_WRITE ) {if (!open_file->invalidHandle) {/* found a good writable file */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }else {@@ -1836,9 +1841,7 @@ refind_writable:if (inv_file) { any_available = false; -spin_lock (&inv_file->file_info_lock); -cifsFileInfo_get_locked (inv_file); -spin_unlock (&inv_file->file_info_lock); +cifsFileInfo_get (inv_file); }spin_unlock (&tcon->open_file_lock); --2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Thanks, Steve
A message that is not in the archive (sent off-list or not yet received): CAH2r5mucfYLVKDX7JWaN1g90+NKneK_GUACzrt3ab8hYOPuF3Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
I tested this patchset, along with the following on top of 4.4 kernel, in our XenServer stress test (450 Virtual Machine life cycle operations with 2 different SMB3 targets, Windows and Netapp).
The list of tested patches follows:
cifs-Limit-the-overall-credit-acquired fix_memory_leaks_in_cifs_do_mount compare_prepaths_when_comparing_superblocks move_check_for_prefix_path_to_within_cifs_get_root display_number_of_credits_available set_previous_session_id_correctly_on_smb3_reconnect smb3__guids_should_be_constructed_as_random_but_valid_uuids fs-cifs__keep_guid_when_assigning_fid_to_fileinfo fix_regression_which_breaks_dfs_mounting clarify_locking_of_cifs_file_and_tcon_structures_and_make_more_granular fs-cifs__reopen_persistent_handles_on_reconnect expose_module_parameters_in_sysfs smb3__add_mount_parameter_to_allow_user_to_override_max_credits cifs__fix_persistent_handles_re-opening_on_reconnect cifs__reset_read_oplock_to_none_if_we_have_mandatory_locks_after_reopen
Without the recent fixes to tcon_open_file_list loop, the stress test failed (a temporary fix was to loop through it with the safe loop alternative).
Overall the stress tests are passing.
Regards,
Germano
Quoted 109 lines · Steve French
patch merged in with the patch noted above (and the other two patches from Pavel also merged) into cifs-2.6.git for-next
Quoted 102 lines · Pavel Shilovsky
From: Pavel Shilovsky <[email protected]>
This fix is supposed to be squashed into
"Clarify locking of cifs file and tcon structures and make more granular".Signed-off-by Pavel Shilovsky <[email protected]>--- fs/cifs/file.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)fs/cifs/file.c +12
-10@@ -318,14 +318,14 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file, oplock =0 ; } +spin_lock (&tcon->open_file_lock);if (fid->pending_open->oplock !=CIFS_OPLOCK_NO_CHANGE && oplock) oplock = fid->pending_open->oplock; -cifs_del_pending_open (fid->pending_open); +list_del (&fid->pending_open->olist); fid->purge_cache = false; server->ops->set_fid (cfile, fid, oplock); -spin_lock (&tcon->open_file_lock);list_add (&cfile->tlist, &tcon->openFileList);/* if readable file instance put first in list*/ @@ -354,7 +354,7 @@ cifsFileInfo_get(struct cifsFileInfo *cifs_file)/* * Release a reference on the file private data. This may involve closing * the filehandle out on the server. Must be called without holding -* cifs_file->file_info_lock. +* tcon->open_file_lock and cifs_file->file_info_lock. */ void cifsFileInfo_put (struct cifsFileInfo *cifs_file) {@@ -369,11 +369,15 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)struct cifs_pending_open open;bool oplock_break_cancelled; +spin_lock (&tcon->open_file_lock); +spin_lock (&cifs_file->file_info_lock);if (--cifs_file->count >0 ) {spin_unlock (&cifs_file->file_info_lock); +spin_unlock (&tcon->open_file_lock);return ; } +spin_unlock (&cifs_file->file_info_lock);if (server->ops->get_lease_key) server->ops->get_lease_key (inode, &fid);@@ -397,7 +401,8 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)set_bit (CIFS_INO_INVALID_MAPPING , &cifsi->flags);cifs_set_oplock_level (cifsi,0 ); } -spin_unlock (&cifs_file->file_info_lock); + +spin_unlock (&tcon->open_file_lock); oplock_break_cancelled =cancel_work_sync (&cifs_file->oplock_break);@@ -1765,7 +1770,7 @@ struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode,if (!open_file->invalidHandle) {/* found a good file */ /* lock it so it will not be closed on us */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }/* else might as well continue, and look for @@ -1819,7 +1824,7 @@ refind_writable:if (OPEN_FMODE (open_file->f_flags) &FMODE_WRITE ) {if (!open_file->invalidHandle) {/* found a good writable file */ -cifsFileInfo_get_locked (open_file); +cifsFileInfo_get (open_file);spin_unlock (&tcon->open_file_lock);return open_file; }else {@@ -1836,9 +1841,7 @@ refind_writable:if (inv_file) { any_available = false; -spin_lock (&inv_file->file_info_lock); -cifsFileInfo_get_locked (inv_file); -spin_unlock (&inv_file->file_info_lock); +cifsFileInfo_get (inv_file); }spin_unlock (&tcon->open_file_lock); --2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html