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