GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / lustre / 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, 2015, 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 <obd_support.h>
36 #include <lustre_import.h>
37 #include <lustre_net.h>
38 #include <obd.h>
39 #include <lustre_lib.h>
40 #include <lprocfs_status.h>
41
42 #define OBD_STATFS_NODELAY      0x0001  /* requests should be send without delay
43                                          * and resends for avoid deadlocks
44                                          */
45 #define OBD_STATFS_FROM_CACHE   0x0002  /* the statfs callback should not update
46                                          * obd_osfs_age
47                                          */
48 #define OBD_STATFS_FOR_MDT0     0x0004  /* The statfs is only for retrieving
49                                          * information from MDT0.
50                                          */
51
52 /* OBD Device Declarations */
53 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
54 extern rwlock_t obd_dev_lock;
55
56 /* OBD Operations Declarations */
57 struct obd_device *class_exp2obd(struct obd_export *);
58 int class_handle_ioctl(unsigned int cmd, unsigned long arg);
59 int lustre_get_jobid(char *jobid);
60
61 struct lu_device_type;
62
63 /* genops.c */
64 extern struct list_head obd_types;
65 struct obd_export *class_conn2export(struct lustre_handle *);
66 int class_register_type(struct obd_ops *, struct md_ops *,
67                         const char *nm, struct lu_device_type *ldt);
68 int class_unregister_type(const char *nm);
69
70 struct obd_device *class_newdev(const char *type_name, const char *name);
71 void class_release_dev(struct obd_device *obd);
72
73 int class_name2dev(const char *name);
74 struct obd_device *class_name2obd(const char *name);
75 int class_uuid2dev(struct obd_uuid *uuid);
76 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
77                                          const char *typ_name,
78                                          struct obd_uuid *grp_uuid);
79 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
80                                           int *next);
81 struct obd_device *class_num2obd(int num);
82
83 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
84
85 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
86
87 int obd_zombie_impexp_init(void);
88 void obd_zombie_impexp_stop(void);
89 void obd_zombie_barrier(void);
90
91 int obd_get_request_slot(struct client_obd *cli);
92 void obd_put_request_slot(struct client_obd *cli);
93 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
94 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
95 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, u16 max);
96 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
97
98 u16 obd_get_mod_rpc_slot(struct client_obd *cli, u32 opc,
99                          struct lookup_intent *it);
100 void obd_put_mod_rpc_slot(struct client_obd *cli, u32 opc,
101                           struct lookup_intent *it, u16 tag);
102
103 struct llog_handle;
104 struct llog_rec_hdr;
105 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
106                          struct llog_rec_hdr *, void *);
107
108 /* obd_config.c */
109 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
110 int class_process_config(struct lustre_cfg *lcfg);
111 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
112                              struct lustre_cfg *lcfg, void *data);
113
114 /* For interoperability */
115 struct cfg_interop_param {
116         char *old_param;
117         char *new_param;
118 };
119
120 int class_find_param(char *buf, char *key, char **valp);
121 struct cfg_interop_param *class_find_old_param(const char *param,
122                                                struct cfg_interop_param *ptr);
123 int class_get_next_param(char **params, char *copy);
124 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
125 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
126 int class_parse_net(char *buf, u32 *net, char **endh);
127 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
128 int class_match_net(char *buf, char *key, u32 net);
129
130 struct obd_device *class_incref(struct obd_device *obd,
131                                 const char *scope, const void *source);
132 void class_decref(struct obd_device *obd,
133                   const char *scope, const void *source);
134 int class_config_llog_handler(const struct lu_env *env,
135                               struct llog_handle *handle,
136                               struct llog_rec_hdr *rec, void *data);
137 int class_add_uuid(const char *uuid, __u64 nid);
138
139 /*obdecho*/
140 void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
141
142 #define CFG_F_START     0x01   /* Set when we start updating from a log */
143 #define CFG_F_MARKER    0x02   /* We are within a maker */
144 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
145 #define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
146 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
147
148 /* Passed as data param to class_config_parse_llog */
149 struct config_llog_instance {
150         char           *cfg_obdname;
151         void           *cfg_instance;
152         struct super_block *cfg_sb;
153         struct obd_uuid     cfg_uuid;
154         llog_cb_t           cfg_callback;
155         int              cfg_last_idx; /* for partial llog processing */
156         int              cfg_flags;
157 };
158
159 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
160                             char *name, struct config_llog_instance *cfg);
161 enum {
162         CONFIG_T_CONFIG  = 0,
163         CONFIG_T_SPTLRPC = 1,
164         CONFIG_T_RECOVER = 2,
165         CONFIG_T_PARAMS  = 3,
166         CONFIG_T_MAX     = 4
167 };
168
169 #define PARAMS_FILENAME "params"
170 #define LCTL_UPCALL     "lctl"
171
172 /* list of active configuration logs  */
173 struct config_llog_data {
174         struct ldlm_res_id        cld_resid;
175         struct config_llog_instance cld_cfg;
176         struct list_head                  cld_list_chain;
177         atomic_t                cld_refcount;
178         struct config_llog_data    *cld_sptlrpc;/* depended sptlrpc log */
179         struct config_llog_data    *cld_params; /* common parameters log */
180         struct config_llog_data    *cld_recover;/* imperative recover log */
181         struct obd_export         *cld_mgcexp;
182         struct mutex                cld_lock;
183         int                      cld_type;
184         unsigned int            cld_stopping:1, /* we were told to stop
185                                                  * watching
186                                                  */
187                                 cld_lostlock:1; /* lock not requeued */
188         char                    cld_logname[0];
189 };
190
191 struct lustre_profile {
192         struct list_head       lp_list;
193         char        *lp_profile;
194         char        *lp_dt;
195         char        *lp_md;
196         int                     lp_refs;
197         bool                    lp_list_deleted;
198 };
199
200 struct lustre_profile *class_get_profile(const char *prof);
201 void class_del_profile(const char *prof);
202 void class_put_profile(struct lustre_profile *lprof);
203 void class_del_profiles(void);
204
205 #if LUSTRE_TRACKS_LOCK_EXP_REFS
206
207 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
208 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
209 extern void (*class_export_dump_hook)(struct obd_export *);
210
211 #else
212
213 #define __class_export_add_lock_ref(exp, lock)       do {} while (0)
214 #define __class_export_del_lock_ref(exp, lock)       do {} while (0)
215
216 #endif
217
218 /* genops.c */
219 struct obd_export *class_export_get(struct obd_export *exp);
220 void class_export_put(struct obd_export *exp);
221 struct obd_export *class_new_export(struct obd_device *obddev,
222                                     struct obd_uuid *cluuid);
223 void class_unlink_export(struct obd_export *exp);
224
225 struct obd_import *class_import_get(struct obd_import *);
226 void class_import_put(struct obd_import *);
227 struct obd_import *class_new_import(struct obd_device *obd);
228 void class_destroy_import(struct obd_import *exp);
229
230 void class_put_type(struct obd_type *type);
231 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
232                   struct obd_uuid *cluuid);
233 int class_disconnect(struct obd_export *exp);
234 void class_fail_export(struct obd_export *exp);
235 int class_manual_cleanup(struct obd_device *obd);
236
237 static inline void class_export_rpc_inc(struct obd_export *exp)
238 {
239         atomic_inc(&(exp)->exp_rpc_count);
240         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",
241                (exp), atomic_read(&(exp)->exp_rpc_count));
242 }
243
244 static inline void class_export_rpc_dec(struct obd_export *exp)
245 {
246         LASSERT_ATOMIC_POS(&exp->exp_rpc_count);
247         atomic_dec(&(exp)->exp_rpc_count);
248         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",
249                (exp), atomic_read(&(exp)->exp_rpc_count));
250 }
251
252 static inline struct obd_export *class_export_lock_get(struct obd_export *exp,
253                                                        struct ldlm_lock *lock)
254 {
255         atomic_inc(&(exp)->exp_locks_count);
256         __class_export_add_lock_ref(exp, lock);
257         CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n",
258                (exp), atomic_read(&(exp)->exp_locks_count));
259         return class_export_get(exp);
260 }
261
262 static inline void class_export_lock_put(struct obd_export *exp,
263                                          struct ldlm_lock *lock)
264 {
265         LASSERT_ATOMIC_POS(&exp->exp_locks_count);
266         atomic_dec(&(exp)->exp_locks_count);
267         __class_export_del_lock_ref(exp, lock);
268         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n",
269                (exp), atomic_read(&(exp)->exp_locks_count));
270         class_export_put(exp);
271 }
272
273 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
274 {
275         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
276                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
277                 0);
278 }
279
280 static inline int lprocfs_climp_check(struct obd_device *obd)
281 {
282         down_read(&(obd)->u.cli.cl_sem);
283         if (!(obd)->u.cli.cl_import) {
284                 up_read(&(obd)->u.cli.cl_sem);
285                 return -ENODEV;
286         }
287         return 0;
288 }
289
290 struct inode;
291 struct lu_attr;
292 struct obdo;
293
294 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
295
296 #define OBT(dev)        (dev)->obd_type
297 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->op
298 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->op
299 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
300
301 /* Ensure obd_setup: used for cleanup which must be called
302  * while obd is stopping
303  */
304 static inline int obd_check_dev(struct obd_device *obd)
305 {
306         if (!obd) {
307                 CERROR("NULL device\n");
308                 return -ENODEV;
309         }
310         return 0;
311 }
312
313 /* ensure obd_setup and !obd_stopping */
314 static inline int obd_check_dev_active(struct obd_device *obd)
315 {
316         int rc;
317
318         rc = obd_check_dev(obd);
319         if (rc)
320                 return rc;
321         if (!obd->obd_set_up || obd->obd_stopping) {
322                 CERROR("Device %d not setup\n", obd->obd_minor);
323                 return -ENODEV;
324         }
325         return rc;
326 }
327
328 #define OBD_COUNTER_OFFSET(op)                            \
329         ((offsetof(struct obd_ops, op) -                  \
330           offsetof(struct obd_ops, iocontrol))          \
331          / sizeof(((struct obd_ops *)(0))->iocontrol))
332
333 #define OBD_COUNTER_INCREMENT(obdx, op)                    \
334         if ((obdx)->obd_stats) {                                  \
335                 unsigned int coffset;                        \
336                 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
337                         OBD_COUNTER_OFFSET(op);            \
338                 LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
339                 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
340         }
341
342 #define EXP_COUNTER_INCREMENT(export, op)                                   \
343         if ((export)->exp_obd->obd_stats) {                       \
344                 unsigned int coffset;                                   \
345                 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
346                         OBD_COUNTER_OFFSET(op);                       \
347                 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
348                 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
349         }
350
351 #define MD_COUNTER_OFFSET(op)                              \
352         ((offsetof(struct md_ops, op) -            \
353           offsetof(struct md_ops, getstatus))            \
354          / sizeof(((struct md_ops *)(0))->getstatus))
355
356 #define MD_COUNTER_INCREMENT(obdx, op)                     \
357         if ((obd)->md_stats) {                     \
358                 unsigned int coffset;                       \
359                 coffset = (unsigned int)((obdx)->md_cntr_base) + \
360                         MD_COUNTER_OFFSET(op);             \
361                 LASSERT(coffset < (obdx)->md_stats->ls_num);     \
362                 lprocfs_counter_incr((obdx)->md_stats, coffset); \
363         }
364
365 #define EXP_MD_COUNTER_INCREMENT(export, op)                             \
366         if ((export)->exp_obd->obd_stats) {                               \
367                 unsigned int coffset;                                   \
368                 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) +  \
369                         MD_COUNTER_OFFSET(op);                         \
370                 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num);      \
371                 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset);  \
372                 if ((export)->exp_md_stats)                               \
373                         lprocfs_counter_incr(                           \
374                                 (export)->exp_md_stats, coffset);           \
375         }
376
377 #define EXP_CHECK_MD_OP(exp, op)                                \
378 do {                                                        \
379         if (!(exp)) {                               \
380                 CERROR("obd_" #op ": NULL export\n");      \
381                 return -ENODEV;                         \
382         }                                                      \
383         if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) {   \
384                 CERROR("obd_" #op ": cleaned up obd\n");        \
385                 return -EOPNOTSUPP;                         \
386         }                                                      \
387         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
388                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
389                        (exp)->exp_obd->obd_name,                \
390                        (exp)->exp_obd->obd_minor);            \
391                 return -EOPNOTSUPP;                         \
392         }                                                      \
393 } while (0)
394
395 #define OBD_CHECK_DT_OP(obd, op, err)                      \
396 do {                                                        \
397         if (!OBT(obd) || !OBP((obd), op)) {                  \
398                 if (err)                                        \
399                         CERROR("obd_" #op ": dev %d no operation\n",    \
400                                obd->obd_minor);          \
401                 return err;                                 \
402         }                                                      \
403 } while (0)
404
405 #define EXP_CHECK_DT_OP(exp, op)                                \
406 do {                                                        \
407         if (!(exp)) {                               \
408                 CERROR("obd_" #op ": NULL export\n");      \
409                 return -ENODEV;                         \
410         }                                                      \
411         if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) {   \
412                 CERROR("obd_" #op ": cleaned up obd\n");        \
413                 return -EOPNOTSUPP;                         \
414         }                                                      \
415         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
416                 CERROR("obd_" #op ": dev %d no operation\n",    \
417                        (exp)->exp_obd->obd_minor);            \
418                 return -EOPNOTSUPP;                         \
419         }                                                      \
420 } while (0)
421
422 #define CTXT_CHECK_OP(ctxt, op, err)                             \
423 do {                                                             \
424         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
425                 if (err)                                             \
426                         CERROR("lop_" #op ": dev %d no operation\n", \
427                                ctxt->loc_obd->obd_minor);           \
428                 return err;                                      \
429         }                                                           \
430 } while (0)
431
432 static inline int class_devno_max(void)
433 {
434         return MAX_OBD_DEVICES;
435 }
436
437 static inline int obd_get_info(const struct lu_env *env,
438                                struct obd_export *exp, __u32 keylen,
439                                void *key, __u32 *vallen, void *val)
440 {
441         int rc;
442
443         EXP_CHECK_DT_OP(exp, get_info);
444         EXP_COUNTER_INCREMENT(exp, get_info);
445
446         rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
447         return rc;
448 }
449
450 static inline int obd_set_info_async(const struct lu_env *env,
451                                      struct obd_export *exp, u32 keylen,
452                                      void *key, u32 vallen, void *val,
453                                      struct ptlrpc_request_set *set)
454 {
455         int rc;
456
457         EXP_CHECK_DT_OP(exp, set_info_async);
458         EXP_COUNTER_INCREMENT(exp, set_info_async);
459
460         rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
461                                                val, set);
462         return rc;
463 }
464
465 /*
466  * obd-lu integration.
467  *
468  * Functionality is being moved into new lu_device-based layering, but some
469  * pieces of configuration process are still based on obd devices.
470  *
471  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
472  * subsume ->o_setup() methods of obd devices they replace. The same for
473  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
474  * result, obd_setup() and obd_process_config() branch and call one XOR
475  * another.
476  *
477  * Yet neither lu_device_type_operations::ldto_device_fini() nor
478  * lu_device_type_operations::ldto_device_free() fully implement the
479  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
480  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
481  */
482
483 #define DECLARE_LU_VARS(ldt, d)          \
484         struct lu_device_type *ldt;       \
485         struct lu_device *d
486
487 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
488 {
489         int rc;
490         DECLARE_LU_VARS(ldt, d);
491
492         ldt = obd->obd_type->typ_lu;
493         if (ldt) {
494                 struct lu_context  session_ctx;
495                 struct lu_env env;
496
497                 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
498                 session_ctx.lc_thread = NULL;
499                 lu_context_enter(&session_ctx);
500
501                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
502                 if (rc == 0) {
503                         env.le_ses = &session_ctx;
504                         d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
505                         lu_env_fini(&env);
506                         if (!IS_ERR(d)) {
507                                 obd->obd_lu_dev = d;
508                                 d->ld_obd = obd;
509                                 rc = 0;
510                         } else {
511                                 rc = PTR_ERR(d);
512                         }
513                 }
514                 lu_context_exit(&session_ctx);
515                 lu_context_fini(&session_ctx);
516
517         } else {
518                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
519                 OBD_COUNTER_INCREMENT(obd, setup);
520                 rc = OBP(obd, setup)(obd, cfg);
521         }
522         return rc;
523 }
524
525 static inline int obd_precleanup(struct obd_device *obd)
526 {
527         int rc;
528         DECLARE_LU_VARS(ldt, d);
529
530         rc = obd_check_dev(obd);
531         if (rc)
532                 return rc;
533         ldt = obd->obd_type->typ_lu;
534         d = obd->obd_lu_dev;
535         if (ldt && d) {
536                 struct lu_env env;
537
538                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
539                 if (!rc) {
540                         ldt->ldt_ops->ldto_device_fini(&env, d);
541                         lu_env_fini(&env);
542                 }
543         }
544         OBD_CHECK_DT_OP(obd, precleanup, 0);
545         OBD_COUNTER_INCREMENT(obd, precleanup);
546
547         rc = OBP(obd, precleanup)(obd);
548         return rc;
549 }
550
551 static inline int obd_cleanup(struct obd_device *obd)
552 {
553         int rc;
554         DECLARE_LU_VARS(ldt, d);
555
556         rc = obd_check_dev(obd);
557         if (rc)
558                 return rc;
559
560         ldt = obd->obd_type->typ_lu;
561         d = obd->obd_lu_dev;
562         if (ldt && d) {
563                 struct lu_env env;
564
565                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
566                 if (rc == 0) {
567                         ldt->ldt_ops->ldto_device_free(&env, d);
568                         lu_env_fini(&env);
569                         obd->obd_lu_dev = NULL;
570                 }
571         }
572         OBD_CHECK_DT_OP(obd, cleanup, 0);
573         OBD_COUNTER_INCREMENT(obd, cleanup);
574
575         rc = OBP(obd, cleanup)(obd);
576         return rc;
577 }
578
579 static inline void obd_cleanup_client_import(struct obd_device *obd)
580 {
581         /* If we set up but never connected, the
582          * client import will not have been cleaned.
583          */
584         down_write(&obd->u.cli.cl_sem);
585         if (obd->u.cli.cl_import) {
586                 struct obd_import *imp;
587
588                 imp = obd->u.cli.cl_import;
589                 CDEBUG(D_CONFIG, "%s: client import never connected\n",
590                        obd->obd_name);
591                 ptlrpc_invalidate_import(imp);
592                 client_destroy_import(imp);
593                 obd->u.cli.cl_import = NULL;
594         }
595         up_write(&obd->u.cli.cl_sem);
596 }
597
598 static inline int
599 obd_process_config(struct obd_device *obd, int datalen, void *data)
600 {
601         int rc;
602         DECLARE_LU_VARS(ldt, d);
603
604         rc = obd_check_dev(obd);
605         if (rc)
606                 return rc;
607
608         obd->obd_process_conf = 1;
609         ldt = obd->obd_type->typ_lu;
610         d = obd->obd_lu_dev;
611         if (ldt && d) {
612                 struct lu_env env;
613
614                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
615                 if (rc == 0) {
616                         rc = d->ld_ops->ldo_process_config(&env, d, data);
617                         lu_env_fini(&env);
618                 }
619         } else {
620                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
621                 rc = OBP(obd, process_config)(obd, datalen, data);
622         }
623         OBD_COUNTER_INCREMENT(obd, process_config);
624         obd->obd_process_conf = 0;
625
626         return rc;
627 }
628
629 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
630                              struct obdo *obdo)
631 {
632         int rc;
633
634         EXP_CHECK_DT_OP(exp, create);
635         EXP_COUNTER_INCREMENT(exp, create);
636
637         rc = OBP(exp->exp_obd, create)(env, exp, obdo);
638         return rc;
639 }
640
641 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
642                               struct obdo *obdo)
643 {
644         int rc;
645
646         EXP_CHECK_DT_OP(exp, destroy);
647         EXP_COUNTER_INCREMENT(exp, destroy);
648
649         rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
650         return rc;
651 }
652
653 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
654                               struct obdo *oa)
655 {
656         int rc;
657
658         EXP_CHECK_DT_OP(exp, getattr);
659         EXP_COUNTER_INCREMENT(exp, getattr);
660
661         rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
662         return rc;
663 }
664
665 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
666                               struct obdo *oa)
667 {
668         int rc;
669
670         EXP_CHECK_DT_OP(exp, setattr);
671         EXP_COUNTER_INCREMENT(exp, setattr);
672
673         rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
674         return rc;
675 }
676
677 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
678                                int priority)
679 {
680         struct obd_device *obd = imp->imp_obd;
681         int rc;
682
683         rc = obd_check_dev_active(obd);
684         if (rc)
685                 return rc;
686         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
687         OBD_COUNTER_INCREMENT(obd, add_conn);
688
689         rc = OBP(obd, add_conn)(imp, uuid, priority);
690         return rc;
691 }
692
693 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
694 {
695         struct obd_device *obd = imp->imp_obd;
696         int rc;
697
698         rc = obd_check_dev_active(obd);
699         if (rc)
700                 return rc;
701         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
702         OBD_COUNTER_INCREMENT(obd, del_conn);
703
704         rc = OBP(obd, del_conn)(imp, uuid);
705         return rc;
706 }
707
708 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
709 {
710         struct obd_uuid *uuid;
711
712         OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
713         EXP_COUNTER_INCREMENT(exp, get_uuid);
714
715         uuid = OBP(exp->exp_obd, get_uuid)(exp);
716         return uuid;
717 }
718
719 /** Create a new /a exp on device /a obd for the uuid /a cluuid
720  * @param exp New export handle
721  * @param d Connect data, supported flags are set, flags also understood
722  *    by obd are returned.
723  */
724 static inline int obd_connect(const struct lu_env *env,
725                               struct obd_export **exp, struct obd_device *obd,
726                               struct obd_uuid *cluuid,
727                               struct obd_connect_data *data,
728                               void *localdata)
729 {
730         int rc;
731         __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
732                                                          * check
733                                                          */
734
735         rc = obd_check_dev_active(obd);
736         if (rc)
737                 return rc;
738         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
739         OBD_COUNTER_INCREMENT(obd, connect);
740
741         rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
742         /* check that only subset is granted */
743         LASSERT(ergo(data, (data->ocd_connect_flags & ocf) ==
744                                     data->ocd_connect_flags));
745         return rc;
746 }
747
748 static inline int obd_reconnect(const struct lu_env *env,
749                                 struct obd_export *exp,
750                                 struct obd_device *obd,
751                                 struct obd_uuid *cluuid,
752                                 struct obd_connect_data *d,
753                                 void *localdata)
754 {
755         int rc;
756         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
757
758         rc = obd_check_dev_active(obd);
759         if (rc)
760                 return rc;
761         OBD_CHECK_DT_OP(obd, reconnect, 0);
762         OBD_COUNTER_INCREMENT(obd, reconnect);
763
764         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
765         /* check that only subset is granted */
766         LASSERT(ergo(d, (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
767         return rc;
768 }
769
770 static inline int obd_disconnect(struct obd_export *exp)
771 {
772         int rc;
773
774         EXP_CHECK_DT_OP(exp, disconnect);
775         EXP_COUNTER_INCREMENT(exp, disconnect);
776
777         rc = OBP(exp->exp_obd, disconnect)(exp);
778         return rc;
779 }
780
781 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
782                                enum lu_cli_type type)
783 {
784         int rc;
785
786         OBD_CHECK_DT_OP(obd, fid_init, 0);
787         OBD_COUNTER_INCREMENT(obd, fid_init);
788
789         rc = OBP(obd, fid_init)(obd, exp, type);
790         return rc;
791 }
792
793 static inline int obd_fid_fini(struct obd_device *obd)
794 {
795         int rc;
796
797         OBD_CHECK_DT_OP(obd, fid_fini, 0);
798         OBD_COUNTER_INCREMENT(obd, fid_fini);
799
800         rc = OBP(obd, fid_fini)(obd);
801         return rc;
802 }
803
804 static inline int obd_fid_alloc(const struct lu_env *env,
805                                 struct obd_export *exp,
806                                 struct lu_fid *fid,
807                                 struct md_op_data *op_data)
808 {
809         int rc;
810
811         EXP_CHECK_DT_OP(exp, fid_alloc);
812         EXP_COUNTER_INCREMENT(exp, fid_alloc);
813
814         rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
815         return rc;
816 }
817
818 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
819 {
820         int rc;
821
822         OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
823         OBD_COUNTER_INCREMENT(obd, pool_new);
824
825         rc = OBP(obd, pool_new)(obd, poolname);
826         return rc;
827 }
828
829 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
830 {
831         int rc;
832
833         OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
834         OBD_COUNTER_INCREMENT(obd, pool_del);
835
836         rc = OBP(obd, pool_del)(obd, poolname);
837         return rc;
838 }
839
840 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
841 {
842         int rc;
843
844         OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
845         OBD_COUNTER_INCREMENT(obd, pool_add);
846
847         rc = OBP(obd, pool_add)(obd, poolname, ostname);
848         return rc;
849 }
850
851 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
852 {
853         int rc;
854
855         OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
856         OBD_COUNTER_INCREMENT(obd, pool_rem);
857
858         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
859         return rc;
860 }
861
862 static inline void obd_getref(struct obd_device *obd)
863 {
864         if (OBT(obd) && OBP(obd, getref)) {
865                 OBD_COUNTER_INCREMENT(obd, getref);
866                 OBP(obd, getref)(obd);
867         }
868 }
869
870 static inline void obd_putref(struct obd_device *obd)
871 {
872         if (OBT(obd) && OBP(obd, putref)) {
873                 OBD_COUNTER_INCREMENT(obd, putref);
874                 OBP(obd, putref)(obd);
875         }
876 }
877
878 static inline int obd_init_export(struct obd_export *exp)
879 {
880         int rc = 0;
881
882         if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
883             OBP((exp)->exp_obd, init_export))
884                 rc = OBP(exp->exp_obd, init_export)(exp);
885         return rc;
886 }
887
888 static inline int obd_destroy_export(struct obd_export *exp)
889 {
890         if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
891             OBP((exp)->exp_obd, destroy_export))
892                 OBP(exp->exp_obd, destroy_export)(exp);
893         return 0;
894 }
895
896 /* @max_age is the oldest time in jiffies that we accept using a cached data.
897  * If the cache is older than @max_age we will get a new value from the
898  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness.
899  */
900 static inline int obd_statfs_async(struct obd_export *exp,
901                                    struct obd_info *oinfo,
902                                    __u64 max_age,
903                                    struct ptlrpc_request_set *rqset)
904 {
905         int rc = 0;
906         struct obd_device *obd;
907
908         if (!exp || !exp->exp_obd)
909                 return -EINVAL;
910
911         obd = exp->exp_obd;
912         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
913         OBD_COUNTER_INCREMENT(obd, statfs);
914
915         CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
916                obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
917         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
918                 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
919         } else {
920                 CDEBUG(D_SUPER,
921                        "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
922                        obd->obd_name, &obd->obd_osfs,
923                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
924                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
925                 spin_lock(&obd->obd_osfs_lock);
926                 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
927                 spin_unlock(&obd->obd_osfs_lock);
928                 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
929                 if (oinfo->oi_cb_up)
930                         oinfo->oi_cb_up(oinfo, 0);
931         }
932         return rc;
933 }
934
935 static inline int obd_statfs_rqset(struct obd_export *exp,
936                                    struct obd_statfs *osfs, __u64 max_age,
937                                    __u32 flags)
938 {
939         struct ptlrpc_request_set *set = NULL;
940         struct obd_info oinfo = {
941                 .oi_osfs = osfs,
942                 .oi_flags = flags,
943         };
944         int rc = 0;
945
946         set = ptlrpc_prep_set();
947         if (!set)
948                 return -ENOMEM;
949
950         rc = obd_statfs_async(exp, &oinfo, max_age, set);
951         if (rc == 0)
952                 rc = ptlrpc_set_wait(set);
953         ptlrpc_set_destroy(set);
954         return rc;
955 }
956
957 /* @max_age is the oldest time in jiffies that we accept using a cached data.
958  * If the cache is older than @max_age we will get a new value from the
959  * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness.
960  */
961 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
962                              struct obd_statfs *osfs, __u64 max_age,
963                              __u32 flags)
964 {
965         int rc = 0;
966         struct obd_device *obd = exp->exp_obd;
967
968         if (!obd)
969                 return -EINVAL;
970
971         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
972         OBD_COUNTER_INCREMENT(obd, statfs);
973
974         CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
975                obd->obd_osfs_age, max_age);
976         if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
977                 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
978                 if (rc == 0) {
979                         spin_lock(&obd->obd_osfs_lock);
980                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
981                         obd->obd_osfs_age = cfs_time_current_64();
982                         spin_unlock(&obd->obd_osfs_lock);
983                 }
984         } else {
985                 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
986                        obd->obd_name, &obd->obd_osfs,
987                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
988                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
989                 spin_lock(&obd->obd_osfs_lock);
990                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
991                 spin_unlock(&obd->obd_osfs_lock);
992         }
993         return rc;
994 }
995
996 static inline int obd_preprw(const struct lu_env *env, int cmd,
997                              struct obd_export *exp, struct obdo *oa,
998                              int objcount, struct obd_ioobj *obj,
999                              struct niobuf_remote *remote, int *pages,
1000                              struct niobuf_local *local)
1001 {
1002         int rc;
1003
1004         EXP_CHECK_DT_OP(exp, preprw);
1005         EXP_COUNTER_INCREMENT(exp, preprw);
1006
1007         rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1008                                        pages, local);
1009         return rc;
1010 }
1011
1012 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1013                                struct obd_export *exp, struct obdo *oa,
1014                                int objcount, struct obd_ioobj *obj,
1015                                struct niobuf_remote *rnb, int pages,
1016                                struct niobuf_local *local, int rc)
1017 {
1018         EXP_CHECK_DT_OP(exp, commitrw);
1019         EXP_COUNTER_INCREMENT(exp, commitrw);
1020
1021         rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1022                                          rnb, pages, local, rc);
1023         return rc;
1024 }
1025
1026 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1027                                 int len, void *karg, void __user *uarg)
1028 {
1029         int rc;
1030
1031         EXP_CHECK_DT_OP(exp, iocontrol);
1032         EXP_COUNTER_INCREMENT(exp, iocontrol);
1033
1034         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1035         return rc;
1036 }
1037
1038 static inline void obd_import_event(struct obd_device *obd,
1039                                     struct obd_import *imp,
1040                                     enum obd_import_event event)
1041 {
1042         if (!obd) {
1043                 CERROR("NULL device\n");
1044                 return;
1045         }
1046         if (obd->obd_set_up && OBP(obd, import_event)) {
1047                 OBD_COUNTER_INCREMENT(obd, import_event);
1048                 OBP(obd, import_event)(obd, imp, event);
1049         }
1050 }
1051
1052 static inline int obd_notify(struct obd_device *obd,
1053                              struct obd_device *watched,
1054                              enum obd_notify_event ev,
1055                              void *data)
1056 {
1057         int rc;
1058
1059         rc = obd_check_dev(obd);
1060         if (rc)
1061                 return rc;
1062
1063         if (!obd->obd_set_up) {
1064                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1065                 return -EINVAL;
1066         }
1067
1068         if (!OBP(obd, notify)) {
1069                 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1070                 return -ENOSYS;
1071         }
1072
1073         OBD_COUNTER_INCREMENT(obd, notify);
1074         rc = OBP(obd, notify)(obd, watched, ev, data);
1075         return rc;
1076 }
1077
1078 static inline int obd_notify_observer(struct obd_device *observer,
1079                                       struct obd_device *observed,
1080                                       enum obd_notify_event ev,
1081                                       void *data)
1082 {
1083         int rc1;
1084         int rc2;
1085
1086         struct obd_notify_upcall *onu;
1087
1088         if (observer->obd_observer)
1089                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1090         else
1091                 rc1 = 0;
1092         /*
1093          * Also, call non-obd listener, if any
1094          */
1095         onu = &observer->obd_upcall;
1096         if (onu->onu_upcall)
1097                 rc2 = onu->onu_upcall(observer, observed, ev,
1098                                       onu->onu_owner, NULL);
1099         else
1100                 rc2 = 0;
1101
1102         return rc1 ? rc1 : rc2;
1103 }
1104
1105 static inline int obd_quotactl(struct obd_export *exp,
1106                                struct obd_quotactl *oqctl)
1107 {
1108         int rc;
1109
1110         EXP_CHECK_DT_OP(exp, quotactl);
1111         EXP_COUNTER_INCREMENT(exp, quotactl);
1112
1113         rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1114         return rc;
1115 }
1116
1117 static inline int obd_health_check(const struct lu_env *env,
1118                                    struct obd_device *obd)
1119 {
1120         /* returns: 0 on healthy
1121          *       >0 on unhealthy + reason code/flag
1122          *          however the only supported reason == 1 right now
1123          *          We'll need to define some better reasons
1124          *          or flags in the future.
1125          *       <0 on error
1126          */
1127         int rc;
1128
1129         /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1130         if (!obd || !OBT(obd)) {
1131                 CERROR("cleaned up obd\n");
1132                 return -EOPNOTSUPP;
1133         }
1134         if (!obd->obd_set_up || obd->obd_stopping)
1135                 return 0;
1136         if (!OBP(obd, health_check))
1137                 return 0;
1138
1139         rc = OBP(obd, health_check)(env, obd);
1140         return rc;
1141 }
1142
1143 static inline int obd_register_observer(struct obd_device *obd,
1144                                         struct obd_device *observer)
1145 {
1146         int rc;
1147
1148         rc = obd_check_dev(obd);
1149         if (rc)
1150                 return rc;
1151         down_write(&obd->obd_observer_link_sem);
1152         if (obd->obd_observer && observer) {
1153                 up_write(&obd->obd_observer_link_sem);
1154                 return -EALREADY;
1155         }
1156         obd->obd_observer = observer;
1157         up_write(&obd->obd_observer_link_sem);
1158         return 0;
1159 }
1160
1161 /* metadata helpers */
1162 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1163 {
1164         int rc;
1165
1166         EXP_CHECK_MD_OP(exp, getstatus);
1167         EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1168         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1169         return rc;
1170 }
1171
1172 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1173                              struct ptlrpc_request **request)
1174 {
1175         int rc;
1176
1177         EXP_CHECK_MD_OP(exp, getattr);
1178         EXP_MD_COUNTER_INCREMENT(exp, getattr);
1179         rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1180         return rc;
1181 }
1182
1183 static inline int md_null_inode(struct obd_export *exp,
1184                                 const struct lu_fid *fid)
1185 {
1186         int rc;
1187
1188         EXP_CHECK_MD_OP(exp, null_inode);
1189         EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1190         rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1191         return rc;
1192 }
1193
1194 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1195                            struct md_open_data *mod,
1196                            struct ptlrpc_request **request)
1197 {
1198         int rc;
1199
1200         EXP_CHECK_MD_OP(exp, close);
1201         EXP_MD_COUNTER_INCREMENT(exp, close);
1202         rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1203         return rc;
1204 }
1205
1206 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1207                             const void *data, size_t datalen, umode_t mode,
1208                             uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1209                             __u64 rdev, struct ptlrpc_request **request)
1210 {
1211         int rc;
1212
1213         EXP_CHECK_MD_OP(exp, create);
1214         EXP_MD_COUNTER_INCREMENT(exp, create);
1215         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1216                                        uid, gid, cap_effective, rdev, request);
1217         return rc;
1218 }
1219
1220 static inline int md_enqueue(struct obd_export *exp,
1221                              struct ldlm_enqueue_info *einfo,
1222                              const union ldlm_policy_data *policy,
1223                              struct lookup_intent *it,
1224                              struct md_op_data *op_data,
1225                              struct lustre_handle *lockh,
1226                              __u64 extra_lock_flags)
1227 {
1228         int rc;
1229
1230         EXP_CHECK_MD_OP(exp, enqueue);
1231         EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1232         rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1233                                         extra_lock_flags);
1234         return rc;
1235 }
1236
1237 static inline int md_getattr_name(struct obd_export *exp,
1238                                   struct md_op_data *op_data,
1239                                   struct ptlrpc_request **request)
1240 {
1241         int rc;
1242
1243         EXP_CHECK_MD_OP(exp, getattr_name);
1244         EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1245         rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1246         return rc;
1247 }
1248
1249 static inline int md_intent_lock(struct obd_export *exp,
1250                                  struct md_op_data *op_data,
1251                                  struct lookup_intent *it,
1252                                  struct ptlrpc_request **reqp,
1253                                  ldlm_blocking_callback cb_blocking,
1254                                  __u64 extra_lock_flags)
1255 {
1256         int rc;
1257
1258         EXP_CHECK_MD_OP(exp, intent_lock);
1259         EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1260         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1261                                             cb_blocking, extra_lock_flags);
1262         return rc;
1263 }
1264
1265 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1266                           struct ptlrpc_request **request)
1267 {
1268         int rc;
1269
1270         EXP_CHECK_MD_OP(exp, link);
1271         EXP_MD_COUNTER_INCREMENT(exp, link);
1272         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1273         return rc;
1274 }
1275
1276 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1277                             const char *old, size_t oldlen, const char *new,
1278                             size_t newlen, struct ptlrpc_request **request)
1279 {
1280         int rc;
1281
1282         EXP_CHECK_MD_OP(exp, rename);
1283         EXP_MD_COUNTER_INCREMENT(exp, rename);
1284         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1285                                        newlen, request);
1286         return rc;
1287 }
1288
1289 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1290                              void *ea, size_t ealen,
1291                              struct ptlrpc_request **request)
1292 {
1293         int rc;
1294
1295         EXP_CHECK_MD_OP(exp, setattr);
1296         EXP_MD_COUNTER_INCREMENT(exp, setattr);
1297         rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1298         return rc;
1299 }
1300
1301 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1302                           struct ptlrpc_request **request)
1303 {
1304         int rc;
1305
1306         EXP_CHECK_MD_OP(exp, sync);
1307         EXP_MD_COUNTER_INCREMENT(exp, sync);
1308         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1309         return rc;
1310 }
1311
1312 static inline int md_read_page(struct obd_export *exp,
1313                                struct md_op_data *op_data,
1314                                struct md_callback *cb_op,
1315                                __u64  hash_offset,
1316                                struct page **ppage)
1317 {
1318         int rc;
1319
1320         EXP_CHECK_MD_OP(exp, read_page);
1321         EXP_MD_COUNTER_INCREMENT(exp, read_page);
1322         rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1323                                           ppage);
1324         return rc;
1325 }
1326
1327 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1328                             struct ptlrpc_request **request)
1329 {
1330         int rc;
1331
1332         EXP_CHECK_MD_OP(exp, unlink);
1333         EXP_MD_COUNTER_INCREMENT(exp, unlink);
1334         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1335         return rc;
1336 }
1337
1338 static inline int md_get_lustre_md(struct obd_export *exp,
1339                                    struct ptlrpc_request *req,
1340                                    struct obd_export *dt_exp,
1341                                    struct obd_export *md_exp,
1342                                    struct lustre_md *md)
1343 {
1344         EXP_CHECK_MD_OP(exp, get_lustre_md);
1345         EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1346         return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1347 }
1348
1349 static inline int md_free_lustre_md(struct obd_export *exp,
1350                                     struct lustre_md *md)
1351 {
1352         EXP_CHECK_MD_OP(exp, free_lustre_md);
1353         EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1354         return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1355 }
1356
1357 static inline int md_merge_attr(struct obd_export *exp,
1358                                 const struct lmv_stripe_md *lsm,
1359                                 struct cl_attr *attr,
1360                                 ldlm_blocking_callback cb)
1361 {
1362         EXP_CHECK_MD_OP(exp, merge_attr);
1363         EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1364         return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1365 }
1366
1367 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1368                               u64 valid, const char *name,
1369                               const char *input, int input_size,
1370                               int output_size, int flags, __u32 suppgid,
1371                               struct ptlrpc_request **request)
1372 {
1373         EXP_CHECK_MD_OP(exp, setxattr);
1374         EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1375         return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1376                                            input_size, output_size, flags,
1377                                            suppgid, request);
1378 }
1379
1380 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1381                               u64 valid, const char *name,
1382                               const char *input, int input_size,
1383                               int output_size, int flags,
1384                               struct ptlrpc_request **request)
1385 {
1386         EXP_CHECK_MD_OP(exp, getxattr);
1387         EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1388         return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1389                                            input_size, output_size, flags,
1390                                            request);
1391 }
1392
1393 static inline int md_set_open_replay_data(struct obd_export *exp,
1394                                           struct obd_client_handle *och,
1395                                           struct lookup_intent *it)
1396 {
1397         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1398         EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1399         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1400 }
1401
1402 static inline int md_clear_open_replay_data(struct obd_export *exp,
1403                                             struct obd_client_handle *och)
1404 {
1405         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1406         EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1407         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1408 }
1409
1410 static inline int md_set_lock_data(struct obd_export *exp,
1411                                    const struct lustre_handle *lockh,
1412                                    void *data, __u64 *bits)
1413 {
1414         EXP_CHECK_MD_OP(exp, set_lock_data);
1415         EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1416         return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1417 }
1418
1419 static inline int md_cancel_unused(struct obd_export *exp,
1420                                    const struct lu_fid *fid,
1421                                    union ldlm_policy_data *policy,
1422                                    enum ldlm_mode mode,
1423                                    enum ldlm_cancel_flags flags,
1424                                    void *opaque)
1425 {
1426         int rc;
1427
1428         EXP_CHECK_MD_OP(exp, cancel_unused);
1429         EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1430
1431         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1432                                               flags, opaque);
1433         return rc;
1434 }
1435
1436 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1437                                            const struct lu_fid *fid,
1438                                            enum ldlm_type type,
1439                                            union ldlm_policy_data *policy,
1440                                            enum ldlm_mode mode,
1441                                            struct lustre_handle *lockh)
1442 {
1443         EXP_CHECK_MD_OP(exp, lock_match);
1444         EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1445         return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1446                                              policy, mode, lockh);
1447 }
1448
1449 static inline int md_init_ea_size(struct obd_export *exp, u32 easize,
1450                                   u32 def_asize)
1451 {
1452         EXP_CHECK_MD_OP(exp, init_ea_size);
1453         EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1454         return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize);
1455 }
1456
1457 static inline int md_intent_getattr_async(struct obd_export *exp,
1458                                           struct md_enqueue_info *minfo)
1459 {
1460         int rc;
1461
1462         EXP_CHECK_MD_OP(exp, intent_getattr_async);
1463         EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1464         rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1465         return rc;
1466 }
1467
1468 static inline int md_revalidate_lock(struct obd_export *exp,
1469                                      struct lookup_intent *it,
1470                                      struct lu_fid *fid, __u64 *bits)
1471 {
1472         int rc;
1473
1474         EXP_CHECK_MD_OP(exp, revalidate_lock);
1475         EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1476         rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1477         return rc;
1478 }
1479
1480 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1481                                       const struct lmv_stripe_md *lsm,
1482                                       const char *name, int namelen,
1483                                       struct lu_fid *fid)
1484 {
1485         int rc;
1486
1487         EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1488         EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1489         rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1490         return rc;
1491 }
1492
1493 /* Unpack an MD struct from disk to in-memory format.
1494  * Returns +ve size of unpacked MD (0 for free), or -ve error.
1495  *
1496  * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1497  * If *plsm == NULL then it will be allocated.
1498  */
1499 static inline int md_unpackmd(struct obd_export *exp,
1500                               struct lmv_stripe_md **plsm,
1501                               const union lmv_mds_md *lmm, size_t lmm_size)
1502 {
1503         int rc;
1504
1505         EXP_CHECK_MD_OP(exp, unpackmd);
1506         EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1507         rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1508         return rc;
1509 }
1510
1511 /* OBD Metadata Support */
1512
1513 int obd_init_caches(void);
1514 void obd_cleanup_caches(void);
1515
1516 /* support routines */
1517 extern struct kmem_cache *obdo_cachep;
1518
1519 typedef int (*register_lwp_cb)(void *data);
1520
1521 struct lwp_register_item {
1522         struct obd_export **lri_exp;
1523         register_lwp_cb     lri_cb_func;
1524         void               *lri_cb_data;
1525         struct list_head            lri_list;
1526         char                lri_name[MTI_NAME_MAXLEN];
1527 };
1528
1529 /* I'm as embarrassed about this as you are.
1530  *
1531  * <shaver> // XXX do not look into _superhack with remaining eye
1532  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV
1533  */
1534 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1535
1536 /* obd_mount.c */
1537 int lustre_unregister_fs(void);
1538 int lustre_register_fs(void);
1539 int lustre_check_exclusion(struct super_block *sb, char *svname);
1540
1541 /* sysctl.c */
1542 int obd_sysctl_init(void);
1543
1544 /* uuid.c  */
1545 typedef __u8 class_uuid_t[16];
1546 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1547
1548 /* lustre_peer.c    */
1549 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1550 int class_add_uuid(const char *uuid, __u64 nid);
1551 int class_del_uuid(const char *uuid);
1552 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1553 void class_init_uuidlist(void);
1554 void class_exit_uuidlist(void);
1555
1556 /* class_obd.c */
1557 extern char obd_jobid_node[];
1558 extern struct miscdevice obd_psdev;
1559 extern spinlock_t obd_types_lock;
1560 int class_procfs_init(void);
1561 int class_procfs_clean(void);
1562
1563 /* prng.c */
1564 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1565
1566 /* statfs_pack.c */
1567 struct kstatfs;
1568 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1569 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1570
1571 /* root squash info */
1572 struct rw_semaphore;
1573 struct root_squash_info {
1574         uid_t                   rsi_uid;
1575         gid_t                   rsi_gid;
1576         struct list_head        rsi_nosquash_nids;
1577         struct rw_semaphore     rsi_sem;
1578 };
1579
1580 /* linux-module.c */
1581 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1582
1583 #endif /* __LINUX_OBD_CLASS_H */