osd_client.h 5.2 KB

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