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