Whamcloud - gitweb
c940ac1e377d45ebea10e34cd25adec0bb10039f
[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
43 struct obd_import {
44         struct portals_handle     imp_handle;
45         atomic_t                  imp_refcount;
46         struct lustre_handle      imp_dlm_handle; /* client's ldlm export */
47         struct ptlrpc_connection *imp_connection;
48         struct ptlrpc_client     *imp_client;
49         struct list_head          imp_observers;
50         struct list_head          imp_pinger_chain;
51
52         /* Lists of requests that are retained for replay, waiting for a reply,
53          * or waiting for recovery to complete, respectively.
54          */
55         struct list_head          imp_replay_list;
56         struct list_head          imp_sending_list;
57         struct list_head          imp_delayed_list;
58
59         struct obd_device        *imp_obd;
60         wait_queue_head_t         imp_recovery_waitq;
61         __u64                     imp_last_replay_transno;
62         atomic_t                  imp_replay_inflight;
63         enum lustre_imp_state     imp_state;
64         int                       imp_generation;
65         __u32                     imp_conn_cnt;
66         __u64                     imp_max_transno;
67         __u64                     imp_peer_committed_transno;
68         struct obd_uuid           imp_target_uuid; /* XXX -> lustre_name */
69         struct lustre_handle      imp_remote_handle;
70         unsigned long             imp_next_ping;
71         
72         /* Protects flags, level, generation, conn_cnt, *_list */
73         spinlock_t                imp_lock;
74
75         /* flags */
76         int                       imp_invalid:1, imp_replayable:1,
77                                   imp_dlm_fake:1, imp_server_timeout:1,
78                                   imp_initial_recov:1;
79         __u32                     imp_connect_op;
80 };
81
82 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
83                                     int event, void *event_arg, void *cb_data);
84
85 struct obd_import_observer {
86         struct list_head     oio_chain;
87         obd_import_callback  oio_cb;
88         void                *oio_cb_data;
89 };
90
91 void class_observe_import(struct obd_import *imp, obd_import_callback cb,
92                           void *cb_data);
93 void class_unobserve_import(struct obd_import *imp, obd_import_callback cb,
94                             void *cb_data);
95 void class_notify_import_observers(struct obd_import *imp, int event,
96                                    void *event_arg);
97
98 #define IMP_EVENT_ACTIVE   1
99 #define IMP_EVENT_INACTIVE 2
100
101 /* genops.c */
102 struct obd_export;
103 extern struct obd_import *class_exp2cliimp(struct obd_export *);
104 extern struct obd_import *class_conn2cliimp(struct lustre_handle *);
105
106 #endif /* __IMPORT_H */