osd_client.h 4.7 KB

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