Whamcloud - gitweb
LU-5975 quota: remove obsolete quota code
[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         if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
309                 return NULL;
310         return exp->exp_obd->u.obt.obt_lut;
311 }
312
313 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
314 {
315         LASSERT(obd->u.obt.obt_lut);
316         return &obd->u.obt.obt_lut->lut_lsd;
317 }
318 #endif
319
320 /* obdo.c */
321 struct lu_attr;
322 struct inode;
323
324 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
325 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
326
327 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
328 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
329
330 #define OBT(dev)        (dev)->obd_type
331 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
332 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
333 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
334
335 /* Ensure obd_setup: used for cleanup which must be called
336    while obd is stopping */
337 #define OBD_CHECK_DEV(obd)                                      \
338 do {                                                            \
339         if (!(obd)) {                                           \
340                 CERROR("NULL device\n");                        \
341                 RETURN(-ENODEV);                                \
342         }                                                       \
343 } while (0)
344
345 /* ensure obd_setup and !obd_stopping */
346 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
347 do {                                                            \
348         OBD_CHECK_DEV(obd);                                     \
349         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
350                 CERROR("Device %d not setup\n",                 \
351                        (obd)->obd_minor);                       \
352                 RETURN(-ENODEV);                                \
353         }                                                       \
354 } while (0)
355
356
357 #ifdef CONFIG_PROC_FS
358 #define OBD_COUNTER_OFFSET(op)                                                 \
359         ((offsetof(struct obd_ops, o_ ## op) -                                 \
360           offsetof(struct obd_ops, o_iocontrol))                               \
361          / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
362
363 /* The '- 1' below is for o_owner. */
364 #define NUM_OBD_STATS                                                          \
365         (sizeof(struct obd_ops) /                                              \
366          sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
367
368 #define OBD_COUNTER_INCREMENT(obd, op)                                         \
369         lprocfs_counter_incr((obd)->obd_stats,                                 \
370                              (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
371
372 #define EXP_COUNTER_INCREMENT(exp, op)                                         \
373         do {                                                                   \
374                 unsigned int _off;                                             \
375                 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
376                 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off);         \
377                 if ((exp)->exp_obd->obd_uses_nid_stats &&                      \
378                     (exp)->exp_nid_stats != NULL)                              \
379                         lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats,  \
380                                              _off);                            \
381         } while (0)
382
383 #define _MD_COUNTER_OFFSET(m_op)                                               \
384         ((offsetof(struct md_ops, m_op) -                                      \
385           offsetof(struct md_ops, MD_STATS_FIRST_OP)) /                        \
386          sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
387
388 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
389
390 #define NUM_MD_STATS                                                           \
391         (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) -                                \
392          _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
393
394 /* Note that we only increment md counters for ops whose offset is less
395  * than NUM_MD_STATS. This is explained in a comment in the definition
396  * of struct md_ops. */
397 #define EXP_MD_COUNTER_INCREMENT(exp, op)                                      \
398         do {                                                                   \
399                 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS)                      \
400                         lprocfs_counter_incr((exp)->exp_obd->obd_md_stats,     \
401                                         (exp)->exp_obd->obd_md_cntr_base +     \
402                                         MD_COUNTER_OFFSET(op));                \
403         } while (0)
404
405 #else
406 #define OBD_COUNTER_OFFSET(op)
407 #define OBD_COUNTER_INCREMENT(obd, op)
408 #define EXP_COUNTER_INCREMENT(exp, op)
409 #define EXP_MD_COUNTER_INCREMENT(exp, op)
410 #endif
411
412 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
413 {
414         /* Always add in ldlm_stats */
415         tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
416                                                   ,LPROCFS_STATS_FLAG_NOPERCPU);
417         if (tmp->nid_ldlm_stats == NULL)
418                 return -ENOMEM;
419
420         lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
421
422         return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
423                                       tmp->nid_ldlm_stats);
424 }
425
426 #define EXP_CHECK_MD_OP(exp, op)                                \
427 do {                                                            \
428         if ((exp) == NULL) {                                    \
429                 CERROR("obd_" #op ": NULL export\n");           \
430                 RETURN(-ENODEV);                                \
431         }                                                       \
432         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
433                 CERROR("obd_" #op ": cleaned up obd\n");        \
434                 RETURN(-EOPNOTSUPP);                            \
435         }                                                       \
436         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
437                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
438                        (exp)->exp_obd->obd_name,                \
439                        (exp)->exp_obd->obd_minor);              \
440                 RETURN(-EOPNOTSUPP);                            \
441         }                                                       \
442 } while (0)
443
444
445 #define OBD_CHECK_DT_OP(obd, op, err)                           \
446 do {                                                            \
447         if (!OBT(obd) || !OBP((obd), op)) {                     \
448                 if (err)                                        \
449                         CERROR("obd_" #op ": dev %d no operation\n",    \
450                                obd->obd_minor);                 \
451                 RETURN(err);                                    \
452         }                                                       \
453 } while (0)
454
455 #define EXP_CHECK_DT_OP(exp, op)                                \
456 do {                                                            \
457         if ((exp) == NULL) {                                    \
458                 CERROR("obd_" #op ": NULL export\n");           \
459                 RETURN(-ENODEV);                                \
460         }                                                       \
461         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
462                 CERROR("obd_" #op ": cleaned up obd\n");        \
463                 RETURN(-EOPNOTSUPP);                            \
464         }                                                       \
465         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
466                 CERROR("obd_" #op ": dev %d no operation\n",    \
467                        (exp)->exp_obd->obd_minor);              \
468                 RETURN(-EOPNOTSUPP);                            \
469         }                                                       \
470 } while (0)
471
472 #define CTXT_CHECK_OP(ctxt, op, err)                                 \
473 do {                                                                 \
474         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
475                 if (err)                                             \
476                         CERROR("lop_" #op ": dev %d no operation\n", \
477                                ctxt->loc_obd->obd_minor);            \
478                 RETURN(err);                                         \
479         }                                                            \
480 } while (0)
481
482 static inline int class_devno_max(void)
483 {
484         return MAX_OBD_DEVICES;
485 }
486
487 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
488                                __u32 keylen, void *key,
489                                __u32 *vallen, void *val)
490 {
491         int rc;
492         ENTRY;
493
494         EXP_CHECK_DT_OP(exp, get_info);
495         EXP_COUNTER_INCREMENT(exp, get_info);
496
497         rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
498         RETURN(rc);
499 }
500
501 static inline int obd_set_info_async(const struct lu_env *env,
502                                      struct obd_export *exp,
503                                      __u32 keylen, void *key,
504                                      __u32 vallen, void *val,
505                                      struct ptlrpc_request_set *set)
506 {
507         int rc;
508         ENTRY;
509
510         EXP_CHECK_DT_OP(exp, set_info_async);
511         EXP_COUNTER_INCREMENT(exp, set_info_async);
512
513         rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
514                                                val, set);
515         RETURN(rc);
516 }
517
518 /*
519  * obd-lu integration.
520  *
521  * Functionality is being moved into new lu_device-based layering, but some
522  * pieces of configuration process are still based on obd devices.
523  *
524  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
525  * subsume ->o_setup() methods of obd devices they replace. The same for
526  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
527  * result, obd_setup() and obd_process_config() branch and call one XOR
528  * another.
529  *
530  * Yet neither lu_device_type_operations::ldto_device_fini() nor
531  * lu_device_type_operations::ldto_device_free() fully implement the
532  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
533  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
534  */
535
536 #define DECLARE_LU_VARS(ldt, d)                 \
537         struct lu_device_type *ldt;       \
538         struct lu_device *d
539
540 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
541 {
542         int rc;
543         DECLARE_LU_VARS(ldt, d);
544         ENTRY;
545
546         ldt = obd->obd_type->typ_lu;
547         if (ldt != NULL) {
548                 struct lu_context  session_ctx;
549                 struct lu_env env;
550                 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
551                 session_ctx.lc_thread = NULL;
552                 lu_context_enter(&session_ctx);
553
554                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
555                 if (rc == 0) {
556                         env.le_ses = &session_ctx;
557                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
558                         lu_env_fini(&env);
559                         if (!IS_ERR(d)) {
560                                 obd->obd_lu_dev = d;
561                                 d->ld_obd = obd;
562                                 rc = 0;
563                         } else
564                                 rc = PTR_ERR(d);
565                 }
566                 lu_context_exit(&session_ctx);
567                 lu_context_fini(&session_ctx);
568
569         } else {
570                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
571                 OBD_COUNTER_INCREMENT(obd, setup);
572                 rc = OBP(obd, setup)(obd, cfg);
573         }
574         RETURN(rc);
575 }
576
577 static inline int obd_precleanup(struct obd_device *obd,
578                                  enum obd_cleanup_stage cleanup_stage)
579 {
580         int rc;
581         DECLARE_LU_VARS(ldt, d);
582         ENTRY;
583
584         OBD_CHECK_DEV(obd);
585         ldt = obd->obd_type->typ_lu;
586         d = obd->obd_lu_dev;
587         if (ldt != NULL && d != NULL) {
588                 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
589                         struct lu_env env;
590
591                         rc = lu_env_init(&env, ldt->ldt_ctx_tags);
592                         if (rc == 0) {
593                                 ldt->ldt_ops->ldto_device_fini(&env, d);
594                                 lu_env_fini(&env);
595                         }
596                 }
597         }
598         OBD_CHECK_DT_OP(obd, precleanup, 0);
599         OBD_COUNTER_INCREMENT(obd, precleanup);
600
601         rc = OBP(obd, precleanup)(obd, cleanup_stage);
602         RETURN(rc);
603 }
604
605 static inline int obd_cleanup(struct obd_device *obd)
606 {
607         int rc;
608         DECLARE_LU_VARS(ldt, d);
609         ENTRY;
610
611         OBD_CHECK_DEV(obd);
612
613         ldt = obd->obd_type->typ_lu;
614         d = obd->obd_lu_dev;
615         if (ldt != NULL && d != NULL) {
616                 struct lu_env env;
617
618                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
619                 if (rc == 0) {
620                         ldt->ldt_ops->ldto_device_free(&env, d);
621                         lu_env_fini(&env);
622                         obd->obd_lu_dev = NULL;
623                 }
624         }
625         OBD_CHECK_DT_OP(obd, cleanup, 0);
626         OBD_COUNTER_INCREMENT(obd, cleanup);
627
628         rc = OBP(obd, cleanup)(obd);
629         RETURN(rc);
630 }
631
632 static inline void obd_cleanup_client_import(struct obd_device *obd)
633 {
634         ENTRY;
635
636         /* If we set up but never connected, the
637            client import will not have been cleaned. */
638         down_write(&obd->u.cli.cl_sem);
639         if (obd->u.cli.cl_import) {
640                 struct obd_import *imp;
641                 imp = obd->u.cli.cl_import;
642                 CDEBUG(D_CONFIG, "%s: client import never connected\n",
643                        obd->obd_name);
644                 ptlrpc_invalidate_import(imp);
645                 if (imp->imp_rq_pool) {
646                         ptlrpc_free_rq_pool(imp->imp_rq_pool);
647                         imp->imp_rq_pool = NULL;
648                 }
649                 client_destroy_import(imp);
650                 obd->u.cli.cl_import = NULL;
651         }
652         up_write(&obd->u.cli.cl_sem);
653
654         EXIT;
655 }
656
657 static inline int
658 obd_process_config(struct obd_device *obd, int datalen, void *data)
659 {
660         int rc;
661         DECLARE_LU_VARS(ldt, d);
662         ENTRY;
663
664         OBD_CHECK_DEV(obd);
665
666         obd->obd_process_conf = 1;
667         ldt = obd->obd_type->typ_lu;
668         d = obd->obd_lu_dev;
669         if (ldt != NULL && d != NULL) {
670                 struct lu_env env;
671
672                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
673                 if (rc == 0) {
674                         rc = d->ld_ops->ldo_process_config(&env, d, data);
675                         lu_env_fini(&env);
676                 }
677         } else {
678                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
679                 rc = OBP(obd, process_config)(obd, datalen, data);
680         }
681         OBD_COUNTER_INCREMENT(obd, process_config);
682         obd->obd_process_conf = 0;
683
684         RETURN(rc);
685 }
686
687 /* Pack an in-memory MD struct for storage on disk.
688  * Returns +ve size of packed MD (0 for free), or -ve error.
689  *
690  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
691  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
692  * If @*disk_tgt == NULL, it will be allocated
693  */
694 static inline int obd_packmd(struct obd_export *exp,
695                              struct lov_mds_md **disk_tgt,
696                              struct lov_stripe_md *mem_src)
697 {
698         int rc;
699         ENTRY;
700
701         EXP_CHECK_DT_OP(exp, packmd);
702         EXP_COUNTER_INCREMENT(exp, packmd);
703
704         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
705         RETURN(rc);
706 }
707
708 static inline int obd_size_diskmd(struct obd_export *exp,
709                                   struct lov_stripe_md *mem_src)
710 {
711         return obd_packmd(exp, NULL, mem_src);
712 }
713
714 static inline int obd_free_diskmd(struct obd_export *exp,
715                                   struct lov_mds_md **disk_tgt)
716 {
717         LASSERT(disk_tgt);
718         LASSERT(*disk_tgt);
719         /*
720          * LU-2590, for caller's convenience, *disk_tgt could be host
721          * endianness, it needs swab to LE if necessary, while just
722          * lov_mds_md header needs it for figuring out how much memory
723          * needs to be freed.
724          */
725         if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
726             (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
727              ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
728                 lustre_swab_lov_mds_md(*disk_tgt);
729         return obd_packmd(exp, disk_tgt, NULL);
730 }
731
732 /* Unpack an MD struct from disk to in-memory format.
733  * Returns +ve size of unpacked MD (0 for free), or -ve error.
734  *
735  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
736  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
737  * If @*mem_tgt == NULL, it will be allocated
738  */
739 static inline int obd_unpackmd(struct obd_export *exp,
740                                struct lov_stripe_md **mem_tgt,
741                                struct lov_mds_md *disk_src,
742                                int disk_len)
743 {
744         int rc;
745         ENTRY;
746
747         EXP_CHECK_DT_OP(exp, unpackmd);
748         EXP_COUNTER_INCREMENT(exp, unpackmd);
749
750         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
751         RETURN(rc);
752 }
753
754 static inline int obd_free_memmd(struct obd_export *exp,
755                                  struct lov_stripe_md **mem_tgt)
756 {
757         int rc;
758
759         LASSERT(mem_tgt);
760         LASSERT(*mem_tgt);
761         rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
762         *mem_tgt = NULL;
763         return rc;
764 }
765
766 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
767                              struct obdo *obdo, struct obd_trans_info *oti)
768 {
769         int rc;
770         ENTRY;
771
772         EXP_CHECK_DT_OP(exp, create);
773         EXP_COUNTER_INCREMENT(exp, create);
774
775         rc = OBP(exp->exp_obd, create)(env, exp, obdo, oti);
776         RETURN(rc);
777 }
778
779 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
780                               struct obdo *obdo, struct obd_trans_info *oti)
781 {
782         int rc;
783         ENTRY;
784
785         EXP_CHECK_DT_OP(exp, destroy);
786         EXP_COUNTER_INCREMENT(exp, destroy);
787
788         rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, oti);
789         RETURN(rc);
790 }
791
792 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
793                               struct obd_info *oinfo)
794 {
795         int rc;
796         ENTRY;
797
798         EXP_CHECK_DT_OP(exp, getattr);
799         EXP_COUNTER_INCREMENT(exp, getattr);
800
801         rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
802         RETURN(rc);
803 }
804
805 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
806                               struct obd_info *oinfo,
807                               struct obd_trans_info *oti)
808 {
809         int rc;
810         ENTRY;
811
812         EXP_CHECK_DT_OP(exp, setattr);
813         EXP_COUNTER_INCREMENT(exp, setattr);
814
815         rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
816         RETURN(rc);
817 }
818
819 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
820                                int priority)
821 {
822         struct obd_device *obd = imp->imp_obd;
823         int rc;
824         ENTRY;
825
826         OBD_CHECK_DEV_ACTIVE(obd);
827         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
828         OBD_COUNTER_INCREMENT(obd, add_conn);
829
830         rc = OBP(obd, add_conn)(imp, uuid, priority);
831         RETURN(rc);
832 }
833
834 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
835 {
836         struct obd_device *obd = imp->imp_obd;
837         int rc;
838         ENTRY;
839
840         OBD_CHECK_DEV_ACTIVE(obd);
841         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
842         OBD_COUNTER_INCREMENT(obd, del_conn);
843
844         rc = OBP(obd, del_conn)(imp, uuid);
845         RETURN(rc);
846 }
847
848 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
849 {
850         struct obd_uuid *uuid;
851         ENTRY;
852
853         OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
854         EXP_COUNTER_INCREMENT(exp, get_uuid);
855
856         uuid = OBP(exp->exp_obd, get_uuid)(exp);
857         RETURN(uuid);
858 }
859
860 /** Create a new /a exp on device /a obd for the uuid /a cluuid
861  * @param exp New export handle
862  * @param d Connect data, supported flags are set, flags also understood
863  *    by obd are returned.
864  */
865 static inline int obd_connect(const struct lu_env *env,
866                               struct obd_export **exp,struct obd_device *obd,
867                               struct obd_uuid *cluuid,
868                               struct obd_connect_data *data,
869                               void *localdata)
870 {
871         int rc;
872         __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
873                                                    * check */
874         ENTRY;
875
876         OBD_CHECK_DEV_ACTIVE(obd);
877         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
878         OBD_COUNTER_INCREMENT(obd, connect);
879
880         rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
881         /* check that only subset is granted */
882         LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
883                                     data->ocd_connect_flags));
884         RETURN(rc);
885 }
886
887 static inline int obd_reconnect(const struct lu_env *env,
888                                 struct obd_export *exp,
889                                 struct obd_device *obd,
890                                 struct obd_uuid *cluuid,
891                                 struct obd_connect_data *d,
892                                 void *localdata)
893 {
894         int rc;
895         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
896                                                    * check */
897
898         ENTRY;
899
900         OBD_CHECK_DEV_ACTIVE(obd);
901         OBD_CHECK_DT_OP(obd, reconnect, 0);
902         OBD_COUNTER_INCREMENT(obd, reconnect);
903
904         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
905         /* check that only subset is granted */
906         LASSERT(ergo(d != NULL,
907                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
908         RETURN(rc);
909 }
910
911 static inline int obd_disconnect(struct obd_export *exp)
912 {
913         int rc;
914         ENTRY;
915
916         EXP_CHECK_DT_OP(exp, disconnect);
917         EXP_COUNTER_INCREMENT(exp, disconnect);
918
919         rc = OBP(exp->exp_obd, disconnect)(exp);
920         RETURN(rc);
921 }
922
923 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
924                                enum lu_cli_type type)
925 {
926         int rc;
927         ENTRY;
928
929         OBD_CHECK_DT_OP(obd, fid_init, 0);
930         OBD_COUNTER_INCREMENT(obd, fid_init);
931
932         rc = OBP(obd, fid_init)(obd, exp, type);
933         RETURN(rc);
934 }
935
936 static inline int obd_fid_fini(struct obd_device *obd)
937 {
938         int rc;
939         ENTRY;
940
941         OBD_CHECK_DT_OP(obd, fid_fini, 0);
942         OBD_COUNTER_INCREMENT(obd, fid_fini);
943
944         rc = OBP(obd, fid_fini)(obd);
945         RETURN(rc);
946 }
947
948 static inline int obd_fid_alloc(const struct lu_env *env,
949                                 struct obd_export *exp,
950                                 struct lu_fid *fid,
951                                 struct md_op_data *op_data)
952 {
953         int rc;
954         ENTRY;
955
956         EXP_CHECK_DT_OP(exp, fid_alloc);
957         EXP_COUNTER_INCREMENT(exp, fid_alloc);
958
959         rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
960         RETURN(rc);
961 }
962
963 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
964 {
965         int rc;
966         ENTRY;
967
968         OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
969         EXP_COUNTER_INCREMENT(exp, ping);
970
971         rc = OBP(exp->exp_obd, ping)(env, exp);
972         RETURN(rc);
973 }
974
975 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
976 {
977         int rc;
978         ENTRY;
979
980         OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
981         OBD_COUNTER_INCREMENT(obd, pool_new);
982
983         rc = OBP(obd, pool_new)(obd, poolname);
984         RETURN(rc);
985 }
986
987 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
988 {
989         int rc;
990         ENTRY;
991
992         OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
993         OBD_COUNTER_INCREMENT(obd, pool_del);
994
995         rc = OBP(obd, pool_del)(obd, poolname);
996         RETURN(rc);
997 }
998
999 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1000 {
1001         int rc;
1002         ENTRY;
1003
1004         OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1005         OBD_COUNTER_INCREMENT(obd, pool_add);
1006
1007         rc = OBP(obd, pool_add)(obd, poolname, ostname);
1008         RETURN(rc);
1009 }
1010
1011 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1012 {
1013         int rc;
1014         ENTRY;
1015
1016         OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1017         OBD_COUNTER_INCREMENT(obd, pool_rem);
1018
1019         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1020         RETURN(rc);
1021 }
1022
1023 static inline void obd_getref(struct obd_device *obd)
1024 {
1025         ENTRY;
1026         if (OBT(obd) && OBP(obd, getref)) {
1027                 OBD_COUNTER_INCREMENT(obd, getref);
1028                 OBP(obd, getref)(obd);
1029         }
1030         EXIT;
1031 }
1032
1033 static inline void obd_putref(struct obd_device *obd)
1034 {
1035         ENTRY;
1036         if (OBT(obd) && OBP(obd, putref)) {
1037                 OBD_COUNTER_INCREMENT(obd, putref);
1038                 OBP(obd, putref)(obd);
1039         }
1040         EXIT;
1041 }
1042
1043 static inline int obd_init_export(struct obd_export *exp)
1044 {
1045         int rc = 0;
1046
1047         ENTRY;
1048         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1049             OBP((exp)->exp_obd, init_export))
1050                 rc = OBP(exp->exp_obd, init_export)(exp);
1051         RETURN(rc);
1052 }
1053
1054 static inline int obd_destroy_export(struct obd_export *exp)
1055 {
1056         ENTRY;
1057         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1058             OBP((exp)->exp_obd, destroy_export))
1059                 OBP(exp->exp_obd, destroy_export)(exp);
1060         RETURN(0);
1061 }
1062
1063 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1064  * If the cache is older than @max_age we will get a new value from the
1065  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1066 static inline int obd_statfs_async(struct obd_export *exp,
1067                                    struct obd_info *oinfo,
1068                                    __u64 max_age,
1069                                    struct ptlrpc_request_set *rqset)
1070 {
1071         int rc = 0;
1072         struct obd_device *obd;
1073         ENTRY;
1074
1075         if (exp == NULL || exp->exp_obd == NULL)
1076                 RETURN(-EINVAL);
1077
1078         obd = exp->exp_obd;
1079         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1080         OBD_COUNTER_INCREMENT(obd, statfs);
1081
1082         CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1083                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1084         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1085                 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1086         } else {
1087                 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1088                        " objects "LPU64"/"LPU64"\n",
1089                        obd->obd_name, &obd->obd_osfs,
1090                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1091                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1092                 spin_lock(&obd->obd_osfs_lock);
1093                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1094                 spin_unlock(&obd->obd_osfs_lock);
1095                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1096                 if (oinfo->oi_cb_up)
1097                         oinfo->oi_cb_up(oinfo, 0);
1098         }
1099         RETURN(rc);
1100 }
1101
1102 static inline int obd_statfs_rqset(struct obd_export *exp,
1103                                    struct obd_statfs *osfs, __u64 max_age,
1104                                    __u32 flags)
1105 {
1106         struct ptlrpc_request_set *set = NULL;
1107         struct obd_info oinfo = { { { 0 } } };
1108         int rc = 0;
1109         ENTRY;
1110
1111         set =  ptlrpc_prep_set();
1112         if (set == NULL)
1113                 RETURN(-ENOMEM);
1114
1115         oinfo.oi_osfs = osfs;
1116         oinfo.oi_flags = flags;
1117         rc = obd_statfs_async(exp, &oinfo, max_age, set);
1118         if (rc == 0)
1119                 rc = ptlrpc_set_wait(set);
1120         ptlrpc_set_destroy(set);
1121         RETURN(rc);
1122 }
1123
1124 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1125  * If the cache is older than @max_age we will get a new value from the
1126  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1127 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1128                              struct obd_statfs *osfs, __u64 max_age,
1129                              __u32 flags)
1130 {
1131         int rc = 0;
1132         struct obd_device *obd = exp->exp_obd;
1133         ENTRY;
1134
1135         if (obd == NULL)
1136                 RETURN(-EINVAL);
1137
1138         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1139         OBD_COUNTER_INCREMENT(obd, statfs);
1140
1141         CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1142                obd->obd_osfs_age, max_age);
1143         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1144                 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1145                 if (rc == 0) {
1146                         spin_lock(&obd->obd_osfs_lock);
1147                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1148                         obd->obd_osfs_age = cfs_time_current_64();
1149                         spin_unlock(&obd->obd_osfs_lock);
1150                 }
1151         } else {
1152                 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1153                        " objects "LPU64"/"LPU64"\n",
1154                        obd->obd_name, &obd->obd_osfs,
1155                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1156                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1157                 spin_lock(&obd->obd_osfs_lock);
1158                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1159                 spin_unlock(&obd->obd_osfs_lock);
1160         }
1161         RETURN(rc);
1162 }
1163
1164 static inline int obd_preprw(const struct lu_env *env, int cmd,
1165                              struct obd_export *exp, struct obdo *oa,
1166                              int objcount, struct obd_ioobj *obj,
1167                              struct niobuf_remote *remote, int *pages,
1168                              struct niobuf_local *local,
1169                              struct obd_trans_info *oti)
1170 {
1171         int rc;
1172         ENTRY;
1173
1174         EXP_CHECK_DT_OP(exp, preprw);
1175         EXP_COUNTER_INCREMENT(exp, preprw);
1176
1177         rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1178                                        pages, local, oti);
1179         RETURN(rc);
1180 }
1181
1182 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1183                                struct obd_export *exp, struct obdo *oa,
1184                                int objcount, struct obd_ioobj *obj,
1185                                struct niobuf_remote *rnb, int pages,
1186                                struct niobuf_local *local,
1187                                struct obd_trans_info *oti, int rc)
1188 {
1189         ENTRY;
1190
1191         EXP_CHECK_DT_OP(exp, commitrw);
1192         EXP_COUNTER_INCREMENT(exp, commitrw);
1193
1194         rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1195                                          rnb, pages, local, oti, rc);
1196         RETURN(rc);
1197 }
1198
1199 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1200                                 int len, void *karg, void __user *uarg)
1201 {
1202         int rc;
1203         ENTRY;
1204
1205         EXP_CHECK_DT_OP(exp, iocontrol);
1206         EXP_COUNTER_INCREMENT(exp, iocontrol);
1207
1208         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1209         RETURN(rc);
1210 }
1211
1212 static inline void obd_import_event(struct obd_device *obd,
1213                                     struct obd_import *imp,
1214                                     enum obd_import_event event)
1215 {
1216         ENTRY;
1217         if (!obd) {
1218                 CERROR("NULL device\n");
1219                 EXIT;
1220                 return;
1221         }
1222         if (obd->obd_set_up && OBP(obd, import_event)) {
1223                 OBD_COUNTER_INCREMENT(obd, import_event);
1224                 OBP(obd, import_event)(obd, imp, event);
1225         }
1226         EXIT;
1227 }
1228
1229 static inline int obd_notify(struct obd_device *obd,
1230                              struct obd_device *watched,
1231                              enum obd_notify_event ev,
1232                              void *data)
1233 {
1234         int rc;
1235         ENTRY;
1236         OBD_CHECK_DEV(obd);
1237
1238         if (!obd->obd_set_up) {
1239                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1240                 RETURN(-EINVAL);
1241         }
1242
1243         if (!OBP(obd, notify)) {
1244                 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1245                 RETURN(-ENOSYS);
1246         }
1247
1248         OBD_COUNTER_INCREMENT(obd, notify);
1249         rc = OBP(obd, notify)(obd, watched, ev, data);
1250         RETURN(rc);
1251 }
1252
1253 static inline int obd_notify_observer(struct obd_device *observer,
1254                                       struct obd_device *observed,
1255                                       enum obd_notify_event ev,
1256                                       void *data)
1257 {
1258         int rc1;
1259         int rc2;
1260
1261         struct obd_notify_upcall *onu;
1262
1263         if (observer->obd_observer)
1264                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1265         else
1266                 rc1 = 0;
1267         /*
1268          * Also, call non-obd listener, if any
1269          */
1270         onu = &observer->obd_upcall;
1271         if (onu->onu_upcall != NULL)
1272                 rc2 = onu->onu_upcall(observer, observed, ev,
1273                                       onu->onu_owner, NULL);
1274         else
1275                 rc2 = 0;
1276
1277         return rc1 ? rc1 : rc2;
1278 }
1279
1280 static inline int obd_quotactl(struct obd_export *exp,
1281                                struct obd_quotactl *oqctl)
1282 {
1283         int rc;
1284         ENTRY;
1285
1286         EXP_CHECK_DT_OP(exp, quotactl);
1287         EXP_COUNTER_INCREMENT(exp, quotactl);
1288
1289         rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1290         RETURN(rc);
1291 }
1292
1293 static inline int obd_health_check(const struct lu_env *env,
1294                                    struct obd_device *obd)
1295 {
1296         /* returns: 0 on healthy
1297          *         >0 on unhealthy + reason code/flag
1298          *            however the only suppored reason == 1 right now
1299          *            We'll need to define some better reasons
1300          *            or flags in the future.
1301          *         <0 on error
1302          */
1303         int rc;
1304         ENTRY;
1305
1306         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1307         if (obd == NULL || !OBT(obd)) {
1308                 CERROR("cleaned up obd\n");
1309                 RETURN(-EOPNOTSUPP);
1310         }
1311         if (!obd->obd_set_up || obd->obd_stopping)
1312                 RETURN(0);
1313         if (!OBP(obd, health_check))
1314                 RETURN(0);
1315
1316         rc = OBP(obd, health_check)(env, obd);
1317         RETURN(rc);
1318 }
1319
1320 static inline int obd_register_observer(struct obd_device *obd,
1321                                         struct obd_device *observer)
1322 {
1323         ENTRY;
1324         OBD_CHECK_DEV(obd);
1325         down_write(&obd->obd_observer_link_sem);
1326         if (obd->obd_observer && observer) {
1327                 up_write(&obd->obd_observer_link_sem);
1328                 RETURN(-EALREADY);
1329         }
1330         obd->obd_observer = observer;
1331         up_write(&obd->obd_observer_link_sem);
1332         RETURN(0);
1333 }
1334
1335 /* metadata helpers */
1336 static inline int md_getstatus(struct obd_export *exp,
1337                                struct lu_fid *fid, struct obd_capa **pc)
1338 {
1339         int rc;
1340         ENTRY;
1341
1342         EXP_CHECK_MD_OP(exp, getstatus);
1343         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1344         rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1345         RETURN(rc);
1346 }
1347
1348 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1349                              struct ptlrpc_request **request)
1350 {
1351         int rc;
1352         ENTRY;
1353         EXP_CHECK_MD_OP(exp, getattr);
1354         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1355         rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1356         RETURN(rc);
1357 }
1358
1359 static inline int md_null_inode(struct obd_export *exp,
1360                                    const struct lu_fid *fid)
1361 {
1362         int rc;
1363         ENTRY;
1364         EXP_CHECK_MD_OP(exp, null_inode);
1365         EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1366         rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1367         RETURN(rc);
1368 }
1369
1370 static inline int md_find_cbdata(struct obd_export *exp,
1371                                  const struct lu_fid *fid,
1372                                  ldlm_iterator_t it, void *data)
1373 {
1374         int rc;
1375         ENTRY;
1376         EXP_CHECK_MD_OP(exp, find_cbdata);
1377         EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1378         rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1379         RETURN(rc);
1380 }
1381
1382 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1383                            struct md_open_data *mod,
1384                            struct ptlrpc_request **request)
1385 {
1386         int rc;
1387         ENTRY;
1388         EXP_CHECK_MD_OP(exp, close);
1389         EXP_MD_COUNTER_INCREMENT(exp, close);
1390         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1391         RETURN(rc);
1392 }
1393
1394 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1395                             const void *data, size_t datalen, umode_t mode,
1396                             uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1397                             __u64 rdev, struct ptlrpc_request **request)
1398 {
1399         int rc;
1400         ENTRY;
1401         EXP_CHECK_MD_OP(exp, create);
1402         EXP_MD_COUNTER_INCREMENT(exp, create);
1403         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1404                                        uid, gid, cap_effective, rdev, request);
1405         RETURN(rc);
1406 }
1407
1408 static inline int md_enqueue(struct obd_export *exp,
1409                              struct ldlm_enqueue_info *einfo,
1410                              const union ldlm_policy_data *policy,
1411                              struct lookup_intent *it,
1412                              struct md_op_data *op_data,
1413                              struct lustre_handle *lockh,
1414                              __u64 extra_lock_flags)
1415 {
1416         int rc;
1417         ENTRY;
1418         EXP_CHECK_MD_OP(exp, enqueue);
1419         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1420         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1421                                         extra_lock_flags);
1422         RETURN(rc);
1423 }
1424
1425 static inline int md_getattr_name(struct obd_export *exp,
1426                                   struct md_op_data *op_data,
1427                                   struct ptlrpc_request **request)
1428 {
1429         int rc;
1430         ENTRY;
1431         EXP_CHECK_MD_OP(exp, getattr_name);
1432         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1433         rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1434         RETURN(rc);
1435 }
1436
1437 static inline int md_intent_lock(struct obd_export *exp,
1438                                  struct md_op_data *op_data,
1439                                  struct lookup_intent *it,
1440                                  struct ptlrpc_request **reqp,
1441                                  ldlm_blocking_callback cb_blocking,
1442                                  __u64 extra_lock_flags)
1443 {
1444         int rc;
1445         ENTRY;
1446         EXP_CHECK_MD_OP(exp, intent_lock);
1447         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1448         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1449                                             extra_lock_flags);
1450         RETURN(rc);
1451 }
1452
1453 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1454                           struct ptlrpc_request **request)
1455 {
1456         int rc;
1457         ENTRY;
1458         EXP_CHECK_MD_OP(exp, link);
1459         EXP_MD_COUNTER_INCREMENT(exp, link);
1460         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1461         RETURN(rc);
1462 }
1463
1464 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1465                             const char *old, size_t oldlen, const char *new,
1466                             size_t newlen, struct ptlrpc_request **request)
1467 {
1468         int rc;
1469         ENTRY;
1470         EXP_CHECK_MD_OP(exp, rename);
1471         EXP_MD_COUNTER_INCREMENT(exp, rename);
1472         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1473                                        newlen, request);
1474         RETURN(rc);
1475 }
1476
1477 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1478                              void *ea, size_t ealen,
1479                              struct ptlrpc_request **request)
1480 {
1481         int rc;
1482         ENTRY;
1483         EXP_CHECK_MD_OP(exp, setattr);
1484         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1485         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1486         RETURN(rc);
1487 }
1488
1489 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1490                            struct obd_capa *oc, struct ptlrpc_request **request)
1491 {
1492         int rc;
1493         ENTRY;
1494         EXP_CHECK_MD_OP(exp, fsync);
1495         EXP_MD_COUNTER_INCREMENT(exp, fsync);
1496         rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1497         RETURN(rc);
1498 }
1499
1500 static inline int md_read_page(struct obd_export *exp,
1501                                struct md_op_data *op_data,
1502                                struct md_callback *cb_op,
1503                                __u64  hash_offset,
1504                                struct page **ppage)
1505 {
1506         int rc;
1507         ENTRY;
1508         EXP_CHECK_MD_OP(exp, read_page);
1509         EXP_MD_COUNTER_INCREMENT(exp, read_page);
1510         rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1511                                           ppage);
1512         RETURN(rc);
1513 }
1514
1515 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1516                             struct ptlrpc_request **request)
1517 {
1518         int rc;
1519         ENTRY;
1520         EXP_CHECK_MD_OP(exp, unlink);
1521         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1522         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1523         RETURN(rc);
1524 }
1525
1526 static inline int md_get_lustre_md(struct obd_export *exp,
1527                                    struct ptlrpc_request *req,
1528                                    struct obd_export *dt_exp,
1529                                    struct obd_export *md_exp,
1530                                    struct lustre_md *md)
1531 {
1532         ENTRY;
1533         EXP_CHECK_MD_OP(exp, get_lustre_md);
1534         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1535         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1536 }
1537
1538 static inline int md_free_lustre_md(struct obd_export *exp,
1539                                     struct lustre_md *md)
1540 {
1541         ENTRY;
1542         EXP_CHECK_MD_OP(exp, free_lustre_md);
1543         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1544         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1545 }
1546
1547 static inline int md_merge_attr(struct obd_export *exp,
1548                                 const struct lmv_stripe_md *lsm,
1549                                 struct cl_attr *attr,
1550                                 ldlm_blocking_callback cb)
1551 {
1552         ENTRY;
1553         EXP_CHECK_MD_OP(exp, merge_attr);
1554         EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1555         RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1556 }
1557
1558 static inline int md_setxattr(struct obd_export *exp,
1559                               const struct lu_fid *fid, struct obd_capa *oc,
1560                               u64 valid, const char *name,
1561                               const char *input, int input_size,
1562                               int output_size, int flags, __u32 suppgid,
1563                               struct ptlrpc_request **request)
1564 {
1565         ENTRY;
1566         EXP_CHECK_MD_OP(exp, setxattr);
1567         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1568         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1569                                            input_size, output_size, flags,
1570                                            suppgid, request));
1571 }
1572
1573 static inline int md_getxattr(struct obd_export *exp,
1574                               const struct lu_fid *fid, struct obd_capa *oc,
1575                               u64 valid, const char *name,
1576                               const char *input, int input_size,
1577                               int output_size, int flags,
1578                               struct ptlrpc_request **request)
1579 {
1580         ENTRY;
1581         EXP_CHECK_MD_OP(exp, getxattr);
1582         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1583         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1584                                            input_size, output_size, flags,
1585                                            request));
1586 }
1587
1588 static inline int md_set_open_replay_data(struct obd_export *exp,
1589                                           struct obd_client_handle *och,
1590                                           struct lookup_intent *it)
1591 {
1592         ENTRY;
1593         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1594         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1595         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1596 }
1597
1598 static inline int md_clear_open_replay_data(struct obd_export *exp,
1599                                             struct obd_client_handle *och)
1600 {
1601         ENTRY;
1602         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1603         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1604         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1605 }
1606
1607 static inline int md_set_lock_data(struct obd_export *exp,
1608                                    __u64 *lockh, void *data, __u64 *bits)
1609 {
1610         ENTRY;
1611         EXP_CHECK_MD_OP(exp, set_lock_data);
1612         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1613         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1614 }
1615
1616 static inline int md_cancel_unused(struct obd_export *exp,
1617                                    const struct lu_fid *fid,
1618                                    ldlm_policy_data_t *policy,
1619                                    ldlm_mode_t mode,
1620                                    ldlm_cancel_flags_t flags,
1621                                    void *opaque)
1622 {
1623         int rc;
1624         ENTRY;
1625
1626         EXP_CHECK_MD_OP(exp, cancel_unused);
1627         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1628
1629         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1630                                               flags, opaque);
1631         RETURN(rc);
1632 }
1633
1634 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1635                                         const struct lu_fid *fid,
1636                                         ldlm_type_t type,
1637                                         ldlm_policy_data_t *policy,
1638                                         ldlm_mode_t mode,
1639                                         struct lustre_handle *lockh)
1640 {
1641         ENTRY;
1642         EXP_CHECK_MD_OP(exp, lock_match);
1643         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1644         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1645                                              policy, mode, lockh));
1646 }
1647
1648 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1649                                   int def_asize, int cookiesize,
1650                                   int def_cookiesize)
1651 {
1652         ENTRY;
1653         EXP_CHECK_MD_OP(exp, init_ea_size);
1654         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1655         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1656                                                cookiesize, def_cookiesize));
1657 }
1658
1659 static inline int md_get_remote_perm(struct obd_export *exp,
1660                                      const struct lu_fid *fid,
1661                                      struct obd_capa *oc, __u32 suppgid,
1662                                      struct ptlrpc_request **request)
1663 {
1664         ENTRY;
1665         EXP_CHECK_MD_OP(exp, get_remote_perm);
1666         EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1667         RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1668                                                   request));
1669 }
1670
1671 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1672                                 renew_capa_cb_t cb)
1673 {
1674         int rc;
1675         ENTRY;
1676         EXP_CHECK_MD_OP(exp, renew_capa);
1677         EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1678         rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1679         RETURN(rc);
1680 }
1681
1682 static inline int md_unpack_capa(struct obd_export *exp,
1683                                  struct ptlrpc_request *req,
1684                                  const struct req_msg_field *field,
1685                                  struct obd_capa **oc)
1686 {
1687         int rc;
1688         ENTRY;
1689         EXP_CHECK_MD_OP(exp, unpack_capa);
1690         EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1691         rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1692         RETURN(rc);
1693 }
1694
1695 static inline int md_intent_getattr_async(struct obd_export *exp,
1696                                           struct md_enqueue_info *minfo,
1697                                           struct ldlm_enqueue_info *einfo)
1698 {
1699         int rc;
1700         ENTRY;
1701         EXP_CHECK_MD_OP(exp, intent_getattr_async);
1702         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1703         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1704         RETURN(rc);
1705 }
1706
1707 static inline int md_revalidate_lock(struct obd_export *exp,
1708                                      struct lookup_intent *it,
1709                                      struct lu_fid *fid, __u64 *bits)
1710 {
1711         int rc;
1712         ENTRY;
1713         EXP_CHECK_MD_OP(exp, revalidate_lock);
1714         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1715         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1716         RETURN(rc);
1717 }
1718
1719 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1720                                       const struct lmv_stripe_md *lsm,
1721                                       const char *name, int namelen,
1722                                       struct lu_fid *fid)
1723 {
1724         int rc;
1725         ENTRY;
1726         EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1727         EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1728         rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1729         RETURN(rc);
1730 }
1731
1732 /* OBD Metadata Support */
1733
1734 extern int obd_init_caches(void);
1735 extern void obd_cleanup_caches(void);
1736
1737 /* support routines */
1738 extern struct kmem_cache *obdo_cachep;
1739
1740 #define OBDO_ALLOC(ptr)                                                       \
1741 do {                                                                          \
1742         OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS);             \
1743 } while(0)
1744
1745 #define OBDO_FREE(ptr)                                                        \
1746 do {                                                                          \
1747         OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                                \
1748 } while(0)
1749
1750
1751 typedef int (*register_lwp_cb)(void *data);
1752
1753 struct lwp_register_item {
1754         struct obd_export **lri_exp;
1755         register_lwp_cb     lri_cb_func;
1756         void               *lri_cb_data;
1757         struct list_head            lri_list;
1758         char                lri_name[MTI_NAME_MAXLEN];
1759 };
1760
1761 /* I'm as embarrassed about this as you are.
1762  *
1763  * <shaver> // XXX do not look into _superhack with remaining eye
1764  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1765 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1766
1767 /* obd_mount.c */
1768 #ifdef HAVE_SERVER_SUPPORT
1769 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1770                              register_lwp_cb cb_func, void *cb_data);
1771 void lustre_deregister_lwp_item(struct obd_export **exp);
1772 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1773 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1774 #endif /* HAVE_SERVER_SUPPORT */
1775 int lustre_register_fs(void);
1776 int lustre_unregister_fs(void);
1777 int lustre_check_exclusion(struct super_block *sb, char *svname);
1778
1779 /* sysctl.c */
1780 extern void obd_sysctl_init (void);
1781 extern void obd_sysctl_clean (void);
1782
1783 /* uuid.c  */
1784 typedef __u8 class_uuid_t[16];
1785 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1786
1787 /* lustre_peer.c    */
1788 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1789 int class_add_uuid(const char *uuid, __u64 nid);
1790 int class_del_uuid (const char *uuid);
1791 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1792 void class_init_uuidlist(void);
1793 void class_exit_uuidlist(void);
1794
1795 /* prng.c */
1796 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1797
1798 /* statfs_pack.c */
1799 struct kstatfs;
1800 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1801 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1802
1803 /* root squash info */
1804 struct rw_semaphore;
1805 struct root_squash_info {
1806         uid_t                   rsi_uid;
1807         gid_t                   rsi_gid;
1808         struct list_head        rsi_nosquash_nids;
1809         struct rw_semaphore     rsi_sem;
1810 };
1811
1812 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1813
1814 /* linux-module.c */
1815 extern struct miscdevice obd_psdev;
1816 int class_procfs_init(void);
1817 int class_procfs_clean(void);
1818
1819 #endif /* __LINUX_OBD_CLASS_H */