Commit | Line | Data |
---|---|---|
f24e9980 SW |
1 | #ifndef _FS_CEPH_OSD_CLIENT_H |
2 | #define _FS_CEPH_OSD_CLIENT_H | |
3 | ||
4 | #include <linux/completion.h> | |
415e49a9 | 5 | #include <linux/kref.h> |
f24e9980 SW |
6 | #include <linux/mempool.h> |
7 | #include <linux/rbtree.h> | |
8 | ||
6c4a1915 AE |
9 | #include <linux/ceph/types.h> |
10 | #include <linux/ceph/osdmap.h> | |
11 | #include <linux/ceph/messenger.h> | |
12 | #include <linux/ceph/auth.h> | |
c885837f | 13 | #include <linux/ceph/pagelist.h> |
f24e9980 SW |
14 | |
15 | struct ceph_msg; | |
16 | struct ceph_snap_context; | |
17 | struct ceph_osd_request; | |
18 | struct ceph_osd_client; | |
19 | ||
20 | /* | |
21 | * completion callback for async writepages | |
22 | */ | |
85e084fe | 23 | typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *); |
26be8808 | 24 | typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool); |
f24e9980 | 25 | |
63244fa1 ID |
26 | #define CEPH_HOMELESS_OSD -1 |
27 | ||
f24e9980 SW |
28 | /* a given osd we're communicating with */ |
29 | struct ceph_osd { | |
30 | atomic_t o_ref; | |
31 | struct ceph_osd_client *o_osdc; | |
32 | int o_osd; | |
33 | int o_incarnation; | |
34 | struct rb_node o_node; | |
35 | struct ceph_connection o_con; | |
36 | struct list_head o_requests; | |
a40c4f10 | 37 | struct list_head o_linger_requests; |
f5a2041b | 38 | struct list_head o_osd_lru; |
6c4a1915 | 39 | struct ceph_auth_handshake o_auth; |
f5a2041b | 40 | unsigned long lru_ttl; |
422d2cb8 | 41 | struct list_head o_keepalive_item; |
f24e9980 SW |
42 | }; |
43 | ||
3f1af42a ID |
44 | #define CEPH_OSD_SLAB_OPS 2 |
45 | #define CEPH_OSD_MAX_OPS 16 | |
1b83bef2 | 46 | |
2ac2b7a6 | 47 | enum ceph_osd_data_type { |
ec9123c5 | 48 | CEPH_OSD_DATA_TYPE_NONE = 0, |
2ac2b7a6 | 49 | CEPH_OSD_DATA_TYPE_PAGES, |
9a5e6d09 | 50 | CEPH_OSD_DATA_TYPE_PAGELIST, |
2ac2b7a6 AE |
51 | #ifdef CONFIG_BLOCK |
52 | CEPH_OSD_DATA_TYPE_BIO, | |
53 | #endif /* CONFIG_BLOCK */ | |
54 | }; | |
55 | ||
2794a82a | 56 | struct ceph_osd_data { |
2ac2b7a6 AE |
57 | enum ceph_osd_data_type type; |
58 | union { | |
2794a82a AE |
59 | struct { |
60 | struct page **pages; | |
e0c59487 | 61 | u64 length; |
2794a82a AE |
62 | u32 alignment; |
63 | bool pages_from_pool; | |
64 | bool own_pages; | |
65 | }; | |
9a5e6d09 | 66 | struct ceph_pagelist *pagelist; |
2794a82a | 67 | #ifdef CONFIG_BLOCK |
fdce58cc AE |
68 | struct { |
69 | struct bio *bio; /* list of bios */ | |
70 | size_t bio_length; /* total in list */ | |
71 | }; | |
2794a82a AE |
72 | #endif /* CONFIG_BLOCK */ |
73 | }; | |
74 | }; | |
75 | ||
79528734 AE |
76 | struct ceph_osd_req_op { |
77 | u16 op; /* CEPH_OSD_OP_* */ | |
7b25bf5f | 78 | u32 flags; /* CEPH_OSD_OP_FLAG_* */ |
de2aa102 | 79 | u32 indata_len; /* request */ |
7665d85b YZ |
80 | u32 outdata_len; /* reply */ |
81 | s32 rval; | |
82 | ||
79528734 | 83 | union { |
49719778 | 84 | struct ceph_osd_data raw_data_in; |
79528734 AE |
85 | struct { |
86 | u64 offset, length; | |
87 | u64 truncate_size; | |
88 | u32 truncate_seq; | |
5476492f | 89 | struct ceph_osd_data osd_data; |
79528734 | 90 | } extent; |
d74b50be | 91 | struct { |
d7d5a007 ID |
92 | u32 name_len; |
93 | u32 value_len; | |
d74b50be YZ |
94 | __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */ |
95 | __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */ | |
96 | struct ceph_osd_data osd_data; | |
97 | } xattr; | |
79528734 AE |
98 | struct { |
99 | const char *class_name; | |
100 | const char *method_name; | |
5476492f | 101 | struct ceph_osd_data request_info; |
04017e29 | 102 | struct ceph_osd_data request_data; |
5476492f | 103 | struct ceph_osd_data response_data; |
79528734 AE |
104 | __u8 class_len; |
105 | __u8 method_len; | |
bb873b53 | 106 | u32 indata_len; |
79528734 AE |
107 | } cls; |
108 | struct { | |
109 | u64 cookie; | |
110 | u64 ver; | |
111 | u32 prot_ver; | |
112 | u32 timeout; | |
113 | __u8 flag; | |
114 | } watch; | |
c647b8a8 ID |
115 | struct { |
116 | u64 expected_object_size; | |
117 | u64 expected_write_size; | |
118 | } alloc_hint; | |
79528734 AE |
119 | }; |
120 | }; | |
121 | ||
63244fa1 ID |
122 | struct ceph_osd_request_target { |
123 | struct ceph_object_id base_oid; | |
124 | struct ceph_object_locator base_oloc; | |
125 | struct ceph_object_id target_oid; | |
126 | struct ceph_object_locator target_oloc; | |
127 | ||
128 | struct ceph_pg pgid; | |
129 | u32 pg_num; | |
130 | u32 pg_num_mask; | |
131 | struct ceph_osds acting; | |
132 | struct ceph_osds up; | |
133 | int size; | |
134 | int min_size; | |
135 | bool sort_bitwise; | |
136 | ||
137 | unsigned int flags; /* CEPH_OSD_FLAG_* */ | |
138 | bool paused; | |
139 | ||
140 | int osd; | |
141 | }; | |
142 | ||
f24e9980 SW |
143 | /* an in-flight request */ |
144 | struct ceph_osd_request { | |
145 | u64 r_tid; /* unique for this client */ | |
146 | struct rb_node r_node; | |
422d2cb8 | 147 | struct list_head r_req_lru_item; |
f24e9980 | 148 | struct list_head r_osd_item; |
a40c4f10 | 149 | struct list_head r_linger_item; |
1d0326b1 | 150 | struct list_head r_linger_osd_item; |
f24e9980 | 151 | struct ceph_osd *r_osd; |
a66dd383 ID |
152 | |
153 | struct ceph_osd_request_target r_t; | |
154 | #define r_base_oid r_t.base_oid | |
155 | #define r_base_oloc r_t.base_oloc | |
156 | #define r_flags r_t.flags | |
f24e9980 SW |
157 | |
158 | struct ceph_msg *r_request, *r_reply; | |
f24e9980 | 159 | u32 r_sent; /* >0 if r_request is sending/sent */ |
1b83bef2 | 160 | |
79528734 AE |
161 | /* request osd ops array */ |
162 | unsigned int r_num_ops; | |
79528734 | 163 | |
1b83bef2 | 164 | int r_result; |
fe5da05e | 165 | bool r_got_reply; |
a40c4f10 | 166 | int r_linger; |
f24e9980 SW |
167 | |
168 | struct ceph_osd_client *r_osdc; | |
415e49a9 | 169 | struct kref r_kref; |
f24e9980 | 170 | bool r_mempool; |
fe5da05e ID |
171 | struct completion r_completion; |
172 | struct completion r_safe_completion; /* fsync waiter */ | |
26be8808 AE |
173 | ceph_osdc_callback_t r_callback; |
174 | ceph_osdc_unsafe_callback_t r_unsafe_callback; | |
f24e9980 SW |
175 | struct list_head r_unsafe_item; |
176 | ||
177 | struct inode *r_inode; /* for use by callbacks */ | |
3d14c5d2 | 178 | void *r_priv; /* ditto */ |
f24e9980 | 179 | |
bb873b53 ID |
180 | /* set by submitter */ |
181 | u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */ | |
182 | struct ceph_snap_context *r_snapc; /* for writes */ | |
183 | struct timespec r_mtime; /* ditto */ | |
184 | u64 r_data_offset; /* ditto */ | |
f24e9980 | 185 | |
bb873b53 ID |
186 | /* internal */ |
187 | unsigned long r_stamp; /* jiffies, send or check time */ | |
188 | int r_attempts; | |
189 | struct ceph_eversion r_replay_version; /* aka reassert_version */ | |
190 | u32 r_last_force_resend; | |
3f1af42a ID |
191 | |
192 | struct ceph_osd_req_op r_ops[]; | |
f24e9980 SW |
193 | }; |
194 | ||
205ee118 ID |
195 | struct ceph_request_redirect { |
196 | struct ceph_object_locator oloc; | |
197 | }; | |
198 | ||
a40c4f10 YS |
199 | struct ceph_osd_event { |
200 | u64 cookie; | |
201 | int one_shot; | |
202 | struct ceph_osd_client *osdc; | |
203 | void (*cb)(u64, u64, u8, void *); | |
204 | void *data; | |
205 | struct rb_node node; | |
206 | struct list_head osd_node; | |
207 | struct kref kref; | |
a40c4f10 YS |
208 | }; |
209 | ||
210 | struct ceph_osd_event_work { | |
211 | struct work_struct work; | |
212 | struct ceph_osd_event *event; | |
213 | u64 ver; | |
214 | u64 notify_id; | |
215 | u8 opcode; | |
216 | }; | |
217 | ||
f24e9980 SW |
218 | struct ceph_osd_client { |
219 | struct ceph_client *client; | |
220 | ||
221 | struct ceph_osdmap *osdmap; /* current map */ | |
222 | struct rw_semaphore map_sem; | |
f24e9980 SW |
223 | |
224 | struct mutex request_mutex; | |
225 | struct rb_root osds; /* osds */ | |
f5a2041b | 226 | struct list_head osd_lru; /* idle osds */ |
f24e9980 SW |
227 | u64 last_tid; /* tid of last request */ |
228 | struct rb_root requests; /* pending requests */ | |
6f6c7006 SW |
229 | struct list_head req_lru; /* in-flight lru */ |
230 | struct list_head req_unsent; /* unsent/need-resend queue */ | |
231 | struct list_head req_notarget; /* map to no osd */ | |
a40c4f10 | 232 | struct list_head req_linger; /* lingering requests */ |
f24e9980 SW |
233 | int num_requests; |
234 | struct delayed_work timeout_work; | |
f5a2041b | 235 | struct delayed_work osds_timeout_work; |
039934b8 | 236 | #ifdef CONFIG_DEBUG_FS |
f24e9980 | 237 | struct dentry *debugfs_file; |
039934b8 | 238 | #endif |
f24e9980 SW |
239 | |
240 | mempool_t *req_mempool; | |
241 | ||
0d59ab81 | 242 | struct ceph_msgpool msgpool_op; |
c16e7869 | 243 | struct ceph_msgpool msgpool_op_reply; |
a40c4f10 YS |
244 | |
245 | spinlock_t event_lock; | |
246 | struct rb_root event_tree; | |
247 | u64 event_count; | |
248 | ||
249 | struct workqueue_struct *notify_wq; | |
f24e9980 SW |
250 | }; |
251 | ||
5522ae0b AE |
252 | extern int ceph_osdc_setup(void); |
253 | extern void ceph_osdc_cleanup(void); | |
254 | ||
f24e9980 SW |
255 | extern int ceph_osdc_init(struct ceph_osd_client *osdc, |
256 | struct ceph_client *client); | |
257 | extern void ceph_osdc_stop(struct ceph_osd_client *osdc); | |
258 | ||
259 | extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc, | |
260 | struct ceph_msg *msg); | |
261 | extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc, | |
262 | struct ceph_msg *msg); | |
263 | ||
49719778 | 264 | extern void osd_req_op_init(struct ceph_osd_request *osd_req, |
144cba14 | 265 | unsigned int which, u16 opcode, u32 flags); |
49719778 AE |
266 | |
267 | extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *, | |
268 | unsigned int which, | |
269 | struct page **pages, u64 length, | |
270 | u32 alignment, bool pages_from_pool, | |
271 | bool own_pages); | |
272 | ||
c99d2d4a AE |
273 | extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req, |
274 | unsigned int which, u16 opcode, | |
33803f33 AE |
275 | u64 offset, u64 length, |
276 | u64 truncate_size, u32 truncate_seq); | |
c99d2d4a AE |
277 | extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req, |
278 | unsigned int which, u64 length); | |
2c63f49a YZ |
279 | extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req, |
280 | unsigned int which, u64 offset_inc); | |
a4ce40a9 AE |
281 | |
282 | extern struct ceph_osd_data *osd_req_op_extent_osd_data( | |
283 | struct ceph_osd_request *osd_req, | |
406e2c9f | 284 | unsigned int which); |
a4ce40a9 AE |
285 | |
286 | extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *, | |
406e2c9f | 287 | unsigned int which, |
a4ce40a9 AE |
288 | struct page **pages, u64 length, |
289 | u32 alignment, bool pages_from_pool, | |
290 | bool own_pages); | |
291 | extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *, | |
406e2c9f | 292 | unsigned int which, |
a4ce40a9 AE |
293 | struct ceph_pagelist *pagelist); |
294 | #ifdef CONFIG_BLOCK | |
295 | extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *, | |
406e2c9f | 296 | unsigned int which, |
a4ce40a9 AE |
297 | struct bio *bio, size_t bio_length); |
298 | #endif /* CONFIG_BLOCK */ | |
299 | ||
04017e29 AE |
300 | extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *, |
301 | unsigned int which, | |
302 | struct ceph_pagelist *pagelist); | |
6c57b554 AE |
303 | extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *, |
304 | unsigned int which, | |
305 | struct page **pages, u64 length, | |
306 | u32 alignment, bool pages_from_pool, | |
307 | bool own_pages); | |
a4ce40a9 | 308 | extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *, |
c99d2d4a | 309 | unsigned int which, |
a4ce40a9 AE |
310 | struct page **pages, u64 length, |
311 | u32 alignment, bool pages_from_pool, | |
312 | bool own_pages); | |
313 | ||
c99d2d4a AE |
314 | extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req, |
315 | unsigned int which, u16 opcode, | |
04017e29 | 316 | const char *class, const char *method); |
d74b50be YZ |
317 | extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which, |
318 | u16 opcode, const char *name, const void *value, | |
319 | size_t size, u8 cmp_op, u8 cmp_mode); | |
c99d2d4a AE |
320 | extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req, |
321 | unsigned int which, u16 opcode, | |
33803f33 | 322 | u64 cookie, u64 version, int flag); |
c647b8a8 ID |
323 | extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req, |
324 | unsigned int which, | |
325 | u64 expected_object_size, | |
326 | u64 expected_write_size); | |
33803f33 | 327 | |
3499e8a5 | 328 | extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, |
3499e8a5 | 329 | struct ceph_snap_context *snapc, |
acead002 | 330 | unsigned int num_ops, |
3499e8a5 | 331 | bool use_mempool, |
54a54007 | 332 | gfp_t gfp_flags); |
13d1ad16 | 333 | int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp); |
3499e8a5 | 334 | |
f24e9980 SW |
335 | extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *, |
336 | struct ceph_file_layout *layout, | |
337 | struct ceph_vino vino, | |
acead002 | 338 | u64 offset, u64 *len, |
715e4cd4 YZ |
339 | unsigned int which, int num_ops, |
340 | int opcode, int flags, | |
f24e9980 | 341 | struct ceph_snap_context *snapc, |
acead002 | 342 | u32 truncate_seq, u64 truncate_size, |
153e5167 | 343 | bool use_mempool); |
f24e9980 | 344 | |
a40c4f10 YS |
345 | extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc, |
346 | struct ceph_osd_request *req); | |
a40c4f10 | 347 | |
9e94af20 ID |
348 | extern void ceph_osdc_get_request(struct ceph_osd_request *req); |
349 | extern void ceph_osdc_put_request(struct ceph_osd_request *req); | |
f24e9980 SW |
350 | |
351 | extern int ceph_osdc_start_request(struct ceph_osd_client *osdc, | |
352 | struct ceph_osd_request *req, | |
353 | bool nofail); | |
c9f9b93d | 354 | extern void ceph_osdc_cancel_request(struct ceph_osd_request *req); |
f24e9980 SW |
355 | extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc, |
356 | struct ceph_osd_request *req); | |
357 | extern void ceph_osdc_sync(struct ceph_osd_client *osdc); | |
358 | ||
dd935f44 JD |
359 | extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc); |
360 | ||
f24e9980 SW |
361 | extern int ceph_osdc_readpages(struct ceph_osd_client *osdc, |
362 | struct ceph_vino vino, | |
363 | struct ceph_file_layout *layout, | |
364 | u64 off, u64 *plen, | |
365 | u32 truncate_seq, u64 truncate_size, | |
b7495fc2 SW |
366 | struct page **pages, int nr_pages, |
367 | int page_align); | |
f24e9980 SW |
368 | |
369 | extern int ceph_osdc_writepages(struct ceph_osd_client *osdc, | |
370 | struct ceph_vino vino, | |
371 | struct ceph_file_layout *layout, | |
372 | struct ceph_snap_context *sc, | |
373 | u64 off, u64 len, | |
374 | u32 truncate_seq, u64 truncate_size, | |
375 | struct timespec *mtime, | |
24808826 | 376 | struct page **pages, int nr_pages); |
f24e9980 | 377 | |
a40c4f10 YS |
378 | /* watch/notify events */ |
379 | extern int ceph_osdc_create_event(struct ceph_osd_client *osdc, | |
380 | void (*event_cb)(u64, u64, u8, void *), | |
3c663bbd | 381 | void *data, struct ceph_osd_event **pevent); |
a40c4f10 | 382 | extern void ceph_osdc_cancel_event(struct ceph_osd_event *event); |
a40c4f10 | 383 | extern void ceph_osdc_put_event(struct ceph_osd_event *event); |
f24e9980 SW |
384 | #endif |
385 |