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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 /** \defgroup obd_import PtlRPC import definitions
37 * Imports are client-side representation of remote obd target.
45 /** \defgroup export export
50 #include <lustre_handles.h>
51 #include <lustre/lustre_idl.h>
55 * Adaptive Timeout stuff
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 */
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 */
73 enum lustre_at_flags {
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 */
86 #define IMP_AT_MAX_PORTALS 8
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];
96 /** Possible import states */
97 enum lustre_imp_state {
98 LUSTRE_IMP_CLOSED = 1,
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,
107 LUSTRE_IMP_EVICTED = 10,
110 /** Returns test string representation of numeric import state \a state */
111 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
113 static char* import_state_names[] = {
114 "<UNKNOWN>", "CLOSED", "NEW", "DISCONN",
115 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
116 "RECOVER", "FULL", "EVICTED",
119 LASSERT (state <= LUSTRE_IMP_EVICTED);
120 return import_state_names[state];
124 * List of import event types
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,
137 * Definition of import connection structure
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;
147 * Time (64 bit jiffies) of last connection attempt on this connection
149 __u64 oic_last_attempt;
153 #define IMP_STATE_HIST_LEN 16
154 struct import_state_hist {
155 enum lustre_imp_state ish_state;
160 * Defintion of PortalRPC import structure.
161 * Imports are representing client-side view to remote target.
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;
179 * Lists of requests that are retained for replay, waiting for a reply,
180 * or waiting for recovery to complete, respectively.
183 struct list_head imp_replay_list;
184 struct list_head imp_sending_list;
185 struct list_head imp_delayed_list;
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.
195 struct list_head imp_committed_list;
196 struct list_head *imp_replay_cursor;
199 /** List of not replied requests */
200 struct list_head imp_unreplied_list;
201 /** Known maximal replied XID */
202 __u64 imp_known_replied_xid;
204 /** obd device for this import */
205 struct obd_device *imp_obd;
208 * some seciruty-related fields
211 struct ptlrpc_sec *imp_sec;
212 struct mutex imp_sec_mutex;
213 cfs_time_t imp_sec_expire;
216 /** Wait queue for those who need to wait for recovery completion */
217 wait_queue_head_t imp_recovery_waitq;
219 /** Number of requests currently in-flight */
220 atomic_t imp_inflight;
221 /** Number of requests currently unregistering */
222 atomic_t imp_unregistering;
223 /** Number of replay requests inflight */
224 atomic_t imp_replay_inflight;
225 /** Number of currently happening import invalidations */
226 atomic_t imp_inval_count;
227 /** Numbner of request timeouts */
228 atomic_t imp_timeouts;
229 /** Current import state */
230 enum lustre_imp_state imp_state;
231 /** Last replay state */
232 enum lustre_imp_state imp_replay_state;
233 /** History of import states */
234 struct import_state_hist imp_state_hist[IMP_STATE_HIST_LEN];
235 int imp_state_hist_idx;
236 /** Current import generation. Incremented on every reconnect */
238 /** Incremented every time we send reconnection request */
241 * \see ptlrpc_free_committed remembers imp_generation value here
242 * after a check to save on unnecessary replay list iterations
244 int imp_last_generation_checked;
245 /** Last tranno we replayed */
246 __u64 imp_last_replay_transno;
247 /** Last transno committed on remote side */
248 __u64 imp_peer_committed_transno;
250 * \see ptlrpc_free_committed remembers last_transno since its last
251 * check here and if last_transno did not change since last run of
252 * ptlrpc_free_committed and import generation is the same, we can
253 * skip looking for requests to remove from replay list as optimisation
255 __u64 imp_last_transno_checked;
257 * Remote export handle. This is how remote side knows what export
258 * we are talking to. Filled from response to connect request
260 struct lustre_handle imp_remote_handle;
261 /** When to perform next ping. time in jiffies. */
262 cfs_time_t imp_next_ping;
263 /** When we last successfully connected. time in 64bit jiffies */
264 __u64 imp_last_success_conn;
266 /** List of all possible connection for import. */
267 struct list_head imp_conn_list;
269 * Current connection. \a imp_connection is imp_conn_current->oic_conn
271 struct obd_import_conn *imp_conn_current;
273 /** Protects flags, level, generation, conn_cnt, *_list */
277 unsigned long imp_no_timeout:1, /* timeouts are disabled */
278 imp_invalid:1, /* evicted */
279 /* administratively disabled */
281 /* try to recover the import */
283 /* don't run recovery (timeout instead) */
285 /* use 1/2 timeout on MDS' OSCs */
286 imp_server_timeout:1,
287 /* VBR: imp in delayed recovery */
288 imp_delayed_recovery:1,
289 /* VBR: if gap was found then no lock replays
291 imp_no_lock_replay:1,
292 /* recovery by versions was failed */
294 /* force an immidiate ping */
296 /* force a scheduled ping */
297 imp_force_next_verify:1,
300 /* resend for replay */
302 /* disable normal recovery, for test only. */
303 imp_no_pinger_recover:1,
304 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
305 /* need IR MNE swab */
308 /* import must be reconnected instead of
309 * chouse new connection */
310 imp_force_reconnect:1,
311 /* import has tried to connect with server */
313 /* connected but not FULL yet */
315 __u32 imp_connect_op;
316 struct obd_connect_data imp_connect_data;
317 __u64 imp_connect_flags_orig;
318 __u64 imp_connect_flags2_orig;
319 int imp_connect_error;
322 /* adjusted based on server capability */
323 __u32 imp_msghdr_flags;
325 /* adaptive timeout data */
326 struct imp_at imp_at;
327 time_t imp_last_reply_time; /* for health check */
331 static inline unsigned int at_est2timeout(unsigned int val)
333 /* add an arbitrary minimum: 125% +5 sec */
334 return (val + (val >> 2) + 5);
337 static inline unsigned int at_timeout2est(unsigned int val)
339 /* restore estimate value from timeout: e=4/5(t-5) */
341 return (max((val << 2) / 5, 5U) - 4);
344 static inline void at_reset_nolock(struct adaptive_timeout *at, int val)
346 at->at_current = val;
347 at->at_worst_ever = val;
348 at->at_worst_time = cfs_time_current_sec();
351 static inline void at_reset(struct adaptive_timeout *at, int val)
353 spin_lock(&at->at_lock);
354 at_reset_nolock(at, val);
355 spin_unlock(&at->at_lock);
358 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
359 memset(at, 0, sizeof(*at));
360 spin_lock_init(&at->at_lock);
361 at->at_flags = flags;
365 static inline void at_reinit(struct adaptive_timeout *at, int val, int flags)
367 spin_lock(&at->at_lock);
369 memset(at->at_hist, 0, sizeof(at->at_hist));
370 at->at_flags = flags;
371 at_reset_nolock(at, val);
372 spin_unlock(&at->at_lock);
375 extern unsigned int at_min;
376 static inline int at_get(struct adaptive_timeout *at) {
377 return (at->at_current > at_min) ? at->at_current : at_min;
379 int at_measured(struct adaptive_timeout *at, unsigned int val);
380 int import_at_get_index(struct obd_import *imp, int portal);
381 extern unsigned int at_max;
382 #define AT_OFF (at_max == 0)
386 extern struct obd_import *class_exp2cliimp(struct obd_export *);
387 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
391 #endif /* __IMPORT_H */