osd_client.h 4.8 KB

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