Whamcloud - gitweb
badfe44d62fb3d5ecbacb5bbca26b90426ecde56
[fs/lustre-release.git] / lustre / include / lustre_import.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __IMPORT_H
38 #define __IMPORT_H
39
40 /** \defgroup export export
41  *
42  * @{
43  */
44
45 #include <lustre_handles.h>
46 #include <lustre/lustre_idl.h>
47
48
49 /* Adaptive Timeout stuff */
50 #define D_ADAPTTO D_OTHER
51 #define AT_BINS 4                  /* "bin" means "N seconds of history" */
52 #define AT_FLG_NOHIST 0x1          /* use last reported value only */
53
54 struct adaptive_timeout {
55         time_t           at_binstart;         /* bin start time */
56         unsigned int     at_hist[AT_BINS];    /* timeout history bins */
57         unsigned int     at_flags;
58         unsigned int     at_current;          /* current timeout value */
59         unsigned int     at_worst_ever;       /* worst-ever timeout value */
60         time_t           at_worst_time;       /* worst-ever timeout timestamp */
61         cfs_spinlock_t   at_lock;
62 };
63
64 enum lustre_imp_state {
65         LUSTRE_IMP_CLOSED     = 1,
66         LUSTRE_IMP_NEW        = 2,
67         LUSTRE_IMP_DISCON     = 3,
68         LUSTRE_IMP_CONNECTING = 4,
69         LUSTRE_IMP_REPLAY     = 5,
70         LUSTRE_IMP_REPLAY_LOCKS = 6,
71         LUSTRE_IMP_REPLAY_WAIT  = 7,
72         LUSTRE_IMP_RECOVER    = 8,
73         LUSTRE_IMP_FULL       = 9,
74         LUSTRE_IMP_EVICTED    = 10,
75 };
76
77 struct ptlrpc_at_array {
78         cfs_list_t       *paa_reqs_array; /* array to hold requests */
79         __u32             paa_size;       /* the size of array */
80         __u32             paa_count;      /* the total count of reqs */
81         time_t            paa_deadline;   /* earliest deadline of reqs */
82         __u32            *paa_reqs_count; /* count of reqs in each entry */
83 };
84
85 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
86 {
87         static char* import_state_names[] = {
88                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
89                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
90                 "RECOVER", "FULL", "EVICTED",
91         };
92
93         LASSERT (state <= LUSTRE_IMP_EVICTED);
94         return import_state_names[state];
95 }
96
97 enum obd_import_event {
98         IMP_EVENT_DISCON     = 0x808001,
99         IMP_EVENT_INACTIVE   = 0x808002,
100         IMP_EVENT_INVALIDATE = 0x808003,
101         IMP_EVENT_ACTIVE     = 0x808004,
102         IMP_EVENT_OCD        = 0x808005,
103 };
104
105 struct obd_import_conn {
106         cfs_list_t                oic_item;
107         struct ptlrpc_connection *oic_conn;
108         struct obd_uuid           oic_uuid;
109         __u64                     oic_last_attempt; /* jiffies, 64-bit */
110 };
111
112 #define IMP_AT_MAX_PORTALS 8
113 struct imp_at {
114         int                     iat_portal[IMP_AT_MAX_PORTALS];
115         struct adaptive_timeout iat_net_latency;
116         struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
117 };
118
119 /* state history */
120 #define IMP_STATE_HIST_LEN 16
121 struct import_state_hist {
122         enum lustre_imp_state ish_state;
123         time_t                ish_time;
124 };
125
126 struct obd_import {
127         struct portals_handle     imp_handle;
128         cfs_atomic_t              imp_refcount;
129         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
130         struct ptlrpc_connection *imp_connection;
131         struct ptlrpc_client     *imp_client;
132         cfs_list_t                imp_pinger_chain;
133         cfs_list_t                imp_zombie_chain; /* queue for destruction */
134
135         /* Lists of requests that are retained for replay, waiting for a reply,
136          * or waiting for recovery to complete, respectively.
137          */
138         cfs_list_t                imp_replay_list;
139         cfs_list_t                imp_sending_list;
140         cfs_list_t                imp_delayed_list;
141
142         struct obd_device        *imp_obd;
143         struct ptlrpc_sec        *imp_sec;
144         cfs_semaphore_t           imp_sec_mutex;
145         cfs_time_t                imp_sec_expire;
146         cfs_waitq_t               imp_recovery_waitq;
147
148         cfs_atomic_t              imp_inflight;
149         cfs_atomic_t              imp_unregistering;
150         cfs_atomic_t              imp_replay_inflight;
151         cfs_atomic_t              imp_inval_count;  /* in-progress invalidations */
152         cfs_atomic_t              imp_timeouts;
153         enum lustre_imp_state     imp_state;
154         struct import_state_hist  imp_state_hist[IMP_STATE_HIST_LEN];
155         int                       imp_state_hist_idx;
156         int                       imp_generation;
157         __u32                     imp_conn_cnt;
158         int                       imp_last_generation_checked;
159         __u64                     imp_last_replay_transno;
160         __u64                     imp_peer_committed_transno;
161         __u64                     imp_last_transno_checked;
162         struct lustre_handle      imp_remote_handle;
163         cfs_time_t                imp_next_ping;   /* jiffies */
164         __u64                     imp_last_success_conn;   /* jiffies, 64-bit */
165
166         /* all available obd_import_conn linked here */
167         cfs_list_t                imp_conn_list;
168         struct obd_import_conn   *imp_conn_current;
169
170         /* Protects flags, level, generation, conn_cnt, *_list */
171         cfs_spinlock_t            imp_lock;
172
173         /* flags */
174         unsigned long             imp_no_timeout:1,       /* timeouts are disabled */
175                                   imp_invalid:1,          /* evicted */
176                                   imp_deactive:1,         /* administratively disabled */
177                                   imp_replayable:1,       /* try to recover the import */
178                                   imp_dlm_fake:1,         /* don't run recovery (timeout instead) */
179                                   imp_server_timeout:1,   /* use 1/2 timeout on MDS' OSCs */
180                                   imp_delayed_recovery:1, /* VBR: imp in delayed recovery */
181                                   imp_no_lock_replay:1,   /* VBR: if gap was found then no lock replays */
182                                   imp_vbr_failed:1,       /* recovery by versions was failed */
183                                   imp_force_verify:1,     /* force an immidiate ping */
184                                   imp_pingable:1,         /* pingable */
185                                   imp_resend_replay:1,    /* resend for replay */
186                                   imp_force_reconnect:1;  /* import must be reconnected instead of chouse new connection */
187         __u32                     imp_connect_op;
188         struct obd_connect_data   imp_connect_data;
189         __u64                     imp_connect_flags_orig;
190         int                       imp_connect_error;
191
192         __u32                     imp_msg_magic;
193         __u32                     imp_msghdr_flags;       /* adjusted based on server capability */
194
195         struct ptlrpc_request_pool *imp_rq_pool;          /* emergency request pool */
196
197         struct imp_at             imp_at;                 /* adaptive timeout data */
198         time_t                    imp_last_reply_time;    /* for health check */
199 };
200
201 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
202                                     int event, void *event_arg, void *cb_data);
203
204 struct obd_import_observer {
205         cfs_list_t           oio_chain;
206         obd_import_callback  oio_cb;
207         void                *oio_cb_data;
208 };
209
210 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
211                           void *cb_data);
212 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
213                             void *cb_data);
214 void class_notify_import_observers(struct obd_import *imp, int event,
215                                    void *event_arg);
216
217 /* import.c */
218 static inline unsigned int at_est2timeout(unsigned int val)
219 {
220         /* add an arbitrary minimum: 125% +5 sec */
221         return (val + (val >> 2) + 5);
222 }
223
224 static inline unsigned int at_timeout2est(unsigned int val)
225 {
226         /* restore estimate value from timeout: e=4/5(t-5) */
227         LASSERT(val);
228         return (max((val << 2) / 5, 5U) - 4);
229 }
230
231 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
232         memset(at, 0, sizeof(*at));
233         at->at_current = val;
234         at->at_worst_ever = val;
235         at->at_worst_time = cfs_time_current_sec();
236         at->at_flags = flags;
237         cfs_spin_lock_init(&at->at_lock);
238 }
239 static inline int at_get(struct adaptive_timeout *at) {
240         return at->at_current;
241 }
242 int at_measured(struct adaptive_timeout *at, unsigned int val);
243 int import_at_get_index(struct obd_import *imp, int portal);
244 extern unsigned int at_max;
245 #define AT_OFF (at_max == 0)
246
247 /* genops.c */
248 struct obd_export;
249 extern struct obd_import *class_exp2cliimp(struct obd_export *);
250 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
251
252 /** @} import */
253
254 #endif /* __IMPORT_H */