0001
0002 #ifndef _FS_CEPH_OSD_CLIENT_H
0003 #define _FS_CEPH_OSD_CLIENT_H
0004
0005 #include <linux/bitrev.h>
0006 #include <linux/completion.h>
0007 #include <linux/kref.h>
0008 #include <linux/mempool.h>
0009 #include <linux/rbtree.h>
0010 #include <linux/refcount.h>
0011 #include <linux/ktime.h>
0012
0013 #include <linux/ceph/types.h>
0014 #include <linux/ceph/osdmap.h>
0015 #include <linux/ceph/messenger.h>
0016 #include <linux/ceph/msgpool.h>
0017 #include <linux/ceph/auth.h>
0018 #include <linux/ceph/pagelist.h>
0019
0020 struct ceph_msg;
0021 struct ceph_snap_context;
0022 struct ceph_osd_request;
0023 struct ceph_osd_client;
0024
0025
0026
0027
0028 typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
0029
0030 #define CEPH_HOMELESS_OSD -1
0031
0032
0033 struct ceph_osd {
0034 refcount_t o_ref;
0035 struct ceph_osd_client *o_osdc;
0036 int o_osd;
0037 int o_incarnation;
0038 struct rb_node o_node;
0039 struct ceph_connection o_con;
0040 struct rb_root o_requests;
0041 struct rb_root o_linger_requests;
0042 struct rb_root o_backoff_mappings;
0043 struct rb_root o_backoffs_by_id;
0044 struct list_head o_osd_lru;
0045 struct ceph_auth_handshake o_auth;
0046 unsigned long lru_ttl;
0047 struct list_head o_keepalive_item;
0048 struct mutex lock;
0049 };
0050
0051 #define CEPH_OSD_SLAB_OPS 2
0052 #define CEPH_OSD_MAX_OPS 16
0053
0054 enum ceph_osd_data_type {
0055 CEPH_OSD_DATA_TYPE_NONE = 0,
0056 CEPH_OSD_DATA_TYPE_PAGES,
0057 CEPH_OSD_DATA_TYPE_PAGELIST,
0058 #ifdef CONFIG_BLOCK
0059 CEPH_OSD_DATA_TYPE_BIO,
0060 #endif
0061 CEPH_OSD_DATA_TYPE_BVECS,
0062 };
0063
0064 struct ceph_osd_data {
0065 enum ceph_osd_data_type type;
0066 union {
0067 struct {
0068 struct page **pages;
0069 u64 length;
0070 u32 alignment;
0071 bool pages_from_pool;
0072 bool own_pages;
0073 };
0074 struct ceph_pagelist *pagelist;
0075 #ifdef CONFIG_BLOCK
0076 struct {
0077 struct ceph_bio_iter bio_pos;
0078 u32 bio_length;
0079 };
0080 #endif
0081 struct {
0082 struct ceph_bvec_iter bvec_pos;
0083 u32 num_bvecs;
0084 };
0085 };
0086 };
0087
0088 struct ceph_osd_req_op {
0089 u16 op;
0090 u32 flags;
0091 u32 indata_len;
0092 u32 outdata_len;
0093 s32 rval;
0094
0095 union {
0096 struct ceph_osd_data raw_data_in;
0097 struct {
0098 u64 offset, length;
0099 u64 truncate_size;
0100 u32 truncate_seq;
0101 struct ceph_osd_data osd_data;
0102 } extent;
0103 struct {
0104 u32 name_len;
0105 u32 value_len;
0106 __u8 cmp_op;
0107 __u8 cmp_mode;
0108 struct ceph_osd_data osd_data;
0109 } xattr;
0110 struct {
0111 const char *class_name;
0112 const char *method_name;
0113 struct ceph_osd_data request_info;
0114 struct ceph_osd_data request_data;
0115 struct ceph_osd_data response_data;
0116 __u8 class_len;
0117 __u8 method_len;
0118 u32 indata_len;
0119 } cls;
0120 struct {
0121 u64 cookie;
0122 __u8 op;
0123 u32 gen;
0124 } watch;
0125 struct {
0126 struct ceph_osd_data request_data;
0127 } notify_ack;
0128 struct {
0129 u64 cookie;
0130 struct ceph_osd_data request_data;
0131 struct ceph_osd_data response_data;
0132 } notify;
0133 struct {
0134 struct ceph_osd_data response_data;
0135 } list_watchers;
0136 struct {
0137 u64 expected_object_size;
0138 u64 expected_write_size;
0139 u32 flags;
0140 } alloc_hint;
0141 struct {
0142 u64 snapid;
0143 u64 src_version;
0144 u8 flags;
0145 u32 src_fadvise_flags;
0146 struct ceph_osd_data osd_data;
0147 } copy_from;
0148 };
0149 };
0150
0151 struct ceph_osd_request_target {
0152 struct ceph_object_id base_oid;
0153 struct ceph_object_locator base_oloc;
0154 struct ceph_object_id target_oid;
0155 struct ceph_object_locator target_oloc;
0156
0157 struct ceph_pg pgid;
0158 struct ceph_spg spgid;
0159 u32 pg_num;
0160 u32 pg_num_mask;
0161 struct ceph_osds acting;
0162 struct ceph_osds up;
0163 int size;
0164 int min_size;
0165 bool sort_bitwise;
0166 bool recovery_deletes;
0167
0168 unsigned int flags;
0169 bool used_replica;
0170 bool paused;
0171
0172 u32 epoch;
0173 u32 last_force_resend;
0174
0175 int osd;
0176 };
0177
0178
0179 struct ceph_osd_request {
0180 u64 r_tid;
0181 struct rb_node r_node;
0182 struct rb_node r_mc_node;
0183 struct work_struct r_complete_work;
0184 struct ceph_osd *r_osd;
0185
0186 struct ceph_osd_request_target r_t;
0187 #define r_base_oid r_t.base_oid
0188 #define r_base_oloc r_t.base_oloc
0189 #define r_flags r_t.flags
0190
0191 struct ceph_msg *r_request, *r_reply;
0192 u32 r_sent;
0193
0194
0195 unsigned int r_num_ops;
0196
0197 int r_result;
0198
0199 struct ceph_osd_client *r_osdc;
0200 struct kref r_kref;
0201 bool r_mempool;
0202 struct completion r_completion;
0203 ceph_osdc_callback_t r_callback;
0204
0205 struct inode *r_inode;
0206 struct list_head r_private_item;
0207 void *r_priv;
0208
0209
0210 u64 r_snapid;
0211 struct ceph_snap_context *r_snapc;
0212 struct timespec64 r_mtime;
0213 u64 r_data_offset;
0214 bool r_linger;
0215
0216
0217 unsigned long r_stamp;
0218 unsigned long r_start_stamp;
0219 ktime_t r_start_latency;
0220 ktime_t r_end_latency;
0221 int r_attempts;
0222 u32 r_map_dne_bound;
0223
0224 struct ceph_osd_req_op r_ops[];
0225 };
0226
0227 struct ceph_request_redirect {
0228 struct ceph_object_locator oloc;
0229 };
0230
0231
0232
0233
0234
0235
0236 struct ceph_osd_reqid {
0237 struct ceph_entity_name name;
0238 __le64 tid;
0239 __le32 inc;
0240 } __packed;
0241
0242 struct ceph_blkin_trace_info {
0243 __le64 trace_id;
0244 __le64 span_id;
0245 __le64 parent_span_id;
0246 } __packed;
0247
0248 typedef void (*rados_watchcb2_t)(void *arg, u64 notify_id, u64 cookie,
0249 u64 notifier_id, void *data, size_t data_len);
0250 typedef void (*rados_watcherrcb_t)(void *arg, u64 cookie, int err);
0251
0252 struct ceph_osd_linger_request {
0253 struct ceph_osd_client *osdc;
0254 u64 linger_id;
0255 bool committed;
0256 bool is_watch;
0257
0258 struct ceph_osd *osd;
0259 struct ceph_osd_request *reg_req;
0260 struct ceph_osd_request *ping_req;
0261 unsigned long ping_sent;
0262 unsigned long watch_valid_thru;
0263 struct list_head pending_lworks;
0264
0265 struct ceph_osd_request_target t;
0266 u32 map_dne_bound;
0267
0268 struct timespec64 mtime;
0269
0270 struct kref kref;
0271 struct mutex lock;
0272 struct rb_node node;
0273 struct rb_node osdc_node;
0274 struct rb_node mc_node;
0275 struct list_head scan_item;
0276
0277 struct completion reg_commit_wait;
0278 struct completion notify_finish_wait;
0279 int reg_commit_error;
0280 int notify_finish_error;
0281 int last_error;
0282
0283 u32 register_gen;
0284 u64 notify_id;
0285
0286 rados_watchcb2_t wcb;
0287 rados_watcherrcb_t errcb;
0288 void *data;
0289
0290 struct ceph_pagelist *request_pl;
0291 struct page **notify_id_pages;
0292
0293 struct page ***preply_pages;
0294 size_t *preply_len;
0295 };
0296
0297 struct ceph_watch_item {
0298 struct ceph_entity_name name;
0299 u64 cookie;
0300 struct ceph_entity_addr addr;
0301 };
0302
0303 struct ceph_spg_mapping {
0304 struct rb_node node;
0305 struct ceph_spg spgid;
0306
0307 struct rb_root backoffs;
0308 };
0309
0310 struct ceph_hobject_id {
0311 void *key;
0312 size_t key_len;
0313 void *oid;
0314 size_t oid_len;
0315 u64 snapid;
0316 u32 hash;
0317 u8 is_max;
0318 void *nspace;
0319 size_t nspace_len;
0320 s64 pool;
0321
0322
0323 u32 hash_reverse_bits;
0324 };
0325
0326 static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id *hoid)
0327 {
0328 hoid->hash_reverse_bits = bitrev32(hoid->hash);
0329 }
0330
0331
0332
0333
0334
0335 struct ceph_osd_backoff {
0336 struct rb_node spg_node;
0337 struct rb_node id_node;
0338
0339 struct ceph_spg spgid;
0340 u64 id;
0341 struct ceph_hobject_id *begin;
0342 struct ceph_hobject_id *end;
0343 };
0344
0345 #define CEPH_LINGER_ID_START 0xffff000000000000ULL
0346
0347 struct ceph_osd_client {
0348 struct ceph_client *client;
0349
0350 struct ceph_osdmap *osdmap;
0351 struct rw_semaphore lock;
0352
0353 struct rb_root osds;
0354 struct list_head osd_lru;
0355 spinlock_t osd_lru_lock;
0356 u32 epoch_barrier;
0357 struct ceph_osd homeless_osd;
0358 atomic64_t last_tid;
0359 u64 last_linger_id;
0360 struct rb_root linger_requests;
0361 struct rb_root map_checks;
0362 struct rb_root linger_map_checks;
0363 atomic_t num_requests;
0364 atomic_t num_homeless;
0365 int abort_err;
0366 struct delayed_work timeout_work;
0367 struct delayed_work osds_timeout_work;
0368 #ifdef CONFIG_DEBUG_FS
0369 struct dentry *debugfs_file;
0370 #endif
0371
0372 mempool_t *req_mempool;
0373
0374 struct ceph_msgpool msgpool_op;
0375 struct ceph_msgpool msgpool_op_reply;
0376
0377 struct workqueue_struct *notify_wq;
0378 struct workqueue_struct *completion_wq;
0379 };
0380
0381 static inline bool ceph_osdmap_flag(struct ceph_osd_client *osdc, int flag)
0382 {
0383 return osdc->osdmap->flags & flag;
0384 }
0385
0386 extern int ceph_osdc_setup(void);
0387 extern void ceph_osdc_cleanup(void);
0388
0389 extern int ceph_osdc_init(struct ceph_osd_client *osdc,
0390 struct ceph_client *client);
0391 extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
0392 extern void ceph_osdc_reopen_osds(struct ceph_osd_client *osdc);
0393
0394 extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
0395 struct ceph_msg *msg);
0396 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
0397 struct ceph_msg *msg);
0398 void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
0399 void ceph_osdc_abort_requests(struct ceph_osd_client *osdc, int err);
0400 void ceph_osdc_clear_abort_err(struct ceph_osd_client *osdc);
0401
0402 #define osd_req_op_data(oreq, whch, typ, fld) \
0403 ({ \
0404 struct ceph_osd_request *__oreq = (oreq); \
0405 unsigned int __whch = (whch); \
0406 BUG_ON(__whch >= __oreq->r_num_ops); \
0407 &__oreq->r_ops[__whch].typ.fld; \
0408 })
0409
0410 struct ceph_osd_req_op *osd_req_op_init(struct ceph_osd_request *osd_req,
0411 unsigned int which, u16 opcode, u32 flags);
0412
0413 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
0414 unsigned int which,
0415 struct page **pages, u64 length,
0416 u32 alignment, bool pages_from_pool,
0417 bool own_pages);
0418
0419 extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
0420 unsigned int which, u16 opcode,
0421 u64 offset, u64 length,
0422 u64 truncate_size, u32 truncate_seq);
0423 extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
0424 unsigned int which, u64 length);
0425 extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
0426 unsigned int which, u64 offset_inc);
0427
0428 extern struct ceph_osd_data *osd_req_op_extent_osd_data(
0429 struct ceph_osd_request *osd_req,
0430 unsigned int which);
0431
0432 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
0433 unsigned int which,
0434 struct page **pages, u64 length,
0435 u32 alignment, bool pages_from_pool,
0436 bool own_pages);
0437 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
0438 unsigned int which,
0439 struct ceph_pagelist *pagelist);
0440 #ifdef CONFIG_BLOCK
0441 void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
0442 unsigned int which,
0443 struct ceph_bio_iter *bio_pos,
0444 u32 bio_length);
0445 #endif
0446 void osd_req_op_extent_osd_data_bvecs(struct ceph_osd_request *osd_req,
0447 unsigned int which,
0448 struct bio_vec *bvecs, u32 num_bvecs,
0449 u32 bytes);
0450 void osd_req_op_extent_osd_data_bvec_pos(struct ceph_osd_request *osd_req,
0451 unsigned int which,
0452 struct ceph_bvec_iter *bvec_pos);
0453
0454 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
0455 unsigned int which,
0456 struct ceph_pagelist *pagelist);
0457 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
0458 unsigned int which,
0459 struct page **pages, u64 length,
0460 u32 alignment, bool pages_from_pool,
0461 bool own_pages);
0462 void osd_req_op_cls_request_data_bvecs(struct ceph_osd_request *osd_req,
0463 unsigned int which,
0464 struct bio_vec *bvecs, u32 num_bvecs,
0465 u32 bytes);
0466 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
0467 unsigned int which,
0468 struct page **pages, u64 length,
0469 u32 alignment, bool pages_from_pool,
0470 bool own_pages);
0471 int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
0472 const char *class, const char *method);
0473 extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
0474 u16 opcode, const char *name, const void *value,
0475 size_t size, u8 cmp_op, u8 cmp_mode);
0476 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
0477 unsigned int which,
0478 u64 expected_object_size,
0479 u64 expected_write_size,
0480 u32 flags);
0481 extern int osd_req_op_copy_from_init(struct ceph_osd_request *req,
0482 u64 src_snapid, u64 src_version,
0483 struct ceph_object_id *src_oid,
0484 struct ceph_object_locator *src_oloc,
0485 u32 src_fadvise_flags,
0486 u32 dst_fadvise_flags,
0487 u32 truncate_seq, u64 truncate_size,
0488 u8 copy_from_flags);
0489
0490 extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
0491 struct ceph_snap_context *snapc,
0492 unsigned int num_ops,
0493 bool use_mempool,
0494 gfp_t gfp_flags);
0495 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
0496
0497 extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
0498 struct ceph_file_layout *layout,
0499 struct ceph_vino vino,
0500 u64 offset, u64 *len,
0501 unsigned int which, int num_ops,
0502 int opcode, int flags,
0503 struct ceph_snap_context *snapc,
0504 u32 truncate_seq, u64 truncate_size,
0505 bool use_mempool);
0506
0507 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
0508 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
0509
0510 void ceph_osdc_start_request(struct ceph_osd_client *osdc,
0511 struct ceph_osd_request *req);
0512 extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
0513 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
0514 struct ceph_osd_request *req);
0515 extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
0516
0517 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
0518 void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
0519
0520 int ceph_osdc_call(struct ceph_osd_client *osdc,
0521 struct ceph_object_id *oid,
0522 struct ceph_object_locator *oloc,
0523 const char *class, const char *method,
0524 unsigned int flags,
0525 struct page *req_page, size_t req_len,
0526 struct page **resp_pages, size_t *resp_len);
0527
0528
0529 struct ceph_osd_linger_request *
0530 ceph_osdc_watch(struct ceph_osd_client *osdc,
0531 struct ceph_object_id *oid,
0532 struct ceph_object_locator *oloc,
0533 rados_watchcb2_t wcb,
0534 rados_watcherrcb_t errcb,
0535 void *data);
0536 int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
0537 struct ceph_osd_linger_request *lreq);
0538
0539 int ceph_osdc_notify_ack(struct ceph_osd_client *osdc,
0540 struct ceph_object_id *oid,
0541 struct ceph_object_locator *oloc,
0542 u64 notify_id,
0543 u64 cookie,
0544 void *payload,
0545 u32 payload_len);
0546 int ceph_osdc_notify(struct ceph_osd_client *osdc,
0547 struct ceph_object_id *oid,
0548 struct ceph_object_locator *oloc,
0549 void *payload,
0550 u32 payload_len,
0551 u32 timeout,
0552 struct page ***preply_pages,
0553 size_t *preply_len);
0554 int ceph_osdc_watch_check(struct ceph_osd_client *osdc,
0555 struct ceph_osd_linger_request *lreq);
0556 int ceph_osdc_list_watchers(struct ceph_osd_client *osdc,
0557 struct ceph_object_id *oid,
0558 struct ceph_object_locator *oloc,
0559 struct ceph_watch_item **watchers,
0560 u32 *num_watchers);
0561 #endif
0562