Whamcloud - gitweb
b=6019
[fs/lustre-release.git] / lustre / include / linux / lustre_import.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001  Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef __IMPORT_H
11 #define __IMPORT_H
12
13 #include <linux/lustre_handles.h>
14 #include <linux/lustre_idl.h>
15
16 enum lustre_imp_state {
17         LUSTRE_IMP_CLOSED     = 1,
18         LUSTRE_IMP_NEW        = 2,
19         LUSTRE_IMP_DISCON     = 3,
20         LUSTRE_IMP_CONNECTING = 4,
21         LUSTRE_IMP_REPLAY     = 5,
22         LUSTRE_IMP_REPLAY_LOCKS = 6,
23         LUSTRE_IMP_REPLAY_WAIT  = 7,
24         LUSTRE_IMP_RECOVER    = 8,
25         LUSTRE_IMP_FULL       = 9,
26         LUSTRE_IMP_EVICTED    = 10,
27 };
28
29 static inline char * ptlrpc_import_state_name(enum lustre_imp_state state)
30 {
31         static char* import_state_names[] = {
32                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN",
33                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT",
34                 "RECOVER", "FULL", "EVICTED",
35         };
36
37         LASSERT (state <= LUSTRE_IMP_EVICTED);
38         return import_state_names[state];
39 }
40
41 enum obd_import_event {
42         IMP_EVENT_DISCON     = 0x808001,
43         IMP_EVENT_INACTIVE   = 0x808002,
44         IMP_EVENT_INVALIDATE = 0x808003,
45         IMP_EVENT_ACTIVE     = 0x808004,
46 };
47
48 struct ptlrpc_sec;
49
50 struct obd_import_conn {
51         struct list_head          oic_item;
52         struct ptlrpc_connection *oic_conn;
53         struct obd_uuid           oic_uuid;
54         unsigned long             oic_last_attempt; /* in jiffies */
55 };
56
57 struct obd_import {
58         struct portals_handle     imp_handle;
59         atomic_t                  imp_refcount;
60         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
61         struct ptlrpc_connection *imp_connection;
62         struct ptlrpc_client     *imp_client;
63         struct list_head          imp_observers;
64         struct list_head          imp_pinger_chain;
65
66         /* Lists of requests that are retained for replay, waiting for a reply,
67          * or waiting for recovery to complete, respectively.
68          */
69         struct list_head          imp_replay_list;
70         struct list_head          imp_sending_list;
71         struct list_head          imp_delayed_list;
72
73         /* list of ongoing raw rpcs (only used by gss) */
74         struct list_head          imp_rawrpc_list;
75
76         struct obd_device        *imp_obd;
77         struct ptlrpc_sec        *imp_sec;
78         wait_queue_head_t         imp_recovery_waitq;
79         __u64                     imp_last_replay_transno;
80         atomic_t                  imp_inflight;
81         atomic_t                  imp_replay_inflight;
82         enum lustre_imp_state     imp_state;
83         int                       imp_generation;
84         __u32                     imp_conn_cnt;
85         __u64                     imp_max_transno;
86         __u64                     imp_peer_committed_transno;
87         struct obd_uuid           imp_target_uuid; /* XXX -> lustre_name */
88         struct lustre_handle      imp_remote_handle;
89         unsigned long             imp_next_ping;
90         unsigned long             imp_connect_start;
91        
92         /* all available obd_import_conn linked here */
93         struct list_head          imp_conn_list;
94         struct obd_import_conn   *imp_conn_current;
95  
96         /* Protects flags, level, generation, conn_cnt, *_list */
97         spinlock_t                imp_lock;
98
99         /* flags */
100         int                       imp_invalid:1, imp_replayable:1,
101                                   imp_dlm_fake:1, imp_server_timeout:1,
102                                   imp_initial_recov:1, imp_force_verify:1,
103                                   imp_pingable:1, imp_resend_replay:1,
104                                   imp_deactive:1,
105                                   imp_waiting_ping_reply:1;
106         __u32                     imp_connect_op;
107         __u32                     imp_connect_flags;
108         struct obd_connect_data   imp_connect_data;
109
110         unsigned long             imp_last_ping_xid;
111         int                       imp_reqs_replayed;
112         int                       imp_locks_replayed;
113 };
114
115 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
116                                     int event, void *event_arg, void *cb_data);
117
118 struct obd_import_observer {
119         struct list_head     oio_chain;
120         obd_import_callback  oio_cb;
121         void                *oio_cb_data;
122 };
123
124 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
125                           void *cb_data);
126 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
127                             void *cb_data);
128 void class_notify_import_observers(struct obd_import *imp, int event,
129                                    void *event_arg);
130
131 #define IMP_EVENT_ACTIVE   1
132 #define IMP_EVENT_INACTIVE 2
133
134 /* genops.c */
135 struct obd_export;
136 extern struct obd_import *class_exp2cliimp(struct obd_export *);
137 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
138
139 #endif /* __IMPORT_H */