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