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