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