Whamcloud - gitweb
LU-3540 lod: update recovery thread
[fs/lustre-release.git] / lustre / target / tgt_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012, 2014, Intel Corporation.
25  */
26 /*
27  * lustre/target/tgt_internal.h
28  *
29  * Lustre Unified Target header file
30  *
31  * Author: Mikhail Pershin <mike.pershin@intel.com>
32  */
33
34 #ifndef _TG_INTERNAL_H
35 #define _TG_INTERNAL_H
36
37 #include <lustre_net.h>
38 #include <lustre/lustre_idl.h>
39 #include <lu_target.h>
40 #include <lustre_export.h>
41 #include <lustre_fid.h>
42 #include <lustre_fld.h>
43 #include <lustre_req_layout.h>
44 #include <lustre_sec.h>
45
46 extern int (*tgt_lfsck_in_notify)(const struct lu_env *env,
47                                   struct dt_device *key,
48                                   struct lfsck_request *lr,
49                                   struct thandle *th);
50 /**
51  * Common data shared by tg-level handlers. This is allocated per-thread to
52  * reduce stack consumption.
53  */
54 struct tgt_thread_info {
55         /* server and client data buffers */
56         struct lr_server_data    tti_lsd;
57         struct lsd_client_data   tti_lcd;
58         struct lu_buf            tti_buf;
59         loff_t                   tti_off;
60
61         struct lu_attr           tti_attr;
62         struct lu_fid            tti_fid1;
63
64         /* transno storage during last_rcvd update */
65         __u64                    tti_transno;
66         __u32                    tti_has_trans:1,
67                                  tti_mult_trans:1;
68
69         /* Updates data for OUT target */
70         struct thandle_exec_args tti_tea;
71         union {
72                 struct {
73                         /* for tgt_readpage()      */
74                         struct lu_rdpg     tti_rdpg;
75                         /* for tgt_sendpage()      */
76                         struct l_wait_info tti_wait_info;
77                 } rdpg;
78                 struct {
79                         struct dt_object_format    tti_update_dof;
80                         struct object_update_reply *tti_update_reply;
81                         struct object_update       *tti_update;
82                         int                        tti_update_reply_index;
83                         struct obdo                tti_obdo;
84                         struct dt_object           *tti_dt_object;
85                 } update;
86         } tti_u;
87         struct lfsck_request tti_lr;
88         struct dt_insert_rec tti_rec;
89 };
90
91 extern struct lu_context_key tgt_thread_key;
92
93 static inline struct tgt_thread_info *tgt_th_info(const struct lu_env *env)
94 {
95         struct tgt_thread_info *tti;
96
97         tti = lu_context_key_get(&env->le_ctx, &tgt_thread_key);
98         LASSERT(tti);
99         return tti;
100 }
101
102 #define MGS_SERVICE_WATCHDOG_FACTOR      (2)
103
104 int tgt_request_handle(struct ptlrpc_request *req);
105
106 /* check if request's xid is equal to last one or not*/
107 static inline int req_xid_is_last(struct ptlrpc_request *req)
108 {
109         struct lsd_client_data *lcd = req->rq_export->exp_target_data.ted_lcd;
110
111         LASSERT(lcd != NULL);
112         return (req->rq_xid == lcd->lcd_last_xid ||
113                 req->rq_xid == lcd->lcd_last_close_xid);
114 }
115
116 static inline char *dt_obd_name(struct dt_device *dt)
117 {
118         return dt->dd_lu_dev.ld_obd->obd_name;
119 }
120
121 /* out_lib.c */
122 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
123                        struct tx_arg *arg);
124 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
125                            tx_exec_func_t func, tx_exec_func_t undo,
126                            const char *file, int line);
127
128 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
129                         struct lu_attr *attr, struct lu_fid *parent_fid,
130                         struct dt_object_format *dof,
131                         struct thandle_exec_args *ta, struct thandle *th,
132                         struct object_update_reply *reply,
133                         int index, const char *file, int line);
134
135 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
136                           const struct lu_attr *attr,
137                           struct thandle_exec_args *ta, struct thandle *th,
138                           struct object_update_reply *reply, int index,
139                           const char *file, int line);
140
141 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
142                        const struct lu_buf *buf, loff_t pos,
143                        struct thandle_exec_args *ta, struct thandle *th,
144                        struct object_update_reply *reply, int index,
145                        const char *file, int line);
146
147 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
148                            const struct lu_buf *buf, const char *name,
149                            int flags, struct thandle_exec_args *ta,
150                            struct thandle *th,
151                            struct object_update_reply *reply, int index,
152                            const char *file, int line);
153
154 int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
155                            const char *name, struct thandle_exec_args *ta,
156                            struct thandle *th,
157                            struct object_update_reply *reply, int index,
158                            const char *file, int line);
159
160 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
161                          struct thandle_exec_args *ta, struct thandle *th,
162                          struct object_update_reply *reply, int index,
163                          const char *file, int line);
164
165 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
166                          struct thandle_exec_args *ta, struct thandle *th,
167                          struct object_update_reply *reply, int index,
168                          const char *file, int line);
169
170 int out_index_insert_add_exec(const struct lu_env *env,
171                               struct dt_object *dt_obj,
172                               const struct dt_rec *rec,
173                               const struct dt_key *key,
174                               struct thandle_exec_args *ta,
175                               struct thandle *th,
176                               struct object_update_reply *reply,
177                               int index, const char *file, int line);
178
179 int out_index_delete_add_exec(const struct lu_env *env,
180                               struct dt_object *dt_obj,
181                               const struct dt_key *key,
182                               struct thandle_exec_args *ta,
183                               struct thandle *th,
184                               struct object_update_reply *reply,
185                               int index, const char *file, int line);
186
187 int out_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
188                          struct thandle_exec_args *ta, struct thandle *th,
189                          struct object_update_reply *reply,
190                          int index, const char *file, int line);
191
192 /* Update handlers */
193 int out_handle(struct tgt_session_info *tsi);
194
195 #define out_tx_create(env, obj, attr, fid, dof, ta, th, reply, idx) \
196         out_create_add_exec(env, obj, attr, fid, dof, ta, th, reply, idx, \
197                             __FILE__, __LINE__)
198
199 #define out_tx_attr_set(env, obj, attr, ta, th, reply, idx) \
200         out_attr_set_add_exec(env, obj, attr, ta, th, reply, idx, \
201                               __FILE__, __LINE__)
202
203 #define out_tx_xattr_set(env, obj, buf, name, fl, ta, th, reply, idx)   \
204         out_xattr_set_add_exec(env, obj, buf, name, fl, ta, th, reply, idx, \
205                                __FILE__, __LINE__)
206
207 #define out_tx_xattr_del(env, obj, name, ta, th, reply, idx)    \
208         out_xattr_del_add_exec(env, obj, name, ta, th, reply, idx,      \
209                                __FILE__, __LINE__)
210
211 #define out_tx_ref_add(env, obj, ta, th, reply, idx) \
212         out_ref_add_add_exec(env, obj, ta, th, reply, idx,      \
213                              __FILE__, __LINE__)
214
215 #define out_tx_ref_del(env, obj, ta, th, reply, idx) \
216         out_ref_del_add_exec(env, obj, ta, th, reply, idx,      \
217                              __FILE__, __LINE__)
218
219 #define out_tx_index_insert(env, obj, rec, key, ta, th, reply, idx) \
220         out_index_insert_add_exec(env, obj, rec, key, ta, th, reply, idx, \
221                                   __FILE__, __LINE__)
222
223 #define out_tx_index_delete(env, obj, key, ta, th, reply, idx) \
224         out_index_delete_add_exec(env, obj, key, ta, th, reply, idx, \
225                                   __FILE__, __LINE__)
226
227 #define out_tx_destroy(env, obj, ta, th, reply, idx) \
228         out_destroy_add_exec(env, obj, ta, th, reply, idx,      \
229                              __FILE__, __LINE__)
230
231 #define out_tx_write(env, obj, buf, pos, ta, th, reply, idx) \
232         out_write_add_exec(env, obj, buf, pos, ta, th, reply, idx,\
233                            __FILE__, __LINE__)
234
235 const char *update_op_str(__u16 opcode);
236
237 extern struct page *tgt_page_to_corrupt;
238
239 struct tgt_thread_big_cache {
240         struct niobuf_local     local[PTLRPC_MAX_BRW_PAGES];
241 };
242
243 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt);
244 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
245                      void *cookie);
246 int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th,
247                     void *cookie);
248
249 void update_records_dump(const struct update_records *records,
250                          unsigned int mask, bool dump_updates);
251 int check_and_prepare_update_record(const struct lu_env *env,
252                                     struct thandle_update_records *tur);
253 struct update_thread_info {
254         struct lu_attr                  uti_attr;
255         struct lu_fid                   uti_fid;
256         struct lu_buf                   uti_buf;
257         struct thandle_update_records   uti_tur;
258         struct obdo                     uti_obdo;
259         struct thandle_exec_args        uti_tea;
260         struct dt_insert_rec            uti_rec;
261         struct distribute_txn_replay_req *uti_dtrq;
262 };
263
264 extern struct lu_context_key update_thread_key;
265
266 static inline struct update_thread_info *
267 update_env_info(const struct lu_env *env)
268 {
269         struct update_thread_info *uti;
270
271         uti = lu_context_key_get(&env->le_ctx, &update_thread_key);
272         LASSERT(uti != NULL);
273         return uti;
274 }
275
276 void update_info_init(void);
277 void update_info_fini(void);
278 struct sub_thandle *create_sub_thandle(struct top_multiple_thandle *tmt,
279                                        struct dt_device *dt_dev);
280 int sub_thandle_trans_create(const struct lu_env *env,
281                              struct top_thandle *top_th,
282                              struct sub_thandle *st);
283 void distribute_txn_insert_by_batchid(struct top_multiple_thandle *new);
284 int top_trans_create_tmt(const struct lu_env *env,
285                          struct top_thandle *top_th);
286 #endif /* _TG_INTERNAL_H */