Skip to content

Commit 169379e

Browse files
committed
cachefiles: Mark a backing file in use with an inode flag
Use an inode flag, S_KERNEL_FILE, to mark that a backing file is in use by the kernel to prevent cachefiles or other kernel services from interfering with that file. Using S_SWAPFILE instead isn't really viable as that has other effects in the I/O paths. Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/163819642273.215744.6414248677118690672.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906943215.143852.16972351425323967014.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967154118.1823006.13227551961786743991.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021541207.640689.564689725898537127.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/164021552299.640689.10578652796777392062.stgit@warthog.procyon.org.uk/ # v4
1 parent 72b9578 commit 169379e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

fs/cachefiles/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ extern struct kmem_cache *cachefiles_object_jar;
187187
/*
188188
* namei.c
189189
*/
190+
extern void cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
191+
struct file *file);
190192
extern struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
191193
struct dentry *dir,
192194
const char *name,

fs/cachefiles/namei.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ static bool __cachefiles_mark_inode_in_use(struct cachefiles_object *object,
3131
return can_use;
3232
}
3333

34+
static bool cachefiles_mark_inode_in_use(struct cachefiles_object *object,
35+
struct dentry *dentry)
36+
{
37+
struct inode *inode = d_backing_inode(dentry);
38+
bool can_use;
39+
40+
inode_lock(inode);
41+
can_use = __cachefiles_mark_inode_in_use(object, dentry);
42+
inode_unlock(inode);
43+
return can_use;
44+
}
45+
3446
/*
3547
* Unmark a backing inode. The caller must hold the inode lock.
3648
*/
@@ -43,6 +55,29 @@ static void __cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
4355
trace_cachefiles_mark_inactive(object, inode);
4456
}
4557

58+
/*
59+
* Unmark a backing inode and tell cachefilesd that there's something that can
60+
* be culled.
61+
*/
62+
void cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
63+
struct file *file)
64+
{
65+
struct cachefiles_cache *cache = object->volume->cache;
66+
struct inode *inode = file_inode(file);
67+
68+
if (inode) {
69+
inode_lock(inode);
70+
__cachefiles_unmark_inode_in_use(object, file->f_path.dentry);
71+
inode_unlock(inode);
72+
73+
if (!test_bit(CACHEFILES_OBJECT_USING_TMPFILE, &object->flags)) {
74+
atomic_long_add(inode->i_blocks, &cache->b_released);
75+
if (atomic_inc_return(&cache->f_released))
76+
cachefiles_state_changed(cache);
77+
}
78+
}
79+
}
80+
4681
/*
4782
* get a subdirectory
4883
*/

0 commit comments

Comments
 (0)