Whamcloud - gitweb
fabea5267754aa751d2f84caccc58db37879558b
[fs/lustre-release.git] / lustre / include / lustre_export.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, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 /** \defgroup obd_export PortalRPC export definitions
37  *
38  * @{
39  */
40
41 #ifndef __EXPORT_H
42 #define __EXPORT_H
43
44 /** \defgroup export export
45  *
46  * @{
47  */
48
49 #include <lprocfs_status.h>
50 #include <lustre/lustre_idl.h>
51 #include <lustre_dlm.h>
52
53 struct mds_client_data;
54 struct mdt_client_data;
55 struct mds_idmap_table;
56 struct mdt_idmap_table;
57
58 /**
59  * Target-specific export data
60  */
61 struct tg_export_data {
62         /** Protects led_lcd below */
63         struct mutex            ted_lcd_lock;
64         /** Per-client data for each export */
65         struct lsd_client_data  *ted_lcd;
66         /** Offset of record in last_rcvd file */
67         loff_t                  ted_lr_off;
68         /** Client index in last_rcvd file */
69         int                     ted_lr_idx;
70 };
71
72 /**
73  * MDT-specific export data
74  */
75 struct mdt_export_data {
76         struct tg_export_data   med_ted;
77         /** List of all files opened by client on this MDT */
78         cfs_list_t              med_open_head;
79         spinlock_t              med_open_lock; /* med_open_head, mfd_list */
80         /** Bitmask of all ibit locks this MDT understands */
81         __u64                   med_ibits_known;
82         struct mutex            med_idmap_mutex;
83         struct lustre_idmap_table *med_idmap;
84 };
85
86 struct ec_export_data { /* echo client */
87         cfs_list_t eced_locks;
88 };
89
90 /* In-memory access to client data from OST struct */
91 /** Filter (oss-side) specific import data */
92 struct filter_export_data {
93         struct tg_export_data   fed_ted;
94         spinlock_t              fed_lock;       /**< protects fed_mod_list */
95         long                       fed_dirty;    /* in bytes */
96         long                       fed_grant;    /* in bytes */
97         cfs_list_t                 fed_mod_list; /* files being modified */
98         int                        fed_mod_count;/* items in fed_writing list */
99         long                       fed_pending;  /* bytes just being written */
100         __u32                      fed_group;
101         __u8                       fed_pagesize; /* log2 of client page size */
102 };
103
104 struct mgs_export_data {
105         cfs_list_t              med_clients;    /* mgc fs client via this exp */
106         spinlock_t              med_lock;       /* protect med_clients */
107 };
108
109 /**
110  * per-NID statistics structure.
111  * It tracks access patterns to this export on a per-client-NID basis
112  */
113 struct nid_stat {
114         lnet_nid_t               nid;
115         cfs_hlist_node_t         nid_hash;
116         cfs_list_t               nid_list;
117         struct obd_device       *nid_obd;
118         struct proc_dir_entry   *nid_proc;
119         struct lprocfs_stats    *nid_stats;
120         struct lprocfs_stats    *nid_ldlm_stats;
121         cfs_atomic_t             nid_exp_ref_count; /* for obd_nid_stats_hash
122                                                            exp_nid_stats */
123 };
124
125 #define nidstat_getref(nidstat)                                                \
126 do {                                                                           \
127         cfs_atomic_inc(&(nidstat)->nid_exp_ref_count);                         \
128 } while(0)
129
130 #define nidstat_putref(nidstat)                                                \
131 do {                                                                           \
132         cfs_atomic_dec(&(nidstat)->nid_exp_ref_count);                         \
133         LASSERTF(cfs_atomic_read(&(nidstat)->nid_exp_ref_count) >= 0,          \
134                  "stat %p nid_exp_ref_count < 0\n", nidstat);                  \
135 } while(0)
136
137 enum obd_option {
138         OBD_OPT_FORCE =         0x0001,
139         OBD_OPT_FAILOVER =      0x0002,
140         OBD_OPT_ABORT_RECOV =   0x0004,
141 };
142
143 /**
144  * Export structure. Represents target-side of connection in portals.
145  * Also used in Lustre to connect between layers on the same node when
146  * there is no network-connection in-between.
147  * For every connected client there is an export structure on the server
148  * attached to the same obd device.
149  */
150 struct obd_export {
151         /**
152          * Export handle, it's id is provided to client on connect
153          * Subsequent client RPCs contain this handle id to identify
154          * what export they are talking to.
155          */
156         struct portals_handle     exp_handle;
157         cfs_atomic_t              exp_refcount;
158         /**
159          * Set of counters below is to track where export references are
160          * kept. The exp_rpc_count is used for reconnect handling also,
161          * the cb_count and locks_count are for debug purposes only for now.
162          * The sum of them should be less than exp_refcount by 3
163          */
164         cfs_atomic_t              exp_rpc_count; /* RPC references */
165         cfs_atomic_t              exp_cb_count; /* Commit callback references */
166         /** Number of queued replay requests to be processes */
167         cfs_atomic_t              exp_replay_count;
168         cfs_atomic_t              exp_locks_count; /** Lock references */
169 #if LUSTRE_TRACKS_LOCK_EXP_REFS
170         cfs_list_t                exp_locks_list;
171         spinlock_t                exp_locks_list_guard;
172 #endif
173         /** UUID of client connected to this export */
174         struct obd_uuid           exp_client_uuid;
175         /** To link all exports on an obd device */
176         cfs_list_t                exp_obd_chain;
177         cfs_hlist_node_t          exp_uuid_hash; /** uuid-export hash*/
178         cfs_hlist_node_t          exp_nid_hash; /** nid-export hash */
179         /**
180          * All exports eligible for ping evictor are linked into a list
181          * through this field in "most time since last request on this export"
182          * order
183          * protected by obd_dev_lock
184          */
185         cfs_list_t                exp_obd_chain_timed;
186         /** Obd device of this export */
187         struct obd_device        *exp_obd;
188         /**
189          * "reverse" import to send requests (e.g. from ldlm) back to client
190          * exp_lock protect its change
191          */
192         struct obd_import        *exp_imp_reverse;
193         struct nid_stat          *exp_nid_stats;
194         /** Active connetion */
195         struct ptlrpc_connection *exp_connection;
196         /** Connection count value from last succesful reconnect rpc */
197         __u32                     exp_conn_cnt;
198         /** Hash list of all ldlm locks granted on this export */
199         cfs_hash_t               *exp_lock_hash;
200         /**
201          * Hash list for Posix lock deadlock detection, added with
202          * ldlm_lock::l_exp_flock_hash.
203          */
204         cfs_hash_t               *exp_flock_hash;
205         cfs_list_t                exp_outstanding_replies;
206         cfs_list_t                exp_uncommitted_replies;
207         spinlock_t                exp_uncommitted_replies_lock;
208         /** Last committed transno for this export */
209         __u64                     exp_last_committed;
210         /** When was last request received */
211         cfs_time_t                exp_last_request_time;
212         /** On replay all requests waiting for replay are linked here */
213         cfs_list_t                exp_req_replay_queue;
214         /**
215          * protects exp_flags, exp_outstanding_replies and the change
216          * of exp_imp_reverse
217          */
218         spinlock_t                exp_lock;
219         /** Compatibility flags for this export are embedded into
220          *  exp_connect_data */
221         struct obd_connect_data   exp_connect_data;
222         enum obd_option           exp_flags;
223         unsigned long             exp_failed:1,
224                                   exp_in_recovery:1,
225                                   exp_disconnected:1,
226                                   exp_connecting:1,
227                                   /** VBR: export missed recovery */
228                                   exp_delayed:1,
229                                   /** VBR: failed version checking */
230                                   exp_vbr_failed:1,
231                                   exp_req_replay_needed:1,
232                                   exp_lock_replay_needed:1,
233                                   exp_need_sync:1,
234                                   exp_flvr_changed:1,
235                                   exp_flvr_adapt:1,
236                                   exp_libclient:1, /* liblustre client? */
237                                   /* client timed out and tried to reconnect,
238                                    * but couldn't because of active rpcs */
239                                   exp_abort_active_req:1,
240                                   /* if to swap nidtbl entries for 2.2 clients.
241                                    * Only used by the MGS to fix LU-1644. */
242                                   exp_need_mne_swab:1;
243         /* also protected by exp_lock */
244         enum lustre_sec_part      exp_sp_peer;
245         struct sptlrpc_flavor     exp_flvr;             /* current */
246         struct sptlrpc_flavor     exp_flvr_old[2];      /* about-to-expire */
247         cfs_time_t                exp_flvr_expire[2];   /* seconds */
248
249         /** protects exp_hp_rpcs */
250         spinlock_t                exp_rpc_lock;
251         cfs_list_t                exp_hp_rpcs;  /* (potential) HP RPCs */
252
253         /** blocking dlm lock list, protected by exp_bl_list_lock */
254         cfs_list_t                exp_bl_list;
255         spinlock_t                exp_bl_list_lock;
256
257         /** Target specific data */
258         union {
259                 struct tg_export_data     eu_target_data;
260                 struct mdt_export_data    eu_mdt_data;
261                 struct filter_export_data eu_filter_data;
262                 struct ec_export_data     eu_ec_data;
263                 struct mgs_export_data    eu_mgs_data;
264         } u;
265 };
266
267 #define exp_target_data u.eu_target_data
268 #define exp_mdt_data    u.eu_mdt_data
269 #define exp_filter_data u.eu_filter_data
270 #define exp_ec_data     u.eu_ec_data
271
272 static inline __u64 *exp_connect_flags_ptr(struct obd_export *exp)
273 {
274         return &exp->exp_connect_data.ocd_connect_flags;
275 }
276
277 static inline __u64 exp_connect_flags(struct obd_export *exp)
278 {
279         return *exp_connect_flags_ptr(exp);
280 }
281
282 static inline int exp_max_brw_size(struct obd_export *exp)
283 {
284         LASSERT(exp != NULL);
285         if (exp_connect_flags(exp) & OBD_CONNECT_BRW_SIZE)
286                 return exp->exp_connect_data.ocd_brw_size;
287
288         return ONE_MB_BRW_SIZE;
289 }
290
291 static inline int exp_connect_multibulk(struct obd_export *exp)
292 {
293         return exp_max_brw_size(exp) > ONE_MB_BRW_SIZE;
294 }
295
296 static inline int exp_expired(struct obd_export *exp, cfs_duration_t age)
297 {
298         LASSERT(exp->exp_delayed);
299         return cfs_time_before(cfs_time_add(exp->exp_last_request_time, age),
300                                cfs_time_current_sec());
301 }
302
303 static inline int exp_connect_cancelset(struct obd_export *exp)
304 {
305         LASSERT(exp != NULL);
306         return !!(exp_connect_flags(exp) & OBD_CONNECT_CANCELSET);
307 }
308
309 static inline int exp_connect_lru_resize(struct obd_export *exp)
310 {
311         LASSERT(exp != NULL);
312         return !!(exp_connect_flags(exp) & OBD_CONNECT_LRU_RESIZE);
313 }
314
315 static inline int exp_connect_rmtclient(struct obd_export *exp)
316 {
317         LASSERT(exp != NULL);
318         return !!(exp_connect_flags(exp) & OBD_CONNECT_RMT_CLIENT);
319 }
320
321 static inline int client_is_remote(struct obd_export *exp)
322 {
323         struct obd_import *imp = class_exp2cliimp(exp);
324
325         return !!(imp->imp_connect_data.ocd_connect_flags &
326                   OBD_CONNECT_RMT_CLIENT);
327 }
328
329 static inline int exp_connect_vbr(struct obd_export *exp)
330 {
331         LASSERT(exp != NULL);
332         LASSERT(exp->exp_connection);
333         return !!(exp_connect_flags(exp) & OBD_CONNECT_VBR);
334 }
335
336 static inline int exp_connect_som(struct obd_export *exp)
337 {
338         LASSERT(exp != NULL);
339         return !!(exp_connect_flags(exp) & OBD_CONNECT_SOM);
340 }
341
342 static inline int exp_connect_umask(struct obd_export *exp)
343 {
344         return !!(exp_connect_flags(exp) & OBD_CONNECT_UMASK);
345 }
346
347 static inline int imp_connect_lru_resize(struct obd_import *imp)
348 {
349         struct obd_connect_data *ocd;
350
351         LASSERT(imp != NULL);
352         ocd = &imp->imp_connect_data;
353         return !!(ocd->ocd_connect_flags & OBD_CONNECT_LRU_RESIZE);
354 }
355
356 static inline int exp_connect_layout(struct obd_export *exp)
357 {
358         return !!(exp_connect_flags(exp) & OBD_CONNECT_LAYOUTLOCK);
359 }
360
361 static inline bool exp_connect_lvb_type(struct obd_export *exp)
362 {
363         LASSERT(exp != NULL);
364         if (exp_connect_flags(exp) & OBD_CONNECT_LVB_TYPE)
365                 return true;
366         else
367                 return false;
368 }
369
370 static inline bool imp_connect_lvb_type(struct obd_import *imp)
371 {
372         struct obd_connect_data *ocd;
373
374         LASSERT(imp != NULL);
375         ocd = &imp->imp_connect_data;
376         if (ocd->ocd_connect_flags & OBD_CONNECT_LVB_TYPE)
377                 return true;
378         else
379                 return false;
380 }
381
382 extern struct obd_export *class_conn2export(struct lustre_handle *conn);
383 extern struct obd_device *class_conn2obd(struct lustre_handle *conn);
384
385 /** @} export */
386
387 #endif /* __EXPORT_H */
388 /** @} obd_export */