Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 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) |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 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 | #ifdef CONFIG_FSCACHE_STATS |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 25 | if (!proc_create_single("fs/fscache/stats", S_IFREG | 0444, NULL, |
| 26 | fscache_stats_show)) |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 27 | goto error_stats; |
| 28 | #endif |
| 29 | |
| 30 | #ifdef CONFIG_FSCACHE_HISTOGRAM |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 31 | if (!proc_create_seq("fs/fscache/histogram", S_IFREG | 0444, NULL, |
| 32 | &fscache_histogram_ops)) |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 33 | goto error_histogram; |
| 34 | #endif |
| 35 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 36 | #ifdef CONFIG_FSCACHE_OBJECT_LIST |
| 37 | if (!proc_create("fs/fscache/objects", S_IFREG | 0444, NULL, |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 38 | &fscache_objlist_proc_ops)) |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 39 | goto error_objects; |
| 40 | #endif |
| 41 | |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 42 | _leave(" = 0"); |
| 43 | return 0; |
| 44 | |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 45 | #ifdef CONFIG_FSCACHE_OBJECT_LIST |
| 46 | error_objects: |
| 47 | #endif |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 48 | #ifdef CONFIG_FSCACHE_HISTOGRAM |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 49 | remove_proc_entry("fs/fscache/histogram", NULL); |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 50 | error_histogram: |
| 51 | #endif |
| 52 | #ifdef CONFIG_FSCACHE_STATS |
| 53 | remove_proc_entry("fs/fscache/stats", NULL); |
| 54 | error_stats: |
| 55 | #endif |
| 56 | remove_proc_entry("fs/fscache", NULL); |
| 57 | error_dir: |
| 58 | _leave(" = -ENOMEM"); |
| 59 | return -ENOMEM; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * clean up the /proc/fs/fscache/ directory |
| 64 | */ |
| 65 | void fscache_proc_cleanup(void) |
| 66 | { |
David Howells | 4fbf429 | 2009-11-19 18:11:04 +0000 | [diff] [blame] | 67 | #ifdef CONFIG_FSCACHE_OBJECT_LIST |
| 68 | remove_proc_entry("fs/fscache/objects", NULL); |
| 69 | #endif |
David Howells | 7394daa | 2009-04-03 16:42:37 +0100 | [diff] [blame] | 70 | #ifdef CONFIG_FSCACHE_HISTOGRAM |
| 71 | remove_proc_entry("fs/fscache/histogram", NULL); |
| 72 | #endif |
| 73 | #ifdef CONFIG_FSCACHE_STATS |
| 74 | remove_proc_entry("fs/fscache/stats", NULL); |
| 75 | #endif |
| 76 | remove_proc_entry("fs/fscache", NULL); |
| 77 | } |