xref: /openbmc/linux/fs/cachefiles/namei.c (revision 1bd9c4e4)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* CacheFiles path walking and related routines
3  *
4  * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7 
8 #include <linux/fs.h>
9 #include "internal.h"
10 
11 /*
12  * Mark the backing file as being a cache file if it's not already in use.  The
13  * mark tells the culling request command that it's not allowed to cull the
14  * file or directory.  The caller must hold the inode lock.
15  */
16 static bool __cachefiles_mark_inode_in_use(struct cachefiles_object *object,
17 					   struct dentry *dentry)
18 {
19 	struct inode *inode = d_backing_inode(dentry);
20 	bool can_use = false;
21 
22 	if (!(inode->i_flags & S_KERNEL_FILE)) {
23 		inode->i_flags |= S_KERNEL_FILE;
24 		trace_cachefiles_mark_active(object, inode);
25 		can_use = true;
26 	} else {
27 		pr_notice("cachefiles: Inode already in use: %pd\n", dentry);
28 	}
29 
30 	return can_use;
31 }
32 
33 /*
34  * Unmark a backing inode.  The caller must hold the inode lock.
35  */
36 static void __cachefiles_unmark_inode_in_use(struct cachefiles_object *object,
37 					     struct dentry *dentry)
38 {
39 	struct inode *inode = d_backing_inode(dentry);
40 
41 	inode->i_flags &= ~S_KERNEL_FILE;
42 	trace_cachefiles_mark_inactive(object, inode);
43 }
44