Skip to content

Commit

Permalink
cifs: Add some helper functions
Browse files Browse the repository at this point in the history
Add some helper functions to manipulate the folio marks by iterating
through a list of folios held in an xarray rather than using a page list.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Steve French <sfrench@samba.org>
cc: Shyam Prasad N <nspmangalore@gmail.com>
cc: Rohith Surabattula <rohiths.msft@gmail.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: linux-cifs@vger.kernel.org

Link: https://lore.kernel.org/r/164928616583.457102.15157033997163988344.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/165211418840.3154751.3090684430628501879.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/165348878940.2106726.204291614267188735.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/165364825674.3334034.3356201708659748648.stgit@warthog.procyon.org.uk/ # v3
Link: https://lore.kernel.org/r/166126394799.708021.10637797063862600488.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/166697258147.61150.9940790486999562110.stgit@warthog.procyon.org.uk/ # rfc
Link: https://lore.kernel.org/r/166732030314.3186319.9209944805565413627.stgit@warthog.procyon.org.uk/ # rfc
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
David Howells authored and Steve French committed Feb 20, 2023
1 parent 39bc582 commit b8713c4
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/cifs/cifsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ extern int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma);
extern const struct file_operations cifs_dir_ops;
extern int cifs_dir_open(struct inode *inode, struct file *file);
extern int cifs_readdir(struct file *file, struct dir_context *ctx);
extern void cifs_pages_written_back(struct inode *inode, loff_t start, unsigned int len);
extern void cifs_pages_write_failed(struct inode *inode, loff_t start, unsigned int len);
extern void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsigned int len);

/* Functions related to dir entries */
extern const struct dentry_operations cifs_dentry_ops;
Expand Down
93 changes: 93 additions & 0 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,99 @@
#include "cifs_ioctl.h"
#include "cached_dir.h"

/*
* Completion of write to server.
*/
void cifs_pages_written_back(struct inode *inode, loff_t start, unsigned int len)
{
struct address_space *mapping = inode->i_mapping;
struct folio *folio;
pgoff_t end;

XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE);

if (!len)
return;

rcu_read_lock();

end = (start + len - 1) / PAGE_SIZE;
xas_for_each(&xas, folio, end) {
if (!folio_test_writeback(folio)) {
WARN_ONCE(1, "bad %x @%llx page %lx %lx\n",
len, start, folio_index(folio), end);
continue;
}

folio_detach_private(folio);
folio_end_writeback(folio);
}

rcu_read_unlock();
}

/*
* Failure of write to server.
*/
void cifs_pages_write_failed(struct inode *inode, loff_t start, unsigned int len)
{
struct address_space *mapping = inode->i_mapping;
struct folio *folio;
pgoff_t end;

XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE);

if (!len)
return;

rcu_read_lock();

end = (start + len - 1) / PAGE_SIZE;
xas_for_each(&xas, folio, end) {
if (!folio_test_writeback(folio)) {
WARN_ONCE(1, "bad %x @%llx page %lx %lx\n",
len, start, folio_index(folio), end);
continue;
}

folio_set_error(folio);
folio_end_writeback(folio);
}

rcu_read_unlock();
}

/*
* Redirty pages after a temporary failure.
*/
void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsigned int len)
{
struct address_space *mapping = inode->i_mapping;
struct folio *folio;
pgoff_t end;

XA_STATE(xas, &mapping->i_pages, start / PAGE_SIZE);

if (!len)
return;

rcu_read_lock();

end = (start + len - 1) / PAGE_SIZE;
xas_for_each(&xas, folio, end) {
if (!folio_test_writeback(folio)) {
WARN_ONCE(1, "bad %x @%llx page %lx %lx\n",
len, start, folio_index(folio), end);
continue;
}

filemap_dirty_folio(folio->mapping, folio);
folio_end_writeback(folio);
}

rcu_read_unlock();
}

/*
* Mark as invalid, all open files on tree connections since they
* were closed when session to server was lost.
Expand Down

0 comments on commit b8713c4

Please sign in to comment.