osd_client.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. struct ceph_connection *r_con_filling_msg;
  46. struct ceph_msg *r_request, *r_reply;
  47. int r_result;
  48. int r_flags; /* any additional flags for the osd */
  49. u32 r_sent; /* >0 if r_request is sending/sent */
  50. int r_got_reply;
  51. struct ceph_osd_client *r_osdc;
  52. struct kref r_kref;
  53. bool r_mempool;
  54. struct completion r_completion, r_safe_completion;
  55. ceph_osdc_callback_t r_callback, r_safe_callback;
  56. struct ceph_eversion r_reassert_version;
  57. struct list_head r_unsafe_item;
  58. struct inode *r_inode; /* for use by callbacks */
  59. struct writeback_control *r_wbc; /* ditto */
  60. char r_oid[40]; /* object name */
  61. int r_oid_len;
  62. unsigned long r_stamp; /* send OR check time */
  63. bool r_resend; /* msg send failed, needs retry */
  64. struct ceph_file_layout r_file_layout;
  65. struct ceph_snap_context *r_snapc; /* snap context for writes */
  66. unsigned r_num_pages; /* size of page array (follows) */
  67. struct page **r_pages; /* pages for data payload */
  68. int r_pages_from_pool;
  69. int r_own_pages; /* if true, i own page list */
  70. };
  71. struct ceph_osd_client {
  72. struct ceph_client *client;
  73. struct ceph_osdmap *osdmap; /* current map */
  74. struct rw_semaphore map_sem;
  75. struct completion map_waiters;
  76. u64 last_requested_map;
  77. struct mutex request_mutex;
  78. struct rb_root osds; /* osds */
  79. struct list_head osd_lru; /* idle osds */
  80. u64 timeout_tid; /* tid of timeout triggering rq */
  81. u64 last_tid; /* tid of last request */
  82. struct rb_root requests; /* pending requests */
  83. struct list_head req_lru; /* pending requests lru */
  84. int num_requests;
  85. struct delayed_work timeout_work;
  86. struct delayed_work osds_timeout_work;
  87. #ifdef CONFIG_DEBUG_FS
  88. struct dentry *debugfs_file;
  89. #endif
  90. mempool_t *req_mempool;
  91. struct ceph_msgpool msgpool_op;
  92. struct ceph_msgpool msgpool_op_reply;
  93. };
  94. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  95. struct ceph_client *client);
  96. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  97. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  98. struct ceph_msg *msg);
  99. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  100. struct ceph_msg *msg);
  101. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  102. struct ceph_file_layout *layout,
  103. struct ceph_vino vino,
  104. u64 offset, u64 *len, int op, int flags,
  105. struct ceph_snap_context *snapc,
  106. int do_sync, u32 truncate_seq,
  107. u64 truncate_size,
  108. struct timespec *mtime,
  109. bool use_mempool, int num_reply);
  110. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  111. {
  112. kref_get(&req->r_kref);
  113. }
  114. extern void ceph_osdc_release_request(struct kref *kref);
  115. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  116. {
  117. kref_put(&req->r_kref, ceph_osdc_release_request);
  118. }
  119. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  120. struct ceph_osd_request *req,
  121. bool nofail);
  122. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  123. struct ceph_osd_request *req);
  124. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  125. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  126. struct ceph_vino vino,
  127. struct ceph_file_layout *layout,
  128. u64 off, u64 *plen,
  129. u32 truncate_seq, u64 truncate_size,
  130. struct page **pages, int nr_pages);
  131. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  132. struct ceph_vino vino,
  133. struct ceph_file_layout *layout,
  134. struct ceph_snap_context *sc,
  135. u64 off, u64 len,
  136. u32 truncate_seq, u64 truncate_size,
  137. struct timespec *mtime,
  138. struct page **pages, int nr_pages,
  139. int flags, int do_sync, bool nofail);
  140. #endif