Whamcloud - gitweb
b=23428 Fix lustre built with --enable-lu_ref
[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 (c) 2002, 2010, Oracle and/or its affiliates. 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 /** \defgroup obd_import PtlRPC import definitions
37  * Imports are client-side representation of remote obd target.
38  *
39  * @{
40  */
41
42 #ifndef __IMPORT_H
43 #define __IMPORT_H
44
45 /** \defgroup export export
46  *
47  * @{
48  */
49
50 #include <lustre_handles.h>
51 #include <lustre/lustre_idl.h>
52
53
54 /**
55  * Adaptive Timeout stuff
56  *
57  * @{
58  */
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 */
62
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 */
70         cfs_spinlock_t   at_lock;
71 };
72
73 struct ptlrpc_at_array {
74         cfs_list_t       *paa_reqs_array; /** array to hold requests */
75         __u32             paa_size;       /** the size of array */
76         __u32             paa_count;      /** the total count of reqs */
77         time_t            paa_deadline;   /** the earliest deadline of reqs */
78         __u32            *paa_reqs_count; /** the count of reqs in each entry */
79 };
80
81 #define IMP_AT_MAX_PORTALS 8
82 struct imp_at {
83         int                     iat_portal[IMP_AT_MAX_PORTALS];
84         struct adaptive_timeout iat_net_latency;
85         struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
86 };
87
88
89 /** @} */
90
91 /** Possible import states */
92 enum lustre_imp_state {
93         LUSTRE_IMP_CLOSED     = 1,
94         LUSTRE_IMP_NEW        = 2,
95         LUSTRE_IMP_DISCON     = 3,
96         LUSTRE_IMP_CONNECTING = 4,
97         LUSTRE_IMP_REPLAY     = 5,
98         LUSTRE_IMP_REPLAY_LOCKS = 6,
99         LUSTRE_IMP_REPLAY_WAIT  = 7,
100         LUSTRE_IMP_RECOVER    = 8,
101         LUSTRE_IMP_FULL       = 9,
102         LUSTRE_IMP_EVICTED    = 10,
103 };
104
105 /** Returns test string representation of numeric import state \a state */
106 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
107 {
108         static char* import_state_names[] = {
109                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
110                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
111                 "RECOVER", "FULL", "EVICTED",
112         };
113
114         LASSERT (state <= LUSTRE_IMP_EVICTED);
115         return import_state_names[state];
116 }
117
118 /**
119  * List of import event types
120  */
121 enum obd_import_event {
122         IMP_EVENT_DISCON     = 0x808001,
123         IMP_EVENT_INACTIVE   = 0x808002,
124         IMP_EVENT_INVALIDATE = 0x808003,
125         IMP_EVENT_ACTIVE     = 0x808004,
126         IMP_EVENT_OCD        = 0x808005,
127 };
128
129 /**
130  * Definition of import connection structure
131  */
132 struct obd_import_conn {
133         /** Item for linking connections together */
134         cfs_list_t                oic_item;
135         /** Pointer to actual PortalRPC connection */
136         struct ptlrpc_connection *oic_conn;
137         /** uuid of remote side */
138         struct obd_uuid           oic_uuid;
139         /**
140          * Time (64 bit jiffies) of last connection attempt on this connection
141          */
142         __u64                     oic_last_attempt;
143 };
144
145 /* state history */
146 #define IMP_STATE_HIST_LEN 16
147 struct import_state_hist {
148         enum lustre_imp_state ish_state;
149         time_t                ish_time;
150 };
151
152 /**
153  * Defintion of PortalRPC import structure.
154  * Imports are representing client-side view to remote target.
155  */
156 struct obd_import {
157         /** Local handle (== id) for this import. */
158         struct portals_handle     imp_handle;
159         /** Reference counter */
160         cfs_atomic_t              imp_refcount;
161         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
162         /** Currently active connection */
163         struct ptlrpc_connection *imp_connection;
164         /** PortalRPC client structure for this import */
165         struct ptlrpc_client     *imp_client;
166         /** List element for linking into pinger chain */
167         cfs_list_t                imp_pinger_chain;
168         /** List element for linking into chain for destruction */
169         cfs_list_t                imp_zombie_chain;
170
171         /**
172          * Lists of requests that are retained for replay, waiting for a reply,
173          * or waiting for recovery to complete, respectively.
174          * @{
175          */
176         cfs_list_t                imp_replay_list;
177         cfs_list_t                imp_sending_list;
178         cfs_list_t                imp_delayed_list;
179         /** @} */
180
181         /** obd device for this import */
182         struct obd_device        *imp_obd;
183
184         /**
185          * some seciruty-related fields
186          * @{
187          */
188         struct ptlrpc_sec        *imp_sec;
189         cfs_semaphore_t           imp_sec_mutex;
190         cfs_time_t                imp_sec_expire;
191         /** @} */
192
193         /** Wait queue for those who need to wait for recovery completion */
194         cfs_waitq_t               imp_recovery_waitq;
195
196         /** Number of requests currently in-flight */
197         cfs_atomic_t              imp_inflight;
198         /** Number of requests currently unregistering */
199         cfs_atomic_t              imp_unregistering;
200         /** Number of replay requests inflight */
201         cfs_atomic_t              imp_replay_inflight;
202         /** Number of currently happening import invalidations */
203         cfs_atomic_t              imp_inval_count;
204         /** Numbner of request timeouts */
205         cfs_atomic_t              imp_timeouts;
206         /** Current import state */
207         enum lustre_imp_state     imp_state;
208         /** History of import states */
209         struct import_state_hist  imp_state_hist[IMP_STATE_HIST_LEN];
210         int                       imp_state_hist_idx;
211         /** Current import generation. Incremented on every reconnect */
212         int                       imp_generation;
213         /** Incremented every time we send reconnection request */
214         __u32                     imp_conn_cnt;
215        /** 
216         * \see ptlrpc_free_committed remembers imp_generation value here
217         * after a check to save on unnecessary replay list iterations
218         */
219         int                       imp_last_generation_checked;
220         /** Last tranno we replayed */
221         __u64                     imp_last_replay_transno;
222         /** Last transno committed on remote side */
223         __u64                     imp_peer_committed_transno;
224         /**
225          * \see ptlrpc_free_committed remembers last_transno since its last
226          * check here and if last_transno did not change since last run of
227          * ptlrpc_free_committed and import generation is the same, we can
228          * skip looking for requests to remove from replay list as optimisation
229          */
230         __u64                     imp_last_transno_checked;
231         /**
232          * Remote export handle. This is how remote side knows what export
233          * we are talking to. Filled from response to connect request
234          */
235         struct lustre_handle      imp_remote_handle;
236         /** When to perform next ping. time in jiffies. */
237         cfs_time_t                imp_next_ping;
238         /** When we last succesfully connected. time in 64bit jiffies */
239         __u64                     imp_last_success_conn;
240
241         /** List of all possible connection for import. */
242         cfs_list_t                imp_conn_list;
243         /**
244          * Current connection. \a imp_connection is imp_conn_current->oic_conn
245          */
246         struct obd_import_conn   *imp_conn_current;
247
248         /** Protects flags, level, generation, conn_cnt, *_list */
249         cfs_spinlock_t            imp_lock;
250
251         /* flags */
252         unsigned long             imp_no_timeout:1,       /* timeouts are disabled */
253                                   imp_invalid:1,          /* evicted */
254                                   imp_deactive:1,         /* administratively disabled */
255                                   imp_replayable:1,       /* try to recover the import */
256                                   imp_dlm_fake:1,         /* don't run recovery (timeout instead) */
257                                   imp_server_timeout:1,   /* use 1/2 timeout on MDS' OSCs */
258                                   imp_delayed_recovery:1, /* VBR: imp in delayed recovery */
259                                   imp_no_lock_replay:1,   /* VBR: if gap was found then no lock replays */
260                                   imp_vbr_failed:1,       /* recovery by versions was failed */
261                                   imp_force_verify:1,     /* force an immidiate ping */
262                                   imp_pingable:1,         /* pingable */
263                                   imp_resend_replay:1,    /* resend for replay */
264                                   imp_force_reconnect:1;  /* import must be reconnected instead of chouse new connection */
265         __u32                     imp_connect_op;
266         struct obd_connect_data   imp_connect_data;
267         __u64                     imp_connect_flags_orig;
268         int                       imp_connect_error;
269
270         __u32                     imp_msg_magic;
271         __u32                     imp_msghdr_flags;       /* adjusted based on server capability */
272
273         struct ptlrpc_request_pool *imp_rq_pool;          /* emergency request pool */
274
275         struct imp_at             imp_at;                 /* adaptive timeout data */
276         time_t                    imp_last_reply_time;    /* for health check */
277 };
278
279 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
280                                     int event, void *event_arg, void *cb_data);
281
282 /**
283  * Structure for import observer.
284  * It is possible to register "observer" on an import and every time
285  * something happens to an import (like connect/evict/disconnect)
286  * obderver will get its callback called with event type
287  */
288 struct obd_import_observer {
289         cfs_list_t           oio_chain;
290         obd_import_callback  oio_cb;
291         void                *oio_cb_data;
292 };
293
294 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
295                           void *cb_data);
296 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
297                             void *cb_data);
298 void class_notify_import_observers(struct obd_import *imp, int event,
299                                    void *event_arg);
300
301 /* import.c */
302 static inline unsigned int at_est2timeout(unsigned int val)
303 {
304         /* add an arbitrary minimum: 125% +5 sec */
305         return (val + (val >> 2) + 5);
306 }
307
308 static inline unsigned int at_timeout2est(unsigned int val)
309 {
310         /* restore estimate value from timeout: e=4/5(t-5) */
311         LASSERT(val);
312         return (max((val << 2) / 5, 5U) - 4);
313 }
314
315 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
316         memset(at, 0, sizeof(*at));
317         at->at_current = val;
318         at->at_worst_ever = val;
319         at->at_worst_time = cfs_time_current_sec();
320         at->at_flags = flags;
321         cfs_spin_lock_init(&at->at_lock);
322 }
323 static inline int at_get(struct adaptive_timeout *at) {
324         return at->at_current;
325 }
326 int at_measured(struct adaptive_timeout *at, unsigned int val);
327 int import_at_get_index(struct obd_import *imp, int portal);
328 extern unsigned int at_max;
329 #define AT_OFF (at_max == 0)
330
331 /* genops.c */
332 struct obd_export;
333 extern struct obd_import *class_exp2cliimp(struct obd_export *);
334 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
335
336 /** @} import */
337
338 #endif /* __IMPORT_H */
339
340 /** @} obd_import */