4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 /** \defgroup obd_import PtlRPC import definitions
33 * Imports are client-side representation of remote obd target.
41 /** \defgroup export export
45 #include <linux/atomic.h>
46 #include <linux/list.h>
47 #include <linux/mutex.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>
56 * Adaptive Timeout stuff
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 */
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 unsigned int at_current; /* current timeout value */
69 unsigned int at_worst_ever; /* worst-ever timeout value */
70 time64_t at_worst_time; /* worst-ever timeout timestamp */
74 enum lustre_at_flags {
79 struct ptlrpc_at_array {
80 struct list_head *paa_reqs_array; /** array to hold requests */
81 __u32 paa_size; /** the size of array */
82 __u32 paa_count; /** the total count of reqs */
83 time64_t paa_deadline; /** the earliest deadline of reqs */
84 __u32 *paa_reqs_count; /** the count of reqs in each entry */
87 #define IMP_AT_MAX_PORTALS 8
89 int iat_portal[IMP_AT_MAX_PORTALS];
90 struct adaptive_timeout iat_net_latency;
91 struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
97 /** Possible import states */
98 enum lustre_imp_state {
99 LUSTRE_IMP_CLOSED = 1,
101 LUSTRE_IMP_DISCON = 3,
102 LUSTRE_IMP_CONNECTING = 4,
103 LUSTRE_IMP_REPLAY = 5,
104 LUSTRE_IMP_REPLAY_LOCKS = 6,
105 LUSTRE_IMP_REPLAY_WAIT = 7,
106 LUSTRE_IMP_RECOVER = 8,
108 LUSTRE_IMP_EVICTED = 10,
109 LUSTRE_IMP_IDLE = 11,
113 /** Returns test string representation of numeric import state \a state */
114 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
116 static char *import_state_names[] = {
117 "<UNKNOWN>", "CLOSED", "NEW", "DISCONN",
118 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
119 "RECOVER", "FULL", "EVICTED", "IDLE",
122 LASSERT(state < LUSTRE_IMP_LAST);
123 return import_state_names[state];
127 * List of import event types
129 enum obd_import_event {
130 IMP_EVENT_DISCON = 0x808001,
131 IMP_EVENT_INACTIVE = 0x808002,
132 IMP_EVENT_INVALIDATE = 0x808003,
133 IMP_EVENT_ACTIVE = 0x808004,
134 IMP_EVENT_OCD = 0x808005,
135 IMP_EVENT_DEACTIVATE = 0x808006,
136 IMP_EVENT_ACTIVATE = 0x808007,
140 * Definition of import connection structure
142 struct obd_import_conn {
143 /** Item for linking connections together */
144 struct list_head oic_item;
145 /** Pointer to actual PortalRPC connection */
146 struct ptlrpc_connection *oic_conn;
147 /** uuid of remote side */
148 struct obd_uuid oic_uuid;
150 * Time (64 bit seconds) of last connection attempt on this connection
152 time64_t oic_last_attempt;
156 #define IMP_STATE_HIST_LEN 16
157 struct import_state_hist {
158 enum lustre_imp_state ish_state;
163 * Defintion of PortalRPC import structure.
164 * Imports are representing client-side view to remote target.
167 /** Reference counter */
168 atomic_t imp_refcount;
169 struct lustre_handle imp_dlm_handle; /* client's ldlm export */
170 /** Currently active connection */
171 struct ptlrpc_connection *imp_connection;
172 /** PortalRPC client structure for this import */
173 struct ptlrpc_client *imp_client;
174 /** List element for linking into pinger chain */
175 struct list_head imp_pinger_chain;
176 /** work struct for destruction of import */
177 struct work_struct imp_zombie_work;
180 * Lists of requests that are retained for replay, waiting for a reply,
181 * or waiting for recovery to complete, respectively.
184 struct list_head imp_replay_list;
185 struct list_head imp_sending_list;
186 struct list_head imp_delayed_list;
190 * List of requests that are retained for committed open replay. Once
191 * open is committed, open replay request will be moved from the
192 * imp_replay_list into the imp_committed_list.
193 * The imp_replay_cursor is for accelerating searching during replay.
196 struct list_head imp_committed_list;
197 struct list_head *imp_replay_cursor;
200 /** List of not replied requests */
201 struct list_head imp_unreplied_list;
202 /** Known maximal replied XID */
203 __u64 imp_known_replied_xid;
205 /** obd device for this import */
206 struct obd_device *imp_obd;
209 * some seciruty-related fields
212 struct ptlrpc_sec *imp_sec;
213 struct mutex imp_sec_mutex;
214 time64_t imp_sec_expire;
215 pid_t imp_sec_refpid;
218 /** Wait queue for those who need to wait for recovery completion */
219 wait_queue_head_t imp_recovery_waitq;
221 /** Number of requests currently in-flight */
222 atomic_t imp_inflight;
223 /** Number of requests currently unregistering */
224 atomic_t imp_unregistering;
225 /** Number of replay requests inflight */
226 atomic_t imp_replay_inflight;
227 /** Number of currently happening import invalidations */
228 atomic_t imp_inval_count;
229 /** Numbner of request timeouts */
230 atomic_t imp_timeouts;
231 /** Current import state */
232 enum lustre_imp_state imp_state;
233 /** Last replay state */
234 enum lustre_imp_state imp_replay_state;
235 /** History of import states */
236 struct import_state_hist imp_state_hist[IMP_STATE_HIST_LEN];
237 int imp_state_hist_idx;
238 /** Current import generation. Incremented on every reconnect */
240 /** Idle connection initiated at this generation */
241 int imp_initiated_at;
242 /** Incremented every time we send reconnection request */
245 * \see ptlrpc_free_committed remembers imp_generation value here
246 * after a check to save on unnecessary replay list iterations
248 int imp_last_generation_checked;
249 /** Last tranno we replayed */
250 __u64 imp_last_replay_transno;
251 /** Last transno committed on remote side */
252 __u64 imp_peer_committed_transno;
254 * \see ptlrpc_free_committed remembers last_transno since its last
255 * check here and if last_transno did not change since last run of
256 * ptlrpc_free_committed and import generation is the same, we can
257 * skip looking for requests to remove from replay list as optimisation
259 __u64 imp_last_transno_checked;
261 * Remote export handle. This is how remote side knows what export
262 * we are talking to. Filled from response to connect request
264 struct lustre_handle imp_remote_handle;
265 /** When to perform next ping. time in jiffies. */
266 time64_t imp_next_ping;
267 /** When we last successfully connected. time in 64bit jiffies */
268 time64_t imp_last_success_conn;
270 /** List of all possible connection for import. */
271 struct list_head imp_conn_list;
273 * Current connection. \a imp_connection is imp_conn_current->oic_conn
275 struct obd_import_conn *imp_conn_current;
277 /** Protects flags, level, generation, conn_cnt, *_list */
281 unsigned long imp_no_timeout:1, /* timeouts are disabled */
282 imp_invalid:1, /* evicted */
283 /* administratively disabled */
285 /* try to recover the import */
287 /* don't run recovery (timeout instead) */
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 */
295 /* force an immidiate ping */
297 /* force a scheduled ping */
298 imp_force_next_verify:1,
301 /* resend for replay */
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 */
310 /* connected but not FULL yet */
313 u32 imp_idle_timeout;
315 struct obd_connect_data imp_connect_data;
316 __u64 imp_connect_flags_orig;
317 __u64 imp_connect_flags2_orig;
318 int imp_connect_error;
320 enum lustre_msg_magic imp_msg_magic;
321 /* adjusted based on server capability */
322 enum lustre_msghdr imp_msghdr_flags;
324 /* adaptive timeout data */
325 struct imp_at imp_at;
326 time64_t imp_last_reply_time; /* for health check */
330 static inline unsigned int at_est2timeout(unsigned int val)
332 /* add an arbitrary minimum: 125% +5 sec */
333 return (val + (val >> 2) + 5);
336 static inline unsigned int at_timeout2est(unsigned int val)
338 /* restore estimate value from timeout: e=4/5(t-5) */
340 return (max((val << 2) / 5, 5U) - 4);
343 static inline void at_reset_nolock(struct adaptive_timeout *at, int val)
345 at->at_current = val;
346 at->at_worst_ever = val;
347 at->at_worst_time = ktime_get_real_seconds();
350 static inline void at_reset(struct adaptive_timeout *at, int val)
352 spin_lock(&at->at_lock);
353 at_reset_nolock(at, val);
354 spin_unlock(&at->at_lock);
357 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
358 memset(at, 0, sizeof(*at));
359 spin_lock_init(&at->at_lock);
360 at->at_flags = flags;
364 static inline void at_reinit(struct adaptive_timeout *at, int val, int flags)
366 spin_lock(&at->at_lock);
368 memset(at->at_hist, 0, sizeof(at->at_hist));
369 at->at_flags = flags;
370 at_reset_nolock(at, val);
371 spin_unlock(&at->at_lock);
374 extern unsigned int at_min;
375 static inline int at_get(struct adaptive_timeout *at) {
376 return (at->at_current > at_min) ? at->at_current : at_min;
378 int at_measured(struct adaptive_timeout *at, unsigned int val);
379 int import_at_get_index(struct obd_import *imp, int portal);
380 extern unsigned int at_max;
381 #define AT_OFF (at_max == 0)
385 extern struct obd_import *class_exp2cliimp(struct obd_export *);
389 #endif /* __IMPORT_H */