flexfilelayout.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * NFSv4 flexfile layout driver data structures.
  3. *
  4. * Copyright (c) 2014, Primary Data, Inc. All rights reserved.
  5. *
  6. * Tao Peng <bergwolf@primarydata.com>
  7. */
  8. #ifndef FS_NFS_NFS4FLEXFILELAYOUT_H
  9. #define FS_NFS_NFS4FLEXFILELAYOUT_H
  10. #define FF_FLAGS_NO_LAYOUTCOMMIT 1
  11. #define FF_FLAGS_NO_IO_THRU_MDS 2
  12. #define FF_FLAGS_NO_READ_IO 4
  13. #include "../pnfs.h"
  14. /* XXX: Let's filter out insanely large mirror count for now to avoid oom
  15. * due to network error etc. */
  16. #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096
  17. /* LAYOUTSTATS report interval in ms */
  18. #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
  19. struct nfs4_ff_ds_version {
  20. u32 version;
  21. u32 minor_version;
  22. u32 rsize;
  23. u32 wsize;
  24. bool tightly_coupled;
  25. };
  26. /* chained in global deviceid hlist */
  27. struct nfs4_ff_layout_ds {
  28. struct nfs4_deviceid_node id_node;
  29. u32 ds_versions_cnt;
  30. struct nfs4_ff_ds_version *ds_versions;
  31. struct nfs4_pnfs_ds *ds;
  32. };
  33. struct nfs4_ff_layout_ds_err {
  34. struct list_head list; /* linked in mirror error_list */
  35. u64 offset;
  36. u64 length;
  37. int status;
  38. enum nfs_opnum4 opnum;
  39. nfs4_stateid stateid;
  40. struct nfs4_deviceid deviceid;
  41. };
  42. struct nfs4_ff_io_stat {
  43. __u64 ops_requested;
  44. __u64 bytes_requested;
  45. __u64 ops_completed;
  46. __u64 bytes_completed;
  47. __u64 bytes_not_delivered;
  48. ktime_t total_busy_time;
  49. ktime_t aggregate_completion_time;
  50. };
  51. struct nfs4_ff_busy_timer {
  52. ktime_t start_time;
  53. atomic_t n_ops;
  54. };
  55. struct nfs4_ff_layoutstat {
  56. struct nfs4_ff_io_stat io_stat;
  57. struct nfs4_ff_busy_timer busy_timer;
  58. };
  59. struct nfs4_ff_layout_mirror {
  60. struct pnfs_layout_hdr *layout;
  61. struct list_head mirrors;
  62. u32 ds_count;
  63. u32 efficiency;
  64. struct nfs4_ff_layout_ds *mirror_ds;
  65. u32 fh_versions_cnt;
  66. struct nfs_fh *fh_versions;
  67. nfs4_stateid stateid;
  68. struct rpc_cred __rcu *ro_cred;
  69. struct rpc_cred __rcu *rw_cred;
  70. atomic_t ref;
  71. spinlock_t lock;
  72. struct nfs4_ff_layoutstat read_stat;
  73. struct nfs4_ff_layoutstat write_stat;
  74. ktime_t start_time;
  75. u32 report_interval;
  76. };
  77. struct nfs4_ff_layout_segment {
  78. struct pnfs_layout_segment generic_hdr;
  79. u64 stripe_unit;
  80. u32 flags;
  81. u32 mirror_array_cnt;
  82. struct nfs4_ff_layout_mirror **mirror_array;
  83. };
  84. struct nfs4_flexfile_layout {
  85. struct pnfs_layout_hdr generic_hdr;
  86. struct pnfs_ds_commit_info commit_info;
  87. struct list_head mirrors;
  88. struct list_head error_list; /* nfs4_ff_layout_ds_err */
  89. ktime_t last_report_time; /* Layoutstat report times */
  90. };
  91. static inline struct nfs4_flexfile_layout *
  92. FF_LAYOUT_FROM_HDR(struct pnfs_layout_hdr *lo)
  93. {
  94. return container_of(lo, struct nfs4_flexfile_layout, generic_hdr);
  95. }
  96. static inline struct nfs4_ff_layout_segment *
  97. FF_LAYOUT_LSEG(struct pnfs_layout_segment *lseg)
  98. {
  99. return container_of(lseg,
  100. struct nfs4_ff_layout_segment,
  101. generic_hdr);
  102. }
  103. static inline struct nfs4_deviceid_node *
  104. FF_LAYOUT_DEVID_NODE(struct pnfs_layout_segment *lseg, u32 idx)
  105. {
  106. if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt ||
  107. FF_LAYOUT_LSEG(lseg)->mirror_array[idx] == NULL ||
  108. FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds == NULL)
  109. return NULL;
  110. return &FF_LAYOUT_LSEG(lseg)->mirror_array[idx]->mirror_ds->id_node;
  111. }
  112. static inline struct nfs4_ff_layout_ds *
  113. FF_LAYOUT_MIRROR_DS(struct nfs4_deviceid_node *node)
  114. {
  115. return container_of(node, struct nfs4_ff_layout_ds, id_node);
  116. }
  117. static inline struct nfs4_ff_layout_mirror *
  118. FF_LAYOUT_COMP(struct pnfs_layout_segment *lseg, u32 idx)
  119. {
  120. if (idx >= FF_LAYOUT_LSEG(lseg)->mirror_array_cnt)
  121. return NULL;
  122. return FF_LAYOUT_LSEG(lseg)->mirror_array[idx];
  123. }
  124. static inline u32
  125. FF_LAYOUT_MIRROR_COUNT(struct pnfs_layout_segment *lseg)
  126. {
  127. return FF_LAYOUT_LSEG(lseg)->mirror_array_cnt;
  128. }
  129. static inline bool
  130. ff_layout_no_fallback_to_mds(struct pnfs_layout_segment *lseg)
  131. {
  132. return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_IO_THRU_MDS;
  133. }
  134. static inline bool
  135. ff_layout_no_read_on_rw(struct pnfs_layout_segment *lseg)
  136. {
  137. return FF_LAYOUT_LSEG(lseg)->flags & FF_FLAGS_NO_READ_IO;
  138. }
  139. static inline bool
  140. ff_layout_test_devid_unavailable(struct nfs4_deviceid_node *node)
  141. {
  142. return nfs4_test_deviceid_unavailable(node);
  143. }
  144. static inline int
  145. nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx)
  146. {
  147. return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version;
  148. }
  149. struct nfs4_ff_layout_ds *
  150. nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
  151. gfp_t gfp_flags);
  152. void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
  153. void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
  154. int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
  155. struct nfs4_ff_layout_mirror *mirror, u64 offset,
  156. u64 length, int status, enum nfs_opnum4 opnum,
  157. gfp_t gfp_flags);
  158. int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo,
  159. struct xdr_stream *xdr, int *count,
  160. const struct pnfs_layout_range *range);
  161. struct nfs_fh *
  162. nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx);
  163. struct nfs4_pnfs_ds *
  164. nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
  165. bool fail_return);
  166. struct rpc_clnt *
  167. nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
  168. u32 ds_idx,
  169. struct nfs_client *ds_clp,
  170. struct inode *inode);
  171. struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
  172. u32 ds_idx, struct rpc_cred *mdscred);
  173. bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg);
  174. bool ff_layout_avoid_mds_available_ds(struct pnfs_layout_segment *lseg);
  175. bool ff_layout_avoid_read_on_rw(struct pnfs_layout_segment *lseg);
  176. #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */