Whamcloud - gitweb
LU-7243 misc: update Intel copyright messages 2015
[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, 2015, 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 lsd_reply_data    tti_lrd;
59         struct lu_buf            tti_buf;
60         loff_t                   tti_off;
61
62         struct lu_attr           tti_attr;
63         struct lu_fid            tti_fid1;
64
65         /* transno storage during last_rcvd update */
66         __u64                    tti_transno;
67         __u32                    tti_has_trans:1,
68                                  tti_mult_trans:1;
69
70         /* Updates data for OUT target */
71         struct thandle_exec_args tti_tea;
72         union {
73                 struct {
74                         /* for tgt_readpage()      */
75                         struct lu_rdpg     tti_rdpg;
76                         /* for tgt_sendpage()      */
77                         struct l_wait_info tti_wait_info;
78                 } rdpg;
79                 struct {
80                         /* for out_read()      */
81                         struct lu_rdbuf     tti_rdbuf;
82                         /* for tgt_sendpage()      */
83                         struct l_wait_info tti_wait_info;
84                 } rdbuf;
85                 struct {
86                         struct dt_object_format    tti_update_dof;
87                         struct object_update_reply *tti_update_reply;
88                         struct object_update       *tti_update;
89                         int                        tti_update_reply_index;
90                         struct obdo                tti_obdo;
91                         struct dt_object           *tti_dt_object;
92                 } update;
93         } tti_u;
94         struct lfsck_request tti_lr;
95         struct dt_insert_rec tti_rec;
96 };
97
98 extern struct lu_context_key tgt_thread_key;
99
100 static inline struct tgt_thread_info *tgt_th_info(const struct lu_env *env)
101 {
102         struct tgt_thread_info *tti;
103
104         tti = lu_context_key_get(&env->le_ctx, &tgt_thread_key);
105         LASSERT(tti);
106         return tti;
107 }
108
109 #define MGS_SERVICE_WATCHDOG_FACTOR      (2)
110
111 int tgt_request_handle(struct ptlrpc_request *req);
112
113 /* check if request's xid is equal to last one or not*/
114 static inline int req_xid_is_last(struct ptlrpc_request *req)
115 {
116         struct lsd_client_data *lcd = req->rq_export->exp_target_data.ted_lcd;
117
118         LASSERT(lcd != NULL);
119         return (req->rq_xid == lcd->lcd_last_xid ||
120                 req->rq_xid == lcd->lcd_last_close_xid);
121 }
122
123 static inline char *dt_obd_name(struct dt_device *dt)
124 {
125         return dt->dd_lu_dev.ld_obd->obd_name;
126 }
127
128 /* out_lib.c */
129 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
130                        struct tx_arg *arg);
131 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
132                            tx_exec_func_t func, tx_exec_func_t undo,
133                            const char *file, int line);
134
135 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
136                         struct lu_attr *attr, struct lu_fid *parent_fid,
137                         struct dt_object_format *dof,
138                         struct thandle_exec_args *ta, struct thandle *th,
139                         struct object_update_reply *reply,
140                         int index, const char *file, int line);
141
142 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
143                           const struct lu_attr *attr,
144                           struct thandle_exec_args *ta, struct thandle *th,
145                           struct object_update_reply *reply, int index,
146                           const char *file, int line);
147
148 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
149                        const struct lu_buf *buf, loff_t pos,
150                        struct thandle_exec_args *ta, struct thandle *th,
151                        struct object_update_reply *reply, int index,
152                        const char *file, int line);
153
154 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
155                            const struct lu_buf *buf, const char *name,
156                            int flags, struct thandle_exec_args *ta,
157                            struct thandle *th,
158                            struct object_update_reply *reply, int index,
159                            const char *file, int line);
160
161 int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
162                            const char *name, struct thandle_exec_args *ta,
163                            struct thandle *th,
164                            struct object_update_reply *reply, int index,
165                            const char *file, int line);
166
167 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
168                          struct thandle_exec_args *ta, struct thandle *th,
169                          struct object_update_reply *reply, int index,
170                          const char *file, int line);
171
172 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
173                          struct thandle_exec_args *ta, struct thandle *th,
174                          struct object_update_reply *reply, int index,
175                          const char *file, int line);
176
177 int out_index_insert_add_exec(const struct lu_env *env,
178                               struct dt_object *dt_obj,
179                               const struct dt_rec *rec,
180                               const struct dt_key *key,
181                               struct thandle_exec_args *ta,
182                               struct thandle *th,
183                               struct object_update_reply *reply,
184                               int index, const char *file, int line);
185
186 int out_index_delete_add_exec(const struct lu_env *env,
187                               struct dt_object *dt_obj,
188                               const struct dt_key *key,
189                               struct thandle_exec_args *ta,
190                               struct thandle *th,
191                               struct object_update_reply *reply,
192                               int index, const char *file, int line);
193
194 int out_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
195                          struct thandle_exec_args *ta, struct thandle *th,
196                          struct object_update_reply *reply,
197                          int index, const char *file, int line);
198
199 /* Update handlers */
200 int out_handle(struct tgt_session_info *tsi);
201
202 #define out_tx_create(env, obj, attr, fid, dof, ta, th, reply, idx) \
203         out_create_add_exec(env, obj, attr, fid, dof, ta, th, reply, idx, \
204                             __FILE__, __LINE__)
205
206 #define out_tx_attr_set(env, obj, attr, ta, th, reply, idx) \
207         out_attr_set_add_exec(env, obj, attr, ta, th, reply, idx, \
208                               __FILE__, __LINE__)
209
210 #define out_tx_xattr_set(env, obj, buf, name, fl, ta, th, reply, idx)   \
211         out_xattr_set_add_exec(env, obj, buf, name, fl, ta, th, reply, idx, \
212                                __FILE__, __LINE__)
213
214 #define out_tx_xattr_del(env, obj, name, ta, th, reply, idx)    \
215         out_xattr_del_add_exec(env, obj, name, ta, th, reply, idx,      \
216                                __FILE__, __LINE__)
217
218 #define out_tx_ref_add(env, obj, ta, th, reply, idx) \
219         out_ref_add_add_exec(env, obj, ta, th, reply, idx,      \
220                              __FILE__, __LINE__)
221
222 #define out_tx_ref_del(env, obj, ta, th, reply, idx) \
223         out_ref_del_add_exec(env, obj, ta, th, reply, idx,      \
224                              __FILE__, __LINE__)
225
226 #define out_tx_index_insert(env, obj, rec, key, ta, th, reply, idx) \
227         out_index_insert_add_exec(env, obj, rec, key, ta, th, reply, idx, \
228                                   __FILE__, __LINE__)
229
230 #define out_tx_index_delete(env, obj, key, ta, th, reply, idx) \
231         out_index_delete_add_exec(env, obj, key, ta, th, reply, idx, \
232                                   __FILE__, __LINE__)
233
234 #define out_tx_destroy(env, obj, ta, th, reply, idx) \
235         out_destroy_add_exec(env, obj, ta, th, reply, idx,      \
236                              __FILE__, __LINE__)
237
238 #define out_tx_write(env, obj, buf, pos, ta, th, reply, idx) \
239         out_write_add_exec(env, obj, buf, pos, ta, th, reply, idx,\
240                            __FILE__, __LINE__)
241
242 const char *update_op_str(__u16 opcode);
243
244 extern struct page *tgt_page_to_corrupt;
245
246 struct tgt_thread_big_cache {
247         struct niobuf_local     local[PTLRPC_MAX_BRW_PAGES];
248 };
249
250 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt);
251 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
252                      void *cookie);
253 int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th,
254                     void *cookie);
255 int tgt_handle_received_xid(struct obd_export *exp, __u64 rcvd_xid);
256 int tgt_handle_tag(struct obd_export *exp, __u16 tag);
257
258 void update_records_dump(const struct update_records *records,
259                          unsigned int mask, bool dump_updates);
260 int check_and_prepare_update_record(const struct lu_env *env,
261                                     struct thandle_update_records *tur);
262 struct update_thread_info {
263         struct lu_attr                  uti_attr;
264         struct lu_fid                   uti_fid;
265         struct lu_buf                   uti_buf;
266         struct thandle_update_records   uti_tur;
267         struct obdo                     uti_obdo;
268         struct thandle_exec_args        uti_tea;
269         struct dt_insert_rec            uti_rec;
270         struct distribute_txn_replay_req *uti_dtrq;
271 };
272
273 extern struct lu_context_key update_thread_key;
274
275 static inline struct update_thread_info *
276 update_env_info(const struct lu_env *env)
277 {
278         struct update_thread_info *uti;
279
280         uti = lu_context_key_get(&env->le_ctx, &update_thread_key);
281         LASSERT(uti != NULL);
282         return uti;
283 }
284
285 void update_info_init(void);
286 void update_info_fini(void);
287 struct sub_thandle *create_sub_thandle(struct top_multiple_thandle *tmt,
288                                        struct dt_device *dt_dev);
289 int sub_thandle_trans_create(const struct lu_env *env,
290                              struct top_thandle *top_th,
291                              struct sub_thandle *st);
292 void distribute_txn_insert_by_batchid(struct top_multiple_thandle *new);
293 int top_trans_create_tmt(const struct lu_env *env,
294                          struct top_thandle *top_th);
295 #endif /* _TG_INTERNAL_H */