netfs.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* FS-Cache netfs (client) registration
  2. *
  3. * Copyright (C) 2008 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 Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #define FSCACHE_DEBUG_LEVEL COOKIE
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include "internal.h"
  15. /*
  16. * register a network filesystem for caching
  17. */
  18. int __fscache_register_netfs(struct fscache_netfs *netfs)
  19. {
  20. struct fscache_cookie *candidate, *cookie;
  21. _enter("{%s}", netfs->name);
  22. /* allocate a cookie for the primary index */
  23. candidate = fscache_alloc_cookie(&fscache_fsdef_index,
  24. &fscache_fsdef_netfs_def,
  25. netfs->name, strlen(netfs->name),
  26. &netfs->version, sizeof(netfs->version),
  27. netfs, 0);
  28. if (!candidate) {
  29. _leave(" = -ENOMEM");
  30. return -ENOMEM;
  31. }
  32. candidate->flags = 1 << FSCACHE_COOKIE_ENABLED;
  33. /* check the netfs type is not already present */
  34. cookie = fscache_hash_cookie(candidate);
  35. if (!cookie)
  36. goto already_registered;
  37. if (cookie != candidate) {
  38. trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
  39. fscache_free_cookie(candidate);
  40. }
  41. fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
  42. atomic_inc(&cookie->parent->n_children);
  43. netfs->primary_index = cookie;
  44. pr_notice("Netfs '%s' registered for caching\n", netfs->name);
  45. trace_fscache_netfs(netfs);
  46. _leave(" = 0");
  47. return 0;
  48. already_registered:
  49. fscache_cookie_put(candidate, fscache_cookie_put_dup_netfs);
  50. _leave(" = -EEXIST");
  51. return -EEXIST;
  52. }
  53. EXPORT_SYMBOL(__fscache_register_netfs);
  54. /*
  55. * unregister a network filesystem from the cache
  56. * - all cookies must have been released first
  57. */
  58. void __fscache_unregister_netfs(struct fscache_netfs *netfs)
  59. {
  60. _enter("{%s.%u}", netfs->name, netfs->version);
  61. fscache_relinquish_cookie(netfs->primary_index, NULL, false);
  62. pr_notice("Netfs '%s' unregistered from caching\n", netfs->name);
  63. _leave("");
  64. }
  65. EXPORT_SYMBOL(__fscache_unregister_netfs);