volume.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* volume.h: AFS volume management
  2. *
  3. * Copyright (C) 2002 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. #ifndef _LINUX_AFS_VOLUME_H
  12. #define _LINUX_AFS_VOLUME_H
  13. #include "types.h"
  14. #include "fsclient.h"
  15. #include "kafstimod.h"
  16. #include "kafsasyncd.h"
  17. #include "cache.h"
  18. #define __packed __attribute__((packed))
  19. typedef enum {
  20. AFS_VLUPD_SLEEP, /* sleeping waiting for update timer to fire */
  21. AFS_VLUPD_PENDING, /* on pending queue */
  22. AFS_VLUPD_INPROGRESS, /* op in progress */
  23. AFS_VLUPD_BUSYSLEEP, /* sleeping because server returned EBUSY */
  24. } __attribute__((packed)) afs_vlocation_upd_t;
  25. /*****************************************************************************/
  26. /*
  27. * entry in the cached volume location catalogue
  28. */
  29. struct afs_cache_vlocation
  30. {
  31. uint8_t name[64]; /* volume name (lowercase, padded with NULs) */
  32. uint8_t nservers; /* number of entries used in servers[] */
  33. uint8_t vidmask; /* voltype mask for vid[] */
  34. uint8_t srvtmask[8]; /* voltype masks for servers[] */
  35. #define AFS_VOL_VTM_RW 0x01 /* R/W version of the volume is available (on this server) */
  36. #define AFS_VOL_VTM_RO 0x02 /* R/O version of the volume is available (on this server) */
  37. #define AFS_VOL_VTM_BAK 0x04 /* backup version of the volume is available (on this server) */
  38. afs_volid_t vid[3]; /* volume IDs for R/W, R/O and Bak volumes */
  39. struct in_addr servers[8]; /* fileserver addresses */
  40. time_t rtime; /* last retrieval time */
  41. };
  42. #ifdef AFS_CACHING_SUPPORT
  43. extern struct cachefs_index_def afs_vlocation_cache_index_def;
  44. #endif
  45. /*****************************************************************************/
  46. /*
  47. * volume -> vnode hash table entry
  48. */
  49. struct afs_cache_vhash
  50. {
  51. afs_voltype_t vtype; /* which volume variation */
  52. uint8_t hash_bucket; /* which hash bucket this represents */
  53. } __attribute__((packed));
  54. #ifdef AFS_CACHING_SUPPORT
  55. extern struct cachefs_index_def afs_volume_cache_index_def;
  56. #endif
  57. /*****************************************************************************/
  58. /*
  59. * AFS volume location record
  60. */
  61. struct afs_vlocation
  62. {
  63. atomic_t usage;
  64. struct list_head link; /* link in cell volume location list */
  65. struct afs_timer timeout; /* decaching timer */
  66. struct afs_cell *cell; /* cell to which volume belongs */
  67. #ifdef AFS_CACHING_SUPPORT
  68. struct cachefs_cookie *cache; /* caching cookie */
  69. #endif
  70. struct afs_cache_vlocation vldb; /* volume information DB record */
  71. struct afs_volume *vols[3]; /* volume access record pointer (index by type) */
  72. rwlock_t lock; /* access lock */
  73. unsigned long read_jif; /* time at which last read from vlserver */
  74. struct afs_timer upd_timer; /* update timer */
  75. struct afs_async_op upd_op; /* update operation */
  76. afs_vlocation_upd_t upd_state; /* update state */
  77. unsigned short upd_first_svix; /* first server index during update */
  78. unsigned short upd_curr_svix; /* current server index during update */
  79. unsigned short upd_rej_cnt; /* ENOMEDIUM count during update */
  80. unsigned short upd_busy_cnt; /* EBUSY count during update */
  81. unsigned short valid; /* T if valid */
  82. };
  83. extern int afs_vlocation_lookup(struct afs_cell *cell,
  84. const char *name,
  85. unsigned namesz,
  86. struct afs_vlocation **_vlocation);
  87. #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
  88. extern void afs_put_vlocation(struct afs_vlocation *vlocation);
  89. extern void afs_vlocation_do_timeout(struct afs_vlocation *vlocation);
  90. /*****************************************************************************/
  91. /*
  92. * AFS volume access record
  93. */
  94. struct afs_volume
  95. {
  96. atomic_t usage;
  97. struct afs_cell *cell; /* cell to which belongs (unrefd ptr) */
  98. struct afs_vlocation *vlocation; /* volume location */
  99. #ifdef AFS_CACHING_SUPPORT
  100. struct cachefs_cookie *cache; /* caching cookie */
  101. #endif
  102. afs_volid_t vid; /* volume ID */
  103. afs_voltype_t __packed type; /* type of volume */
  104. char type_force; /* force volume type (suppress R/O -> R/W) */
  105. unsigned short nservers; /* number of server slots filled */
  106. unsigned short rjservers; /* number of servers discarded due to -ENOMEDIUM */
  107. struct afs_server *servers[8]; /* servers on which volume resides (ordered) */
  108. struct rw_semaphore server_sem; /* lock for accessing current server */
  109. };
  110. extern int afs_volume_lookup(const char *name,
  111. struct afs_cell *cell,
  112. int rwpath,
  113. struct afs_volume **_volume);
  114. #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
  115. extern void afs_put_volume(struct afs_volume *volume);
  116. extern int afs_volume_pick_fileserver(struct afs_volume *volume,
  117. struct afs_server **_server);
  118. extern int afs_volume_release_fileserver(struct afs_volume *volume,
  119. struct afs_server *server,
  120. int result);
  121. #endif /* _LINUX_AFS_VOLUME_H */