Whamcloud - gitweb
LU-13004 ptlrpc: Allow BULK_BUF_KIOV to accept a kvec
[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, 2017, 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 <lu_target.h>
39 #include <lustre_export.h>
40 #include <lustre_fid.h>
41 #include <lustre_fld.h>
42 #include <lustre_req_layout.h>
43 #include <lustre_sec.h>
44
45 extern int (*tgt_lfsck_in_notify_local)(const struct lu_env *env,
46                                         struct dt_device *key,
47                                         struct lfsck_req_local *lrl,
48                                         struct thandle *th);
49 /**
50  * Common data shared by tg-level handlers. This is allocated per-thread to
51  * reduce stack consumption.
52  */
53 struct tgt_thread_info {
54         /* server and client data buffers */
55         struct lr_server_data    tti_lsd;
56         struct lsd_client_data   tti_lcd;
57         struct lsd_reply_data    tti_lrd;
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                 } rdpg;
76                 struct {
77                         struct dt_object_format    tti_update_dof;
78                         struct object_update_reply *tti_update_reply;
79                         struct object_update       *tti_update;
80                         int                        tti_update_reply_index;
81                         struct obdo                tti_obdo;
82                         struct dt_object           *tti_dt_object;
83                 } update;
84                 struct obd_statfs osfs; /* for obd_statfs() in OFD/MDT */
85         } tti_u;
86         struct lfsck_req_local tti_lrl;
87         struct dt_insert_rec tti_rec;
88 };
89
90 extern struct lu_context_key tgt_thread_key;
91
92 static inline struct tgt_thread_info *tgt_th_info(const struct lu_env *env)
93 {
94         struct tgt_thread_info *tti;
95
96         tti = lu_context_key_get(&env->le_ctx, &tgt_thread_key);
97         LASSERT(tti);
98         return tti;
99 }
100
101 #define MGS_SERVICE_WATCHDOG_FACTOR      (2)
102
103 int tgt_request_handle(struct ptlrpc_request *req);
104
105 /* check if request's xid is equal to last one or not*/
106 static inline int req_xid_is_last(struct ptlrpc_request *req)
107 {
108         struct lsd_client_data *lcd = req->rq_export->exp_target_data.ted_lcd;
109
110         LASSERT(lcd != NULL);
111         return (req->rq_xid == lcd->lcd_last_xid ||
112                 req->rq_xid == lcd->lcd_last_close_xid);
113 }
114
115 static inline char *dt_obd_name(struct dt_device *dt)
116 {
117         return dt->dd_lu_dev.ld_obd->obd_name;
118 }
119
120 /* out_lib.c */
121 int out_tx_create_exec(const struct lu_env *env, struct thandle *th,
122                        struct tx_arg *arg);
123 struct tx_arg *tx_add_exec(struct thandle_exec_args *ta,
124                            tx_exec_func_t func, tx_exec_func_t undo,
125                            const char *file, int line);
126
127 int out_create_add_exec(const struct lu_env *env, struct dt_object *obj,
128                         struct lu_attr *attr, struct lu_fid *parent_fid,
129                         struct dt_object_format *dof,
130                         struct thandle_exec_args *ta, struct thandle *th,
131                         struct object_update_reply *reply,
132                         int index, const char *file, int line);
133
134 int out_attr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
135                           const struct lu_attr *attr,
136                           struct thandle_exec_args *ta, struct thandle *th,
137                           struct object_update_reply *reply, int index,
138                           const char *file, int line);
139
140 int out_write_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
141                        const struct lu_buf *buf, loff_t pos,
142                        struct thandle_exec_args *ta, struct thandle *th,
143                        struct object_update_reply *reply, int index,
144                        const char *file, int line);
145
146 int out_xattr_set_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
147                            const struct lu_buf *buf, const char *name,
148                            int flags, struct thandle_exec_args *ta,
149                            struct thandle *th,
150                            struct object_update_reply *reply, int index,
151                            const char *file, int line);
152
153 int out_xattr_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
154                            const char *name, struct thandle_exec_args *ta,
155                            struct thandle *th,
156                            struct object_update_reply *reply, int index,
157                            const char *file, int line);
158
159 int out_ref_add_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
160                          struct thandle_exec_args *ta, struct thandle *th,
161                          struct object_update_reply *reply, int index,
162                          const char *file, int line);
163
164 int out_ref_del_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
165                          struct thandle_exec_args *ta, struct thandle *th,
166                          struct object_update_reply *reply, int index,
167                          const char *file, int line);
168
169 int out_index_insert_add_exec(const struct lu_env *env,
170                               struct dt_object *dt_obj,
171                               const struct dt_rec *rec,
172                               const struct dt_key *key,
173                               struct thandle_exec_args *ta,
174                               struct thandle *th,
175                               struct object_update_reply *reply,
176                               int index, const char *file, int line);
177
178 int out_index_delete_add_exec(const struct lu_env *env,
179                               struct dt_object *dt_obj,
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_destroy_add_exec(const struct lu_env *env, struct dt_object *dt_obj,
187                          struct thandle_exec_args *ta, struct thandle *th,
188                          struct object_update_reply *reply,
189                          int index, const char *file, int line);
190
191 /* Update handlers */
192 int out_handle(struct tgt_session_info *tsi);
193
194 #define out_tx_create(env, obj, attr, fid, dof, ta, th, reply, idx) \
195         out_create_add_exec(env, obj, attr, fid, dof, ta, th, reply, idx, \
196                             __FILE__, __LINE__)
197
198 #define out_tx_attr_set(env, obj, attr, ta, th, reply, idx) \
199         out_attr_set_add_exec(env, obj, attr, ta, th, reply, idx, \
200                               __FILE__, __LINE__)
201
202 #define out_tx_xattr_set(env, obj, buf, name, fl, ta, th, reply, idx)   \
203         out_xattr_set_add_exec(env, obj, buf, name, fl, ta, th, reply, idx, \
204                                __FILE__, __LINE__)
205
206 #define out_tx_xattr_del(env, obj, name, ta, th, reply, idx)    \
207         out_xattr_del_add_exec(env, obj, name, ta, th, reply, idx,      \
208                                __FILE__, __LINE__)
209
210 #define out_tx_ref_add(env, obj, ta, th, reply, idx) \
211         out_ref_add_add_exec(env, obj, ta, th, reply, idx,      \
212                              __FILE__, __LINE__)
213
214 #define out_tx_ref_del(env, obj, ta, th, reply, idx) \
215         out_ref_del_add_exec(env, obj, ta, th, reply, idx,      \
216                              __FILE__, __LINE__)
217
218 #define out_tx_index_insert(env, obj, rec, key, ta, th, reply, idx) \
219         out_index_insert_add_exec(env, obj, rec, key, ta, th, reply, idx, \
220                                   __FILE__, __LINE__)
221
222 #define out_tx_index_delete(env, obj, key, ta, th, reply, idx) \
223         out_index_delete_add_exec(env, obj, key, ta, th, reply, idx, \
224                                   __FILE__, __LINE__)
225
226 #define out_tx_destroy(env, obj, ta, th, reply, idx) \
227         out_destroy_add_exec(env, obj, ta, th, reply, idx,      \
228                              __FILE__, __LINE__)
229
230 #define out_tx_write(env, obj, buf, pos, ta, th, reply, idx) \
231         out_write_add_exec(env, obj, buf, pos, ta, th, reply, idx,\
232                            __FILE__, __LINE__)
233
234 const char *update_op_str(__u16 opcode);
235
236 extern struct page *tgt_page_to_corrupt;
237
238 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt);
239 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
240                      void *cookie);
241 int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th,
242                     void *cookie);
243 int tgt_handle_received_xid(struct obd_export *exp, __u64 rcvd_xid);
244 int tgt_handle_tag(struct ptlrpc_request *req);
245
246 void update_records_dump(const struct update_records *records,
247                          unsigned int mask, bool dump_updates);
248 int check_and_prepare_update_record(const struct lu_env *env,
249                                     struct thandle_update_records *tur);
250 struct update_thread_info {
251         struct lu_attr                  uti_attr;
252         struct lu_fid                   uti_fid;
253         struct lu_buf                   uti_buf;
254         struct thandle_update_records   uti_tur;
255         struct obdo                     uti_obdo;
256         struct thandle_exec_args        uti_tea;
257         struct dt_insert_rec            uti_rec;
258         struct distribute_txn_replay_req *uti_dtrq;
259 };
260
261 extern struct lu_context_key update_thread_key;
262
263 static inline struct update_thread_info *
264 update_env_info(const struct lu_env *env)
265 {
266         struct update_thread_info *uti;
267
268         uti = lu_context_key_get(&env->le_ctx, &update_thread_key);
269         LASSERT(uti != NULL);
270         return uti;
271 }
272
273 void update_info_init(void);
274 void update_info_fini(void);
275 struct sub_thandle *create_sub_thandle(struct top_multiple_thandle *tmt,
276                                        struct dt_device *dt_dev);
277 int sub_thandle_trans_create(const struct lu_env *env,
278                              struct top_thandle *top_th,
279                              struct sub_thandle *st);
280 void distribute_txn_insert_by_batchid(struct top_multiple_thandle *new);
281 int top_trans_create_tmt(const struct lu_env *env,
282                          struct top_thandle *top_th);
283
284 void tgt_cancel_slc_locks(struct lu_target *tgt, __u64 transno);
285 void barrier_init(void);
286 void barrier_fini(void);
287
288 /* FMD tracking data */
289 struct tgt_fmd_data {
290         struct list_head fmd_list;        /* linked to tgt_fmd_list */
291         struct lu_fid    fmd_fid;         /* FID being written to */
292         __u64            fmd_mactime_xid; /* xid highest {m,a,c}time setattr */
293         time64_t         fmd_expire;      /* time when the fmd should expire */
294         int              fmd_refcount;    /* reference counter - list holds 1 */
295 };
296
297 /* tgt_fmd.c */
298 extern struct kmem_cache *tgt_fmd_kmem;
299 void tgt_fmd_expire(struct obd_export *exp);
300 void tgt_fmd_cleanup(struct obd_export *exp);
301
302 #endif /* _TG_INTERNAL_H */