Skip to content

Commit 8fb72b4

Browse files
author
Matthew Wilcox (Oracle)
committed
fscache: Convert fscache_set_page_dirty() to fscache_dirty_folio()
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
1 parent 6f31a5a commit 8fb72b4

File tree

10 files changed

+61
-54
lines changed

10 files changed

+61
-54
lines changed

Documentation/filesystems/caching/netfs-api.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,17 @@ The following facilities are provided to manage this:
345345

346346
To support this, the following functions are provided::
347347

348-
int fscache_set_page_dirty(struct page *page,
349-
struct fscache_cookie *cookie);
348+
bool fscache_dirty_folio(struct address_space *mapping,
349+
struct folio *folio,
350+
struct fscache_cookie *cookie);
350351
void fscache_unpin_writeback(struct writeback_control *wbc,
351352
struct fscache_cookie *cookie);
352353
void fscache_clear_inode_writeback(struct fscache_cookie *cookie,
353354
struct inode *inode,
354355
const void *aux);
355356

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

fs/9p/vfs_addr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,20 @@ static int v9fs_write_end(struct file *filp, struct address_space *mapping,
359359
* Mark a page as having been made dirty and thus needing writeback. We also
360360
* need to pin the cache object to write back to.
361361
*/
362-
static int v9fs_set_page_dirty(struct page *page)
362+
static bool v9fs_dirty_folio(struct address_space *mapping, struct folio *folio)
363363
{
364-
struct v9fs_inode *v9inode = V9FS_I(page->mapping->host);
364+
struct v9fs_inode *v9inode = V9FS_I(mapping->host);
365365

366-
return fscache_set_page_dirty(page, v9fs_inode_cookie(v9inode));
366+
return fscache_dirty_folio(mapping, folio, v9fs_inode_cookie(v9inode));
367367
}
368368
#else
369-
#define v9fs_set_page_dirty __set_page_dirty_nobuffers
369+
#define v9fs_dirty_folio filemap_dirty_folio
370370
#endif
371371

372372
const struct address_space_operations v9fs_addr_operations = {
373373
.readpage = v9fs_vfs_readpage,
374374
.readahead = v9fs_vfs_readahead,
375-
.set_page_dirty = v9fs_set_page_dirty,
375+
.dirty_folio = v9fs_dirty_folio,
376376
.writepage = v9fs_vfs_writepage,
377377
.write_begin = v9fs_write_begin,
378378
.write_end = v9fs_write_end,

fs/afs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const struct inode_operations afs_file_inode_operations = {
5454
const struct address_space_operations afs_file_aops = {
5555
.readpage = afs_readpage,
5656
.readahead = afs_readahead,
57-
.set_page_dirty = afs_set_page_dirty,
57+
.dirty_folio = afs_dirty_folio,
5858
.launder_folio = afs_launder_folio,
5959
.releasepage = afs_releasepage,
6060
.invalidate_folio = afs_invalidate_folio,

fs/afs/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,9 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
15211521
* write.c
15221522
*/
15231523
#ifdef CONFIG_AFS_FSCACHE
1524-
extern int afs_set_page_dirty(struct page *);
1524+
bool afs_dirty_folio(struct address_space *, struct folio *);
15251525
#else
1526-
#define afs_set_page_dirty __set_page_dirty_nobuffers
1526+
#define afs_dirty_folio filemap_dirty_folio
15271527
#endif
15281528
extern int afs_write_begin(struct file *file, struct address_space *mapping,
15291529
loff_t pos, unsigned len, unsigned flags,

fs/afs/write.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ static void afs_write_to_cache(struct afs_vnode *vnode, loff_t start, size_t len
2222
* Mark a page as having been made dirty and thus needing writeback. We also
2323
* need to pin the cache object to write back to.
2424
*/
25-
int afs_set_page_dirty(struct page *page)
25+
bool afs_dirty_folio(struct address_space *mapping, struct folio *folio)
2626
{
27-
return fscache_set_page_dirty(page, afs_vnode_cache(AFS_FS_I(page->mapping->host)));
27+
return fscache_dirty_folio(mapping, folio,
28+
afs_vnode_cache(AFS_FS_I(mapping->host)));
2829
}
2930
static void afs_folio_start_fscache(bool caching, struct folio *folio)
3031
{

fs/ceph/addr.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,17 @@ static inline struct ceph_snap_context *page_snap_context(struct page *page)
7676
* Dirty a page. Optimistically adjust accounting, on the assumption
7777
* that we won't race with invalidate. If we do, readjust.
7878
*/
79-
static int ceph_set_page_dirty(struct page *page)
79+
static bool ceph_dirty_folio(struct address_space *mapping, struct folio *folio)
8080
{
81-
struct address_space *mapping = page->mapping;
8281
struct inode *inode;
8382
struct ceph_inode_info *ci;
8483
struct ceph_snap_context *snapc;
8584

86-
if (PageDirty(page)) {
87-
dout("%p set_page_dirty %p idx %lu -- already dirty\n",
88-
mapping->host, page, page->index);
89-
BUG_ON(!PagePrivate(page));
90-
return 0;
85+
if (folio_test_dirty(folio)) {
86+
dout("%p dirty_folio %p idx %lu -- already dirty\n",
87+
mapping->host, folio, folio->index);
88+
BUG_ON(!folio_get_private(folio));
89+
return false;
9190
}
9291

9392
inode = mapping->host;
@@ -111,22 +110,22 @@ static int ceph_set_page_dirty(struct page *page)
111110
if (ci->i_wrbuffer_ref == 0)
112111
ihold(inode);
113112
++ci->i_wrbuffer_ref;
114-
dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d "
113+
dout("%p dirty_folio %p idx %lu head %d/%d -> %d/%d "
115114
"snapc %p seq %lld (%d snaps)\n",
116-
mapping->host, page, page->index,
115+
mapping->host, folio, folio->index,
117116
ci->i_wrbuffer_ref-1, ci->i_wrbuffer_ref_head-1,
118117
ci->i_wrbuffer_ref, ci->i_wrbuffer_ref_head,
119118
snapc, snapc->seq, snapc->num_snaps);
120119
spin_unlock(&ci->i_ceph_lock);
121120

122121
/*
123-
* Reference snap context in page->private. Also set
122+
* Reference snap context in folio->private. Also set
124123
* PagePrivate so that we get invalidate_folio callback.
125124
*/
126-
BUG_ON(PagePrivate(page));
127-
attach_page_private(page, snapc);
125+
BUG_ON(folio_get_private(folio));
126+
folio_attach_private(folio, snapc);
128127

129-
return ceph_fscache_set_page_dirty(page);
128+
return ceph_fscache_dirty_folio(mapping, folio);
130129
}
131130

132131
/*
@@ -1376,7 +1375,7 @@ const struct address_space_operations ceph_aops = {
13761375
.writepages = ceph_writepages_start,
13771376
.write_begin = ceph_write_begin,
13781377
.write_end = ceph_write_end,
1379-
.set_page_dirty = ceph_set_page_dirty,
1378+
.dirty_folio = ceph_dirty_folio,
13801379
.invalidate_folio = ceph_invalidate_folio,
13811380
.releasepage = ceph_releasepage,
13821381
.direct_IO = noop_direct_IO,

fs/ceph/cache.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ static inline void ceph_fscache_unpin_writeback(struct inode *inode,
5454
fscache_unpin_writeback(wbc, ceph_fscache_cookie(ceph_inode(inode)));
5555
}
5656

57-
static inline int ceph_fscache_set_page_dirty(struct page *page)
57+
static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
58+
struct folio *folio)
5859
{
59-
struct inode *inode = page->mapping->host;
60-
struct ceph_inode_info *ci = ceph_inode(inode);
60+
struct ceph_inode_info *ci = ceph_inode(mapping->host);
6161

62-
return fscache_set_page_dirty(page, ceph_fscache_cookie(ci));
62+
return fscache_dirty_folio(mapping, folio, ceph_fscache_cookie(ci));
6363
}
6464

6565
static inline int ceph_begin_cache_operation(struct netfs_read_request *rreq)
@@ -133,9 +133,10 @@ static inline void ceph_fscache_unpin_writeback(struct inode *inode,
133133
{
134134
}
135135

136-
static inline int ceph_fscache_set_page_dirty(struct page *page)
136+
static inline int ceph_fscache_dirty_folio(struct address_space *mapping,
137+
struct folio *folio)
137138
{
138-
return __set_page_dirty_nobuffers(page);
139+
return filemap_dirty_folio(mapping, folio);
139140
}
140141

141142
static inline bool ceph_is_cache_enabled(struct inode *inode)

fs/cifs/file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4939,12 +4939,13 @@ static void cifs_swap_deactivate(struct file *file)
49394939
* need to pin the cache object to write back to.
49404940
*/
49414941
#ifdef CONFIG_CIFS_FSCACHE
4942-
static int cifs_set_page_dirty(struct page *page)
4942+
static bool cifs_dirty_folio(struct address_space *mapping, struct folio *folio)
49434943
{
4944-
return fscache_set_page_dirty(page, cifs_inode_cookie(page->mapping->host));
4944+
return fscache_dirty_folio(mapping, folio,
4945+
cifs_inode_cookie(mapping->host));
49454946
}
49464947
#else
4947-
#define cifs_set_page_dirty __set_page_dirty_nobuffers
4948+
#define cifs_dirty_folio filemap_dirty_folio
49484949
#endif
49494950

49504951
const struct address_space_operations cifs_addr_ops = {
@@ -4954,7 +4955,7 @@ const struct address_space_operations cifs_addr_ops = {
49544955
.writepages = cifs_writepages,
49554956
.write_begin = cifs_write_begin,
49564957
.write_end = cifs_write_end,
4957-
.set_page_dirty = cifs_set_page_dirty,
4958+
.dirty_folio = cifs_dirty_folio,
49584959
.releasepage = cifs_release_page,
49594960
.direct_IO = cifs_direct_io,
49604961
.invalidate_folio = cifs_invalidate_folio,
@@ -4979,7 +4980,7 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
49794980
.writepages = cifs_writepages,
49804981
.write_begin = cifs_write_begin,
49814982
.write_end = cifs_write_end,
4982-
.set_page_dirty = cifs_set_page_dirty,
4983+
.dirty_folio = cifs_dirty_folio,
49834984
.releasepage = cifs_release_page,
49844985
.invalidate_folio = cifs_invalidate_folio,
49854986
.launder_folio = cifs_launder_folio,

fs/fscache/io.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,29 @@ int __fscache_begin_write_operation(struct netfs_cache_resources *cres,
159159
EXPORT_SYMBOL(__fscache_begin_write_operation);
160160

161161
/**
162-
* fscache_set_page_dirty - Mark page dirty and pin a cache object for writeback
163-
* @page: The page being dirtied
162+
* fscache_dirty_folio - Mark folio dirty and pin a cache object for writeback
163+
* @mapping: The mapping the folio belongs to.
164+
* @folio: The folio being dirtied.
164165
* @cookie: The cookie referring to the cache object
165166
*
166-
* Set the dirty flag on a page and pin an in-use cache object in memory when
167-
* dirtying a page so that writeback can later write to it. This is intended
168-
* to be called from the filesystem's ->set_page_dirty() method.
167+
* Set the dirty flag on a folio and pin an in-use cache object in memory
168+
* so that writeback can later write to it. This is intended
169+
* to be called from the filesystem's ->dirty_folio() method.
169170
*
170-
* Returns 1 if PG_dirty was set on the page, 0 otherwise.
171+
* Return: true if the dirty flag was set on the folio, false otherwise.
171172
*/
172-
int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie)
173+
bool fscache_dirty_folio(struct address_space *mapping, struct folio *folio,
174+
struct fscache_cookie *cookie)
173175
{
174-
struct inode *inode = page->mapping->host;
176+
struct inode *inode = mapping->host;
175177
bool need_use = false;
176178

177179
_enter("");
178180

179-
if (!__set_page_dirty_nobuffers(page))
180-
return 0;
181+
if (!filemap_dirty_folio(mapping, folio))
182+
return false;
181183
if (!fscache_cookie_valid(cookie))
182-
return 1;
184+
return true;
183185

184186
if (!(inode->i_state & I_PINNING_FSCACHE_WB)) {
185187
spin_lock(&inode->i_lock);
@@ -192,9 +194,9 @@ int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie)
192194
if (need_use)
193195
fscache_use_cookie(cookie, true);
194196
}
195-
return 1;
197+
return true;
196198
}
197-
EXPORT_SYMBOL(fscache_set_page_dirty);
199+
EXPORT_SYMBOL(fscache_dirty_folio);
198200

199201
struct fscache_write_request {
200202
struct netfs_cache_resources cache_resources;

include/linux/fscache.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,19 @@ static inline void fscache_write_to_cache(struct fscache_cookie *cookie,
616616
}
617617

618618
#if __fscache_available
619-
extern int fscache_set_page_dirty(struct page *page, struct fscache_cookie *cookie);
619+
bool fscache_dirty_folio(struct address_space *mapping, struct folio *folio,
620+
struct fscache_cookie *cookie);
620621
#else
621-
#define fscache_set_page_dirty(PAGE, COOKIE) (__set_page_dirty_nobuffers((PAGE)))
622+
#define fscache_dirty_folio(MAPPING, FOLIO, COOKIE) \
623+
filemap_dirty_folio(MAPPING, FOLIO)
622624
#endif
623625

624626
/**
625627
* fscache_unpin_writeback - Unpin writeback resources
626628
* @wbc: The writeback control
627629
* @cookie: The cookie referring to the cache object
628630
*
629-
* Unpin the writeback resources pinned by fscache_set_page_dirty(). This is
631+
* Unpin the writeback resources pinned by fscache_dirty_folio(). This is
630632
* intended to be called by the netfs's ->write_inode() method.
631633
*/
632634
static inline void fscache_unpin_writeback(struct writeback_control *wbc,

0 commit comments

Comments
 (0)