fsdef.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Filesystem index definition
  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 "internal.h"
  14. static
  15. enum fscache_checkaux fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
  16. const void *data,
  17. uint16_t datalen,
  18. loff_t object_size);
  19. /*
  20. * The root index is owned by FS-Cache itself.
  21. *
  22. * When a netfs requests caching facilities, FS-Cache will, if one doesn't
  23. * already exist, create an entry in the root index with the key being the name
  24. * of the netfs ("AFS" for example), and the auxiliary data holding the index
  25. * structure version supplied by the netfs:
  26. *
  27. * FSDEF
  28. * |
  29. * +-----------+
  30. * | |
  31. * NFS AFS
  32. * [v=1] [v=1]
  33. *
  34. * If an entry with the appropriate name does already exist, the version is
  35. * compared. If the version is different, the entire subtree from that entry
  36. * will be discarded and a new entry created.
  37. *
  38. * The new entry will be an index, and a cookie referring to it will be passed
  39. * to the netfs. This is then the root handle by which the netfs accesses the
  40. * cache. It can create whatever objects it likes in that index, including
  41. * further indices.
  42. */
  43. static struct fscache_cookie_def fscache_fsdef_index_def = {
  44. .name = ".FS-Cache",
  45. .type = FSCACHE_COOKIE_TYPE_INDEX,
  46. };
  47. struct fscache_cookie fscache_fsdef_index = {
  48. .usage = ATOMIC_INIT(1),
  49. .n_active = ATOMIC_INIT(1),
  50. .lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
  51. .backing_objects = HLIST_HEAD_INIT,
  52. .def = &fscache_fsdef_index_def,
  53. .flags = 1 << FSCACHE_COOKIE_ENABLED,
  54. .type = FSCACHE_COOKIE_TYPE_INDEX,
  55. };
  56. EXPORT_SYMBOL(fscache_fsdef_index);
  57. /*
  58. * Definition of an entry in the root index. Each entry is an index, keyed to
  59. * a specific netfs and only applicable to a particular version of the index
  60. * structure used by that netfs.
  61. */
  62. struct fscache_cookie_def fscache_fsdef_netfs_def = {
  63. .name = "FSDEF.netfs",
  64. .type = FSCACHE_COOKIE_TYPE_INDEX,
  65. .check_aux = fscache_fsdef_netfs_check_aux,
  66. };
  67. /*
  68. * check that the index structure version number stored in the auxiliary data
  69. * matches the one the netfs gave us
  70. */
  71. static enum fscache_checkaux fscache_fsdef_netfs_check_aux(
  72. void *cookie_netfs_data,
  73. const void *data,
  74. uint16_t datalen,
  75. loff_t object_size)
  76. {
  77. struct fscache_netfs *netfs = cookie_netfs_data;
  78. uint32_t version;
  79. _enter("{%s},,%hu", netfs->name, datalen);
  80. if (datalen != sizeof(version)) {
  81. _leave(" = OBSOLETE [dl=%d v=%zu]", datalen, sizeof(version));
  82. return FSCACHE_CHECKAUX_OBSOLETE;
  83. }
  84. memcpy(&version, data, sizeof(version));
  85. if (version != netfs->version) {
  86. _leave(" = OBSOLETE [ver=%x net=%x]", version, netfs->version);
  87. return FSCACHE_CHECKAUX_OBSOLETE;
  88. }
  89. _leave(" = OKAY");
  90. return FSCACHE_CHECKAUX_OKAY;
  91. }