Whamcloud - gitweb
land lustre part of b_hd_sec on HEAD.
[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         
32         static char* import_state_names[] = {
33                 "<UNKNOWN>", "CLOSED",  "NEW", "DISCONN", 
34                 "CONNECTING", "REPLAY", "REPLAY_LOCKS", "REPLAY_WAIT", 
35                 "RECOVER", "FULL", "EVICTED",
36         };
37
38         LASSERT (state <= LUSTRE_IMP_EVICTED);
39         return import_state_names[state];
40 }
41
42 enum obd_import_event {
43         IMP_EVENT_DISCON     = 0x808001,
44         IMP_EVENT_INACTIVE   = 0x808002,
45         IMP_EVENT_INVALIDATE = 0x808003,
46         IMP_EVENT_ACTIVE     = 0x808004,
47 };
48
49 struct ptlrpc_sec;
50
51 struct obd_import_conn {
52         struct list_head          oic_item;
53         struct ptlrpc_connection *oic_conn;
54         struct obd_uuid           oic_uuid;
55         unsigned long             oic_last_attempt; /* in jiffies */
56 };
57
58 struct obd_import {
59         struct portals_handle     imp_handle;
60         atomic_t                  imp_refcount;
61         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
62         struct ptlrpc_connection *imp_connection;
63         struct ptlrpc_client     *imp_client;
64         struct list_head          imp_observers;
65         struct list_head          imp_pinger_chain;
66
67         /* Lists of requests that are retained for replay, waiting for a reply,
68          * or waiting for recovery to complete, respectively.
69          */
70         struct list_head          imp_replay_list;
71         struct list_head          imp_sending_list;
72         struct list_head          imp_delayed_list;
73
74         /* list of ongoing raw rpcs (only used by gss) */
75         struct list_head          imp_rawrpc_list;
76
77         struct obd_device        *imp_obd;
78         struct ptlrpc_sec        *imp_sec;
79         wait_queue_head_t         imp_recovery_waitq;
80         __u64                     imp_last_replay_transno;
81         atomic_t                  imp_inflight;
82         atomic_t                  imp_replay_inflight;
83         enum lustre_imp_state     imp_state;
84         int                       imp_generation;
85         __u32                     imp_conn_cnt;
86         __u64                     imp_max_transno;
87         __u64                     imp_peer_committed_transno;
88         struct obd_uuid           imp_target_uuid; /* XXX -> lustre_name */
89         struct lustre_handle      imp_remote_handle;
90         unsigned long             imp_next_ping;
91         unsigned long             imp_connect_start;
92        
93         /* all available obd_import_conn linked here */
94         struct list_head          imp_conn_list;
95         struct obd_import_conn   *imp_conn_current;
96  
97         /* Protects flags, level, generation, conn_cnt, *_list */
98         spinlock_t                imp_lock;
99
100         /* flags */
101         int                       imp_invalid:1, imp_replayable:1,
102                                   imp_dlm_fake:1, imp_server_timeout:1,
103                                   imp_initial_recov:1, imp_force_verify:1,
104                                   imp_pingable:1, imp_resend_replay:1;
105         __u32                     imp_connect_op;
106         __u32                     imp_connect_flags;
107 };
108
109 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
110                                     int event, void *event_arg, void *cb_data);
111
112 struct obd_import_observer {
113         struct list_head     oio_chain;
114         obd_import_callback  oio_cb;
115         void                *oio_cb_data;
116 };
117
118 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
119                           void *cb_data);
120 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
121                             void *cb_data);
122 void class_notify_import_observers(struct obd_import *imp, int event,
123                                    void *event_arg);
124
125 #define IMP_EVENT_ACTIVE   1
126 #define IMP_EVENT_INACTIVE 2
127
128 /* genops.c */
129 struct obd_export;
130 extern struct obd_import *class_exp2cliimp(struct obd_export *);
131 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
132
133 #endif /* __IMPORT_H */