1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
8 #include <lustre_handles.h>
9 #include <lustre/lustre_idl.h>
12 /* Adaptive Timeout stuff */
13 #define D_ADAPTTO D_OTHER
14 #define AT_BINS 4 /* "bin" means "N seconds of history" */
15 #define AT_FLG_NOHIST 0x1 /* use last reported value only */
17 struct adaptive_timeout {
18 time_t at_binstart; /* bin start time */
19 unsigned int at_hist[AT_BINS]; /* timeout history bins */
20 unsigned int at_flags;
21 unsigned int at_current; /* current timeout value */
22 unsigned int at_worst_ever; /* worst-ever timeout value */
23 time_t at_worst_time; /* worst-ever timeout timestamp */
27 enum lustre_imp_state {
28 LUSTRE_IMP_CLOSED = 1,
30 LUSTRE_IMP_DISCON = 3,
31 LUSTRE_IMP_CONNECTING = 4,
32 LUSTRE_IMP_REPLAY = 5,
33 LUSTRE_IMP_REPLAY_LOCKS = 6,
34 LUSTRE_IMP_REPLAY_WAIT = 7,
35 LUSTRE_IMP_RECOVER = 8,
37 LUSTRE_IMP_EVICTED = 10,
40 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
42 static char* import_state_names[] = {
43 "<UNKNOWN>", "CLOSED", "NEW", "DISCONN",
44 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
45 "RECOVER", "FULL", "EVICTED",
48 LASSERT (state <= LUSTRE_IMP_EVICTED);
49 return import_state_names[state];
52 enum obd_import_event {
53 IMP_EVENT_DISCON = 0x808001,
54 IMP_EVENT_INACTIVE = 0x808002,
55 IMP_EVENT_INVALIDATE = 0x808003,
56 IMP_EVENT_ACTIVE = 0x808004,
57 IMP_EVENT_OCD = 0x808005,
60 struct obd_import_conn {
61 struct list_head oic_item;
62 struct ptlrpc_connection *oic_conn;
63 struct obd_uuid oic_uuid;
64 __u64 oic_last_attempt; /* jiffies, 64-bit */
67 #define IMP_AT_MAX_PORTALS 8
69 int iat_portal[IMP_AT_MAX_PORTALS];
70 struct adaptive_timeout iat_net_latency;
71 struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
75 struct portals_handle imp_handle;
76 atomic_t imp_refcount;
77 struct lustre_handle imp_dlm_handle; /* client's ldlm export */
78 struct ptlrpc_connection *imp_connection;
79 struct ptlrpc_client *imp_client;
80 struct list_head imp_pinger_chain;
81 struct list_head imp_zombie_chain; /* queue for destruction */
83 /* Lists of requests that are retained for replay, waiting for a reply,
84 * or waiting for recovery to complete, respectively.
86 struct list_head imp_replay_list;
87 struct list_head imp_sending_list;
88 struct list_head imp_delayed_list;
90 struct obd_device *imp_obd;
91 struct ptlrpc_sec *imp_sec;
92 struct semaphore imp_sec_mutex;
93 cfs_time_t imp_sec_expire;
94 cfs_waitq_t imp_recovery_waitq;
96 atomic_t imp_inflight;
97 atomic_t imp_replay_inflight;
98 atomic_t imp_inval_count;
99 enum lustre_imp_state imp_state;
102 int imp_last_generation_checked;
103 __u64 imp_last_replay_transno;
104 __u64 imp_peer_committed_transno;
105 __u64 imp_last_transno_checked;
106 struct lustre_handle imp_remote_handle;
107 cfs_time_t imp_next_ping; /* jiffies */
108 __u64 imp_last_success_conn; /* jiffies, 64-bit */
110 /* all available obd_import_conn linked here */
111 struct list_head imp_conn_list;
112 struct obd_import_conn *imp_conn_current;
114 /* Protects flags, level, generation, conn_cnt, *_list */
118 unsigned long imp_no_timeout:1, /* timeouts are disabled */
119 imp_invalid:1, /* evicted */
120 imp_deactive:1, /* administratively disabled */
121 imp_replayable:1, /* try to recover the import */
122 imp_dlm_fake:1, /* don't run recovery (timeout instead) */
123 imp_server_timeout:1, /* use 1/2 timeout on MDS' OSCs */
124 imp_initial_recov:1, /* retry the initial connection */
125 imp_initial_recov_bk:1, /* turn off init_recov after trying all failover nids */
126 imp_force_verify:1, /* force an immidiate ping */
127 imp_pingable:1, /* pingable */
128 imp_resend_replay:1, /* resend for replay */
129 imp_recon_bk:1, /* turn off reconnect if all failovers fail */
130 imp_last_recon:1; /* internally used by above */
131 __u32 imp_connect_op;
132 struct obd_connect_data imp_connect_data;
133 __u64 imp_connect_flags_orig;
134 int imp_connect_error;
137 __u32 imp_msghdr_flags; /* adjusted based on server capability */
139 struct ptlrpc_request_pool *imp_rq_pool; /* emergency request pool */
141 struct imp_at imp_at; /* adaptive timeout data */
142 time_t imp_last_reply_time; /* for health check */
145 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
146 int event, void *event_arg, void *cb_data);
148 struct obd_import_observer {
149 struct list_head oio_chain;
150 obd_import_callback oio_cb;
154 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
156 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
158 void class_notify_import_observers(struct obd_import *imp, int event,
162 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
163 memset(at, 0, sizeof(*at));
164 at->at_current = val;
165 at->at_worst_ever = val;
166 at->at_worst_time = cfs_time_current_sec();
167 at->at_flags = flags;
168 spin_lock_init(&at->at_lock);
170 static inline int at_get(struct adaptive_timeout *at) {
171 return at->at_current;
173 int at_add(struct adaptive_timeout *at, unsigned int val);
174 int import_at_get_index(struct obd_import *imp, int portal);
175 extern unsigned int at_max;
176 #define AT_OFF (at_max == 0)
180 extern struct obd_import *class_exp2cliimp(struct obd_export *);
181 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
183 #endif /* __IMPORT_H */