cache.c (a0292f3ebe63f8ed7ea28de57751f6bfb9416242) cache.c (eb497943fa215897f2f60fd28aa6fe52da27ca6c)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * V9FS cache definitions.
4 *
5 * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
6 */
7
8#include <linux/jiffies.h>

--- 185 unchanged lines hidden (view full) ---

194 v9inode,
195 i_size_read(&v9inode->vfs_inode),
196 true);
197 p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
198 inode, old, v9inode->fscache);
199
200 mutex_unlock(&v9inode->fscache_lock);
201}
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * V9FS cache definitions.
4 *
5 * Copyright (C) 2009 by Abhishek Kulkarni <adkulkar@umail.iu.edu>
6 */
7
8#include <linux/jiffies.h>

--- 185 unchanged lines hidden (view full) ---

194 v9inode,
195 i_size_read(&v9inode->vfs_inode),
196 true);
197 p9_debug(P9_DEBUG_FSC, "inode %p revalidating cookie old %p new %p\n",
198 inode, old, v9inode->fscache);
199
200 mutex_unlock(&v9inode->fscache_lock);
201}
202
203int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
204{
205 struct inode *inode = page->mapping->host;
206 struct v9fs_inode *v9inode = V9FS_I(inode);
207
208 BUG_ON(!v9inode->fscache);
209
210 return fscache_maybe_release_page(v9inode->fscache, page, gfp);
211}
212
213void __v9fs_fscache_invalidate_page(struct page *page)
214{
215 struct inode *inode = page->mapping->host;
216 struct v9fs_inode *v9inode = V9FS_I(inode);
217
218 BUG_ON(!v9inode->fscache);
219
220 if (PageFsCache(page)) {
221 fscache_wait_on_page_write(v9inode->fscache, page);
222 BUG_ON(!PageLocked(page));
223 fscache_uncache_page(v9inode->fscache, page);
224 }
225}
226
227static void v9fs_vfs_readpage_complete(struct page *page, void *data,
228 int error)
229{
230 if (!error)
231 SetPageUptodate(page);
232
233 unlock_page(page);
234}
235
236/*
237 * __v9fs_readpage_from_fscache - read a page from cache
238 *
239 * Returns 0 if the pages are in cache and a BIO is submitted,
240 * 1 if the pages are not in cache and -error otherwise.
241 */
242
243int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
244{
245 int ret;
246 const struct v9fs_inode *v9inode = V9FS_I(inode);
247
248 p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
249 if (!v9inode->fscache)
250 return -ENOBUFS;
251
252 ret = fscache_read_or_alloc_page(v9inode->fscache,
253 page,
254 v9fs_vfs_readpage_complete,
255 NULL,
256 GFP_KERNEL);
257 switch (ret) {
258 case -ENOBUFS:
259 case -ENODATA:
260 p9_debug(P9_DEBUG_FSC, "page/inode not in cache %d\n", ret);
261 return 1;
262 case 0:
263 p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
264 return ret;
265 default:
266 p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
267 return ret;
268 }
269}
270
271/*
272 * __v9fs_readpages_from_fscache - read multiple pages from cache
273 *
274 * Returns 0 if the pages are in cache and a BIO is submitted,
275 * 1 if the pages are not in cache and -error otherwise.
276 */
277
278int __v9fs_readpages_from_fscache(struct inode *inode,
279 struct address_space *mapping,
280 struct list_head *pages,
281 unsigned *nr_pages)
282{
283 int ret;
284 const struct v9fs_inode *v9inode = V9FS_I(inode);
285
286 p9_debug(P9_DEBUG_FSC, "inode %p pages %u\n", inode, *nr_pages);
287 if (!v9inode->fscache)
288 return -ENOBUFS;
289
290 ret = fscache_read_or_alloc_pages(v9inode->fscache,
291 mapping, pages, nr_pages,
292 v9fs_vfs_readpage_complete,
293 NULL,
294 mapping_gfp_mask(mapping));
295 switch (ret) {
296 case -ENOBUFS:
297 case -ENODATA:
298 p9_debug(P9_DEBUG_FSC, "pages/inodes not in cache %d\n", ret);
299 return 1;
300 case 0:
301 BUG_ON(!list_empty(pages));
302 BUG_ON(*nr_pages != 0);
303 p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
304 return ret;
305 default:
306 p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
307 return ret;
308 }
309}
310
311/*
312 * __v9fs_readpage_to_fscache - write a page to the cache
313 *
314 */
315
316void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
317{
318 int ret;
319 const struct v9fs_inode *v9inode = V9FS_I(inode);
320
321 p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
322 ret = fscache_write_page(v9inode->fscache, page,
323 i_size_read(&v9inode->vfs_inode), GFP_KERNEL);
324 p9_debug(P9_DEBUG_FSC, "ret = %d\n", ret);
325 if (ret != 0)
326 v9fs_uncache_page(inode, page);
327}
328
329/*
330 * wait for a page to complete writing to the cache
331 */
332void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page)
333{
334 const struct v9fs_inode *v9inode = V9FS_I(inode);
335 p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
336 if (PageFsCache(page))
337 fscache_wait_on_page_write(v9inode->fscache, page);
338}