Whamcloud - gitweb
LU-5517 lfsck: repair invalid nlink count
[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, 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 struct tx_arg;
52 typedef int (*tx_exec_func_t)(const struct lu_env *env, struct thandle *th,
53                               struct tx_arg *ta);
54
55 struct tx_arg {
56         tx_exec_func_t           exec_fn;
57         tx_exec_func_t           undo_fn;
58         struct dt_object        *object;
59         const char              *file;
60         struct object_update_reply *reply;
61         int                      line;
62         int                      index;
63         union {
64                 struct {
65                         struct dt_insert_rec     rec;
66                         const struct dt_key     *key;
67                 } insert;
68                 struct {
69                 } ref;
70                 struct {
71                         struct lu_attr   attr;
72                 } attr_set;
73                 struct {
74                         struct lu_buf    buf;
75                         const char      *name;
76                         int              flags;
77                         __u32            csum;
78                 } xattr_set;
79                 struct {
80                         struct lu_attr                  attr;
81                         struct dt_allocation_hint       hint;
82                         struct dt_object_format         dof;
83                         struct lu_fid                   fid;
84                 } create;
85                 struct {
86                         struct lu_buf   buf;
87                         loff_t          pos;
88                 } write;
89                 struct {
90                         struct ost_body     *body;
91                 } destroy;
92         } u;
93 };
94
95 struct thandle_exec_args {
96         struct thandle          *ta_handle;
97         int                     ta_argno;   /* used args */
98         int                     ta_alloc_args; /* allocated args count */
99         struct tx_arg           **ta_args;
100 };
101
102 /**
103  * Common data shared by tg-level handlers. This is allocated per-thread to
104  * reduce stack consumption.
105  */
106 struct tgt_thread_info {
107         /* server and client data buffers */
108         struct lr_server_data    tti_lsd;
109         struct lsd_client_data   tti_lcd;
110         struct lu_buf            tti_buf;
111         loff_t                   tti_off;
112
113         struct lu_attr           tti_attr;
114         struct lu_fid            tti_fid1;
115
116         /* transno storage during last_rcvd update */
117         __u64                    tti_transno;
118         __u32                    tti_has_trans:1,
119                                  tti_mult_trans:1;
120
121         /* Updates data for OUT target */
122         struct thandle_exec_args tti_tea;
123         union {
124                 struct {
125                         /* for tgt_readpage()      */
126                         struct lu_rdpg     tti_rdpg;
127                         /* for tgt_sendpage()      */
128                         struct l_wait_info tti_wait_info;
129                 } rdpg;
130                 struct {
131                         struct dt_object_format    tti_update_dof;
132                         struct object_update_reply *tti_update_reply;
133                         struct object_update       *tti_update;
134                         int                        tti_update_reply_index;
135                         struct obdo                tti_obdo;
136                         struct dt_object           *tti_dt_object;
137                 } update;
138         } tti_u;
139         struct lfsck_request tti_lr;
140         struct dt_insert_rec tti_rec;
141 };
142
143 extern struct lu_context_key tgt_thread_key;
144
145 static inline struct tgt_thread_info *tgt_th_info(const struct lu_env *env)
146 {
147         struct tgt_thread_info *tti;
148
149         tti = lu_context_key_get(&env->le_ctx, &tgt_thread_key);
150         LASSERT(tti);
151         return tti;
152 }
153
154 #define MGS_SERVICE_WATCHDOG_FACTOR      (2)
155
156 int tgt_request_handle(struct ptlrpc_request *req);
157
158 /* check if request's xid is equal to last one or not*/
159 static inline int req_xid_is_last(struct ptlrpc_request *req)
160 {
161         struct lsd_client_data *lcd = req->rq_export->exp_target_data.ted_lcd;
162
163         LASSERT(lcd != NULL);
164         return (req->rq_xid == lcd->lcd_last_xid ||
165                 req->rq_xid == lcd->lcd_last_close_xid);
166 }
167
168 static inline char *dt_obd_name(struct dt_device *dt)
169 {
170         return dt->dd_lu_dev.ld_obd->obd_name;
171 }
172
173 /* Update handlers */
174 int out_handle(struct tgt_session_info *tsi);
175
176 #define out_tx_create(info, obj, attr, fid, dof, th, reply, idx) \
177         __out_tx_create(info, obj, attr, fid, dof, th, reply, idx, \
178                         __FILE__, __LINE__)
179
180 #define out_tx_attr_set(info, obj, attr, th, reply, idx) \
181         __out_tx_attr_set(info, obj, attr, th, reply, idx, \
182                           __FILE__, __LINE__)
183
184 #define out_tx_xattr_set(info, obj, buf, name, fl, th, reply, idx)      \
185         __out_tx_xattr_set(info, obj, buf, name, fl, th, reply, idx,    \
186                            __FILE__, __LINE__)
187
188 #define out_tx_xattr_del(info, obj, name, th, reply, idx)       \
189         __out_tx_xattr_del(info, obj, name, th, reply, idx,     \
190                            __FILE__, __LINE__)
191
192 #define out_tx_ref_add(info, obj, th, reply, idx) \
193         __out_tx_ref_add(info, obj, th, reply, idx, __FILE__, __LINE__)
194
195 #define out_tx_ref_del(info, obj, th, reply, idx) \
196         __out_tx_ref_del(info, obj, th, reply, idx, __FILE__, __LINE__)
197
198 #define out_tx_index_insert(info, obj, rec, key, th, reply, idx) \
199         __out_tx_index_insert(info, obj, rec, key, th, reply, idx, \
200                               __FILE__, __LINE__)
201
202 #define out_tx_index_delete(info, obj, key, th, reply, idx) \
203         __out_tx_index_delete(info, obj, key, th, reply, idx, \
204                               __FILE__, __LINE__)
205
206 #define out_tx_destroy(info, obj, th, reply, idx) \
207         __out_tx_destroy(info, obj, th, reply, idx, __FILE__, __LINE__)
208
209 #define out_tx_write(info, obj, buf, pos, th, reply, idx) \
210         __out_tx_write(info, obj, buf, pos, th, reply, idx, __FILE__, __LINE__)
211
212 extern struct page *tgt_page_to_corrupt;
213
214 struct tgt_thread_big_cache {
215         struct niobuf_local     local[PTLRPC_MAX_BRW_PAGES];
216 };
217
218 int tgt_server_data_init(const struct lu_env *env, struct lu_target *tgt);
219 int tgt_txn_start_cb(const struct lu_env *env, struct thandle *th,
220                      void *cookie);
221 int tgt_txn_stop_cb(const struct lu_env *env, struct thandle *th,
222                     void *cookie);
223
224 #endif /* _TG_INTERNAL_H */