Skip to content

Commit 85f2d6b

Browse files
Suresh JayaramanSteve French
authored andcommitted
cifs: FS-Cache page management
Takes care of invalidation and release of FS-Cache marked pages and also invalidation of the FsCache page flag when the inode is removed. Signed-off-by: Suresh Jayaraman <sjayaraman@suse.de> Acked-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent 9451a9a commit 85f2d6b

4 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎fs/cifs/cache.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,42 @@ fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,
290290
return FSCACHE_CHECKAUX_OKAY;
291291
}
292292

293+
static void cifs_fscache_inode_now_uncached(void *cookie_netfs_data)
294+
{
295+
struct cifsInodeInfo *cifsi = cookie_netfs_data;
296+
struct pagevec pvec;
297+
pgoff_t first;
298+
int loop, nr_pages;
299+
300+
pagevec_init(&pvec, 0);
301+
first = 0;
302+
303+
cFYI(1, "cifs inode 0x%p now uncached", cifsi);
304+
305+
for (;;) {
306+
nr_pages = pagevec_lookup(&pvec,
307+
cifsi->vfs_inode.i_mapping, first,
308+
PAGEVEC_SIZE - pagevec_count(&pvec));
309+
if (!nr_pages)
310+
break;
311+
312+
for (loop = 0; loop < nr_pages; loop++)
313+
ClearPageFsCache(pvec.pages[loop]);
314+
315+
first = pvec.pages[nr_pages - 1]->index + 1;
316+
317+
pvec.nr = nr_pages;
318+
pagevec_release(&pvec);
319+
cond_resched();
320+
}
321+
}
322+
293323
const struct fscache_cookie_def cifs_fscache_inode_object_def = {
294324
.name = "CIFS.uniqueid",
295325
.type = FSCACHE_COOKIE_TYPE_DATAFILE,
296326
.get_key = cifs_fscache_inode_get_key,
297327
.get_attr = cifs_fscache_inode_get_attr,
298328
.get_aux = cifs_fscache_inode_get_aux,
299329
.check_aux = cifs_fscache_inode_check_aux,
330+
.now_uncached = cifs_fscache_inode_now_uncached,
300331
};

‎fs/cifs/file.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,22 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping,
22672267
return rc;
22682268
}
22692269

2270+
static int cifs_release_page(struct page *page, gfp_t gfp)
2271+
{
2272+
if (PagePrivate(page))
2273+
return 0;
2274+
2275+
return cifs_fscache_release_page(page, gfp);
2276+
}
2277+
2278+
static void cifs_invalidate_page(struct page *page, unsigned long offset)
2279+
{
2280+
struct cifsInodeInfo *cifsi = CIFS_I(page->mapping->host);
2281+
2282+
if (offset == 0)
2283+
cifs_fscache_invalidate_page(page, &cifsi->vfs_inode);
2284+
}
2285+
22702286
static void
22712287
cifs_oplock_break(struct slow_work *work)
22722288
{
@@ -2340,6 +2356,8 @@ const struct address_space_operations cifs_addr_ops = {
23402356
.write_begin = cifs_write_begin,
23412357
.write_end = cifs_write_end,
23422358
.set_page_dirty = __set_page_dirty_nobuffers,
2359+
.releasepage = cifs_release_page,
2360+
.invalidatepage = cifs_invalidate_page,
23432361
/* .sync_page = cifs_sync_page, */
23442362
/* .direct_IO = */
23452363
};
@@ -2356,6 +2374,8 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
23562374
.write_begin = cifs_write_begin,
23572375
.write_end = cifs_write_end,
23582376
.set_page_dirty = __set_page_dirty_nobuffers,
2377+
.releasepage = cifs_release_page,
2378+
.invalidatepage = cifs_invalidate_page,
23592379
/* .sync_page = cifs_sync_page, */
23602380
/* .direct_IO = */
23612381
};

‎fs/cifs/fscache.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,29 @@ void cifs_fscache_reset_inode_cookie(struct inode *inode)
124124
cifsi->fscache, old);
125125
}
126126
}
127+
128+
int cifs_fscache_release_page(struct page *page, gfp_t gfp)
129+
{
130+
if (PageFsCache(page)) {
131+
struct inode *inode = page->mapping->host;
132+
struct cifsInodeInfo *cifsi = CIFS_I(inode);
133+
134+
cFYI(1, "CIFS: fscache release page (0x%p/0x%p)",
135+
page, cifsi->fscache);
136+
if (!fscache_maybe_release_page(cifsi->fscache, page, gfp))
137+
return 0;
138+
}
139+
140+
return 1;
141+
}
142+
143+
void __cifs_fscache_invalidate_page(struct page *page, struct inode *inode)
144+
{
145+
struct cifsInodeInfo *cifsi = CIFS_I(inode);
146+
struct fscache_cookie *cookie = cifsi->fscache;
147+
148+
cFYI(1, "CIFS: fscache invalidatepage (0x%p/0x%p)", page, cookie);
149+
fscache_wait_on_page_write(cookie, page);
150+
fscache_uncache_page(cookie, page);
151+
}
152+

‎fs/cifs/fscache.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ extern void cifs_fscache_release_inode_cookie(struct inode *);
4848
extern void cifs_fscache_set_inode_cookie(struct inode *, struct file *);
4949
extern void cifs_fscache_reset_inode_cookie(struct inode *);
5050

51+
extern void __cifs_fscache_invalidate_page(struct page *, struct inode *);
52+
extern int cifs_fscache_release_page(struct page *page, gfp_t gfp);
53+
54+
static inline void cifs_fscache_invalidate_page(struct page *page,
55+
struct inode *inode)
56+
{
57+
if (PageFsCache(page))
58+
__cifs_fscache_invalidate_page(page, inode);
59+
}
60+
5161
#else /* CONFIG_CIFS_FSCACHE */
5262
static inline int cifs_fscache_register(void) { return 0; }
5363
static inline void cifs_fscache_unregister(void) {}
@@ -64,7 +74,13 @@ static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {}
6474
static inline void cifs_fscache_set_inode_cookie(struct inode *inode,
6575
struct file *filp) {}
6676
static inline void cifs_fscache_reset_inode_cookie(struct inode *inode) {}
77+
static inline void cifs_fscache_release_page(struct page *page, gfp_t gfp)
78+
{
79+
return 1; /* May release page */
80+
}
6781

82+
static inline int cifs_fscache_invalidate_page(struct page *page,
83+
struct inode *) {}
6884

6985
#endif /* CONFIG_CIFS_FSCACHE */
7086

0 commit comments

Comments
 (0)