flexfilelayout.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #include "../pnfs.h"
  13. /* XXX: Let's filter out insanely large mirror count for now to avoid oom
  14. * due to network error etc. */
  15. #define NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT 4096
  16. /* LAYOUTSTATS report interval in ms */
  17. #define FF_LAYOUTSTATS_REPORT_INTERVAL (60000L)
  18. struct nfs4_ff_ds_version {
  19. u32 version;
  20. u32 minor_version;
  21. u32 rsize;
  22. u32 wsize;
  23. bool tightly_coupled;
  24. };
  25. /* chained in global deviceid hlist */
  26. struct nfs4_ff_layout_ds {
  27. struct nfs4_deviceid_node id_node;
  28. u32 ds_versions_cnt;
  29. struct nfs4_ff_ds_version *ds_versions;
  30. struct nfs4_pnfs_ds *ds;
  31. };
  32. struct nfs4_ff_layout_ds_err {
  33. struct list_head list; /* linked in mirror error_list */
  34. u64 offset;
  35. u64 length;
  36. int status;
  37. enum nfs_opnum4 opnum;
  38. nfs4_stateid stateid;
  39. struct nfs4_deviceid deviceid;
  40. };
  41. struct nfs4_ff_io_stat {
  42. __u64 ops_requested;
  43. __u64 bytes_requested;
  44. __u64 ops_completed;
  45. __u64 bytes_completed;
  46. __u64 bytes_not_delivered;
  47. ktime_t total_busy_time;
  48. ktime_t aggregate_completion_time;
  49. };
  50. struct nfs4_ff_busy_timer {
  51. ktime_t start_time;
  52. atomic_t n_ops;
  53. };
  54. struct nfs4_ff_layoutstat {
  55. struct nfs4_ff_io_stat io_stat;
  56. struct nfs4_ff_busy_timer busy_timer;
  57. };
  58. struct nfs4_ff_layout_mirror {
  59. struct pnfs_layout_hdr *layout;
  60. struct list_head mirrors;
  61. u32 ds_count;
  62. u32 efficiency;
  63. struct nfs4_ff_layout_ds *mirror_ds;
  64. u32 fh_versions_cnt;
  65. struct nfs_fh *fh_versions;
  66. nfs4_stateid stateid;
  67. u32 uid;
  68. u32 gid;
  69. struct rpc_cred *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. ktime_t last_report_time;
  76. u32 report_interval;
  77. };
  78. struct nfs4_ff_layout_segment {
  79. struct pnfs_layout_segment generic_hdr;
  80. u64 stripe_unit;
  81. u32 flags;
  82. u32 mirror_array_cnt;
  83. struct nfs4_ff_layout_mirror **mirror_array;
  84. };
  85. struct nfs4_flexfile_layout {
  86. struct pnfs_layout_hdr generic_hdr;
  87. struct pnfs_ds_commit_info commit_info;
  88. struct list_head mirrors;
  89. struct list_head error_list; /* nfs4_ff_layout_ds_err */
  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_test_devid_unavailable(struct nfs4_deviceid_node *node)
  136. {
  137. return nfs4_test_deviceid_unavailable(node);
  138. }
  139. static inline int
  140. nfs4_ff_layout_ds_version(struct pnfs_layout_segment *lseg, u32 ds_idx)
  141. {
  142. return FF_LAYOUT_COMP(lseg, ds_idx)->mirror_ds->ds_versions[0].version;
  143. }
  144. struct nfs4_ff_layout_ds *
  145. nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
  146. gfp_t gfp_flags);
  147. void nfs4_ff_layout_put_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
  148. void nfs4_ff_layout_free_deviceid(struct nfs4_ff_layout_ds *mirror_ds);
  149. int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
  150. struct nfs4_ff_layout_mirror *mirror, u64 offset,
  151. u64 length, int status, enum nfs_opnum4 opnum,
  152. gfp_t gfp_flags);
  153. int ff_layout_encode_ds_ioerr(struct nfs4_flexfile_layout *flo,
  154. struct xdr_stream *xdr, int *count,
  155. const struct pnfs_layout_range *range);
  156. struct nfs_fh *
  157. nfs4_ff_layout_select_ds_fh(struct pnfs_layout_segment *lseg, u32 mirror_idx);
  158. struct nfs4_pnfs_ds *
  159. nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx,
  160. bool fail_return);
  161. struct rpc_clnt *
  162. nfs4_ff_find_or_create_ds_client(struct pnfs_layout_segment *lseg,
  163. u32 ds_idx,
  164. struct nfs_client *ds_clp,
  165. struct inode *inode);
  166. struct rpc_cred *ff_layout_get_ds_cred(struct pnfs_layout_segment *lseg,
  167. u32 ds_idx, struct rpc_cred *mdscred);
  168. bool ff_layout_has_available_ds(struct pnfs_layout_segment *lseg);
  169. #endif /* FS_NFS_NFS4FLEXFILELAYOUT_H */