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