main.c 2.4 KB

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