Whamcloud - gitweb
b=3055
[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
5 #ifndef __IMPORT_H
6 #define __IMPORT_H
7
8 #include <lustre_handles.h>
9 #include <lustre/lustre_idl.h>
10
11
12 /* Adaptive Timeout stuff */
13 #define D_ADAPTTO D_OTHER
14 #define AT_BINS 4                  /* "bin" means "N seconds of history" */
15 #define AT_TIMEBASE_DEFAULT 600    /* remembered history (sec) (should be
16                                       evenly divisible by AT_BINS) */
17 #define AT_FLG_NOHIST 0x1          /* use last reported value only */
18 #define AT_FLG_MIN    0x2          /* use a minimum limit */
19
20 struct adaptive_timeout {
21         time_t       at_binstart;         /* bin start time */
22         time_t       at_binlimit;         /* bin time limit */
23         unsigned int at_hist[AT_BINS];    /* timeout history bins */
24         unsigned int at_flags;
25         unsigned int at_current;          /* current timeout value */
26         unsigned int at_worst_ever;       /* worst-ever timeout value */
27         time_t       at_worst_time;       /* worst-ever timeout timestamp */
28         spinlock_t   at_lock;
29 };
30
31 enum lustre_imp_state {
32         LUSTRE_IMP_CLOSED     = 1,
33         LUSTRE_IMP_NEW        = 2,
34         LUSTRE_IMP_DISCON     = 3,
35         LUSTRE_IMP_CONNECTING = 4,
36         LUSTRE_IMP_REPLAY     = 5,
37         LUSTRE_IMP_REPLAY_LOCKS = 6,
38         LUSTRE_IMP_REPLAY_WAIT  = 7,
39         LUSTRE_IMP_RECOVER    = 8,
40         LUSTRE_IMP_FULL       = 9,
41         LUSTRE_IMP_EVICTED    = 10,
42 };
43
44 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
45 {
46         static char* import_state_names[] = {
47                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
48                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
49                 "RECOVER", "FULL", "EVICTED",
50         };
51
52         LASSERT (state <= LUSTRE_IMP_EVICTED);
53         return import_state_names[state];
54 }
55
56 enum obd_import_event {
57         IMP_EVENT_DISCON     = 0x808001,
58         IMP_EVENT_INACTIVE   = 0x808002,
59         IMP_EVENT_INVALIDATE = 0x808003,
60         IMP_EVENT_ACTIVE     = 0x808004,
61         IMP_EVENT_OCD        = 0x808005,
62 };
63
64 struct obd_import_conn {
65         struct list_head          oic_item;
66         struct ptlrpc_connection *oic_conn;
67         struct obd_uuid           oic_uuid;
68         __u64                     oic_last_attempt; /* jiffies, 64-bit */
69 };
70
71 #define IMP_AT_MAX_PORTALS 4
72 struct imp_at {
73         int                     iat_portal[IMP_AT_MAX_PORTALS];
74         struct adaptive_timeout iat_net_latency;
75         struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
76         time_t                  iat_drain; /* hack to slow reconnect reqs */
77 };
78
79 struct obd_import {
80         struct portals_handle     imp_handle;
81         atomic_t                  imp_refcount;
82         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
83         struct ptlrpc_connection *imp_connection;
84         struct ptlrpc_client     *imp_client;
85         struct list_head          imp_pinger_chain;
86         struct list_head          imp_zombie_chain; /* queue for destruction */
87
88         /* Lists of requests that are retained for replay, waiting for a reply,
89          * or waiting for recovery to complete, respectively.
90          */
91         struct list_head          imp_replay_list;
92         struct list_head          imp_sending_list;
93         struct list_head          imp_delayed_list;
94
95         struct obd_device        *imp_obd;
96         cfs_waitq_t               imp_recovery_waitq;
97
98         atomic_t                  imp_inflight;
99         atomic_t                  imp_replay_inflight;
100         atomic_t                  imp_inval_count;
101         enum lustre_imp_state     imp_state;
102         int                       imp_generation;
103         __u32                     imp_conn_cnt;
104         int                       imp_last_generation_checked;
105         __u64                     imp_last_replay_transno;
106         __u64                     imp_peer_committed_transno;
107         __u64                     imp_last_transno_checked;
108         struct lustre_handle      imp_remote_handle;
109         cfs_time_t                imp_next_ping;   /* jiffies */
110         __u64                     imp_last_success_conn;   /* jiffies, 64-bit */
111
112         /* all available obd_import_conn linked here */
113         struct list_head          imp_conn_list;
114         struct obd_import_conn   *imp_conn_current;
115
116         /* Protects flags, level, generation, conn_cnt, *_list */
117         spinlock_t                imp_lock;
118
119         /* flags */
120         unsigned int              imp_invalid:1,          /* evicted */
121                                   imp_deactive:1,         /* administratively disabled */
122                                   imp_replayable:1,       /* try to recover the import */
123                                   imp_dlm_fake:1,         /* don't run recovery (timeout instead) */
124                                   imp_server_timeout:1,   /* use 1/2 timeout on MDS' OSCs */
125                                   imp_initial_recov:1,    /* retry the initial connection */  
126                                   imp_initial_recov_bk:1, /* turn off init_recov after trying all failover nids */
127                                   imp_force_verify:1,     /* force an immidiate ping */
128                                   imp_pingable:1,         /* pingable */
129                                   imp_resend_replay:1,    /* resend for replay */
130                                   imp_recon_bk:1,         /* turn off reconnect if all failovers fail */
131                                   imp_last_recon:1;       /* internally used by above */
132         __u32                     imp_connect_op;
133         struct obd_connect_data   imp_connect_data;
134         __u64                     imp_connect_flags_orig;
135
136         __u32                     imp_msg_magic;
137         __u32                     imp_msg_flags;          /* adjusted based on server capability */
138
139         struct ptlrpc_request_pool *imp_rq_pool;          /* emergency request pool */
140
141         struct imp_at             imp_at;                 /* adaptive timeout data */
142         time_t                    imp_last_reply_time;    /* for health check */
143 };
144
145 /* import.c */
146 static inline void at_init(struct adaptive_timeout *at, int val, int timebase,
147                            int flags) {
148         memset(at, 0, sizeof(*at));
149         at->at_binlimit = timebase / AT_BINS;
150         at->at_current = val;
151         at->at_worst_ever = val;
152         at->at_worst_time = cfs_time_current_sec();
153         at->at_flags = flags;
154         spin_lock_init(&at->at_lock);
155 }
156 static inline int at_get(struct adaptive_timeout *at) {
157         extern unsigned int adaptive_timeout_max;
158         if (adaptive_timeout_max)
159                 return min(at->at_current, adaptive_timeout_max);
160         return at->at_current;
161 }
162 void at_add(struct adaptive_timeout *at, unsigned int val);
163 int import_at_get_index(struct obd_import *imp, int portal);
164 int import_at_get_ldlm(struct obd_import *imp);
165 #define AT_OFF (adaptive_timeout_max == 0)
166
167 /* genops.c */
168 struct obd_export;
169 extern struct obd_import *class_exp2cliimp(struct obd_export *);
170 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
171
172 #endif /* __IMPORT_H */