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