cache.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* AFS caching stuff
  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 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. #include <linux/sched.h>
  12. #include "internal.h"
  13. static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
  14. const void *buffer,
  15. uint16_t buflen,
  16. loff_t object_size);
  17. struct fscache_netfs afs_cache_netfs = {
  18. .name = "afs",
  19. .version = 2,
  20. };
  21. struct fscache_cookie_def afs_cell_cache_index_def = {
  22. .name = "AFS.cell",
  23. .type = FSCACHE_COOKIE_TYPE_INDEX,
  24. };
  25. struct fscache_cookie_def afs_volume_cache_index_def = {
  26. .name = "AFS.volume",
  27. .type = FSCACHE_COOKIE_TYPE_INDEX,
  28. };
  29. struct fscache_cookie_def afs_vnode_cache_index_def = {
  30. .name = "AFS.vnode",
  31. .type = FSCACHE_COOKIE_TYPE_DATAFILE,
  32. .check_aux = afs_vnode_cache_check_aux,
  33. };
  34. /*
  35. * check that the auxiliary data indicates that the entry is still valid
  36. */
  37. static enum fscache_checkaux afs_vnode_cache_check_aux(void *cookie_netfs_data,
  38. const void *buffer,
  39. uint16_t buflen,
  40. loff_t object_size)
  41. {
  42. struct afs_vnode *vnode = cookie_netfs_data;
  43. struct afs_vnode_cache_aux aux;
  44. _enter("{%x,%x,%llx},%p,%u",
  45. vnode->fid.vnode, vnode->fid.unique, vnode->status.data_version,
  46. buffer, buflen);
  47. memcpy(&aux, buffer, sizeof(aux));
  48. /* check the size of the data is what we're expecting */
  49. if (buflen != sizeof(aux)) {
  50. _leave(" = OBSOLETE [len %hx != %zx]", buflen, sizeof(aux));
  51. return FSCACHE_CHECKAUX_OBSOLETE;
  52. }
  53. if (vnode->status.data_version != aux.data_version) {
  54. _leave(" = OBSOLETE [vers %llx != %llx]",
  55. aux.data_version, vnode->status.data_version);
  56. return FSCACHE_CHECKAUX_OBSOLETE;
  57. }
  58. _leave(" = SUCCESS");
  59. return FSCACHE_CHECKAUX_OKAY;
  60. }