@@ -3022,6 +3022,45 @@ cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
return -ENOENT;
}
+static int cifs_wait_writeback_killable(struct address_space *mapping,
+ loff_t start, loff_t end)
+{
+ pgoff_t end_index = end >> PAGE_SHIFT;
+ pgoff_t index = start >> PAGE_SHIFT;
+ struct folio_batch fbatch;
+ int rc = 0;
+
+ folio_batch_init(&fbatch);
+ while (!rc &&
+ filemap_get_folios_tag(mapping, &index, end_index,
+ PAGECACHE_TAG_WRITEBACK, &fbatch)) {
+ for (unsigned int i = 0;
+ !rc && i < folio_batch_count(&fbatch); i++)
+ rc = folio_wait_writeback_killable(fbatch.folios[i]);
+ folio_batch_release(&fbatch);
+ cond_resched();
+ }
+ return rc;
+}
+
+static int cifs_file_write_and_wait_killable(struct file *file,
+ loff_t start, loff_t end)
+{
+ struct address_space *mapping = file->f_mapping;
+ int rc, rc2;
+
+ if (end < start)
+ return 0;
+
+ rc = filemap_fdatawrite_range(mapping, start, end);
+ if (cifs_wait_writeback_killable(mapping, start, end))
+ return -EINTR;
+ rc2 = file_check_and_advance_wb_err(file);
+ if (!rc)
+ rc = rc2;
+ return rc;
+}
+
/*
* Flush data on a strict file.
*/
@@ -3033,7 +3072,7 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
unsigned int xid;
int rc;
- rc = file_write_and_wait_range(file, start, end);
+ rc = cifs_file_write_and_wait_killable(file, start, end);
if (rc) {
trace_cifs_fsync_err(inode->i_ino, rc);
return rc;
@@ -3065,7 +3104,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
struct inode *inode = file_inode(file);
struct cifs_sb_info *cifs_sb = CIFS_SB(file);
- rc = file_write_and_wait_range(file, start, end);
+ rc = cifs_file_write_and_wait_killable(file, start, end);
if (rc) {
trace_cifs_fsync_err(file_inode(file)->i_ino, rc);
return rc;
@@ -3100,25 +3139,6 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return rc;
}
-static int cifs_wait_writeback_killable(struct address_space *mapping)
-{
- struct folio_batch fbatch;
- pgoff_t index = 0;
- int rc = 0;
-
- folio_batch_init(&fbatch);
- while (!rc &&
- filemap_get_folios_tag(mapping, &index, (pgoff_t)-1,
- PAGECACHE_TAG_WRITEBACK, &fbatch)) {
- for (unsigned int i = 0;
- !rc && i < folio_batch_count(&fbatch); i++)
- rc = folio_wait_writeback_killable(fbatch.folios[i]);
- folio_batch_release(&fbatch);
- cond_resched();
- }
- return rc;
-}
-
/*
* As file closes, flush all cached write data for this inode checking
* for write behind errors.
@@ -3131,7 +3151,7 @@ int cifs_flush(struct file *file, fl_owner_t id)
if (file->f_mode & FMODE_WRITE) {
rc = filemap_fdatawrite(mapping);
- if (cifs_wait_writeback_killable(mapping))
+ if (cifs_wait_writeback_killable(mapping, 0, LLONG_MAX))
return 0;
rc2 = filemap_check_errors(mapping);
if (!rc)
cifs_fsync() and cifs_strict_fsync() wait uninterruptibly for writeback through file_write_and_wait_range(). As with close, a task killed in fsync(2) on a hard mount with an unresponsive server is stuck in D state until the server comes back. Wait killably instead, using the same helper as cifs_flush(). The writeback keeps going and its errors stay in the mapping; only the dying caller stops waiting for it. Signed-off-by: Paulo Alcantara <pc@manguebit.org> Cc: stable@vger.kernel.org --- fs/smb/client/file.c | 64 +++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 22 deletions(-)