main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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) 2021 Red Hat, Inc. All Rights Reserved.
  6. * Written by David Howells ([email protected])
  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. #include <linux/netfs.h>
  21. #include <trace/events/netfs.h>
  22. #define CREATE_TRACE_POINTS
  23. #include "internal.h"
  24. unsigned cachefiles_debug;
  25. module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
  26. MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
  27. MODULE_DESCRIPTION("Mounted-filesystem based cache");
  28. MODULE_AUTHOR("Red Hat, Inc.");
  29. MODULE_LICENSE("GPL");
  30. struct kmem_cache *cachefiles_object_jar;
  31. static struct miscdevice cachefiles_dev = {
  32. .minor = MISC_DYNAMIC_MINOR,
  33. .name = "cachefiles",
  34. .fops = &cachefiles_daemon_fops,
  35. };
  36. /*
  37. * initialise the fs caching module
  38. */
  39. static int __init cachefiles_init(void)
  40. {
  41. int ret;
  42. ret = cachefiles_register_error_injection();
  43. if (ret < 0)
  44. goto error_einj;
  45. ret = misc_register(&cachefiles_dev);
  46. if (ret < 0)
  47. goto error_dev;
  48. /* create an object jar */
  49. ret = -ENOMEM;
  50. cachefiles_object_jar =
  51. kmem_cache_create("cachefiles_object_jar",
  52. sizeof(struct cachefiles_object),
  53. 0, SLAB_HWCACHE_ALIGN, NULL);
  54. if (!cachefiles_object_jar) {
  55. pr_notice("Failed to allocate an object jar\n");
  56. goto error_object_jar;
  57. }
  58. pr_info("Loaded\n");
  59. return 0;
  60. error_object_jar:
  61. misc_deregister(&cachefiles_dev);
  62. error_dev:
  63. cachefiles_unregister_error_injection();
  64. error_einj:
  65. pr_err("failed to register: %d\n", ret);
  66. return ret;
  67. }
  68. fs_initcall(cachefiles_init);
  69. /*
  70. * clean up on module removal
  71. */
  72. static void __exit cachefiles_exit(void)
  73. {
  74. pr_info("Unloading\n");
  75. kmem_cache_destroy(cachefiles_object_jar);
  76. misc_deregister(&cachefiles_dev);
  77. cachefiles_unregister_error_injection();
  78. }
  79. module_exit(cachefiles_exit);