osd_client.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #ifndef _FS_CEPH_OSD_CLIENT_H
  2. #define _FS_CEPH_OSD_CLIENT_H
  3. #include <linux/completion.h>
  4. #include <linux/kref.h>
  5. #include <linux/mempool.h>
  6. #include <linux/rbtree.h>
  7. #include "types.h"
  8. #include "osdmap.h"
  9. #include "messenger.h"
  10. struct ceph_msg;
  11. struct ceph_snap_context;
  12. struct ceph_osd_request;
  13. struct ceph_osd_client;
  14. struct ceph_authorizer;
  15. /*
  16. * completion callback for async writepages
  17. */
  18. typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
  19. struct ceph_msg *);
  20. /* a given osd we're communicating with */
  21. struct ceph_osd {
  22. atomic_t o_ref;
  23. struct ceph_osd_client *o_osdc;
  24. int o_osd;
  25. int o_incarnation;
  26. struct rb_node o_node;
  27. struct ceph_connection o_con;
  28. struct list_head o_requests;
  29. struct list_head o_osd_lru;
  30. struct ceph_authorizer *o_authorizer;
  31. void *o_authorizer_buf, *o_authorizer_reply_buf;
  32. size_t o_authorizer_buf_len, o_authorizer_reply_buf_len;
  33. unsigned long lru_ttl;
  34. int o_marked_for_keepalive;
  35. struct list_head o_keepalive_item;
  36. };
  37. /* an in-flight request */
  38. struct ceph_osd_request {
  39. u64 r_tid; /* unique for this client */
  40. struct rb_node r_node;
  41. struct list_head r_req_lru_item;
  42. struct list_head r_osd_item;
  43. struct ceph_osd *r_osd;
  44. struct ceph_pg r_pgid;
  45. int r_pg_osds[CEPH_PG_MAX_SIZE];
  46. int r_num_pg_osds;
  47. struct ceph_connection *r_con_filling_msg;
  48. struct ceph_msg *r_request, *r_reply;
  49. int r_result;
  50. int r_flags; /* any additional flags for the osd */
  51. u32 r_sent; /* >0 if r_request is sending/sent */
  52. int r_got_reply;
  53. struct ceph_osd_client *r_osdc;
  54. struct kref r_kref;
  55. bool r_mempool;
  56. struct completion r_completion, r_safe_completion;
  57. ceph_osdc_callback_t r_callback, r_safe_callback;
  58. struct ceph_eversion r_reassert_version;
  59. struct list_head r_unsafe_item;
  60. struct inode *r_inode; /* for use by callbacks */
  61. char r_oid[40]; /* object name */
  62. int r_oid_len;
  63. unsigned long r_stamp; /* send OR check time */
  64. bool r_resend; /* msg send failed, needs retry */
  65. struct ceph_file_layout r_file_layout;
  66. struct ceph_snap_context *r_snapc; /* snap context for writes */
  67. unsigned r_num_pages; /* size of page array (follows) */
  68. struct page **r_pages; /* pages for data payload */
  69. int r_pages_from_pool;
  70. int r_own_pages; /* if true, i own page list */
  71. };
  72. struct ceph_osd_client {
  73. struct ceph_client *client;
  74. struct ceph_osdmap *osdmap; /* current map */
  75. struct rw_semaphore map_sem;
  76. struct completion map_waiters;
  77. u64 last_requested_map;
  78. struct mutex request_mutex;
  79. struct rb_root osds; /* osds */
  80. struct list_head osd_lru; /* idle osds */
  81. u64 timeout_tid; /* tid of timeout triggering rq */
  82. u64 last_tid; /* tid of last request */
  83. struct rb_root requests; /* pending requests */
  84. struct list_head req_lru; /* pending requests lru */
  85. int num_requests;
  86. struct delayed_work timeout_work;
  87. struct delayed_work osds_timeout_work;
  88. #ifdef CONFIG_DEBUG_FS
  89. struct dentry *debugfs_file;
  90. #endif
  91. mempool_t *req_mempool;
  92. struct ceph_msgpool msgpool_op;
  93. struct ceph_msgpool msgpool_op_reply;
  94. };
  95. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  96. struct ceph_client *client);
  97. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  98. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  99. struct ceph_msg *msg);
  100. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  101. struct ceph_msg *msg);
  102. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  103. struct ceph_file_layout *layout,
  104. struct ceph_vino vino,
  105. u64 offset, u64 *len, int op, int flags,
  106. struct ceph_snap_context *snapc,
  107. int do_sync, u32 truncate_seq,
  108. u64 truncate_size,
  109. struct timespec *mtime,
  110. bool use_mempool, int num_reply);
  111. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  112. {
  113. kref_get(&req->r_kref);
  114. }
  115. extern void ceph_osdc_release_request(struct kref *kref);
  116. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  117. {
  118. kref_put(&req->r_kref, ceph_osdc_release_request);
  119. }
  120. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  121. struct ceph_osd_request *req,
  122. bool nofail);
  123. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  124. struct ceph_osd_request *req);
  125. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  126. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  127. struct ceph_vino vino,
  128. struct ceph_file_layout *layout,
  129. u64 off, u64 *plen,
  130. u32 truncate_seq, u64 truncate_size,
  131. struct page **pages, int nr_pages);
  132. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  133. struct ceph_vino vino,
  134. struct ceph_file_layout *layout,
  135. struct ceph_snap_context *sc,
  136. u64 off, u64 len,
  137. u32 truncate_seq, u64 truncate_size,
  138. struct timespec *mtime,
  139. struct page **pages, int nr_pages,
  140. int flags, int do_sync, bool nofail);
  141. #endif