Whamcloud - gitweb
LU-13274 uapi: make lnet UAPI headers C99 compliant
[fs/lustre-release.git] / lustre / include / lustre_import.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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 /** \defgroup obd_import PtlRPC import definitions
33  * Imports are client-side representation of remote obd target.
34  *
35  * @{
36  */
37
38 #ifndef __IMPORT_H
39 #define __IMPORT_H
40
41 /** \defgroup export export
42  *
43  * @{
44  */
45 #include <linux/atomic.h>
46 #include <linux/list.h>
47 #include <linux/mutex.h>
48 #include <linux/refcount.h>
49 #include <linux/spinlock.h>
50 #include <linux/time.h>
51 #include <linux/types.h>
52 #include <linux/workqueue.h>
53 #include <libcfs/libcfs.h>
54 #include <uapi/linux/lustre/lustre_idl.h>
55
56 /**
57  * Adaptive Timeout stuff
58  *
59  * @{
60  */
61 #define D_ADAPTTO D_OTHER
62 #define AT_BINS 4                  /* "bin" means "N seconds of history" */
63 #define AT_FLG_NOHIST 0x1          /* use last reported value only */
64
65 struct adaptive_timeout {
66         time64_t        at_binstart;         /* bin start time */
67         unsigned int    at_hist[AT_BINS];    /* timeout history bins */
68         unsigned int    at_flags;
69         unsigned int    at_current;          /* current timeout value */
70         unsigned int    at_worst_ever;       /* worst-ever timeout value */
71         time64_t        at_worst_time;       /* worst-ever timeout timestamp */
72         spinlock_t      at_lock;
73 };
74
75 enum lustre_at_flags {
76         LATF_SKIP       = 0x0,
77         LATF_STATS      = 0x1,
78 };
79
80 struct ptlrpc_at_array {
81         struct list_head *paa_reqs_array; /** array to hold requests */
82         __u32             paa_size;       /** the size of array */
83         __u32             paa_count;      /** the total count of reqs */
84         time64_t          paa_deadline;   /** the earliest deadline of reqs */
85         __u32            *paa_reqs_count; /** the count of reqs in each entry */
86 };
87
88 #define IMP_AT_MAX_PORTALS 8
89 struct imp_at {
90         int                     iat_portal[IMP_AT_MAX_PORTALS];
91         struct adaptive_timeout iat_net_latency;
92         struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
93 };
94
95
96 /** @} */
97
98 /** Possible import states */
99 enum lustre_imp_state {
100         LUSTRE_IMP_CLOSED     = 1,
101         LUSTRE_IMP_NEW        = 2,
102         LUSTRE_IMP_DISCON     = 3,
103         LUSTRE_IMP_CONNECTING = 4,
104         LUSTRE_IMP_REPLAY     = 5,
105         LUSTRE_IMP_REPLAY_LOCKS = 6,
106         LUSTRE_IMP_REPLAY_WAIT  = 7,
107         LUSTRE_IMP_RECOVER    = 8,
108         LUSTRE_IMP_FULL       = 9,
109         LUSTRE_IMP_EVICTED    = 10,
110         LUSTRE_IMP_IDLE       = 11,
111         LUSTRE_IMP_LAST
112 };
113
114 /** Returns test string representation of numeric import state \a state */
115 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
116 {
117         static char *import_state_names[] = {
118                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
119                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
120                 "RECOVER", "FULL", "EVICTED", "IDLE",
121         };
122
123         LASSERT(state < LUSTRE_IMP_LAST);
124         return import_state_names[state];
125 }
126
127 /**
128  * List of import event types
129  */
130 enum obd_import_event {
131         IMP_EVENT_DISCON     = 0x808001,
132         IMP_EVENT_INACTIVE   = 0x808002,
133         IMP_EVENT_INVALIDATE = 0x808003,
134         IMP_EVENT_ACTIVE     = 0x808004,
135         IMP_EVENT_OCD        = 0x808005,
136         IMP_EVENT_DEACTIVATE = 0x808006,
137         IMP_EVENT_ACTIVATE   = 0x808007,
138 };
139
140 /**
141  * Definition of import connection structure
142  */
143 struct obd_import_conn {
144         /** Item for linking connections together */
145         struct list_head          oic_item;
146         /** Pointer to actual PortalRPC connection */
147         struct ptlrpc_connection *oic_conn;
148         /** uuid of remote side */
149         struct obd_uuid           oic_uuid;
150         /**
151          * Time (64 bit seconds) of last connection attempt on this connection
152          */
153         time64_t                  oic_last_attempt;
154 };
155
156 /* state history */
157 #define IMP_STATE_HIST_LEN 16
158 struct import_state_hist {
159         enum lustre_imp_state   ish_state;
160         time64_t                ish_time;
161 };
162
163 /**
164  * Defintion of PortalRPC import structure.
165  * Imports are representing client-side view to remote target.
166  */
167 struct obd_import {
168         /** Reference counter */
169         refcount_t                imp_refcount;
170         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
171         /** Currently active connection */
172         struct ptlrpc_connection *imp_connection;
173         /** PortalRPC client structure for this import */
174         struct ptlrpc_client     *imp_client;
175         /** List element for linking into pinger chain */
176         struct list_head          imp_pinger_chain;
177         /** work struct for destruction of import */
178         struct work_struct        imp_zombie_work;
179
180         /**
181          * Lists of requests that are retained for replay, waiting for a reply,
182          * or waiting for recovery to complete, respectively.
183          * @{
184          */
185         struct list_head        imp_replay_list;
186         struct list_head        imp_sending_list;
187         struct list_head        imp_delayed_list;
188         /** @} */
189
190         /**
191          * List of requests that are retained for committed open replay. Once
192          * open is committed, open replay request will be moved from the
193          * imp_replay_list into the imp_committed_list.
194          * The imp_replay_cursor is for accelerating searching during replay.
195          * @{
196          */
197         struct list_head        imp_committed_list;
198         struct list_head        *imp_replay_cursor;
199         /** @} */
200
201         /** List of not replied requests */
202         struct list_head        imp_unreplied_list;
203         /** Known maximal replied XID */
204         __u64                   imp_known_replied_xid;
205
206         /** obd device for this import */
207         struct obd_device       *imp_obd;
208
209         /**
210          * some seciruty-related fields
211          * @{
212          */
213         struct ptlrpc_sec        *imp_sec;
214         rwlock_t                  imp_sec_lock;
215         time64_t                imp_sec_expire;
216         pid_t                     imp_sec_refpid;
217         /** @} */
218
219         /** Wait queue for those who need to wait for recovery completion */
220         wait_queue_head_t         imp_recovery_waitq;
221
222         /** Number of requests currently in-flight */
223         atomic_t                  imp_inflight;
224         /** Number of requests currently unregistering */
225         atomic_t                  imp_unregistering;
226         /** Number of replay requests inflight */
227         atomic_t                  imp_replay_inflight;
228         /** Number of currently happening import invalidations */
229         atomic_t                  imp_inval_count;
230         /** Numbner of request timeouts */
231         atomic_t                  imp_timeouts;
232         /** Current import state */
233         enum lustre_imp_state     imp_state;
234         /** Last replay state */
235         enum lustre_imp_state     imp_replay_state;
236         /** History of import states */
237         struct import_state_hist  imp_state_hist[IMP_STATE_HIST_LEN];
238         int                       imp_state_hist_idx;
239         /** Current import generation. Incremented on every reconnect */
240         int                       imp_generation;
241         /** Idle connection initiated at this generation */
242         int                       imp_initiated_at;
243         /** Incremented every time we send reconnection request */
244         __u32                     imp_conn_cnt;
245        /** 
246         * \see ptlrpc_free_committed remembers imp_generation value here
247         * after a check to save on unnecessary replay list iterations
248         */
249         int                       imp_last_generation_checked;
250         /** Last tranno we replayed */
251         __u64                     imp_last_replay_transno;
252         /** Last transno committed on remote side */
253         __u64                     imp_peer_committed_transno;
254         /**
255          * \see ptlrpc_free_committed remembers last_transno since its last
256          * check here and if last_transno did not change since last run of
257          * ptlrpc_free_committed and import generation is the same, we can
258          * skip looking for requests to remove from replay list as optimisation
259          */
260         __u64                     imp_last_transno_checked;
261         /**
262          * Remote export handle. This is how remote side knows what export
263          * we are talking to. Filled from response to connect request
264          */
265         struct lustre_handle      imp_remote_handle;
266         /** When to perform next ping. time in jiffies. */
267         time64_t                imp_next_ping;
268         /** When we last successfully connected. time in 64bit jiffies */
269         time64_t                imp_last_success_conn;
270
271         /** List of all possible connection for import. */
272         struct list_head        imp_conn_list;
273         /**
274          * Current connection. \a imp_connection is imp_conn_current->oic_conn
275          */
276         struct obd_import_conn   *imp_conn_current;
277
278         /** Protects flags, level, generation, conn_cnt, *_list */
279         spinlock_t                imp_lock;
280
281         /* flags */
282         unsigned long             imp_invalid:1,    /* evicted */
283                                   /* administratively disabled */
284                                   imp_deactive:1,
285                                   /* try to recover the import */
286                                   imp_replayable:1,
287                                   /* don't run recovery (timeout instead) */
288                                   imp_dlm_fake:1,
289                                   /* use 1/2 timeout on MDS' OSCs */
290                                   imp_server_timeout:1,
291                                   /* VBR: imp in delayed recovery */
292                                   imp_delayed_recovery:1,
293                                   /* recovery by versions was failed */
294                                   imp_vbr_failed:1,
295                                   /* force an immidiate ping */
296                                   imp_force_verify:1,
297                                   /* force a scheduled ping */
298                                   imp_force_next_verify:1,
299                                   /* pingable */
300                                   imp_pingable:1,
301                                   /* resend for replay */
302                                   imp_resend_replay:1,
303                                   /* disable normal recovery, for test only. */
304                                   imp_no_pinger_recover:1,
305                                   /* import must be reconnected instead of
306                                    * chouse new connection */
307                                   imp_force_reconnect:1,
308                                   /* import has tried to connect with server */
309                                   imp_connect_tried:1,
310                                   /* connected but not FULL yet */
311                                   imp_connected:1,
312                                   /* grant shrink disabled */
313                                   imp_grant_shrink_disabled:1,
314                                   /* to supress LCONSOLE() at conn.restore */
315                                   imp_was_idle:1;
316         u32                       imp_connect_op;
317         u32                       imp_idle_timeout;
318         u32                       imp_idle_debug;
319         struct obd_connect_data   imp_connect_data;
320         __u64                     imp_connect_flags_orig;
321         __u64                     imp_connect_flags2_orig;
322         int                       imp_connect_error;
323
324         enum lustre_msg_magic   imp_msg_magic;
325                                 /* adjusted based on server capability */
326         enum lustre_msghdr      imp_msghdr_flags;
327
328                                 /* adaptive timeout data */
329         struct imp_at           imp_at;
330         time64_t                imp_last_reply_time;    /* for health check */
331 };
332
333 /* import.c */
334 static inline unsigned int at_est2timeout(unsigned int val)
335 {
336         /* add an arbitrary minimum: 125% +5 sec */
337         return (val + (val >> 2) + 5);
338 }
339
340 static inline timeout_t at_timeout2est(timeout_t timeout)
341 {
342         /* restore estimate value from timeout: e=4/5(t-5) */
343         LASSERT(timeout > 0);
344         return max((timeout << 2) / 5, 5) - 4;
345 }
346
347 static inline void at_reset_nolock(struct adaptive_timeout *at, int val)
348 {
349         at->at_current = val;
350         at->at_worst_ever = val;
351         at->at_worst_time = ktime_get_real_seconds();
352 }
353
354 static inline void at_reset(struct adaptive_timeout *at, int val)
355 {
356         spin_lock(&at->at_lock);
357         at_reset_nolock(at, val);
358         spin_unlock(&at->at_lock);
359 }
360
361 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
362         memset(at, 0, sizeof(*at));
363         spin_lock_init(&at->at_lock);
364         at->at_flags = flags;
365         at_reset(at, val);
366 }
367
368 static inline void at_reinit(struct adaptive_timeout *at, int val, int flags)
369 {
370         spin_lock(&at->at_lock);
371         at->at_binstart = 0;
372         memset(at->at_hist, 0, sizeof(at->at_hist));
373         at->at_flags = flags;
374         at_reset_nolock(at, val);
375         spin_unlock(&at->at_lock);
376 }
377
378 extern unsigned int at_min;
379 static inline int at_get(struct adaptive_timeout *at) {
380         return (at->at_current > at_min) ? at->at_current : at_min;
381 }
382 int at_measured(struct adaptive_timeout *at, unsigned int val);
383 int import_at_get_index(struct obd_import *imp, int portal);
384 extern unsigned int at_max;
385 #define AT_OFF (at_max == 0)
386
387 /* genops.c */
388 struct obd_export;
389 extern struct obd_import *class_exp2cliimp(struct obd_export *);
390
391 /** @} import */
392
393 #endif /* __IMPORT_H */
394
395 /** @} obd_import */