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 /** obd device for this import */
200 struct obd_device *imp_obd;
203 * some seciruty-related fields
206 struct ptlrpc_sec *imp_sec;
207 struct mutex imp_sec_mutex;
208 cfs_time_t imp_sec_expire;
211 /** Wait queue for those who need to wait for recovery completion */
212 wait_queue_head_t imp_recovery_waitq;
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 */
233 /** Incremented every time we send reconnection request */
236 * \see ptlrpc_free_committed remembers imp_generation value here
237 * after a check to save on unnecessary replay list iterations
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;
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
250 __u64 imp_last_transno_checked;
252 * Remote export handle. This is how remote side knows what export
253 * we are talking to. Filled from response to connect request
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;
261 /** List of all possible connection for import. */
262 struct list_head imp_conn_list;
264 * Current connection. \a imp_connection is imp_conn_current->oic_conn
266 struct obd_import_conn *imp_conn_current;
268 /** Protects flags, level, generation, conn_cnt, *_list */
272 unsigned long imp_no_timeout:1, /* timeouts are disabled */
273 imp_invalid:1, /* evicted */
274 /* administratively disabled */
276 /* try to recover the import */
278 /* don't run recovery (timeout instead) */
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
286 imp_no_lock_replay:1,
287 /* recovery by versions was failed */
289 /* force an immidiate ping */
291 /* force a scheduled ping */
292 imp_force_next_verify:1,
295 /* resend for replay */
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 */
303 /* import must be reconnected instead of
304 * chouse new connection */
305 imp_force_reconnect:1,
306 /* import has tried to connect with server */
308 __u32 imp_connect_op;
309 struct obd_connect_data imp_connect_data;
310 __u64 imp_connect_flags_orig;
311 int imp_connect_error;
314 __u32 imp_msghdr_flags; /* adjusted based on server capability */
316 struct ptlrpc_request_pool *imp_rq_pool; /* emergency request pool */
318 struct imp_at imp_at; /* adaptive timeout data */
319 time_t imp_last_reply_time; /* for health check */
323 static inline unsigned int at_est2timeout(unsigned int val)
325 /* add an arbitrary minimum: 125% +5 sec */
326 return (val + (val >> 2) + 5);
329 static inline unsigned int at_timeout2est(unsigned int val)
331 /* restore estimate value from timeout: e=4/5(t-5) */
333 return (max((val << 2) / 5, 5U) - 4);
336 static inline void at_reset(struct adaptive_timeout *at, int val) {
337 spin_lock(&at->at_lock);
338 at->at_current = val;
339 at->at_worst_ever = val;
340 at->at_worst_time = cfs_time_current_sec();
341 spin_unlock(&at->at_lock);
343 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
344 memset(at, 0, sizeof(*at));
345 spin_lock_init(&at->at_lock);
346 at->at_flags = flags;
349 extern unsigned int at_min;
350 static inline int at_get(struct adaptive_timeout *at) {
351 return (at->at_current > at_min) ? at->at_current : at_min;
353 int at_measured(struct adaptive_timeout *at, unsigned int val);
354 int import_at_get_index(struct obd_import *imp, int portal);
355 extern unsigned int at_max;
356 #define AT_OFF (at_max == 0)
360 extern struct obd_import *class_exp2cliimp(struct obd_export *);
361 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
365 #endif /* __IMPORT_H */