at v3.1 8.7 kB view raw
1#ifndef _FS_CEPH_OSD_CLIENT_H 2#define _FS_CEPH_OSD_CLIENT_H 3 4#include <linux/completion.h> 5#include <linux/kref.h> 6#include <linux/mempool.h> 7#include <linux/rbtree.h> 8 9#include "types.h" 10#include "osdmap.h" 11#include "messenger.h" 12 13struct ceph_msg; 14struct ceph_snap_context; 15struct ceph_osd_request; 16struct ceph_osd_client; 17struct ceph_authorizer; 18struct ceph_pagelist; 19 20/* 21 * completion callback for async writepages 22 */ 23typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *, 24 struct ceph_msg *); 25 26/* a given osd we're communicating with */ 27struct ceph_osd { 28 atomic_t o_ref; 29 struct ceph_osd_client *o_osdc; 30 int o_osd; 31 int o_incarnation; 32 struct rb_node o_node; 33 struct ceph_connection o_con; 34 struct list_head o_requests; 35 struct list_head o_linger_requests; 36 struct list_head o_osd_lru; 37 struct ceph_authorizer *o_authorizer; 38 void *o_authorizer_buf, *o_authorizer_reply_buf; 39 size_t o_authorizer_buf_len, o_authorizer_reply_buf_len; 40 unsigned long lru_ttl; 41 int o_marked_for_keepalive; 42 struct list_head o_keepalive_item; 43}; 44 45/* an in-flight request */ 46struct ceph_osd_request { 47 u64 r_tid; /* unique for this client */ 48 struct rb_node r_node; 49 struct list_head r_req_lru_item; 50 struct list_head r_osd_item; 51 struct list_head r_linger_item; 52 struct list_head r_linger_osd; 53 struct ceph_osd *r_osd; 54 struct ceph_pg r_pgid; 55 int r_pg_osds[CEPH_PG_MAX_SIZE]; 56 int r_num_pg_osds; 57 58 struct ceph_connection *r_con_filling_msg; 59 60 struct ceph_msg *r_request, *r_reply; 61 int r_result; 62 int r_flags; /* any additional flags for the osd */ 63 u32 r_sent; /* >0 if r_request is sending/sent */ 64 int r_got_reply; 65 int r_linger; 66 67 struct ceph_osd_client *r_osdc; 68 struct kref r_kref; 69 bool r_mempool; 70 struct completion r_completion, r_safe_completion; 71 ceph_osdc_callback_t r_callback, r_safe_callback; 72 struct ceph_eversion r_reassert_version; 73 struct list_head r_unsafe_item; 74 75 struct inode *r_inode; /* for use by callbacks */ 76 void *r_priv; /* ditto */ 77 78 char r_oid[40]; /* object name */ 79 int r_oid_len; 80 unsigned long r_stamp; /* send OR check time */ 81 82 struct ceph_file_layout r_file_layout; 83 struct ceph_snap_context *r_snapc; /* snap context for writes */ 84 unsigned r_num_pages; /* size of page array (follows) */ 85 unsigned r_page_alignment; /* io offset in first page */ 86 struct page **r_pages; /* pages for data payload */ 87 int r_pages_from_pool; 88 int r_own_pages; /* if true, i own page list */ 89#ifdef CONFIG_BLOCK 90 struct bio *r_bio; /* instead of pages */ 91#endif 92 93 struct ceph_pagelist *r_trail; /* trailing part of the data */ 94}; 95 96struct ceph_osd_event { 97 u64 cookie; 98 int one_shot; 99 struct ceph_osd_client *osdc; 100 void (*cb)(u64, u64, u8, void *); 101 void *data; 102 struct rb_node node; 103 struct list_head osd_node; 104 struct kref kref; 105 struct completion completion; 106}; 107 108struct ceph_osd_event_work { 109 struct work_struct work; 110 struct ceph_osd_event *event; 111 u64 ver; 112 u64 notify_id; 113 u8 opcode; 114}; 115 116struct ceph_osd_client { 117 struct ceph_client *client; 118 119 struct ceph_osdmap *osdmap; /* current map */ 120 struct rw_semaphore map_sem; 121 struct completion map_waiters; 122 u64 last_requested_map; 123 124 struct mutex request_mutex; 125 struct rb_root osds; /* osds */ 126 struct list_head osd_lru; /* idle osds */ 127 u64 timeout_tid; /* tid of timeout triggering rq */ 128 u64 last_tid; /* tid of last request */ 129 struct rb_root requests; /* pending requests */ 130 struct list_head req_lru; /* in-flight lru */ 131 struct list_head req_unsent; /* unsent/need-resend queue */ 132 struct list_head req_notarget; /* map to no osd */ 133 struct list_head req_linger; /* lingering requests */ 134 int num_requests; 135 struct delayed_work timeout_work; 136 struct delayed_work osds_timeout_work; 137#ifdef CONFIG_DEBUG_FS 138 struct dentry *debugfs_file; 139#endif 140 141 mempool_t *req_mempool; 142 143 struct ceph_msgpool msgpool_op; 144 struct ceph_msgpool msgpool_op_reply; 145 146 spinlock_t event_lock; 147 struct rb_root event_tree; 148 u64 event_count; 149 150 struct workqueue_struct *notify_wq; 151}; 152 153struct ceph_osd_req_op { 154 u16 op; /* CEPH_OSD_OP_* */ 155 u32 flags; /* CEPH_OSD_FLAG_* */ 156 union { 157 struct { 158 u64 offset, length; 159 u64 truncate_size; 160 u32 truncate_seq; 161 } extent; 162 struct { 163 const char *name; 164 u32 name_len; 165 const char *val; 166 u32 value_len; 167 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */ 168 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */ 169 } xattr; 170 struct { 171 const char *class_name; 172 __u8 class_len; 173 const char *method_name; 174 __u8 method_len; 175 __u8 argc; 176 const char *indata; 177 u32 indata_len; 178 } cls; 179 struct { 180 u64 cookie, count; 181 } pgls; 182 struct { 183 u64 snapid; 184 } snap; 185 struct { 186 u64 cookie; 187 u64 ver; 188 __u8 flag; 189 u32 prot_ver; 190 u32 timeout; 191 } watch; 192 }; 193 u32 payload_len; 194}; 195 196extern int ceph_osdc_init(struct ceph_osd_client *osdc, 197 struct ceph_client *client); 198extern void ceph_osdc_stop(struct ceph_osd_client *osdc); 199 200extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc, 201 struct ceph_msg *msg); 202extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc, 203 struct ceph_msg *msg); 204 205extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc, 206 struct ceph_file_layout *layout, 207 u64 snapid, 208 u64 off, u64 *plen, u64 *bno, 209 struct ceph_osd_request *req, 210 struct ceph_osd_req_op *op); 211 212extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc, 213 int flags, 214 struct ceph_snap_context *snapc, 215 struct ceph_osd_req_op *ops, 216 bool use_mempool, 217 gfp_t gfp_flags, 218 struct page **pages, 219 struct bio *bio); 220 221extern void ceph_osdc_build_request(struct ceph_osd_request *req, 222 u64 off, u64 *plen, 223 struct ceph_osd_req_op *src_ops, 224 struct ceph_snap_context *snapc, 225 struct timespec *mtime, 226 const char *oid, 227 int oid_len); 228 229extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *, 230 struct ceph_file_layout *layout, 231 struct ceph_vino vino, 232 u64 offset, u64 *len, int op, int flags, 233 struct ceph_snap_context *snapc, 234 int do_sync, u32 truncate_seq, 235 u64 truncate_size, 236 struct timespec *mtime, 237 bool use_mempool, int num_reply, 238 int page_align); 239 240extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc, 241 struct ceph_osd_request *req); 242extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc, 243 struct ceph_osd_request *req); 244 245static inline void ceph_osdc_get_request(struct ceph_osd_request *req) 246{ 247 kref_get(&req->r_kref); 248} 249extern void ceph_osdc_release_request(struct kref *kref); 250static inline void ceph_osdc_put_request(struct ceph_osd_request *req) 251{ 252 kref_put(&req->r_kref, ceph_osdc_release_request); 253} 254 255extern int ceph_osdc_start_request(struct ceph_osd_client *osdc, 256 struct ceph_osd_request *req, 257 bool nofail); 258extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc, 259 struct ceph_osd_request *req); 260extern void ceph_osdc_sync(struct ceph_osd_client *osdc); 261 262extern int ceph_osdc_readpages(struct ceph_osd_client *osdc, 263 struct ceph_vino vino, 264 struct ceph_file_layout *layout, 265 u64 off, u64 *plen, 266 u32 truncate_seq, u64 truncate_size, 267 struct page **pages, int nr_pages, 268 int page_align); 269 270extern int ceph_osdc_writepages(struct ceph_osd_client *osdc, 271 struct ceph_vino vino, 272 struct ceph_file_layout *layout, 273 struct ceph_snap_context *sc, 274 u64 off, u64 len, 275 u32 truncate_seq, u64 truncate_size, 276 struct timespec *mtime, 277 struct page **pages, int nr_pages, 278 int flags, int do_sync, bool nofail); 279 280/* watch/notify events */ 281extern int ceph_osdc_create_event(struct ceph_osd_client *osdc, 282 void (*event_cb)(u64, u64, u8, void *), 283 int one_shot, void *data, 284 struct ceph_osd_event **pevent); 285extern void ceph_osdc_cancel_event(struct ceph_osd_event *event); 286extern int ceph_osdc_wait_event(struct ceph_osd_event *event, 287 unsigned long timeout); 288extern void ceph_osdc_put_event(struct ceph_osd_event *event); 289#endif 290