fscache: Procfile to display cookies
[linux-2.6-microblaze.git] / fs / fscache / proc.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* FS-Cache statistics viewing interface
3  *
4  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5  * Written by David Howells (dhowells@redhat.com)
6  */
7
8 #define FSCACHE_DEBUG_LEVEL OPERATION
9 #include <linux/module.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include "internal.h"
13
14 /*
15  * initialise the /proc/fs/fscache/ directory
16  */
17 int __init fscache_proc_init(void)
18 {
19         _enter("");
20
21         if (!proc_mkdir("fs/fscache", NULL))
22                 goto error_dir;
23
24         if (!proc_create_seq("fs/fscache/cookies", S_IFREG | 0444, NULL,
25                              &fscache_cookies_seq_ops))
26                 goto error_cookies;
27
28 #ifdef CONFIG_FSCACHE_STATS
29         if (!proc_create_single("fs/fscache/stats", S_IFREG | 0444, NULL,
30                         fscache_stats_show))
31                 goto error_stats;
32 #endif
33
34 #ifdef CONFIG_FSCACHE_HISTOGRAM
35         if (!proc_create_seq("fs/fscache/histogram", S_IFREG | 0444, NULL,
36                          &fscache_histogram_ops))
37                 goto error_histogram;
38 #endif
39
40 #ifdef CONFIG_FSCACHE_OBJECT_LIST
41         if (!proc_create("fs/fscache/objects", S_IFREG | 0444, NULL,
42                          &fscache_objlist_proc_ops))
43                 goto error_objects;
44 #endif
45
46         _leave(" = 0");
47         return 0;
48
49 #ifdef CONFIG_FSCACHE_OBJECT_LIST
50 error_objects:
51 #endif
52 #ifdef CONFIG_FSCACHE_HISTOGRAM
53         remove_proc_entry("fs/fscache/histogram", NULL);
54 error_histogram:
55 #endif
56 #ifdef CONFIG_FSCACHE_STATS
57         remove_proc_entry("fs/fscache/stats", NULL);
58 error_stats:
59 #endif
60         remove_proc_entry("fs/fscache/cookies", NULL);
61 error_cookies:
62         remove_proc_entry("fs/fscache", NULL);
63 error_dir:
64         _leave(" = -ENOMEM");
65         return -ENOMEM;
66 }
67
68 /*
69  * clean up the /proc/fs/fscache/ directory
70  */
71 void fscache_proc_cleanup(void)
72 {
73 #ifdef CONFIG_FSCACHE_OBJECT_LIST
74         remove_proc_entry("fs/fscache/objects", NULL);
75 #endif
76 #ifdef CONFIG_FSCACHE_HISTOGRAM
77         remove_proc_entry("fs/fscache/histogram", NULL);
78 #endif
79 #ifdef CONFIG_FSCACHE_STATS
80         remove_proc_entry("fs/fscache/stats", NULL);
81 #endif
82         remove_proc_entry("fs/fscache/cookies", NULL);
83         remove_proc_entry("fs/fscache", NULL);
84 }