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