Whamcloud - gitweb
72a83afc7471182828fa42a95efffa8eac9679a9
[fs/lustre-release.git] / lustre / include / lustre_export.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __EXPORT_H
38 #define __EXPORT_H
39
40 #include <lprocfs_status.h>
41 #include <lustre/lustre_idl.h>
42 #include <lustre_dlm.h>
43 #include <class_hash.h>
44
45 struct mds_client_data;
46 struct mdt_client_data;
47 struct mds_idmap_table;
48 struct mdt_idmap_table;
49
50 struct lu_export_data {
51         /** Protects led_lcd below */
52         struct semaphore        led_lcd_lock;
53         /** Per-client data for each export */
54         struct lsd_client_data *led_lcd;
55         /** Offset of record in last_rcvd file */
56         loff_t                  led_lr_off;
57         /** Client index in last_rcvd file */
58         int                     led_lr_idx;
59 };
60
61 struct mdt_export_data {
62         struct lu_export_data   med_led;
63         struct list_head        med_open_head;
64         spinlock_t              med_open_lock; /* lock med_open_head, mfd_list*/
65         __u64                   med_ibits_known;
66         struct semaphore           med_idmap_sem;
67         struct lustre_idmap_table *med_idmap;
68 };
69
70 #define med_lcd_lock    med_led.led_lcd_lock
71 #define med_lcd         med_led.led_lcd
72 #define med_lr_off      med_led.led_lr_off
73 #define med_lr_idx      med_led.led_lr_idx
74
75 struct osc_creator {
76         spinlock_t              oscc_lock;
77         struct list_head        oscc_wait_create_list;
78         struct obd_device       *oscc_obd;
79         obd_id                  oscc_last_id;//last available pre-created object
80         obd_id                  oscc_next_id;// what object id to give out next
81         int                     oscc_grow_count;
82         /**
83          * Limit oscc_grow_count value, can be changed via proc fs
84          */
85         int                     oscc_max_grow_count;
86         struct obdo             oscc_oa;
87         int                     oscc_flags;
88         cfs_waitq_t             oscc_waitq; /* creating procs wait on this */
89 };
90
91 struct ec_export_data { /* echo client */
92         struct list_head eced_locks;
93 };
94
95 /* In-memory access to client data from OST struct */
96 struct filter_export_data {
97         struct lu_export_data      fed_led;
98         spinlock_t                 fed_lock;     /**< protects fed_mod_list */
99         long                       fed_dirty;    /* in bytes */
100         long                       fed_grant;    /* in bytes */
101         struct list_head           fed_mod_list; /* files being modified */
102         int                        fed_mod_count;/* items in fed_writing list */
103         long                       fed_pending;  /* bytes just being written */
104         __u32                      fed_group;
105 };
106
107 #define fed_lcd_lock    fed_led.led_lcd_lock
108 #define fed_lcd         fed_led.led_lcd
109 #define fed_lr_off      fed_led.led_lr_off
110 #define fed_lr_idx      fed_led.led_lr_idx
111
112 typedef struct nid_stat {
113         lnet_nid_t               nid;
114         struct hlist_node        nid_hash;
115         struct list_head         nid_list;
116         struct obd_device       *nid_obd;
117         struct proc_dir_entry   *nid_proc;
118         struct lprocfs_stats    *nid_stats;
119         struct lprocfs_stats    *nid_ldlm_stats;
120         struct brw_stats        *nid_brw_stats;
121         atomic_t                 nid_exp_ref_count; /* for obd_nid_stats_hash
122                                                            exp_nid_stats */
123 }nid_stat_t;
124
125 #define nidstat_getref(nidstat)                                                \
126 do {                                                                           \
127         atomic_inc(&(nidstat)->nid_exp_ref_count);                             \
128 } while(0)
129
130 #define nidstat_putref(nidstat)                                                \
131 do {                                                                           \
132         atomic_dec(&(nidstat)->nid_exp_ref_count);                             \
133         LASSERTF(atomic_read(&(nidstat)->nid_exp_ref_count) >= 0,              \
134                  "stat %p nid_exp_ref_count < 0\n", nidstat);                  \
135 } while(0)
136
137 enum obd_option {
138         OBD_OPT_FORCE =         0x0001,
139         OBD_OPT_FAILOVER =      0x0002,
140         OBD_OPT_ABORT_RECOV =   0x0004,
141 };
142
143 struct obd_export {
144         struct portals_handle     exp_handle;
145         atomic_t                  exp_refcount;
146         /**
147          * Set of counters below is to track where export references are
148          * kept. The exp_rpc_count is used for reconnect handling also,
149          * the cb_count and locks_count are for debug purposes only for now.
150          * The sum of them should be less than exp_refcount by 3
151          */
152         atomic_t                  exp_rpc_count; /** RPC references */
153         atomic_t                  exp_cb_count; /** Commit callback references */
154         atomic_t                  exp_locks_count; /** Lock references */
155
156         atomic_t                  exp_replay_count;
157         struct obd_uuid           exp_client_uuid;
158         struct list_head          exp_obd_chain;
159         struct hlist_node         exp_uuid_hash; /* uuid-export hash*/
160         struct hlist_node         exp_nid_hash; /* nid-export hash */
161         /* exp_obd_chain_timed fo ping evictor, protected by obd_dev_lock */
162         struct list_head          exp_obd_chain_timed;
163         struct obd_device        *exp_obd;
164         struct obd_import        *exp_imp_reverse; /* to make RPCs backwards */
165         struct nid_stat          *exp_nid_stats;
166         struct lprocfs_stats     *exp_md_stats;
167         struct ptlrpc_connection *exp_connection;
168         __u32                     exp_conn_cnt;
169         lustre_hash_t            *exp_lock_hash; /* existing lock hash */
170         spinlock_t                exp_lock_hash_lock;
171         struct list_head          exp_outstanding_replies;
172         struct list_head          exp_uncommitted_replies;
173         spinlock_t                exp_uncommitted_replies_lock;
174         __u64                     exp_last_committed;
175         cfs_time_t                exp_last_request_time;
176         struct list_head          exp_req_replay_queue;
177         spinlock_t                exp_lock; /* protects flags int below */
178         /* ^ protects exp_outstanding_replies too */
179         __u64                     exp_connect_flags;
180         enum obd_option           exp_flags;
181         unsigned long             exp_failed:1,
182                                   exp_in_recovery:1,
183                                   exp_disconnected:1,
184                                   exp_connecting:1,
185                                   /** VBR: export missed recovery */
186                                   exp_delayed:1,
187                                   /** VBR: failed version checking */
188                                   exp_vbr_failed:1,
189                                   exp_req_replay_needed:1,
190                                   exp_lock_replay_needed:1,
191                                   exp_need_sync:1,
192                                   exp_flvr_changed:1,
193                                   exp_flvr_adapt:1,
194                                   exp_libclient:1, /* liblustre client? */
195                                   /* client timed out and tried to reconnect,
196                                    * but couldn't because of active rpcs */
197                                   exp_abort_active_req:1;
198         struct list_head          exp_queued_rpc;  /* RPC to be handled */
199         /* also protected by exp_lock */
200         enum lustre_sec_part      exp_sp_peer;
201         struct sptlrpc_flavor     exp_flvr;             /* current */
202         struct sptlrpc_flavor     exp_flvr_old[2];      /* about-to-expire */
203         cfs_time_t                exp_flvr_expire[2];   /* seconds */
204
205         union {
206                 struct lu_export_data     eu_target_data;
207                 struct mdt_export_data    eu_mdt_data;
208                 struct filter_export_data eu_filter_data;
209                 struct ec_export_data     eu_ec_data;
210         } u;
211 };
212
213 #define exp_target_data u.eu_target_data
214 #define exp_mdt_data    u.eu_mdt_data
215 #define exp_filter_data u.eu_filter_data
216 #define exp_ec_data     u.eu_ec_data
217
218 static inline int exp_expired(struct obd_export *exp, cfs_duration_t age)
219 {
220         LASSERT(exp->exp_delayed);
221         return cfs_time_before(cfs_time_add(exp->exp_last_request_time, age),
222                                cfs_time_current_sec());
223 }
224
225 static inline int exp_connect_cancelset(struct obd_export *exp)
226 {
227         LASSERT(exp != NULL);
228         return !!(exp->exp_connect_flags & OBD_CONNECT_CANCELSET);
229 }
230
231 static inline int exp_connect_lru_resize(struct obd_export *exp)
232 {
233         LASSERT(exp != NULL);
234         return !!(exp->exp_connect_flags & OBD_CONNECT_LRU_RESIZE);
235 }
236
237 static inline int exp_connect_rmtclient(struct obd_export *exp)
238 {
239         LASSERT(exp != NULL);
240         return !!(exp->exp_connect_flags & OBD_CONNECT_RMT_CLIENT);
241 }
242
243 static inline int client_is_remote(struct obd_export *exp)
244 {
245         struct obd_import *imp = class_exp2cliimp(exp);
246
247         return !!(imp->imp_connect_data.ocd_connect_flags &
248                   OBD_CONNECT_RMT_CLIENT);
249 }
250
251 static inline int exp_connect_vbr(struct obd_export *exp)
252 {
253         LASSERT(exp != NULL);
254         LASSERT(exp->exp_connection);
255         return !!(exp->exp_connect_flags & OBD_CONNECT_VBR);
256 }
257
258 static inline int exp_connect_som(struct obd_export *exp)
259 {
260         LASSERT(exp != NULL);
261         return !!(exp->exp_connect_flags & OBD_CONNECT_SOM);
262 }
263
264 static inline int imp_connect_lru_resize(struct obd_import *imp)
265 {
266         struct obd_connect_data *ocd;
267
268         LASSERT(imp != NULL);
269         ocd = &imp->imp_connect_data;
270         return !!(ocd->ocd_connect_flags & OBD_CONNECT_LRU_RESIZE);
271 }
272
273 extern struct obd_export *class_conn2export(struct lustre_handle *conn);
274 extern struct obd_device *class_conn2obd(struct lustre_handle *conn);
275
276 #endif /* __EXPORT_H */