Whamcloud - gitweb
LU-5814 obd: remove unused LSM parameters
[fs/lustre-release.git] / lustre / include / obd_class.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2014, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #ifndef __CLASS_OBD_H
37 #define __CLASS_OBD_H
38
39
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
43 #include <obd.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
47
48 #define OBD_STATFS_NODELAY      0x0001  /* requests should be send without delay
49                                          * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE   0x0002  /* the statfs callback should not update
51                                          * obd_osfs_age */
52 #define OBD_STATFS_PTLRPCD      0x0004  /* requests will be sent via ptlrpcd
53                                          * instead of a specific set. This
54                                          * means that we cannot rely on the set
55                                          * interpret routine to be called.
56                                          * lov_statfs_fini() must thus be called
57                                          * by the request interpret routine */
58 #define OBD_STATFS_FOR_MDT0     0x0008  /* The statfs is only for retrieving
59                                          * information from MDT0. */
60
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern struct list_head obd_types;
64 extern spinlock_t obd_types_lock;
65 extern rwlock_t obd_dev_lock;
66
67 /* OBD Operations Declarations */
68 extern struct obd_device *class_conn2obd(struct lustre_handle *);
69 extern struct obd_device *class_exp2obd(struct obd_export *);
70 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
71 extern int lustre_get_jobid(char *jobid);
72
73 struct lu_device_type;
74
75 /* genops.c */
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
78                         struct lprocfs_vars *module_vars,
79                         const char *nm, struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
81
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
84
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91                                           const char * typ_name,
92                                           struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
94                                            int *next);
95 struct obd_device * class_num2obd(int num);
96 int get_devices_count(void);
97
98 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
99
100 char *obd_export_nid2str(struct obd_export *exp);
101
102 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
103 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
105
106 int obd_zombie_impexp_init(void);
107 void obd_zombie_impexp_stop(void);
108 void obd_zombie_impexp_cull(void);
109 void obd_zombie_barrier(void);
110 void obd_exports_barrier(struct obd_device *obd);
111 int kuc_len(int payload_len);
112 struct kuc_hdr * kuc_ptr(void *p);
113 int kuc_ispayload(void *p);
114 void *kuc_alloc(int payload_len, int transport, int type);
115 void kuc_free(void *p, int payload_len);
116 int obd_get_request_slot(struct client_obd *cli);
117 void obd_put_request_slot(struct client_obd *cli);
118 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
119 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
120
121 struct llog_handle;
122 struct llog_rec_hdr;
123 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
124                          struct llog_rec_hdr *, void *);
125 /* obd_config.c */
126 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
127                                      const char *new_name);
128 int class_process_config(struct lustre_cfg *lcfg);
129 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
130                              struct lustre_cfg *lcfg, void *data);
131 int class_attach(struct lustre_cfg *lcfg);
132 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
133 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
134 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
135 struct obd_device *class_incref(struct obd_device *obd,
136                                 const char *scope, const void *source);
137 void class_decref(struct obd_device *obd,
138                   const char *scope, const void *source);
139 void dump_exports(struct obd_device *obd, int locks);
140 int class_config_llog_handler(const struct lu_env *env,
141                               struct llog_handle *handle,
142                               struct llog_rec_hdr *rec, void *data);
143 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
144 int class_add_uuid(const char *uuid, __u64 nid);
145
146 #define CFG_F_START     0x01   /* Set when we start updating from a log */
147 #define CFG_F_MARKER    0x02   /* We are within a maker */
148 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
149 #define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
150 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
151
152 /* Passed as data param to class_config_parse_llog */
153 struct config_llog_instance {
154         char                    *cfg_obdname;
155         void                    *cfg_instance;
156         struct super_block      *cfg_sb;
157         struct obd_uuid          cfg_uuid;
158         llog_cb_t                cfg_callback;
159         int                      cfg_last_idx; /* for partial llog processing */
160         int                      cfg_flags;
161         __u32                    cfg_lwp_idx;
162 };
163 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
164                             char *name, struct config_llog_instance *cfg);
165 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
166                            char *name, struct config_llog_instance *cfg);
167
168 enum {
169         CONFIG_T_CONFIG  = 0,
170         CONFIG_T_SPTLRPC = 1,
171         CONFIG_T_RECOVER = 2,
172         CONFIG_T_PARAMS  = 3,
173         CONFIG_T_MAX     = 4
174 };
175
176 #define PARAMS_FILENAME "params"
177 #define LCTL_UPCALL     "lctl"
178
179 /* list of active configuration logs  */
180 struct config_llog_data {
181         struct ldlm_res_id          cld_resid;
182         struct config_llog_instance cld_cfg;
183         struct list_head            cld_list_chain;
184         atomic_t                    cld_refcount;
185         struct config_llog_data    *cld_sptlrpc;/* depended sptlrpc log */
186         struct config_llog_data    *cld_params; /* common parameters log */
187         struct config_llog_data    *cld_recover;/* imperative recover log */
188         struct obd_export          *cld_mgcexp;
189         struct mutex                cld_lock;
190         int                         cld_type;
191         unsigned int                cld_stopping:1, /* we were told to stop
192                                                      * watching */
193                                     cld_lostlock:1; /* lock not requeued */
194         char                        cld_logname[0];
195 };
196
197 struct lustre_profile {
198         struct list_head         lp_list;
199         char                    *lp_profile;
200         char                    *lp_dt;
201         char                    *lp_md;
202 };
203
204 struct lustre_profile *class_get_profile(const char * prof);
205 void class_del_profile(const char *prof);
206 void class_del_profiles(void);
207
208 #if LUSTRE_TRACKS_LOCK_EXP_REFS
209
210 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
211 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
212 extern void (*class_export_dump_hook)(struct obd_export *);
213
214 #else
215
216 #define __class_export_add_lock_ref(exp, lock)             do {} while(0)
217 #define __class_export_del_lock_ref(exp, lock)             do {} while(0)
218
219 #endif
220
221 #define class_export_rpc_inc(exp)                                       \
222 ({                                                                      \
223         atomic_inc(&(exp)->exp_rpc_count);                              \
224         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
225                (exp), atomic_read(&(exp)->exp_rpc_count));              \
226 })
227
228 #define class_export_rpc_dec(exp)                                       \
229 ({                                                                      \
230         LASSERT_ATOMIC_POS(&exp->exp_rpc_count);                        \
231         atomic_dec(&(exp)->exp_rpc_count);                              \
232         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
233                (exp), atomic_read(&(exp)->exp_rpc_count));              \
234 })
235
236 #define class_export_lock_get(exp, lock)                                \
237 ({                                                                      \
238         atomic_inc(&(exp)->exp_locks_count);                            \
239         __class_export_add_lock_ref(exp, lock);                         \
240         CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
241                (exp), atomic_read(&(exp)->exp_locks_count));            \
242         class_export_get(exp);                                          \
243 })
244
245 #define class_export_lock_put(exp, lock)                                \
246 ({                                                                      \
247         LASSERT_ATOMIC_POS(&exp->exp_locks_count);                      \
248         atomic_dec(&(exp)->exp_locks_count);                            \
249         __class_export_del_lock_ref(exp, lock);                         \
250         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
251                (exp), atomic_read(&(exp)->exp_locks_count));            \
252         class_export_put(exp);                                          \
253 })
254
255 #define class_export_cb_get(exp)                                        \
256 ({                                                                      \
257         atomic_inc(&(exp)->exp_cb_count);                               \
258         CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
259                (exp), atomic_read(&(exp)->exp_cb_count));               \
260         class_export_get(exp);                                          \
261 })
262
263 #define class_export_cb_put(exp)                                        \
264 ({                                                                      \
265         LASSERT_ATOMIC_POS(&exp->exp_cb_count);                         \
266         atomic_dec(&(exp)->exp_cb_count);                               \
267         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
268                (exp), atomic_read(&(exp)->exp_cb_count));               \
269         class_export_put(exp);                                          \
270 })
271
272 /* genops.c */
273 struct obd_export *class_export_get(struct obd_export *exp);
274 void class_export_put(struct obd_export *exp);
275 struct obd_export *class_new_export(struct obd_device *obddev,
276                                     struct obd_uuid *cluuid);
277 void class_unlink_export(struct obd_export *exp);
278
279 struct obd_import *class_import_get(struct obd_import *);
280 void class_import_put(struct obd_import *);
281 struct obd_import *class_new_import(struct obd_device *obd);
282 void class_destroy_import(struct obd_import *exp);
283
284 struct obd_type *class_search_type(const char *name);
285 struct obd_type *class_get_type(const char *name);
286 void class_put_type(struct obd_type *type);
287 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
288                   struct obd_uuid *cluuid);
289 int class_disconnect(struct obd_export *exp);
290 void class_fail_export(struct obd_export *exp);
291 int class_connected_export(struct obd_export *exp);
292 void class_disconnect_exports(struct obd_device *obddev);
293 int class_manual_cleanup(struct obd_device *obd);
294 void class_disconnect_stale_exports(struct obd_device *,
295                                     int (*test_export)(struct obd_export *));
296 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
297 {
298         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
299                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
300                 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
301                 0);
302 }
303
304 #ifdef HAVE_SERVER_SUPPORT
305 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
306 {
307         LASSERT(exp->exp_obd);
308         return exp->exp_obd->u.obt.obt_lut;
309 }
310
311 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
312 {
313         LASSERT(obd->u.obt.obt_lut);
314         return &obd->u.obt.obt_lut->lut_lsd;
315 }
316 #endif
317
318 /* obdo.c */
319 struct lu_attr;
320 struct inode;
321
322 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
323 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
324
325 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
326 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
327
328 #define OBT(dev)        (dev)->obd_type
329 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
330 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
331 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
332
333 /* Ensure obd_setup: used for cleanup which must be called
334    while obd is stopping */
335 #define OBD_CHECK_DEV(obd)                                      \
336 do {                                                            \
337         if (!(obd)) {                                           \
338                 CERROR("NULL device\n");                        \
339                 RETURN(-ENODEV);                                \
340         }                                                       \
341 } while (0)
342
343 /* ensure obd_setup and !obd_stopping */
344 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
345 do {                                                            \
346         OBD_CHECK_DEV(obd);                                     \
347         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
348                 CERROR("Device %d not setup\n",                 \
349                        (obd)->obd_minor);                       \
350                 RETURN(-ENODEV);                                \
351         }                                                       \
352 } while (0)
353
354
355 #ifdef CONFIG_PROC_FS
356 #define OBD_COUNTER_OFFSET(op)                                                 \
357         ((offsetof(struct obd_ops, o_ ## op) -                                 \
358           offsetof(struct obd_ops, o_iocontrol))                               \
359          / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
360
361 /* The '- 1' below is for o_owner. */
362 #define NUM_OBD_STATS                                                          \
363         (sizeof(struct obd_ops) /                                              \
364          sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
365
366 #define OBD_COUNTER_INCREMENT(obd, op)                                         \
367         lprocfs_counter_incr((obd)->obd_stats,                                 \
368                              (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
369
370 #define EXP_COUNTER_INCREMENT(exp, op)                                         \
371         do {                                                                   \
372                 unsigned int _off;                                             \
373                 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
374                 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off);         \
375                 if ((exp)->exp_obd->obd_uses_nid_stats &&                      \
376                     (exp)->exp_nid_stats != NULL)                              \
377                         lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats,  \
378                                              _off);                            \
379         } while (0)
380
381 #define _MD_COUNTER_OFFSET(m_op)                                               \
382         ((offsetof(struct md_ops, m_op) -                                      \
383           offsetof(struct md_ops, MD_STATS_FIRST_OP)) /                        \
384          sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
385
386 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
387
388 #define NUM_MD_STATS                                                           \
389         (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) -                                \
390          _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
391
392 /* Note that we only increment md counters for ops whose offset is less
393  * than NUM_MD_STATS. This is explained in a comment in the definition
394  * of struct md_ops. */
395 #define EXP_MD_COUNTER_INCREMENT(exp, op)                                      \
396         do {                                                                   \
397                 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS)                      \
398                         lprocfs_counter_incr((exp)->exp_obd->obd_md_stats,     \
399                                         (exp)->exp_obd->obd_md_cntr_base +     \
400                                         MD_COUNTER_OFFSET(op));                \
401         } while (0)
402
403 #else
404 #define OBD_COUNTER_OFFSET(op)
405 #define OBD_COUNTER_INCREMENT(obd, op)
406 #define EXP_COUNTER_INCREMENT(exp, op)
407 #define EXP_MD_COUNTER_INCREMENT(exp, op)
408 #endif
409
410 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
411 {
412         /* Always add in ldlm_stats */
413         tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
414                                                   ,LPROCFS_STATS_FLAG_NOPERCPU);
415         if (tmp->nid_ldlm_stats == NULL)
416                 return -ENOMEM;
417
418         lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
419
420         return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
421                                       tmp->nid_ldlm_stats);
422 }
423
424 #define EXP_CHECK_MD_OP(exp, op)                                \
425 do {                                                            \
426         if ((exp) == NULL) {                                    \
427                 CERROR("obd_" #op ": NULL export\n");           \
428                 RETURN(-ENODEV);                                \
429         }                                                       \
430         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
431                 CERROR("obd_" #op ": cleaned up obd\n");        \
432                 RETURN(-EOPNOTSUPP);                            \
433         }                                                       \
434         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
435                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
436                        (exp)->exp_obd->obd_name,                \
437                        (exp)->exp_obd->obd_minor);              \
438                 RETURN(-EOPNOTSUPP);                            \
439         }                                                       \
440 } while (0)
441
442
443 #define OBD_CHECK_DT_OP(obd, op, err)                           \
444 do {                                                            \
445         if (!OBT(obd) || !OBP((obd), op)) {                     \
446                 if (err)                                        \
447                         CERROR("obd_" #op ": dev %d no operation\n",    \
448                                obd->obd_minor);                 \
449                 RETURN(err);                                    \
450         }                                                       \
451 } while (0)
452
453 #define EXP_CHECK_DT_OP(exp, op)                                \
454 do {                                                            \
455         if ((exp) == NULL) {                                    \
456                 CERROR("obd_" #op ": NULL export\n");           \
457                 RETURN(-ENODEV);                                \
458         }                                                       \
459         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
460                 CERROR("obd_" #op ": cleaned up obd\n");        \
461                 RETURN(-EOPNOTSUPP);                            \
462         }                                                       \
463         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
464                 CERROR("obd_" #op ": dev %d no operation\n",    \
465                        (exp)->exp_obd->obd_minor);              \
466                 RETURN(-EOPNOTSUPP);                            \
467         }                                                       \
468 } while (0)
469
470 #define CTXT_CHECK_OP(ctxt, op, err)                                 \
471 do {                                                                 \
472         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
473                 if (err)                                             \
474                         CERROR("lop_" #op ": dev %d no operation\n", \
475                                ctxt->loc_obd->obd_minor);            \
476                 RETURN(err);                                         \
477         }                                                            \
478 } while (0)
479
480 static inline int class_devno_max(void)
481 {
482         return MAX_OBD_DEVICES;
483 }
484
485 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
486                                __u32 keylen, void *key,
487                                __u32 *vallen, void *val)
488 {
489         int rc;
490         ENTRY;
491
492         EXP_CHECK_DT_OP(exp, get_info);
493         EXP_COUNTER_INCREMENT(exp, get_info);
494
495         rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
496         RETURN(rc);
497 }
498
499 static inline int obd_set_info_async(const struct lu_env *env,
500                                      struct obd_export *exp,
501                                      __u32 keylen, void *key,
502                                      __u32 vallen, void *val,
503                                      struct ptlrpc_request_set *set)
504 {
505         int rc;
506         ENTRY;
507
508         EXP_CHECK_DT_OP(exp, set_info_async);
509         EXP_COUNTER_INCREMENT(exp, set_info_async);
510
511         rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
512                                                val, set);
513         RETURN(rc);
514 }
515
516 /*
517  * obd-lu integration.
518  *
519  * Functionality is being moved into new lu_device-based layering, but some
520  * pieces of configuration process are still based on obd devices.
521  *
522  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
523  * subsume ->o_setup() methods of obd devices they replace. The same for
524  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
525  * result, obd_setup() and obd_process_config() branch and call one XOR
526  * another.
527  *
528  * Yet neither lu_device_type_operations::ldto_device_fini() nor
529  * lu_device_type_operations::ldto_device_free() fully implement the
530  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
531  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
532  */
533
534 #define DECLARE_LU_VARS(ldt, d)                 \
535         struct lu_device_type *ldt;       \
536         struct lu_device *d
537
538 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
539 {
540         int rc;
541         DECLARE_LU_VARS(ldt, d);
542         ENTRY;
543
544         ldt = obd->obd_type->typ_lu;
545         if (ldt != NULL) {
546                 struct lu_context  session_ctx;
547                 struct lu_env env;
548                 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
549                 session_ctx.lc_thread = NULL;
550                 lu_context_enter(&session_ctx);
551
552                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
553                 if (rc == 0) {
554                         env.le_ses = &session_ctx;
555                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
556                         lu_env_fini(&env);
557                         if (!IS_ERR(d)) {
558                                 obd->obd_lu_dev = d;
559                                 d->ld_obd = obd;
560                                 rc = 0;
561                         } else
562                                 rc = PTR_ERR(d);
563                 }
564                 lu_context_exit(&session_ctx);
565                 lu_context_fini(&session_ctx);
566
567         } else {
568                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
569                 OBD_COUNTER_INCREMENT(obd, setup);
570                 rc = OBP(obd, setup)(obd, cfg);
571         }
572         RETURN(rc);
573 }
574
575 static inline int obd_precleanup(struct obd_device *obd,
576                                  enum obd_cleanup_stage cleanup_stage)
577 {
578         int rc;
579         DECLARE_LU_VARS(ldt, d);
580         ENTRY;
581
582         OBD_CHECK_DEV(obd);
583         ldt = obd->obd_type->typ_lu;
584         d = obd->obd_lu_dev;
585         if (ldt != NULL && d != NULL) {
586                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
587                         struct lu_env env;
588
589                         rc = lu_env_init(&env, ldt->ldt_ctx_tags);
590                         if (rc == 0) {
591                                 ldt->ldt_ops->ldto_device_fini(&env, d);
592                                 lu_env_fini(&env);
593                         }
594                 }
595         }
596         OBD_CHECK_DT_OP(obd, precleanup, 0);
597         OBD_COUNTER_INCREMENT(obd, precleanup);
598
599         rc = OBP(obd, precleanup)(obd, cleanup_stage);
600         RETURN(rc);
601 }
602
603 static inline int obd_cleanup(struct obd_device *obd)
604 {
605         int rc;
606         DECLARE_LU_VARS(ldt, d);
607         ENTRY;
608
609         OBD_CHECK_DEV(obd);
610
611         ldt = obd->obd_type->typ_lu;
612         d = obd->obd_lu_dev;
613         if (ldt != NULL && d != NULL) {
614                 struct lu_env env;
615
616                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
617                 if (rc == 0) {
618                         ldt->ldt_ops->ldto_device_free(&env, d);
619                         lu_env_fini(&env);
620                         obd->obd_lu_dev = NULL;
621                 }
622         }
623         OBD_CHECK_DT_OP(obd, cleanup, 0);
624         OBD_COUNTER_INCREMENT(obd, cleanup);
625
626         rc = OBP(obd, cleanup)(obd);
627         RETURN(rc);
628 }
629
630 static inline void obd_cleanup_client_import(struct obd_device *obd)
631 {
632         ENTRY;
633
634         /* If we set up but never connected, the
635            client import will not have been cleaned. */
636         down_write(&obd->u.cli.cl_sem);
637         if (obd->u.cli.cl_import) {
638                 struct obd_import *imp;
639                 imp = obd->u.cli.cl_import;
640                 CDEBUG(D_CONFIG, "%s: client import never connected\n",
641                        obd->obd_name);
642                 ptlrpc_invalidate_import(imp);
643                 if (imp->imp_rq_pool) {
644                         ptlrpc_free_rq_pool(imp->imp_rq_pool);
645                         imp->imp_rq_pool = NULL;
646                 }
647                 client_destroy_import(imp);
648                 obd->u.cli.cl_import = NULL;
649         }
650         up_write(&obd->u.cli.cl_sem);
651
652         EXIT;
653 }
654
655 static inline int
656 obd_process_config(struct obd_device *obd, int datalen, void *data)
657 {
658         int rc;
659         DECLARE_LU_VARS(ldt, d);
660         ENTRY;
661
662         OBD_CHECK_DEV(obd);
663
664         obd->obd_process_conf = 1;
665         ldt = obd->obd_type->typ_lu;
666         d = obd->obd_lu_dev;
667         if (ldt != NULL && d != NULL) {
668                 struct lu_env env;
669
670                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
671                 if (rc == 0) {
672                         rc = d->ld_ops->ldo_process_config(&env, d, data);
673                         lu_env_fini(&env);
674                 }
675         } else {
676                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
677                 rc = OBP(obd, process_config)(obd, datalen, data);
678         }
679         OBD_COUNTER_INCREMENT(obd, process_config);
680         obd->obd_process_conf = 0;
681
682         RETURN(rc);
683 }
684
685 /* Pack an in-memory MD struct for storage on disk.
686  * Returns +ve size of packed MD (0 for free), or -ve error.
687  *
688  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
689  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
690  * If @*disk_tgt == NULL, it will be allocated
691  */
692 static inline int obd_packmd(struct obd_export *exp,
693                              struct lov_mds_md **disk_tgt,
694                              struct lov_stripe_md *mem_src)
695 {
696         int rc;
697         ENTRY;
698
699         EXP_CHECK_DT_OP(exp, packmd);
700         EXP_COUNTER_INCREMENT(exp, packmd);
701
702         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
703         RETURN(rc);
704 }
705
706 static inline int obd_size_diskmd(struct obd_export *exp,
707                                   struct lov_stripe_md *mem_src)
708 {
709         return obd_packmd(exp, NULL, mem_src);
710 }
711
712 static inline int obd_free_diskmd(struct obd_export *exp,
713                                   struct lov_mds_md **disk_tgt)
714 {
715         LASSERT(disk_tgt);
716         LASSERT(*disk_tgt);
717         /*
718          * LU-2590, for caller's convenience, *disk_tgt could be host
719          * endianness, it needs swab to LE if necessary, while just
720          * lov_mds_md header needs it for figuring out how much memory
721          * needs to be freed.
722          */
723         if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
724             (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
725              ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
726                 lustre_swab_lov_mds_md(*disk_tgt);
727         return obd_packmd(exp, disk_tgt, NULL);
728 }
729
730 /* Unpack an MD struct from disk to in-memory format.
731  * Returns +ve size of unpacked MD (0 for free), or -ve error.
732  *
733  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
734  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
735  * If @*mem_tgt == NULL, it will be allocated
736  */
737 static inline int obd_unpackmd(struct obd_export *exp,
738                                struct lov_stripe_md **mem_tgt,
739                                struct lov_mds_md *disk_src,
740                                int disk_len)
741 {
742         int rc;
743         ENTRY;
744
745         EXP_CHECK_DT_OP(exp, unpackmd);
746         EXP_COUNTER_INCREMENT(exp, unpackmd);
747
748         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
749         RETURN(rc);
750 }
751
752 static inline int obd_free_memmd(struct obd_export *exp,
753                                  struct lov_stripe_md **mem_tgt)
754 {
755         int rc;
756
757         LASSERT(mem_tgt);
758         LASSERT(*mem_tgt);
759         rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
760         *mem_tgt = NULL;
761         return rc;
762 }
763
764 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
765                              struct obdo *obdo, struct obd_trans_info *oti)
766 {
767         int rc;
768         ENTRY;
769
770         EXP_CHECK_DT_OP(exp, create);
771         EXP_COUNTER_INCREMENT(exp, create);
772
773         rc = OBP(exp->exp_obd, create)(env, exp, obdo, oti);
774         RETURN(rc);
775 }
776
777 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
778                               struct obdo *obdo, struct obd_trans_info *oti)
779 {
780         int rc;
781         ENTRY;
782
783         EXP_CHECK_DT_OP(exp, destroy);
784         EXP_COUNTER_INCREMENT(exp, destroy);
785
786         rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, oti);
787         RETURN(rc);
788 }
789
790 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
791                               struct obd_info *oinfo)
792 {
793         int rc;
794         ENTRY;
795
796         EXP_CHECK_DT_OP(exp, getattr);
797         EXP_COUNTER_INCREMENT(exp, getattr);
798
799         rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
800         RETURN(rc);
801 }
802
803 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
804                               struct obd_info *oinfo,
805                               struct obd_trans_info *oti)
806 {
807         int rc;
808         ENTRY;
809
810         EXP_CHECK_DT_OP(exp, setattr);
811         EXP_COUNTER_INCREMENT(exp, setattr);
812
813         rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
814         RETURN(rc);
815 }
816
817 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
818                                int priority)
819 {
820         struct obd_device *obd = imp->imp_obd;
821         int rc;
822         ENTRY;
823
824         OBD_CHECK_DEV_ACTIVE(obd);
825         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
826         OBD_COUNTER_INCREMENT(obd, add_conn);
827
828         rc = OBP(obd, add_conn)(imp, uuid, priority);
829         RETURN(rc);
830 }
831
832 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
833 {
834         struct obd_device *obd = imp->imp_obd;
835         int rc;
836         ENTRY;
837
838         OBD_CHECK_DEV_ACTIVE(obd);
839         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
840         OBD_COUNTER_INCREMENT(obd, del_conn);
841
842         rc = OBP(obd, del_conn)(imp, uuid);
843         RETURN(rc);
844 }
845
846 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
847 {
848         struct obd_uuid *uuid;
849         ENTRY;
850
851         OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
852         EXP_COUNTER_INCREMENT(exp, get_uuid);
853
854         uuid = OBP(exp->exp_obd, get_uuid)(exp);
855         RETURN(uuid);
856 }
857
858 /** Create a new /a exp on device /a obd for the uuid /a cluuid
859  * @param exp New export handle
860  * @param d Connect data, supported flags are set, flags also understood
861  *    by obd are returned.
862  */
863 static inline int obd_connect(const struct lu_env *env,
864                               struct obd_export **exp,struct obd_device *obd,
865                               struct obd_uuid *cluuid,
866                               struct obd_connect_data *data,
867                               void *localdata)
868 {
869         int rc;
870         __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
871                                                    * check */
872         ENTRY;
873
874         OBD_CHECK_DEV_ACTIVE(obd);
875         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
876         OBD_COUNTER_INCREMENT(obd, connect);
877
878         rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
879         /* check that only subset is granted */
880         LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
881                                     data->ocd_connect_flags));
882         RETURN(rc);
883 }
884
885 static inline int obd_reconnect(const struct lu_env *env,
886                                 struct obd_export *exp,
887                                 struct obd_device *obd,
888                                 struct obd_uuid *cluuid,
889                                 struct obd_connect_data *d,
890                                 void *localdata)
891 {
892         int rc;
893         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
894                                                    * check */
895
896         ENTRY;
897
898         OBD_CHECK_DEV_ACTIVE(obd);
899         OBD_CHECK_DT_OP(obd, reconnect, 0);
900         OBD_COUNTER_INCREMENT(obd, reconnect);
901
902         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
903         /* check that only subset is granted */
904         LASSERT(ergo(d != NULL,
905                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
906         RETURN(rc);
907 }
908
909 static inline int obd_disconnect(struct obd_export *exp)
910 {
911         int rc;
912         ENTRY;
913
914         EXP_CHECK_DT_OP(exp, disconnect);
915         EXP_COUNTER_INCREMENT(exp, disconnect);
916
917         rc = OBP(exp->exp_obd, disconnect)(exp);
918         RETURN(rc);
919 }
920
921 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
922                                enum lu_cli_type type)
923 {
924         int rc;
925         ENTRY;
926
927         OBD_CHECK_DT_OP(obd, fid_init, 0);
928         OBD_COUNTER_INCREMENT(obd, fid_init);
929
930         rc = OBP(obd, fid_init)(obd, exp, type);
931         RETURN(rc);
932 }
933
934 static inline int obd_fid_fini(struct obd_device *obd)
935 {
936         int rc;
937         ENTRY;
938
939         OBD_CHECK_DT_OP(obd, fid_fini, 0);
940         OBD_COUNTER_INCREMENT(obd, fid_fini);
941
942         rc = OBP(obd, fid_fini)(obd);
943         RETURN(rc);
944 }
945
946 static inline int obd_fid_alloc(const struct lu_env *env,
947                                 struct obd_export *exp,
948                                 struct lu_fid *fid,
949                                 struct md_op_data *op_data)
950 {
951         int rc;
952         ENTRY;
953
954         EXP_CHECK_DT_OP(exp, fid_alloc);
955         EXP_COUNTER_INCREMENT(exp, fid_alloc);
956
957         rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
958         RETURN(rc);
959 }
960
961 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
962 {
963         int rc;
964         ENTRY;
965
966         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
967         EXP_COUNTER_INCREMENT(exp, ping);
968
969         rc = OBP(exp->exp_obd, ping)(env, exp);
970         RETURN(rc);
971 }
972
973 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
974 {
975         int rc;
976         ENTRY;
977
978         OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
979         OBD_COUNTER_INCREMENT(obd, pool_new);
980
981         rc = OBP(obd, pool_new)(obd, poolname);
982         RETURN(rc);
983 }
984
985 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
986 {
987         int rc;
988         ENTRY;
989
990         OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
991         OBD_COUNTER_INCREMENT(obd, pool_del);
992
993         rc = OBP(obd, pool_del)(obd, poolname);
994         RETURN(rc);
995 }
996
997 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
998 {
999         int rc;
1000         ENTRY;
1001
1002         OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1003         OBD_COUNTER_INCREMENT(obd, pool_add);
1004
1005         rc = OBP(obd, pool_add)(obd, poolname, ostname);
1006         RETURN(rc);
1007 }
1008
1009 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1010 {
1011         int rc;
1012         ENTRY;
1013
1014         OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1015         OBD_COUNTER_INCREMENT(obd, pool_rem);
1016
1017         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1018         RETURN(rc);
1019 }
1020
1021 static inline void obd_getref(struct obd_device *obd)
1022 {
1023         ENTRY;
1024         if (OBT(obd) && OBP(obd, getref)) {
1025                 OBD_COUNTER_INCREMENT(obd, getref);
1026                 OBP(obd, getref)(obd);
1027         }
1028         EXIT;
1029 }
1030
1031 static inline void obd_putref(struct obd_device *obd)
1032 {
1033         ENTRY;
1034         if (OBT(obd) && OBP(obd, putref)) {
1035                 OBD_COUNTER_INCREMENT(obd, putref);
1036                 OBP(obd, putref)(obd);
1037         }
1038         EXIT;
1039 }
1040
1041 static inline int obd_init_export(struct obd_export *exp)
1042 {
1043         int rc = 0;
1044
1045         ENTRY;
1046         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1047             OBP((exp)->exp_obd, init_export))
1048                 rc = OBP(exp->exp_obd, init_export)(exp);
1049         RETURN(rc);
1050 }
1051
1052 static inline int obd_destroy_export(struct obd_export *exp)
1053 {
1054         ENTRY;
1055         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1056             OBP((exp)->exp_obd, destroy_export))
1057                 OBP(exp->exp_obd, destroy_export)(exp);
1058         RETURN(0);
1059 }
1060
1061 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1062  * If the cache is older than @max_age we will get a new value from the
1063  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1064 static inline int obd_statfs_async(struct obd_export *exp,
1065                                    struct obd_info *oinfo,
1066                                    __u64 max_age,
1067                                    struct ptlrpc_request_set *rqset)
1068 {
1069         int rc = 0;
1070         struct obd_device *obd;
1071         ENTRY;
1072
1073         if (exp == NULL || exp->exp_obd == NULL)
1074                 RETURN(-EINVAL);
1075
1076         obd = exp->exp_obd;
1077         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1078         OBD_COUNTER_INCREMENT(obd, statfs);
1079
1080         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1081                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1082         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1083                 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1084         } else {
1085                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1086                        " objects "LPU64"/"LPU64"\n",
1087                        obd->obd_name, &obd->obd_osfs,
1088                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1089                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1090                 spin_lock(&obd->obd_osfs_lock);
1091                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1092                 spin_unlock(&obd->obd_osfs_lock);
1093                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1094                 if (oinfo->oi_cb_up)
1095                         oinfo->oi_cb_up(oinfo, 0);
1096         }
1097         RETURN(rc);
1098 }
1099
1100 static inline int obd_statfs_rqset(struct obd_export *exp,
1101                                    struct obd_statfs *osfs, __u64 max_age,
1102                                    __u32 flags)
1103 {
1104         struct ptlrpc_request_set *set = NULL;
1105         struct obd_info oinfo = { { { 0 } } };
1106         int rc = 0;
1107         ENTRY;
1108
1109         set =  ptlrpc_prep_set();
1110         if (set == NULL)
1111                 RETURN(-ENOMEM);
1112
1113         oinfo.oi_osfs = osfs;
1114         oinfo.oi_flags = flags;
1115         rc = obd_statfs_async(exp, &oinfo, max_age, set);
1116         if (rc == 0)
1117                 rc = ptlrpc_set_wait(set);
1118         ptlrpc_set_destroy(set);
1119         RETURN(rc);
1120 }
1121
1122 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1123  * If the cache is older than @max_age we will get a new value from the
1124  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1125 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1126                              struct obd_statfs *osfs, __u64 max_age,
1127                              __u32 flags)
1128 {
1129         int rc = 0;
1130         struct obd_device *obd = exp->exp_obd;
1131         ENTRY;
1132
1133         if (obd == NULL)
1134                 RETURN(-EINVAL);
1135
1136         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1137         OBD_COUNTER_INCREMENT(obd, statfs);
1138
1139         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1140                obd->obd_osfs_age, max_age);
1141         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1142                 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1143                 if (rc == 0) {
1144                         spin_lock(&obd->obd_osfs_lock);
1145                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1146                         obd->obd_osfs_age = cfs_time_current_64();
1147                         spin_unlock(&obd->obd_osfs_lock);
1148                 }
1149         } else {
1150                 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1151                        " objects "LPU64"/"LPU64"\n",
1152                        obd->obd_name, &obd->obd_osfs,
1153                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1154                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1155                 spin_lock(&obd->obd_osfs_lock);
1156                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1157                 spin_unlock(&obd->obd_osfs_lock);
1158         }
1159         RETURN(rc);
1160 }
1161
1162 static inline int obd_preprw(const struct lu_env *env, int cmd,
1163                              struct obd_export *exp, struct obdo *oa,
1164                              int objcount, struct obd_ioobj *obj,
1165                              struct niobuf_remote *remote, int *pages,
1166                              struct niobuf_local *local,
1167                              struct obd_trans_info *oti)
1168 {
1169         int rc;
1170         ENTRY;
1171
1172         EXP_CHECK_DT_OP(exp, preprw);
1173         EXP_COUNTER_INCREMENT(exp, preprw);
1174
1175         rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1176                                        pages, local, oti);
1177         RETURN(rc);
1178 }
1179
1180 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1181                                struct obd_export *exp, struct obdo *oa,
1182                                int objcount, struct obd_ioobj *obj,
1183                                struct niobuf_remote *rnb, int pages,
1184                                struct niobuf_local *local,
1185                                struct obd_trans_info *oti, int rc)
1186 {
1187         ENTRY;
1188
1189         EXP_CHECK_DT_OP(exp, commitrw);
1190         EXP_COUNTER_INCREMENT(exp, commitrw);
1191
1192         rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1193                                          rnb, pages, local, oti, rc);
1194         RETURN(rc);
1195 }
1196
1197 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1198                                 int len, void *karg, void __user *uarg)
1199 {
1200         int rc;
1201         ENTRY;
1202
1203         EXP_CHECK_DT_OP(exp, iocontrol);
1204         EXP_COUNTER_INCREMENT(exp, iocontrol);
1205
1206         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1207         RETURN(rc);
1208 }
1209
1210 static inline void obd_import_event(struct obd_device *obd,
1211                                     struct obd_import *imp,
1212                                     enum obd_import_event event)
1213 {
1214         ENTRY;
1215         if (!obd) {
1216                 CERROR("NULL device\n");
1217                 EXIT;
1218                 return;
1219         }
1220         if (obd->obd_set_up && OBP(obd, import_event)) {
1221                 OBD_COUNTER_INCREMENT(obd, import_event);
1222                 OBP(obd, import_event)(obd, imp, event);
1223         }
1224         EXIT;
1225 }
1226
1227 static inline int obd_notify(struct obd_device *obd,
1228                              struct obd_device *watched,
1229                              enum obd_notify_event ev,
1230                              void *data)
1231 {
1232         int rc;
1233         ENTRY;
1234         OBD_CHECK_DEV(obd);
1235
1236         if (!obd->obd_set_up) {
1237                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1238                 RETURN(-EINVAL);
1239         }
1240
1241         if (!OBP(obd, notify)) {
1242                 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1243                 RETURN(-ENOSYS);
1244         }
1245
1246         OBD_COUNTER_INCREMENT(obd, notify);
1247         rc = OBP(obd, notify)(obd, watched, ev, data);
1248         RETURN(rc);
1249 }
1250
1251 static inline int obd_notify_observer(struct obd_device *observer,
1252                                       struct obd_device *observed,
1253                                       enum obd_notify_event ev,
1254                                       void *data)
1255 {
1256         int rc1;
1257         int rc2;
1258
1259         struct obd_notify_upcall *onu;
1260
1261         if (observer->obd_observer)
1262                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1263         else
1264                 rc1 = 0;
1265         /*
1266          * Also, call non-obd listener, if any
1267          */
1268         onu = &observer->obd_upcall;
1269         if (onu->onu_upcall != NULL)
1270                 rc2 = onu->onu_upcall(observer, observed, ev,
1271                                       onu->onu_owner, NULL);
1272         else
1273                 rc2 = 0;
1274
1275         return rc1 ? rc1 : rc2;
1276 }
1277
1278 static inline int obd_quotacheck(struct obd_export *exp,
1279                                  struct obd_quotactl *oqctl)
1280 {
1281         int rc;
1282         ENTRY;
1283
1284         EXP_CHECK_DT_OP(exp, quotacheck);
1285         EXP_COUNTER_INCREMENT(exp, quotacheck);
1286
1287         rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1288         RETURN(rc);
1289 }
1290
1291 static inline int obd_quotactl(struct obd_export *exp,
1292                                struct obd_quotactl *oqctl)
1293 {
1294         int rc;
1295         ENTRY;
1296
1297         EXP_CHECK_DT_OP(exp, quotactl);
1298         EXP_COUNTER_INCREMENT(exp, quotactl);
1299
1300         rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1301         RETURN(rc);
1302 }
1303
1304 static inline int obd_health_check(const struct lu_env *env,
1305                                    struct obd_device *obd)
1306 {
1307         /* returns: 0 on healthy
1308          *         >0 on unhealthy + reason code/flag
1309          *            however the only suppored reason == 1 right now
1310          *            We'll need to define some better reasons
1311          *            or flags in the future.
1312          *         <0 on error
1313          */
1314         int rc;
1315         ENTRY;
1316
1317         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1318         if (obd == NULL || !OBT(obd)) {
1319                 CERROR("cleaned up obd\n");
1320                 RETURN(-EOPNOTSUPP);
1321         }
1322         if (!obd->obd_set_up || obd->obd_stopping)
1323                 RETURN(0);
1324         if (!OBP(obd, health_check))
1325                 RETURN(0);
1326
1327         rc = OBP(obd, health_check)(env, obd);
1328         RETURN(rc);
1329 }
1330
1331 static inline int obd_register_observer(struct obd_device *obd,
1332                                         struct obd_device *observer)
1333 {
1334         ENTRY;
1335         OBD_CHECK_DEV(obd);
1336         down_write(&obd->obd_observer_link_sem);
1337         if (obd->obd_observer && observer) {
1338                 up_write(&obd->obd_observer_link_sem);
1339                 RETURN(-EALREADY);
1340         }
1341         obd->obd_observer = observer;
1342         up_write(&obd->obd_observer_link_sem);
1343         RETURN(0);
1344 }
1345
1346 /* metadata helpers */
1347 static inline int md_getstatus(struct obd_export *exp,
1348                                struct lu_fid *fid, struct obd_capa **pc)
1349 {
1350         int rc;
1351         ENTRY;
1352
1353         EXP_CHECK_MD_OP(exp, getstatus);
1354         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1355         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1356         RETURN(rc);
1357 }
1358
1359 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1360                              struct ptlrpc_request **request)
1361 {
1362         int rc;
1363         ENTRY;
1364         EXP_CHECK_MD_OP(exp, getattr);
1365         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1366         rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1367         RETURN(rc);
1368 }
1369
1370 static inline int md_null_inode(struct obd_export *exp,
1371                                    const struct lu_fid *fid)
1372 {
1373         int rc;
1374         ENTRY;
1375         EXP_CHECK_MD_OP(exp, null_inode);
1376         EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1377         rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1378         RETURN(rc);
1379 }
1380
1381 static inline int md_find_cbdata(struct obd_export *exp,
1382                                  const struct lu_fid *fid,
1383                                  ldlm_iterator_t it, void *data)
1384 {
1385         int rc;
1386         ENTRY;
1387         EXP_CHECK_MD_OP(exp, find_cbdata);
1388         EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1389         rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1390         RETURN(rc);
1391 }
1392
1393 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1394                            struct md_open_data *mod,
1395                            struct ptlrpc_request **request)
1396 {
1397         int rc;
1398         ENTRY;
1399         EXP_CHECK_MD_OP(exp, close);
1400         EXP_MD_COUNTER_INCREMENT(exp, close);
1401         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1402         RETURN(rc);
1403 }
1404
1405 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1406                             const void *data, size_t datalen, umode_t mode,
1407                             uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1408                             __u64 rdev, struct ptlrpc_request **request)
1409 {
1410         int rc;
1411         ENTRY;
1412         EXP_CHECK_MD_OP(exp, create);
1413         EXP_MD_COUNTER_INCREMENT(exp, create);
1414         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1415                                        uid, gid, cap_effective, rdev, request);
1416         RETURN(rc);
1417 }
1418
1419 static inline int md_enqueue(struct obd_export *exp,
1420                              struct ldlm_enqueue_info *einfo,
1421                              const union ldlm_policy_data *policy,
1422                              struct lookup_intent *it,
1423                              struct md_op_data *op_data,
1424                              struct lustre_handle *lockh,
1425                              __u64 extra_lock_flags)
1426 {
1427         int rc;
1428         ENTRY;
1429         EXP_CHECK_MD_OP(exp, enqueue);
1430         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1431         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1432                                         extra_lock_flags);
1433         RETURN(rc);
1434 }
1435
1436 static inline int md_getattr_name(struct obd_export *exp,
1437                                   struct md_op_data *op_data,
1438                                   struct ptlrpc_request **request)
1439 {
1440         int rc;
1441         ENTRY;
1442         EXP_CHECK_MD_OP(exp, getattr_name);
1443         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1444         rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1445         RETURN(rc);
1446 }
1447
1448 static inline int md_intent_lock(struct obd_export *exp,
1449                                  struct md_op_data *op_data,
1450                                  struct lookup_intent *it,
1451                                  struct ptlrpc_request **reqp,
1452                                  ldlm_blocking_callback cb_blocking,
1453                                  __u64 extra_lock_flags)
1454 {
1455         int rc;
1456         ENTRY;
1457         EXP_CHECK_MD_OP(exp, intent_lock);
1458         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1459         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1460                                             extra_lock_flags);
1461         RETURN(rc);
1462 }
1463
1464 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1465                           struct ptlrpc_request **request)
1466 {
1467         int rc;
1468         ENTRY;
1469         EXP_CHECK_MD_OP(exp, link);
1470         EXP_MD_COUNTER_INCREMENT(exp, link);
1471         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1472         RETURN(rc);
1473 }
1474
1475 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1476                             const char *old, size_t oldlen, const char *new,
1477                             size_t newlen, struct ptlrpc_request **request)
1478 {
1479         int rc;
1480         ENTRY;
1481         EXP_CHECK_MD_OP(exp, rename);
1482         EXP_MD_COUNTER_INCREMENT(exp, rename);
1483         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1484                                        newlen, request);
1485         RETURN(rc);
1486 }
1487
1488 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1489                              void *ea, size_t ealen,
1490                              struct ptlrpc_request **request)
1491 {
1492         int rc;
1493         ENTRY;
1494         EXP_CHECK_MD_OP(exp, setattr);
1495         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1496         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1497         RETURN(rc);
1498 }
1499
1500 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1501                            struct obd_capa *oc, struct ptlrpc_request **request)
1502 {
1503         int rc;
1504         ENTRY;
1505         EXP_CHECK_MD_OP(exp, fsync);
1506         EXP_MD_COUNTER_INCREMENT(exp, fsync);
1507         rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1508         RETURN(rc);
1509 }
1510
1511 static inline int md_read_page(struct obd_export *exp,
1512                                struct md_op_data *op_data,
1513                                struct md_callback *cb_op,
1514                                __u64  hash_offset,
1515                                struct page **ppage)
1516 {
1517         int rc;
1518         ENTRY;
1519         EXP_CHECK_MD_OP(exp, read_page);
1520         EXP_MD_COUNTER_INCREMENT(exp, read_page);
1521         rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1522                                           ppage);
1523         RETURN(rc);
1524 }
1525
1526 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1527                             struct ptlrpc_request **request)
1528 {
1529         int rc;
1530         ENTRY;
1531         EXP_CHECK_MD_OP(exp, unlink);
1532         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1533         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1534         RETURN(rc);
1535 }
1536
1537 static inline int md_get_lustre_md(struct obd_export *exp,
1538                                    struct ptlrpc_request *req,
1539                                    struct obd_export *dt_exp,
1540                                    struct obd_export *md_exp,
1541                                    struct lustre_md *md)
1542 {
1543         ENTRY;
1544         EXP_CHECK_MD_OP(exp, get_lustre_md);
1545         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1546         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1547 }
1548
1549 static inline int md_free_lustre_md(struct obd_export *exp,
1550                                     struct lustre_md *md)
1551 {
1552         ENTRY;
1553         EXP_CHECK_MD_OP(exp, free_lustre_md);
1554         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1555         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1556 }
1557
1558 static inline int md_merge_attr(struct obd_export *exp,
1559                                 const struct lmv_stripe_md *lsm,
1560                                 struct cl_attr *attr,
1561                                 ldlm_blocking_callback cb)
1562 {
1563         ENTRY;
1564         EXP_CHECK_MD_OP(exp, merge_attr);
1565         EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1566         RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1567 }
1568
1569 static inline int md_setxattr(struct obd_export *exp,
1570                               const struct lu_fid *fid, struct obd_capa *oc,
1571                               u64 valid, const char *name,
1572                               const char *input, int input_size,
1573                               int output_size, int flags, __u32 suppgid,
1574                               struct ptlrpc_request **request)
1575 {
1576         ENTRY;
1577         EXP_CHECK_MD_OP(exp, setxattr);
1578         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1579         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1580                                            input_size, output_size, flags,
1581                                            suppgid, request));
1582 }
1583
1584 static inline int md_getxattr(struct obd_export *exp,
1585                               const struct lu_fid *fid, struct obd_capa *oc,
1586                               u64 valid, const char *name,
1587                               const char *input, int input_size,
1588                               int output_size, int flags,
1589                               struct ptlrpc_request **request)
1590 {
1591         ENTRY;
1592         EXP_CHECK_MD_OP(exp, getxattr);
1593         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1594         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1595                                            input_size, output_size, flags,
1596                                            request));
1597 }
1598
1599 static inline int md_set_open_replay_data(struct obd_export *exp,
1600                                           struct obd_client_handle *och,
1601                                           struct lookup_intent *it)
1602 {
1603         ENTRY;
1604         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1605         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1606         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1607 }
1608
1609 static inline int md_clear_open_replay_data(struct obd_export *exp,
1610                                             struct obd_client_handle *och)
1611 {
1612         ENTRY;
1613         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1614         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1615         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1616 }
1617
1618 static inline int md_set_lock_data(struct obd_export *exp,
1619                                    __u64 *lockh, void *data, __u64 *bits)
1620 {
1621         ENTRY;
1622         EXP_CHECK_MD_OP(exp, set_lock_data);
1623         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1624         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1625 }
1626
1627 static inline int md_cancel_unused(struct obd_export *exp,
1628                                    const struct lu_fid *fid,
1629                                    ldlm_policy_data_t *policy,
1630                                    ldlm_mode_t mode,
1631                                    ldlm_cancel_flags_t flags,
1632                                    void *opaque)
1633 {
1634         int rc;
1635         ENTRY;
1636
1637         EXP_CHECK_MD_OP(exp, cancel_unused);
1638         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1639
1640         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1641                                               flags, opaque);
1642         RETURN(rc);
1643 }
1644
1645 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1646                                         const struct lu_fid *fid,
1647                                         ldlm_type_t type,
1648                                         ldlm_policy_data_t *policy,
1649                                         ldlm_mode_t mode,
1650                                         struct lustre_handle *lockh)
1651 {
1652         ENTRY;
1653         EXP_CHECK_MD_OP(exp, lock_match);
1654         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1655         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1656                                              policy, mode, lockh));
1657 }
1658
1659 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1660                                   int def_asize, int cookiesize,
1661                                   int def_cookiesize)
1662 {
1663         ENTRY;
1664         EXP_CHECK_MD_OP(exp, init_ea_size);
1665         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1666         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1667                                                cookiesize, def_cookiesize));
1668 }
1669
1670 static inline int md_get_remote_perm(struct obd_export *exp,
1671                                      const struct lu_fid *fid,
1672                                      struct obd_capa *oc, __u32 suppgid,
1673                                      struct ptlrpc_request **request)
1674 {
1675         ENTRY;
1676         EXP_CHECK_MD_OP(exp, get_remote_perm);
1677         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1678         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1679                                                   request));
1680 }
1681
1682 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1683                                 renew_capa_cb_t cb)
1684 {
1685         int rc;
1686         ENTRY;
1687         EXP_CHECK_MD_OP(exp, renew_capa);
1688         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1689         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1690         RETURN(rc);
1691 }
1692
1693 static inline int md_unpack_capa(struct obd_export *exp,
1694                                  struct ptlrpc_request *req,
1695                                  const struct req_msg_field *field,
1696                                  struct obd_capa **oc)
1697 {
1698         int rc;
1699         ENTRY;
1700         EXP_CHECK_MD_OP(exp, unpack_capa);
1701         EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1702         rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1703         RETURN(rc);
1704 }
1705
1706 static inline int md_intent_getattr_async(struct obd_export *exp,
1707                                           struct md_enqueue_info *minfo,
1708                                           struct ldlm_enqueue_info *einfo)
1709 {
1710         int rc;
1711         ENTRY;
1712         EXP_CHECK_MD_OP(exp, intent_getattr_async);
1713         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1714         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1715         RETURN(rc);
1716 }
1717
1718 static inline int md_revalidate_lock(struct obd_export *exp,
1719                                      struct lookup_intent *it,
1720                                      struct lu_fid *fid, __u64 *bits)
1721 {
1722         int rc;
1723         ENTRY;
1724         EXP_CHECK_MD_OP(exp, revalidate_lock);
1725         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1726         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1727         RETURN(rc);
1728 }
1729
1730 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1731                                       const struct lmv_stripe_md *lsm,
1732                                       const char *name, int namelen,
1733                                       struct lu_fid *fid)
1734 {
1735         int rc;
1736         ENTRY;
1737         EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1738         EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1739         rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1740         RETURN(rc);
1741 }
1742
1743 /* OBD Metadata Support */
1744
1745 extern int obd_init_caches(void);
1746 extern void obd_cleanup_caches(void);
1747
1748 /* support routines */
1749 extern struct kmem_cache *obdo_cachep;
1750
1751 #define OBDO_ALLOC(ptr)                                                       \
1752 do {                                                                          \
1753         OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS);             \
1754 } while(0)
1755
1756 #define OBDO_FREE(ptr)                                                        \
1757 do {                                                                          \
1758         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1759 } while(0)
1760
1761
1762 typedef int (*register_lwp_cb)(void *data);
1763
1764 struct lwp_register_item {
1765         struct obd_export **lri_exp;
1766         register_lwp_cb     lri_cb_func;
1767         void               *lri_cb_data;
1768         struct list_head            lri_list;
1769         char                lri_name[MTI_NAME_MAXLEN];
1770 };
1771
1772 /* I'm as embarrassed about this as you are.
1773  *
1774  * <shaver> // XXX do not look into _superhack with remaining eye
1775  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1776 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1777
1778 /* obd_mount.c */
1779 #ifdef HAVE_SERVER_SUPPORT
1780 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1781                              register_lwp_cb cb_func, void *cb_data);
1782 void lustre_deregister_lwp_item(struct obd_export **exp);
1783 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1784 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1785 #endif /* HAVE_SERVER_SUPPORT */
1786 int lustre_register_fs(void);
1787 int lustre_unregister_fs(void);
1788 int lustre_check_exclusion(struct super_block *sb, char *svname);
1789
1790 /* sysctl.c */
1791 extern void obd_sysctl_init (void);
1792 extern void obd_sysctl_clean (void);
1793
1794 /* uuid.c  */
1795 typedef __u8 class_uuid_t[16];
1796 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1797
1798 /* lustre_peer.c    */
1799 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1800 int class_add_uuid(const char *uuid, __u64 nid);
1801 int class_del_uuid (const char *uuid);
1802 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1803 void class_init_uuidlist(void);
1804 void class_exit_uuidlist(void);
1805
1806 /* prng.c */
1807 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1808
1809 /* statfs_pack.c */
1810 struct kstatfs;
1811 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1812 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1813
1814 /* root squash info */
1815 struct rw_semaphore;
1816 struct root_squash_info {
1817         uid_t                   rsi_uid;
1818         gid_t                   rsi_gid;
1819         struct list_head        rsi_nosquash_nids;
1820         struct rw_semaphore     rsi_sem;
1821 };
1822
1823 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1824
1825 /* linux-module.c */
1826 extern struct miscdevice obd_psdev;
1827 int class_procfs_init(void);
1828 int class_procfs_clean(void);
1829
1830 #endif /* __LINUX_OBD_CLASS_H */