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