pnfs.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * pNFS client data structures.
  3. *
  4. * Copyright (c) 2002
  5. * The Regents of the University of Michigan
  6. * All Rights Reserved
  7. *
  8. * Dean Hildebrand <dhildebz@umich.edu>
  9. *
  10. * Permission is granted to use, copy, create derivative works, and
  11. * redistribute this software and such derivative works for any purpose,
  12. * so long as the name of the University of Michigan is not used in
  13. * any advertising or publicity pertaining to the use or distribution
  14. * of this software without specific, written prior authorization. If
  15. * the above copyright notice or any other identification of the
  16. * University of Michigan is included in any copy of any portion of
  17. * this software, then the disclaimer below must also be included.
  18. *
  19. * This software is provided as is, without representation or warranty
  20. * of any kind either express or implied, including without limitation
  21. * the implied warranties of merchantability, fitness for a particular
  22. * purpose, or noninfringement. The Regents of the University of
  23. * Michigan shall not be liable for any damages, including special,
  24. * indirect, incidental, or consequential damages, with respect to any
  25. * claim arising out of or in connection with the use of the software,
  26. * even if it has been or is hereafter advised of the possibility of
  27. * such damages.
  28. */
  29. #ifndef FS_NFS_PNFS_H
  30. #define FS_NFS_PNFS_H
  31. enum {
  32. NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */
  33. NFS_LSEG_ROC, /* roc bit received from server */
  34. };
  35. struct pnfs_layout_segment {
  36. struct list_head pls_list;
  37. struct pnfs_layout_range pls_range;
  38. atomic_t pls_refcount;
  39. unsigned long pls_flags;
  40. struct pnfs_layout_hdr *pls_layout;
  41. };
  42. #ifdef CONFIG_NFS_V4_1
  43. #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4"
  44. enum {
  45. NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */
  46. NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */
  47. NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */
  48. NFS_LAYOUT_ROC, /* some lseg had roc bit set */
  49. NFS_LAYOUT_DESTROYED, /* no new use of layout allowed */
  50. };
  51. /* Per-layout driver specific registration structure */
  52. struct pnfs_layoutdriver_type {
  53. struct list_head pnfs_tblid;
  54. const u32 id;
  55. const char *name;
  56. struct module *owner;
  57. int (*set_layoutdriver) (struct nfs_server *);
  58. int (*clear_layoutdriver) (struct nfs_server *);
  59. struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr);
  60. void (*free_lseg) (struct pnfs_layout_segment *lseg);
  61. };
  62. struct pnfs_layout_hdr {
  63. atomic_t plh_refcount;
  64. struct list_head plh_layouts; /* other client layouts */
  65. struct list_head plh_bulk_recall; /* clnt list of bulk recalls */
  66. struct list_head plh_segs; /* layout segments list */
  67. nfs4_stateid plh_stateid;
  68. atomic_t plh_outstanding; /* number of RPCs out */
  69. unsigned long plh_block_lgets; /* block LAYOUTGET if >0 */
  70. u32 plh_barrier; /* ignore lower seqids */
  71. unsigned long plh_flags;
  72. struct inode *plh_inode;
  73. };
  74. struct pnfs_device {
  75. struct nfs4_deviceid dev_id;
  76. unsigned int layout_type;
  77. unsigned int mincount;
  78. struct page **pages;
  79. void *area;
  80. unsigned int pgbase;
  81. unsigned int pglen;
  82. };
  83. /*
  84. * Device ID RCU cache. A device ID is unique per client ID and layout type.
  85. */
  86. #define NFS4_DEVICE_ID_HASH_BITS 5
  87. #define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
  88. #define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
  89. static inline u32
  90. nfs4_deviceid_hash(struct nfs4_deviceid *id)
  91. {
  92. unsigned char *cptr = (unsigned char *)id->data;
  93. unsigned int nbytes = NFS4_DEVICEID4_SIZE;
  94. u32 x = 0;
  95. while (nbytes--) {
  96. x *= 37;
  97. x += *cptr++;
  98. }
  99. return x & NFS4_DEVICE_ID_HASH_MASK;
  100. }
  101. struct pnfs_deviceid_node {
  102. struct hlist_node de_node;
  103. struct nfs4_deviceid de_id;
  104. atomic_t de_ref;
  105. };
  106. struct pnfs_deviceid_cache {
  107. spinlock_t dc_lock;
  108. atomic_t dc_ref;
  109. void (*dc_free_callback)(struct pnfs_deviceid_node *);
  110. struct hlist_head dc_deviceids[NFS4_DEVICE_ID_HASH_SIZE];
  111. };
  112. extern int pnfs_alloc_init_deviceid_cache(struct nfs_client *,
  113. void (*free_callback)(struct pnfs_deviceid_node *));
  114. extern void pnfs_put_deviceid_cache(struct nfs_client *);
  115. extern struct pnfs_deviceid_node *pnfs_find_get_deviceid(
  116. struct pnfs_deviceid_cache *,
  117. struct nfs4_deviceid *);
  118. extern struct pnfs_deviceid_node *pnfs_add_deviceid(
  119. struct pnfs_deviceid_cache *,
  120. struct pnfs_deviceid_node *);
  121. extern void pnfs_put_deviceid(struct pnfs_deviceid_cache *c,
  122. struct pnfs_deviceid_node *devid);
  123. extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *);
  124. extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
  125. /* nfs4proc.c */
  126. extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
  127. struct pnfs_device *dev);
  128. extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp);
  129. /* pnfs.c */
  130. void get_layout_hdr(struct pnfs_layout_hdr *lo);
  131. struct pnfs_layout_segment *
  132. pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
  133. enum pnfs_iomode access_type);
  134. void set_pnfs_layoutdriver(struct nfs_server *, u32 id);
  135. void unset_pnfs_layoutdriver(struct nfs_server *);
  136. int pnfs_layout_process(struct nfs4_layoutget *lgp);
  137. void pnfs_free_lseg_list(struct list_head *tmp_list);
  138. void pnfs_destroy_layout(struct nfs_inode *);
  139. void pnfs_destroy_all_layouts(struct nfs_client *);
  140. void put_layout_hdr(struct pnfs_layout_hdr *lo);
  141. void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo,
  142. const nfs4_stateid *new,
  143. bool update_barrier);
  144. int pnfs_choose_layoutget_stateid(nfs4_stateid *dst,
  145. struct pnfs_layout_hdr *lo,
  146. struct nfs4_state *open_state);
  147. int mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
  148. struct list_head *tmp_list,
  149. u32 iomode);
  150. bool pnfs_roc(struct inode *ino);
  151. void pnfs_roc_release(struct inode *ino);
  152. void pnfs_roc_set_barrier(struct inode *ino, u32 barrier);
  153. bool pnfs_roc_drain(struct inode *ino, u32 *barrier);
  154. static inline int lo_fail_bit(u32 iomode)
  155. {
  156. return iomode == IOMODE_RW ?
  157. NFS_LAYOUT_RW_FAILED : NFS_LAYOUT_RO_FAILED;
  158. }
  159. /* Return true if a layout driver is being used for this mountpoint */
  160. static inline int pnfs_enabled_sb(struct nfs_server *nfss)
  161. {
  162. return nfss->pnfs_curr_ld != NULL;
  163. }
  164. #else /* CONFIG_NFS_V4_1 */
  165. static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
  166. {
  167. }
  168. static inline void pnfs_destroy_layout(struct nfs_inode *nfsi)
  169. {
  170. }
  171. static inline struct pnfs_layout_segment *
  172. pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
  173. enum pnfs_iomode access_type)
  174. {
  175. return NULL;
  176. }
  177. static inline bool
  178. pnfs_roc(struct inode *ino)
  179. {
  180. return false;
  181. }
  182. static inline void
  183. pnfs_roc_release(struct inode *ino)
  184. {
  185. }
  186. static inline void
  187. pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
  188. {
  189. }
  190. static inline bool
  191. pnfs_roc_drain(struct inode *ino, u32 *barrier)
  192. {
  193. return false;
  194. }
  195. static inline void set_pnfs_layoutdriver(struct nfs_server *s, u32 id)
  196. {
  197. }
  198. static inline void unset_pnfs_layoutdriver(struct nfs_server *s)
  199. {
  200. }
  201. #endif /* CONFIG_NFS_V4_1 */
  202. #endif /* FS_NFS_PNFS_H */