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