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