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