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