main.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Network filesystem caching backend to use cache files on a premounted
  3. * filesystem
  4. *
  5. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells (dhowells@redhat.com)
  7. */
  8. #include <linux/module.h>
  9. #include <linux/init.h>
  10. #include <linux/sched.h>
  11. #include <linux/completion.h>
  12. #include <linux/slab.h>
  13. #include <linux/fs.h>
  14. #include <linux/file.h>
  15. #include <linux/namei.h>
  16. #include <linux/mount.h>
  17. #include <linux/statfs.h>
  18. #include <linux/sysctl.h>
  19. #include <linux/miscdevice.h>
  20. #define CREATE_TRACE_POINTS
  21. #include "internal.h"
  22. unsigned cachefiles_debug;
  23. module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
  24. MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
  25. MODULE_DESCRIPTION("Mounted-filesystem based cache");
  26. MODULE_AUTHOR("Red Hat, Inc.");
  27. MODULE_LICENSE("GPL");
  28. MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
  29. struct kmem_cache *cachefiles_object_jar;
  30. static struct miscdevice cachefiles_dev = {
  31. .minor = MISC_DYNAMIC_MINOR,
  32. .name = "cachefiles",
  33. .fops = &cachefiles_daemon_fops,
  34. };
  35. static void cachefiles_object_init_once(void *_object)
  36. {
  37. struct cachefiles_object *object = _object;
  38. memset(object, 0, sizeof(*object));
  39. spin_lock_init(&object->work_lock);
  40. }
  41. /*
  42. * initialise the fs caching module
  43. */
  44. static int __init cachefiles_init(void)
  45. {
  46. int ret;
  47. ret = misc_register(&cachefiles_dev);
  48. if (ret < 0)
  49. goto error_dev;
  50. /* create an object jar */
  51. ret = -ENOMEM;
  52. cachefiles_object_jar =
  53. kmem_cache_create("cachefiles_object_jar",
  54. sizeof(struct cachefiles_object),
  55. 0,
  56. SLAB_HWCACHE_ALIGN,
  57. cachefiles_object_init_once);
  58. if (!cachefiles_object_jar) {
  59. pr_notice("Failed to allocate an object jar\n");
  60. goto error_object_jar;
  61. }
  62. ret = cachefiles_proc_init();
  63. if (ret < 0)
  64. goto error_proc;
  65. pr_info("Loaded\n");
  66. return 0;
  67. error_proc:
  68. kmem_cache_destroy(cachefiles_object_jar);
  69. error_object_jar:
  70. misc_deregister(&cachefiles_dev);
  71. error_dev:
  72. pr_err("failed to register: %d\n", ret);
  73. return ret;
  74. }
  75. fs_initcall(cachefiles_init);
  76. /*
  77. * clean up on module removal
  78. */
  79. static void __exit cachefiles_exit(void)
  80. {
  81. pr_info("Unloading\n");
  82. cachefiles_proc_cleanup();
  83. kmem_cache_destroy(cachefiles_object_jar);
  84. misc_deregister(&cachefiles_dev);
  85. }
  86. module_exit(cachefiles_exit);