1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <lustre_handles.h>
41 #include <lustre/lustre_idl.h>
44 /* Adaptive Timeout stuff */
45 #define D_ADAPTTO D_OTHER
46 #define AT_BINS 4 /* "bin" means "N seconds of history" */
47 #define AT_FLG_NOHIST 0x1 /* use last reported value only */
49 struct adaptive_timeout {
50 time_t at_binstart; /* bin start time */
51 unsigned int at_hist[AT_BINS]; /* timeout history bins */
52 unsigned int at_flags;
53 unsigned int at_current; /* current timeout value */
54 unsigned int at_worst_ever; /* worst-ever timeout value */
55 time_t at_worst_time; /* worst-ever timeout timestamp */
59 enum lustre_imp_state {
60 LUSTRE_IMP_CLOSED = 1,
62 LUSTRE_IMP_DISCON = 3,
63 LUSTRE_IMP_CONNECTING = 4,
64 LUSTRE_IMP_REPLAY = 5,
65 LUSTRE_IMP_REPLAY_LOCKS = 6,
66 LUSTRE_IMP_REPLAY_WAIT = 7,
67 LUSTRE_IMP_RECOVER = 8,
69 LUSTRE_IMP_EVICTED = 10,
72 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
74 static char* import_state_names[] = {
75 "<UNKNOWN>", "CLOSED", "NEW", "DISCONN",
76 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
77 "RECOVER", "FULL", "EVICTED",
80 LASSERT (state <= LUSTRE_IMP_EVICTED);
81 return import_state_names[state];
84 enum obd_import_event {
85 IMP_EVENT_DISCON = 0x808001,
86 IMP_EVENT_INACTIVE = 0x808002,
87 IMP_EVENT_INVALIDATE = 0x808003,
88 IMP_EVENT_ACTIVE = 0x808004,
89 IMP_EVENT_OCD = 0x808005,
92 struct obd_import_conn {
93 struct list_head oic_item;
94 struct ptlrpc_connection *oic_conn;
95 struct obd_uuid oic_uuid;
96 __u64 oic_last_attempt; /* jiffies, 64-bit */
99 #define IMP_AT_MAX_PORTALS 8
101 int iat_portal[IMP_AT_MAX_PORTALS];
102 struct adaptive_timeout iat_net_latency;
103 struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
107 struct portals_handle imp_handle;
108 atomic_t imp_refcount;
109 struct lustre_handle imp_dlm_handle; /* client's ldlm export */
110 struct ptlrpc_connection *imp_connection;
111 struct ptlrpc_client *imp_client;
112 struct list_head imp_pinger_chain;
113 struct list_head imp_zombie_chain; /* queue for destruction */
115 /* Lists of requests that are retained for replay, waiting for a reply,
116 * or waiting for recovery to complete, respectively.
118 struct list_head imp_replay_list;
119 struct list_head imp_sending_list;
120 struct list_head imp_delayed_list;
122 struct obd_device *imp_obd;
123 struct ptlrpc_sec *imp_sec;
124 struct semaphore imp_sec_mutex;
125 cfs_time_t imp_sec_expire;
126 cfs_waitq_t imp_recovery_waitq;
128 atomic_t imp_inflight;
129 atomic_t imp_unregistering;
130 atomic_t imp_replay_inflight;
131 atomic_t imp_inval_count;
132 enum lustre_imp_state imp_state;
135 int imp_last_generation_checked;
136 __u64 imp_last_replay_transno;
137 __u64 imp_peer_committed_transno;
138 __u64 imp_last_transno_checked;
139 struct lustre_handle imp_remote_handle;
140 cfs_time_t imp_next_ping; /* jiffies */
141 __u64 imp_last_success_conn; /* jiffies, 64-bit */
143 /* all available obd_import_conn linked here */
144 struct list_head imp_conn_list;
145 struct obd_import_conn *imp_conn_current;
147 /* Protects flags, level, generation, conn_cnt, *_list */
151 unsigned long imp_no_timeout:1, /* timeouts are disabled */
152 imp_invalid:1, /* evicted */
153 imp_deactive:1, /* administratively disabled */
154 imp_replayable:1, /* try to recover the import */
155 imp_dlm_fake:1, /* don't run recovery (timeout instead) */
156 imp_server_timeout:1, /* use 1/2 timeout on MDS' OSCs */
157 imp_initial_recov:1, /* retry the initial connection */
158 imp_initial_recov_bk:1, /* turn off init_recov after trying all failover nids */
159 imp_force_verify:1, /* force an immidiate ping */
160 imp_pingable:1, /* pingable */
161 imp_resend_replay:1, /* resend for replay */
162 imp_recon_bk:1, /* turn off reconnect if all failovers fail */
163 imp_last_recon:1; /* internally used by above */
164 __u32 imp_connect_op;
165 struct obd_connect_data imp_connect_data;
166 __u64 imp_connect_flags_orig;
167 int imp_connect_error;
170 __u32 imp_msghdr_flags; /* adjusted based on server capability */
172 struct ptlrpc_request_pool *imp_rq_pool; /* emergency request pool */
174 struct imp_at imp_at; /* adaptive timeout data */
175 time_t imp_last_reply_time; /* for health check */
178 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
179 int event, void *event_arg, void *cb_data);
181 struct obd_import_observer {
182 struct list_head oio_chain;
183 obd_import_callback oio_cb;
187 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
189 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
191 void class_notify_import_observers(struct obd_import *imp, int event,
195 static inline unsigned int at_est2timeout(unsigned int val)
197 /* add an arbitrary minimum: 125% +5 sec */
198 return (val + (val >> 2) + 5);
201 static inline unsigned int at_timeout2est(unsigned int val)
203 /* restore estimate value from timeout */
205 return ((val - 1) / 5 * 4);
208 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
209 memset(at, 0, sizeof(*at));
210 at->at_current = val;
211 at->at_worst_ever = val;
212 at->at_worst_time = cfs_time_current_sec();
213 at->at_flags = flags;
214 spin_lock_init(&at->at_lock);
216 static inline int at_get(struct adaptive_timeout *at) {
217 return at->at_current;
219 int at_add(struct adaptive_timeout *at, unsigned int val);
220 int import_at_get_index(struct obd_import *imp, int portal);
221 extern unsigned int at_max;
222 #define AT_OFF (at_max == 0)
226 extern struct obd_import *class_exp2cliimp(struct obd_export *);
227 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
229 #endif /* __IMPORT_H */