pnfs.h 5.6 KB

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