file.c (2cee6fbb7f01bcb25f11ef1439e89a29de4c0c1d) file.c (523d27cda149cfc8c99159c0f68f690e4d3b9d14)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* AFS filesystem file handling
3 *
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#include <linux/kernel.h>

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

153 if (file->f_mode & FMODE_WRITE) {
154 ret = afs_cache_wb_key(vnode, af);
155 if (ret < 0)
156 goto error_af;
157 }
158
159 if (file->f_flags & O_TRUNC)
160 set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* AFS filesystem file handling
3 *
4 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#include <linux/kernel.h>

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

153 if (file->f_mode & FMODE_WRITE) {
154 ret = afs_cache_wb_key(vnode, af);
155 if (ret < 0)
156 goto error_af;
157 }
158
159 if (file->f_flags & O_TRUNC)
160 set_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags);
161
161
162 fscache_use_cookie(afs_vnode_cache(vnode), file->f_mode & FMODE_WRITE);
163
162 file->private_data = af;
163 _leave(" = 0");
164 return 0;
165
166error_af:
167 kfree(af);
168error_key:
169 key_put(key);
170error:
171 _leave(" = %d", ret);
172 return ret;
173}
174
175/*
176 * release an AFS file or directory and discard its key
177 */
178int afs_release(struct inode *inode, struct file *file)
179{
164 file->private_data = af;
165 _leave(" = 0");
166 return 0;
167
168error_af:
169 kfree(af);
170error_key:
171 key_put(key);
172error:
173 _leave(" = %d", ret);
174 return ret;
175}
176
177/*
178 * release an AFS file or directory and discard its key
179 */
180int afs_release(struct inode *inode, struct file *file)
181{
182 struct afs_vnode_cache_aux aux;
180 struct afs_vnode *vnode = AFS_FS_I(inode);
181 struct afs_file *af = file->private_data;
183 struct afs_vnode *vnode = AFS_FS_I(inode);
184 struct afs_file *af = file->private_data;
185 loff_t i_size;
182 int ret = 0;
183
184 _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
185
186 if ((file->f_mode & FMODE_WRITE))
187 ret = vfs_fsync(file, 0);
188
189 file->private_data = NULL;
190 if (af->wb)
191 afs_put_wb_key(af->wb);
186 int ret = 0;
187
188 _enter("{%llx:%llu},", vnode->fid.vid, vnode->fid.vnode);
189
190 if ((file->f_mode & FMODE_WRITE))
191 ret = vfs_fsync(file, 0);
192
193 file->private_data = NULL;
194 if (af->wb)
195 afs_put_wb_key(af->wb);
196
197 if ((file->f_mode & FMODE_WRITE)) {
198 i_size = i_size_read(&vnode->vfs_inode);
199 afs_set_cache_aux(vnode, &aux);
200 fscache_unuse_cookie(afs_vnode_cache(vnode), &aux, &i_size);
201 } else {
202 fscache_unuse_cookie(afs_vnode_cache(vnode), NULL, NULL);
203 }
204
192 key_put(af->key);
193 kfree(af);
194 afs_prune_wb_keys(vnode);
195 _leave(" = %d", ret);
196 return ret;
197}
198
199/*

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

347
348static void afs_init_rreq(struct netfs_read_request *rreq, struct file *file)
349{
350 rreq->netfs_priv = key_get(afs_file_key(file));
351}
352
353static bool afs_is_cache_enabled(struct inode *inode)
354{
205 key_put(af->key);
206 kfree(af);
207 afs_prune_wb_keys(vnode);
208 _leave(" = %d", ret);
209 return ret;
210}
211
212/*

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

360
361static void afs_init_rreq(struct netfs_read_request *rreq, struct file *file)
362{
363 rreq->netfs_priv = key_get(afs_file_key(file));
364}
365
366static bool afs_is_cache_enabled(struct inode *inode)
367{
355 return fscache_cookie_enabled(afs_vnode_cache(AFS_FS_I(inode)));
368 struct fscache_cookie *cookie = afs_vnode_cache(AFS_FS_I(inode));
369
370 return fscache_cookie_enabled(cookie) && cookie->cache_priv;
356}
357
358static int afs_begin_cache_operation(struct netfs_read_request *rreq)
359{
360#ifdef CONFIG_AFS_FSCACHE
361 struct afs_vnode *vnode = AFS_FS_I(rreq->inode);
362
371}
372
373static int afs_begin_cache_operation(struct netfs_read_request *rreq)
374{
375#ifdef CONFIG_AFS_FSCACHE
376 struct afs_vnode *vnode = AFS_FS_I(rreq->inode);
377
363 return fscache_begin_read_operation(rreq, afs_vnode_cache(vnode));
378 return fscache_begin_read_operation(&rreq->cache_resources,
379 afs_vnode_cache(vnode));
364#else
365 return -ENOBUFS;
366#endif
367}
368
369static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len,
370 struct folio *folio, void **_fsdata)
371{

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

477 folio_wait_fscache(folio);
478 _leave("");
479}
480
481/*
482 * release a page and clean up its private state if it's not busy
483 * - return true if the page can now be released, false if not
484 */
380#else
381 return -ENOBUFS;
382#endif
383}
384
385static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len,
386 struct folio *folio, void **_fsdata)
387{

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

493 folio_wait_fscache(folio);
494 _leave("");
495}
496
497/*
498 * release a page and clean up its private state if it's not busy
499 * - return true if the page can now be released, false if not
500 */
485static int afs_releasepage(struct page *page, gfp_t gfp_flags)
501static int afs_releasepage(struct page *page, gfp_t gfp)
486{
487 struct folio *folio = page_folio(page);
488 struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
489
490 _enter("{{%llx:%llu}[%lu],%lx},%x",
491 vnode->fid.vid, vnode->fid.vnode, folio_index(folio), folio->flags,
502{
503 struct folio *folio = page_folio(page);
504 struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
505
506 _enter("{{%llx:%llu}[%lu],%lx},%x",
507 vnode->fid.vid, vnode->fid.vnode, folio_index(folio), folio->flags,
492 gfp_flags);
508 gfp);
493
494 /* deny if page is being written to the cache and the caller hasn't
495 * elected to wait */
496#ifdef CONFIG_AFS_FSCACHE
497 if (folio_test_fscache(folio)) {
509
510 /* deny if page is being written to the cache and the caller hasn't
511 * elected to wait */
512#ifdef CONFIG_AFS_FSCACHE
513 if (folio_test_fscache(folio)) {
498 if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS))
514 if (!gfpflags_allow_blocking(gfp) || !(gfp & __GFP_FS))
499 return false;
500 folio_wait_fscache(folio);
501 }
515 return false;
516 folio_wait_fscache(folio);
517 }
518 fscache_note_page_release(afs_vnode_cache(vnode));
502#endif
503
504 if (folio_test_private(folio)) {
505 trace_afs_folio_dirty(vnode, tracepoint_string("rel"), folio);
506 folio_detach_private(folio);
507 }
508
509 /* Indicate that the folio can be released */

--- 89 unchanged lines hidden ---
519#endif
520
521 if (folio_test_private(folio)) {
522 trace_afs_folio_dirty(vnode, tracepoint_string("rel"), folio);
523 folio_detach_private(folio);
524 }
525
526 /* Indicate that the folio can be released */

--- 89 unchanged lines hidden ---