main.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* General filesystem local caching manager
  2. *
  3. * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #define FSCACHE_DEBUG_LEVEL CACHE
  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 "internal.h"
  18. MODULE_DESCRIPTION("FS Cache Manager");
  19. MODULE_AUTHOR("Red Hat, Inc.");
  20. MODULE_LICENSE("GPL");
  21. unsigned fscache_defer_lookup = 1;
  22. module_param_named(defer_lookup, fscache_defer_lookup, uint,
  23. S_IWUSR | S_IRUGO);
  24. MODULE_PARM_DESC(fscache_defer_lookup,
  25. "Defer cookie lookup to background thread");
  26. unsigned fscache_defer_create = 1;
  27. module_param_named(defer_create, fscache_defer_create, uint,
  28. S_IWUSR | S_IRUGO);
  29. MODULE_PARM_DESC(fscache_defer_create,
  30. "Defer cookie creation to background thread");
  31. unsigned fscache_debug;
  32. module_param_named(debug, fscache_debug, uint,
  33. S_IWUSR | S_IRUGO);
  34. MODULE_PARM_DESC(fscache_debug,
  35. "FS-Cache debugging mask");
  36. struct kobject *fscache_root;
  37. /*
  38. * initialise the fs caching module
  39. */
  40. static int __init fscache_init(void)
  41. {
  42. int ret;
  43. ret = slow_work_register_user(THIS_MODULE);
  44. if (ret < 0)
  45. goto error_slow_work;
  46. ret = fscache_proc_init();
  47. if (ret < 0)
  48. goto error_proc;
  49. fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
  50. sizeof(struct fscache_cookie),
  51. 0,
  52. 0,
  53. fscache_cookie_init_once);
  54. if (!fscache_cookie_jar) {
  55. printk(KERN_NOTICE
  56. "FS-Cache: Failed to allocate a cookie jar\n");
  57. ret = -ENOMEM;
  58. goto error_cookie_jar;
  59. }
  60. fscache_root = kobject_create_and_add("fscache", kernel_kobj);
  61. if (!fscache_root)
  62. goto error_kobj;
  63. printk(KERN_NOTICE "FS-Cache: Loaded\n");
  64. return 0;
  65. error_kobj:
  66. kmem_cache_destroy(fscache_cookie_jar);
  67. error_cookie_jar:
  68. fscache_proc_cleanup();
  69. error_proc:
  70. slow_work_unregister_user(THIS_MODULE);
  71. error_slow_work:
  72. return ret;
  73. }
  74. fs_initcall(fscache_init);
  75. /*
  76. * clean up on module removal
  77. */
  78. static void __exit fscache_exit(void)
  79. {
  80. _enter("");
  81. kobject_put(fscache_root);
  82. kmem_cache_destroy(fscache_cookie_jar);
  83. fscache_proc_cleanup();
  84. slow_work_unregister_user(THIS_MODULE);
  85. printk(KERN_NOTICE "FS-Cache: Unloaded\n");
  86. }
  87. module_exit(fscache_exit);
  88. /*
  89. * wait_on_bit() sleep function for uninterruptible waiting
  90. */
  91. int fscache_wait_bit(void *flags)
  92. {
  93. schedule();
  94. return 0;
  95. }
  96. EXPORT_SYMBOL(fscache_wait_bit);
  97. /*
  98. * wait_on_bit() sleep function for interruptible waiting
  99. */
  100. int fscache_wait_bit_interruptible(void *flags)
  101. {
  102. schedule();
  103. return signal_pending(current);
  104. }
  105. EXPORT_SYMBOL(fscache_wait_bit_interruptible);