include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / include / linux / ceph / osd_client.h
blobf88eacb111d4151dc5491797fe0e03faaadc26a9
1 #ifndef _FS_CEPH_OSD_CLIENT_H
2 #define _FS_CEPH_OSD_CLIENT_H
4 #include <linux/completion.h>
5 #include <linux/kref.h>
6 #include <linux/mempool.h>
7 #include <linux/rbtree.h>
9 #include "types.h"
10 #include "osdmap.h"
11 #include "messenger.h"
13 struct ceph_msg;
14 struct ceph_snap_context;
15 struct ceph_osd_request;
16 struct ceph_osd_client;
17 struct ceph_authorizer;
18 struct ceph_pagelist;
21 * completion callback for async writepages
23 typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
24 struct ceph_msg *);
26 /* a given osd we're communicating with */
27 struct 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;
45 /* an in-flight request */
46 struct 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;
58 struct ceph_connection *r_con_filling_msg;
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;
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;
75 struct inode *r_inode; /* for use by callbacks */
76 void *r_priv; /* ditto */
78 char r_oid[40]; /* object name */
79 int r_oid_len;
80 unsigned long r_stamp; /* send OR check time */
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
93 struct ceph_pagelist *r_trail; /* trailing part of the data */
96 struct 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;
108 struct 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;
116 struct ceph_osd_client {
117 struct ceph_client *client;
119 struct ceph_osdmap *osdmap; /* current map */
120 struct rw_semaphore map_sem;
121 struct completion map_waiters;
122 u64 last_requested_map;
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
141 mempool_t *req_mempool;
143 struct ceph_msgpool msgpool_op;
144 struct ceph_msgpool msgpool_op_reply;
146 spinlock_t event_lock;
147 struct rb_root event_tree;
148 u64 event_count;
150 struct workqueue_struct *notify_wq;
153 struct 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;
193 u32 payload_len;
196 extern int ceph_osdc_init(struct ceph_osd_client *osdc,
197 struct ceph_client *client);
198 extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
200 extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
201 struct ceph_msg *msg);
202 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
203 struct ceph_msg *msg);
205 extern 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);
212 extern 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);
221 extern 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);
229 extern 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);
240 extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
241 struct ceph_osd_request *req);
242 extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
243 struct ceph_osd_request *req);
245 static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
247 kref_get(&req->r_kref);
249 extern void ceph_osdc_release_request(struct kref *kref);
250 static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
252 kref_put(&req->r_kref, ceph_osdc_release_request);
255 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
256 struct ceph_osd_request *req,
257 bool nofail);
258 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
259 struct ceph_osd_request *req);
260 extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
262 extern 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);
270 extern 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);
280 /* watch/notify events */
281 extern 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);
285 extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
286 extern int ceph_osdc_wait_event(struct ceph_osd_event *event,
287 unsigned long timeout);
288 extern void ceph_osdc_put_event(struct ceph_osd_event *event);
289 #endif