proc.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #define FSCACHE_DEBUG_LEVEL OPERATION
  8. #include <linux/module.h>
  9. #include <linux/proc_fs.h>
  10. #include <linux/seq_file.h>
  11. #include "internal.h"
  12. /*
  13. * initialise the /proc/fs/fscache/ directory
  14. */
  15. int __init fscache_proc_init(void)
  16. {
  17. _enter("");
  18. if (!proc_mkdir("fs/fscache", NULL))
  19. goto error_dir;
  20. #ifdef CONFIG_FSCACHE_STATS
  21. if (!proc_create_single("fs/fscache/stats", S_IFREG | 0444, NULL,
  22. fscache_stats_show))
  23. goto error_stats;
  24. #endif
  25. #ifdef CONFIG_FSCACHE_HISTOGRAM
  26. if (!proc_create_seq("fs/fscache/histogram", S_IFREG | 0444, NULL,
  27. &fscache_histogram_ops))
  28. goto error_histogram;
  29. #endif
  30. #ifdef CONFIG_FSCACHE_OBJECT_LIST
  31. if (!proc_create("fs/fscache/objects", S_IFREG | 0444, NULL,
  32. &fscache_objlist_proc_ops))
  33. goto error_objects;
  34. #endif
  35. _leave(" = 0");
  36. return 0;
  37. #ifdef CONFIG_FSCACHE_OBJECT_LIST
  38. error_objects:
  39. #endif
  40. #ifdef CONFIG_FSCACHE_HISTOGRAM
  41. remove_proc_entry("fs/fscache/histogram", NULL);
  42. error_histogram:
  43. #endif
  44. #ifdef CONFIG_FSCACHE_STATS
  45. remove_proc_entry("fs/fscache/stats", NULL);
  46. error_stats:
  47. #endif
  48. remove_proc_entry("fs/fscache", NULL);
  49. error_dir:
  50. _leave(" = -ENOMEM");
  51. return -ENOMEM;
  52. }
  53. /*
  54. * clean up the /proc/fs/fscache/ directory
  55. */
  56. void fscache_proc_cleanup(void)
  57. {
  58. #ifdef CONFIG_FSCACHE_OBJECT_LIST
  59. remove_proc_entry("fs/fscache/objects", NULL);
  60. #endif
  61. #ifdef CONFIG_FSCACHE_HISTOGRAM
  62. remove_proc_entry("fs/fscache/histogram", NULL);
  63. #endif
  64. #ifdef CONFIG_FSCACHE_STATS
  65. remove_proc_entry("fs/fscache/stats", NULL);
  66. #endif
  67. remove_proc_entry("fs/fscache", NULL);
  68. }