main.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include "internal.h"
  25. unsigned cachefiles_debug;
  26. module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
  27. MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
  28. MODULE_DESCRIPTION("Mounted-filesystem based cache");
  29. MODULE_AUTHOR("Red Hat, Inc.");
  30. MODULE_LICENSE("GPL");
  31. struct kmem_cache *cachefiles_object_jar;
  32. static struct miscdevice cachefiles_dev = {
  33. .minor = MISC_DYNAMIC_MINOR,
  34. .name = "cachefiles",
  35. .fops = &cachefiles_daemon_fops,
  36. };
  37. static void cachefiles_object_init_once(void *_object)
  38. {
  39. struct cachefiles_object *object = _object;
  40. memset(object, 0, sizeof(*object));
  41. spin_lock_init(&object->work_lock);
  42. }
  43. /*
  44. * initialise the fs caching module
  45. */
  46. static int __init cachefiles_init(void)
  47. {
  48. int ret;
  49. ret = misc_register(&cachefiles_dev);
  50. if (ret < 0)
  51. goto error_dev;
  52. /* create an object jar */
  53. ret = -ENOMEM;
  54. cachefiles_object_jar =
  55. kmem_cache_create("cachefiles_object_jar",
  56. sizeof(struct cachefiles_object),
  57. 0,
  58. SLAB_HWCACHE_ALIGN,
  59. cachefiles_object_init_once);
  60. if (!cachefiles_object_jar) {
  61. pr_notice("Failed to allocate an object jar\n");
  62. goto error_object_jar;
  63. }
  64. ret = cachefiles_proc_init();
  65. if (ret < 0)
  66. goto error_proc;
  67. pr_info("Loaded\n");
  68. return 0;
  69. error_proc:
  70. kmem_cache_destroy(cachefiles_object_jar);
  71. error_object_jar:
  72. misc_deregister(&cachefiles_dev);
  73. error_dev:
  74. pr_err("failed to register: %d\n", ret);
  75. return ret;
  76. }
  77. fs_initcall(cachefiles_init);
  78. /*
  79. * clean up on module removal
  80. */
  81. static void __exit cachefiles_exit(void)
  82. {
  83. pr_info("Unloading\n");
  84. cachefiles_proc_cleanup();
  85. kmem_cache_destroy(cachefiles_object_jar);
  86. misc_deregister(&cachefiles_dev);
  87. }
  88. module_exit(cachefiles_exit);