blob: 913f83f1c9008ca9efc6ace755a8678200e7a7bc [file] [log] [blame]
David Howells1bd9c4e2021-11-18 08:58:08 +00001// 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 */
16static 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 */
36static 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}