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