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