Whamcloud - gitweb
LU-8508 nodemap: improve object handling in cache saving
[fs/lustre-release.git] / lustre / include / lustre_import.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
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         spinlock_t      at_lock;
71 };
72
73 enum lustre_at_flags {
74         LATF_SKIP       = 0x0,
75         LATF_STATS      = 0x1,
76 };
77
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 */
84 };
85
86 #define IMP_AT_MAX_PORTALS 8
87 struct imp_at {
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];
91 };
92
93
94 /** @} */
95
96 /** Possible import states */
97 enum lustre_imp_state {
98         LUSTRE_IMP_CLOSED     = 1,
99         LUSTRE_IMP_NEW        = 2,
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,
106         LUSTRE_IMP_FULL       = 9,
107         LUSTRE_IMP_EVICTED    = 10,
108 };
109
110 /** Returns test string representation of numeric import state \a state */
111 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
112 {
113         static char* import_state_names[] = {
114                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
115                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
116                 "RECOVER", "FULL", "EVICTED",
117         };
118
119         LASSERT (state <= LUSTRE_IMP_EVICTED);
120         return import_state_names[state];
121 }
122
123 /**
124  * List of import event types
125  */
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,
134 };
135
136 /**
137  * Definition of import connection structure
138  */
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;
146         /**
147          * Time (64 bit jiffies) of last connection attempt on this connection
148          */
149         __u64                     oic_last_attempt;
150 };
151
152 /* state history */
153 #define IMP_STATE_HIST_LEN 16
154 struct import_state_hist {
155         enum lustre_imp_state ish_state;
156         time_t                ish_time;
157 };
158
159 /**
160  * Defintion of PortalRPC import structure.
161  * Imports are representing client-side view to remote target.
162  */
163 struct obd_import {
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;
177
178         /**
179          * Lists of requests that are retained for replay, waiting for a reply,
180          * or waiting for recovery to complete, respectively.
181          * @{
182          */
183         struct list_head        imp_replay_list;
184         struct list_head        imp_sending_list;
185         struct list_head        imp_delayed_list;
186         /** @} */
187
188         /**
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.
193          * @{
194          */
195         struct list_head        imp_committed_list;
196         struct list_head        *imp_replay_cursor;
197         /** @} */
198
199         /** List of not replied requests */
200         struct list_head        imp_unreplied_list;
201         /** Known maximal replied XID */
202         __u64                   imp_known_replied_xid;
203
204         /** obd device for this import */
205         struct obd_device       *imp_obd;
206
207         /**
208          * some seciruty-related fields
209          * @{
210          */
211         struct ptlrpc_sec        *imp_sec;
212         struct mutex              imp_sec_mutex;
213         cfs_time_t                imp_sec_expire;
214         /** @} */
215
216         /** Wait queue for those who need to wait for recovery completion */
217         wait_queue_head_t         imp_recovery_waitq;
218
219         /** Number of requests currently in-flight */
220         atomic_t                  imp_inflight;
221         /** Number of requests currently unregistering */
222         atomic_t                  imp_unregistering;
223         /** Number of replay requests inflight */
224         atomic_t                  imp_replay_inflight;
225         /** Number of currently happening import invalidations */
226         atomic_t                  imp_inval_count;
227         /** Numbner of request timeouts */
228         atomic_t                  imp_timeouts;
229         /** Current import state */
230         enum lustre_imp_state     imp_state;
231         /** Last replay state */
232         enum lustre_imp_state     imp_replay_state;
233         /** History of import states */
234         struct import_state_hist  imp_state_hist[IMP_STATE_HIST_LEN];
235         int                       imp_state_hist_idx;
236         /** Current import generation. Incremented on every reconnect */
237         int                       imp_generation;
238         /** Incremented every time we send reconnection request */
239         __u32                     imp_conn_cnt;
240        /** 
241         * \see ptlrpc_free_committed remembers imp_generation value here
242         * after a check to save on unnecessary replay list iterations
243         */
244         int                       imp_last_generation_checked;
245         /** Last tranno we replayed */
246         __u64                     imp_last_replay_transno;
247         /** Last transno committed on remote side */
248         __u64                     imp_peer_committed_transno;
249         /**
250          * \see ptlrpc_free_committed remembers last_transno since its last
251          * check here and if last_transno did not change since last run of
252          * ptlrpc_free_committed and import generation is the same, we can
253          * skip looking for requests to remove from replay list as optimisation
254          */
255         __u64                     imp_last_transno_checked;
256         /**
257          * Remote export handle. This is how remote side knows what export
258          * we are talking to. Filled from response to connect request
259          */
260         struct lustre_handle      imp_remote_handle;
261         /** When to perform next ping. time in jiffies. */
262         cfs_time_t                imp_next_ping;
263         /** When we last successfully connected. time in 64bit jiffies */
264         __u64                     imp_last_success_conn;
265
266         /** List of all possible connection for import. */
267         struct list_head        imp_conn_list;
268         /**
269          * Current connection. \a imp_connection is imp_conn_current->oic_conn
270          */
271         struct obd_import_conn   *imp_conn_current;
272
273         /** Protects flags, level, generation, conn_cnt, *_list */
274         spinlock_t                imp_lock;
275
276         /* flags */
277         unsigned long             imp_no_timeout:1, /* timeouts are disabled */
278                                   imp_invalid:1,    /* evicted */
279                                   /* administratively disabled */
280                                   imp_deactive:1,
281                                   /* try to recover the import */
282                                   imp_replayable:1,
283                                   /* don't run recovery (timeout instead) */
284                                   imp_dlm_fake:1,
285                                   /* use 1/2 timeout on MDS' OSCs */
286                                   imp_server_timeout:1,
287                                   /* VBR: imp in delayed recovery */
288                                   imp_delayed_recovery:1,
289                                   /* VBR: if gap was found then no lock replays
290                                    */
291                                   imp_no_lock_replay:1,
292                                   /* recovery by versions was failed */
293                                   imp_vbr_failed:1,
294                                   /* force an immidiate ping */
295                                   imp_force_verify:1,
296                                   /* force a scheduled ping */
297                                   imp_force_next_verify:1,
298                                   /* pingable */
299                                   imp_pingable:1,
300                                   /* resend for replay */
301                                   imp_resend_replay:1,
302                                   /* disable normal recovery, for test only. */
303                                   imp_no_pinger_recover:1,
304 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
305                                   /* need IR MNE swab */
306                                   imp_need_mne_swab:1,
307 #endif
308                                   /* import must be reconnected instead of
309                                    * chouse new connection */
310                                   imp_force_reconnect:1,
311                                   /* import has tried to connect with server */
312                                   imp_connect_tried:1,
313                                   /* connected but not FULL yet */
314                                   imp_connected:1;
315         __u32                     imp_connect_op;
316         struct obd_connect_data   imp_connect_data;
317         __u64                     imp_connect_flags_orig;
318         __u64                     imp_connect_flags2_orig;
319         int                       imp_connect_error;
320
321         __u32                     imp_msg_magic;
322                                   /* adjusted based on server capability */
323         __u32                     imp_msghdr_flags;
324
325                                   /* adaptive timeout data */
326         struct imp_at             imp_at;
327         time_t                    imp_last_reply_time;    /* for health check */
328 };
329
330 /* import.c */
331 static inline unsigned int at_est2timeout(unsigned int val)
332 {
333         /* add an arbitrary minimum: 125% +5 sec */
334         return (val + (val >> 2) + 5);
335 }
336
337 static inline unsigned int at_timeout2est(unsigned int val)
338 {
339         /* restore estimate value from timeout: e=4/5(t-5) */
340         LASSERT(val);
341         return (max((val << 2) / 5, 5U) - 4);
342 }
343
344 static inline void at_reset_nolock(struct adaptive_timeout *at, int val)
345 {
346         at->at_current = val;
347         at->at_worst_ever = val;
348         at->at_worst_time = cfs_time_current_sec();
349 }
350
351 static inline void at_reset(struct adaptive_timeout *at, int val)
352 {
353         spin_lock(&at->at_lock);
354         at_reset_nolock(at, val);
355         spin_unlock(&at->at_lock);
356 }
357
358 static inline void at_init(struct adaptive_timeout *at, int val, int flags) {
359         memset(at, 0, sizeof(*at));
360         spin_lock_init(&at->at_lock);
361         at->at_flags = flags;
362         at_reset(at, val);
363 }
364
365 static inline void at_reinit(struct adaptive_timeout *at, int val, int flags)
366 {
367         spin_lock(&at->at_lock);
368         at->at_binstart = 0;
369         memset(at->at_hist, 0, sizeof(at->at_hist));
370         at->at_flags = flags;
371         at_reset_nolock(at, val);
372         spin_unlock(&at->at_lock);
373 }
374
375 extern unsigned int at_min;
376 static inline int at_get(struct adaptive_timeout *at) {
377         return (at->at_current > at_min) ? at->at_current : at_min;
378 }
379 int at_measured(struct adaptive_timeout *at, unsigned int val);
380 int import_at_get_index(struct obd_import *imp, int portal);
381 extern unsigned int at_max;
382 #define AT_OFF (at_max == 0)
383
384 /* genops.c */
385 struct obd_export;
386 extern struct obd_import *class_exp2cliimp(struct obd_export *);
387 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
388
389 /** @} import */
390
391 #endif /* __IMPORT_H */
392
393 /** @} obd_import */