Skip to content

Commit

Permalink
fscache: Convert fscache_set_page_dirty() to fscache_dirty_folio()
Browse files Browse the repository at this point in the history
Convert all users of fscache_set_page_dirty to use fscache_dirty_folio.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Tested-by: Damien Le Moal <[email protected]>
Acked-by: Damien Le Moal <[email protected]>
Tested-by: Mike Marshall <[email protected]> # orangefs
Tested-by: David Howells <[email protected]> # afs
  • Loading branch information
Matthew Wilcox (Oracle) committed Mar 15, 2022
1 parent 6f31a5a commit 8fb72b4
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 54 deletions.
7 changes: 4 additions & 3 deletions Documentation/filesystems/caching/netfs-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,17 @@ The following facilities are provided to manage this:

To support this, the following functions are provided::

int fscache_set_page_dirty(struct page *page,
struct fscache_cookie *cookie);
bool fscache_dirty_folio(struct address_space *mapping,
struct folio *folio,
struct fscache_cookie *cookie);
void fscache_unpin_writeback(struct writeback_control *wbc,
struct fscache_cookie *cookie);
void fscache_clear_inode_writeback(struct fscache_cookie *cookie,
struct inode *inode,
const void *aux);

The *set* function is intended to be called from the filesystem's
``set_page_dirty`` address space operation. If ``I_PINNING_FSCACHE_WB`` is not
``dirty_folio`` address space operation. If ``I_PINNING_FSCACHE_WB`` is not
set, it sets that flag and increments the use count on the cookie (the caller
must already have called ``fscache_use_cookie()``).

Expand Down
10 changes: 5 additions & 5 deletions fs/9p/vfs_addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,20 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping,
* Mark a page as having been made dirty and thus needing writeback. We also
* need to pin the cache object to write back to.
*/
static int v9fs_set_page_dirty(struct page *page)
static bool v9fs_dirty_folio(struct address_space *mapping, struct folio *folio)
{
struct v9fs_inode *v9inode = V9FS_I(page->mapping->host);
struct v9fs_inode *v9inode = V9FS_I(mapping->host);

return fscache_set_page_dirty(page, v9fs_inode_cookie(v9inode));
return fscache_dirty_folio(mapping, folio, v9fs_inode_cookie(v9inode));
}
#else
#define v9fs_set_page_dirty __set_page_dirty_nobuffers
#define v9fs_dirty_folio filemap_dirty_folio
#endif

