pnfs.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. };
  34. struct pnfs_layout_segment {
  35. struct list_head pls_list;
  36. struct pnfs_layout_range pls_range;
  37. atomic_t pls_refcount;
  38. unsigned long pls_flags;
  39. struct pnfs_layout_hdr *pls_layout;
  40. };
  41. #ifdef CONFIG_NFS_V4_1
  42. #define LAYOUT_NFSV4_1_MODULE_PREFIX "nfs-layouttype4"
  43. enum {
  44. NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */
  45. NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */
  46. NFS_LAYOUT_DESTROYED, /* no new use of layout allowed */
  47. };
  48. /* Per-layout driver specific registration structure */
  49. struct pnfs_layoutdriver_type {
  50. struct list_head pnfs_tblid;
  51. const u32 id;
  52. const char *name;
  53. struct module *owner;
  54. int (*set_layoutdriver) (struct nfs_server *);
  55. int (*clear_layoutdriver) (struct nfs_server *);
  56. struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid, struct nfs4_layoutget_res *lgr);
  57. void (*free_lseg) (struct pnfs_layout_segment *lseg);
  58. };
  59. struct pnfs_layout_hdr {
  60. unsigned long plh_refcount;
  61. struct list_head plh_layouts; /* other client layouts */
  62. struct list_head plh_segs; /* layout segments list */
  63. nfs4_stateid plh_stateid;
  64. unsigned long plh_flags;
  65. struct inode *plh_inode;
  66. };
  67. struct pnfs_device {
  68. struct nfs4_deviceid dev_id;
  69. unsigned int layout_type;
  70. unsigned int mincount;
  71. struct page **pages;
  72. void *area;
  73. unsigned int pgbase;
  74. unsigned int pglen;
  75. };
  76. /*
  77. * Device ID RCU cache. A device ID is unique per client ID and layout type.
  78. */
  79. #define NFS4_DEVICE_ID_HASH_BITS 5
  80. #define NFS4_DEVICE_ID_HASH_SIZE (1 << NFS4_DEVICE_ID_HASH_BITS)
  81. #define NFS4_DEVICE_ID_HASH_MASK (NFS4_DEVICE_ID_HASH_SIZE - 1)
  82. static inline u32
  83. nfs4_deviceid_hash(struct nfs4_deviceid *id)
  84. {
  85. unsigned char *cptr = (unsigned char *)id->data;
  86. unsigned int nbytes = NFS4_DEVICEID4_SIZE;
  87. u32 x = 0;
  88. while (nbytes--) {
  89. x *= 37;
  90. x += *cptr++;
  91. }
  92. return x & NFS4_DEVICE_ID_HASH_MASK;
  93. }
  94. struct pnfs_deviceid_node {
  95. struct hlist_node de_node;
  96. struct nfs4_deviceid de_id;
  97. atomic_t de_ref;
  98. };
  99. struct pnfs_deviceid_cache {
  100. spinlock_t dc_lock;
  101. atomic_t dc_ref;
  102. void (*dc_free_callback)(struct pnfs_deviceid_node *);
  103. struct hlist_head dc_deviceids[NFS4_DEVICE_ID_HASH_SIZE];
  104. };
  105. extern int pnfs_alloc_init_deviceid_cache(struct nfs_client *,
  106. void (*free_callback)(struct pnfs_deviceid_node *));
  107. extern void pnfs_put_deviceid_cache(struct nfs_client *);
  108. extern struct pnfs_deviceid_node *pnfs_find_get_deviceid(
  109. struct pnfs_deviceid_cache *,
  110. struct nfs4_deviceid *);
  111. extern struct pnfs_deviceid_node *pnfs_add_deviceid(
  112. struct pnfs_deviceid_cache *,
  113. struct pnfs_deviceid_node *);
  114. extern void pnfs_put_deviceid(struct pnfs_deviceid_cache *c,
  115. struct pnfs_deviceid_node *devid);
  116. extern int pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *);
  117. extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
  118. /* nfs4proc.c */
  119. extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
  120. struct pnfs_device *dev);
  121. extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp);
  122. /* pnfs.c */
  123. struct pnfs_layout_segment *
  124. pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
  125. enum pnfs_iomode access_type);
  126. void set_pnfs_layoutdriver(struct nfs_server *, u32 id);
  127. void unset_pnfs_layoutdriver(struct nfs_server *);
  128. int pnfs_layout_process(struct nfs4_layoutget *lgp);
  129. void pnfs_destroy_layout(struct nfs_inode *);
  130. void pnfs_destroy_all_layouts(struct nfs_client *);
  131. void put_layout_hdr(struct inode *inode);
  132. int pnfs_choose_layoutget_stateid(nfs4_stateid *dst,
  133. struct pnfs_layout_hdr *lo,
  134. struct nfs4_state *open_state);
  135. static inline int lo_fail_bit(u32 iomode)
  136. {
  137. return iomode == IOMODE_RW ?
  138. NFS_LAYOUT_RW_FAILED : NFS_LAYOUT_RO_FAILED;
  139. }
  140. /* Return true if a layout driver is being used for this mountpoint */
  141. static inline int pnfs_enabled_sb(struct nfs_server *nfss)
  142. {
  143. return nfss->pnfs_curr_ld != NULL;
  144. }
  145. #else /* CONFIG_NFS_V4_1 */
  146. static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
  147. {
  148. }
  149. static inline void pnfs_destroy_layout(struct nfs_inode *nfsi)
  150. {
  151. }
  152. static inline struct pnfs_layout_segment *
  153. pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx,
  154. enum pnfs_iomode access_type)
  155. {
  156. return NULL;
  157. }
  158. static inline void set_pnfs_layoutdriver(struct nfs_server *s, u32 id)
  159. {
  160. }
  161. static inline void unset_pnfs_layoutdriver(struct nfs_server *s)
  162. {
  163. }
  164. #endif /* CONFIG_NFS_V4_1 */
  165. #endif /* FS_NFS_PNFS_H */