const struct address_space_operations v9fs_addr_operations = {
.readpage = v9fs_vfs_readpage,
.readahead = v9fs_vfs_readahead,
.set_page_dirty = v9fs_set_page_dirty,
.dirty_folio = v9fs_dirty_folio,
.writepage = v9fs_vfs_writepage,
.write_begin = v9fs_write_begin,
.write_end = v9fs_write_end,
Expand Down
2 changes: 1 addition & 1 deletion fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const struct inode_operations afs_file_inode_operations = {
const struct address_space_operations afs_file_aops = {
.readpage = afs_readpage,
.readahead = afs_readahead,
.set_page_dirty = afs_set_page_dirty,
.dirty_folio = afs_dirty_folio,
.launder_folio = afs_launder_folio,
.releasepage = afs_releasepage,
.invalidate_folio = afs_invalidate_folio,
Expand Down
4 changes: 2 additions & 2 deletions fs/afs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1521,9 +1521,9 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
* write.c
*/
#ifdef CONFIG_AFS_FSCACHE
extern int afs_set_page_dirty(struct page *);
bool afs_dirty_folio(struct address_space *, struct folio *);
#else
#define afs_set_page_dirty __set_page_dirty_nobuffers
#define afs_dirty_folio filemap_dirty_folio
#endif
extern int afs_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
Expand Down
5 changes: 3 additions & 2 deletions fs/afs/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ static void afs_write_to_cache(struct afs_vnode *vnode, loff_t start, size_t len
* Mark a page as having been made dirty and thus needing writeback. We also
* need to pin the cache object to write back to.
*/
int afs_set_page_dirty(struct page *page)
bool afs_dirty_folio(struct address_space *mapping, struct folio *folio)
{
return fscache_set_page_dirty(page, afs_vnode_cache(AFS_FS_I(page->mapping->host)));
return fscache_dirty_folio(mapping, folio,
afs_vnode_cache(AFS_FS_I(mapping->host)));
}
static void afs_folio_start_fscache(bool caching, struct folio *folio)
{
Expand Down
27 changes: 13 additions & 14 deletions fs/ceph/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,17 @@ static inline struct ceph_snap_context *page_snap_context(struct page *page)
* Dirty a page. Optimistically adjust accounting, on the assumption
* that we won't race with invalidate. If we do, readjust.
*/
static int ceph_set_page_dirty(struct page *page)
static bool ceph_dirty_folio(struct address_space *mapping, struct folio *folio)
{
struct address_space *mapping = page->mapping;
struct inode *inode;
struct ceph_inode_info *ci;
struct ceph_snap_context *snapc;

if (PageDirty(page)) {
dout("%p set_page_dirty %p idx %lu -- already dirty\n",
mapping->host, page, page->index);
BUG_ON(!PagePrivate(page));
return 0;
if (folio_test_dirty(folio)) {
dout("%p dirty_folio %p idx %lu -- already dirty\n",
mapping->host, folio, folio->index);
BUG_ON(!folio_get_private(folio));
return false;
}

inode = mapping->host;
Expand All @@ -111,22 +110,22 @@ static int ceph_set_page_dirty(struct page *page)
if (ci->i_wrbuffer_ref == 0)
ihold(inode);
++ci->i_wrbuffer_ref;
dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d "
dout("%p dirty_folio %p idx %lu head %d/%d -> %d/%d "
"snapc %p seq %lld (%d snaps)\n",
mapping->host, page, page->index,
mapping->host, folio, folio->index,
ci->i_wrbuffer_ref-1, ci->i_wrbuffer_ref_head-1,
ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head,
snapc, snapc->seq, snapc->num_snaps);
spin_unlock(&ci->i_ceph_lock);

/*
* Reference snap context in page->private. Also set
* Reference snap context in folio->private. Also set
* PagePrivate so that we get invalidate_folio callback.
*/
BUG_ON(PagePrivate(page));
attach_page_private(page, snapc);
BUG_ON(folio_get_private(folio));
folio_attach_private(folio, snapc);

return ceph_fscache_set_page_dirty(page);
return ceph_fscache_dirty_folio(mapping, folio);
}

/*
Expand Down Expand Up @@ -1376,7 +1375,7 @@ const struct address_space_operations ceph_aops = {
.writepages = ceph_writepages_start,
.write_begin = ceph_write_begin,
.write_end = ceph_write_end,
.set_page_dirty = ceph_set_page_dirty,
.dirty_folio = ceph_dirty_folio,
.invalidate_folio = ceph_invalidate_folio,
.releasepage = ceph_releasepage,
.direct_IO = noop_direct_IO,
Expand Down
13 changes: 7 additions & 6 deletions fs/ceph/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ static inline void ceph_fscache_unpin_writeback(struct inode *inode,
fscache_unpin_writeback(wbc, ceph_fscache_cookie(ceph_inode(inode)));
}

static inline int ceph_fscache_set_page_dirty(struct page *page)
static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
struct folio *folio)
{
struct inode *inode = page->mapping->host;
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_inode_info *ci = ceph_inode(mapping->host);

return fscache_set_page_dirty(page, ceph_fscache_cookie(ci));
return fscache_dirty_folio(mapping, folio, ceph_fscache_cookie(ci));
}

static inline int ceph_begin_cache_operation(struct netfs_read_request *rreq)
Expand Down Expand Up @@ -133,9 +133,10 @@ static inline void ceph_fscache_unpin_writeback(struct inode *inode,
{
}

static inline int ceph_fscache_set_page_dirty(struct page *page)
static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
struct folio *folio)
{
return __set_page_dirty_nobuffers(page);
return filemap_dirty_folio(mapping, folio);
}

static inline bool ceph_is_cache_enabled(struct inode *inode)
Expand Down
11 changes: 6 additions & 5 deletions fs/cifs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -4939,12 +4939,13 @@ static void cifs_swap_deactivate(struct file *file)
* need to pin the cache object to write back to.
*/
#ifdef CONFIG_CIFS_FSCACHE
static int cifs_set_page_dirty(struct page *page)
static bool cifs_dirty_folio(struct address_space *mapping, struct folio *folio)
{
return fscache_set_page_dirty(page, cifs_inode_cookie(page->mapping->host));
return fscache_dirty_folio(mapping, folio,
cifs_inode_cookie(mapping->host));
}
#else
#define cifs_set_page_dirty __set_page_dirty_nobuffers
#define cifs_dirty_folio filemap_dirty_folio
#endif

const struct address_space_operations cifs_addr_ops = {
Expand All @@ -4954,7 +4955,7 @@ const struct address_space_operations cifs_addr_ops = {
.writepages = cifs_writepages,
.write_begin = cifs_write_begin,
.write_end = cifs_write_end,
.set_page_dirty = cifs_set_page_dirty,
.dirty_folio = cifs_dirty_folio,
.releasepage = cifs_release_page,
.direct_IO = cifs_direct_io,
.invalidate_folio = cifs_invalidate_folio,
Expand All @@ -4979,7 +4980,7 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
.writepages = cifs_writepages,
.write_begin = cifs_write_begin,
.write_end = cifs_write_end,
.set_page_dirty = cifs_set_page_dirty,
.dirty_folio = cifs_dirty_folio,
.releasepage = cifs_release_page,
.invalidate_folio = cifs_invalidate_folio,
.launder_folio = cifs_launder_folio,
Expand Down
28 changes: 15 additions & 13 deletions fs/fscache/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,29 @@ int __fscache_begin_write_operation(struct netfs_cache_resources *cres,
EXPORT_SYMBOL(__fscache_begin_write_operation);

/**
* fscache_set_page_dirty - Mark page dirty and pin a cache object for writeback
* @page: The page being dirtied
* fscache_dirty_folio - Mark folio dirty and pin a cache object for writeback
* @mapping: The mapping the folio belongs to.
* @folio: The folio being dirtied.
* @cookie: The cookie referring to the cache object
*
* Set the dirty flag on a page and pin an in-use cache object in memory when
* dirtying a page so that writeback can later write to it. This is intended
* to be called from the filesystem's ->set_page_dirty() method.
* Set the dirty flag on a folio and pin an in-use cache object in memory
* so that writeback can later write to it. This is intended
* to be called from the filesystem's ->dirty_folio() method.
*
* Returns 1 if PG_dirty was set on the page, 0 otherwise.
* Return: true if the dirty flag was set on the folio, false otherwise.
*/
int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie)
bool fscache_dirty_folio(struct address_space *mapping, struct folio *folio,
struct fscache_cookie *cookie)
{
struct inode *inode = page->mapping->host;
struct inode *inode = mapping->host;
bool need_use = false;

_enter("");

if (!__set_page_dirty_nobuffers(page))
return 0;
if (!filemap_dirty_folio(mapping, folio))
return false;
if (!fscache_cookie_valid(cookie))
return 1;
return true;

if (!(inode->i_state & I_PINNING_FSCACHE_WB)) {
spin_lock(&inode->i_lock);
Expand All @@ -192,9 +194,9 @@ int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie)
if (need_use)
fscache_use_cookie(cookie, true);
}
return 1;
return true;
}
EXPORT_SYMBOL(fscache_set_page_dirty);
EXPORT_SYMBOL(fscache_dirty_folio);

struct fscache_write_request {
struct netfs_cache_resources cache_resources;
Expand Down
8 changes: 5 additions & 3 deletions include/linux/fscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,17 +616,19 @@ static inline void fscache_write_to_cache(struct fscache_cookie *cookie,
}

#if __fscache_available
extern int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie);
bool fscache_dirty_folio(struct address_space *mapping, struct folio *folio,
struct fscache_cookie *cookie);
#else
#define fscache_set_page_dirty(PAGE, COOKIE) (__set_page_dirty_nobuffers((PAGE)))
#define fscache_dirty_folio(MAPPING, FOLIO, COOKIE) \
filemap_dirty_folio(MAPPING, FOLIO)
#endif

/**
* fscache_unpin_writeback - Unpin writeback resources
* @wbc: The writeback control
* @cookie: The cookie referring to the cache object
*
* Unpin the writeback resources pinned by fscache_set_page_dirty(). This is
* Unpin the writeback resources pinned by fscache_dirty_folio(). This is
* intended to be called by the netfs's ->write_inode() method.
*/
static inline void fscache_unpin_writeback(struct writeback_control *wbc,
Expand Down

0 comments on commit 8fb72b4

Please sign in to comment.