Whamcloud - gitweb
modify dt_index_operations to be usable as generic index
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
25
26 #ifndef __KERNEL__
27 #include <sys/types.h>
28 #include <libcfs/list.h>
29 #else
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
33 #include <linux/fs.h>
34 #include <linux/dcache.h>
35 #include <linux/time.h>
36 #include <linux/timer.h>
37 #endif
38
39 #include <linux/obd_support.h>
40 #include <linux/lustre_import.h>
41 #include <linux/lustre_net.h>
42 #include <linux/obd.h>
43 #include <linux/lustre_lib.h>
44 #include <linux/lustre_idl.h>
45 #include <linux/lprocfs_status.h>
46
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 520
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
50 extern spinlock_t obd_dev_lock;
51
52 /* OBD Operations Declarations */
53 extern struct obd_device *class_conn2obd(struct lustre_handle *);
54 extern struct obd_device *class_exp2obd(struct obd_export *);
55
56 struct lu_device_type;
57
58 /* genops.c */
59 struct obd_export *class_conn2export(struct lustre_handle *);
60 int class_register_type(struct obd_ops *, struct md_ops *,
61                         struct lprocfs_vars *, const char *nm,
62                         struct lu_device_type *ldt);
63 int class_unregister_type(const char *nm);
64
65 struct obd_device *class_newdev(struct obd_type *type, char *name);
66 void class_release_dev(struct obd_device *obd);
67
68 int class_name2dev(const char *name);
69 struct obd_device *class_name2obd(const char *name);
70 int class_uuid2dev(struct obd_uuid *uuid);
71 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
72 void class_obd_list(void);
73 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
74                                           const char * typ_name,
75                                           struct obd_uuid *grp_uuid);
76 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
77                                              struct obd_uuid *grp_uuid);
78 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
79                                            int *next);
80
81 int oig_init(struct obd_io_group **oig);
82 void oig_add_one(struct obd_io_group *oig,
83                   struct oig_callback_context *occ);
84 void oig_complete_one(struct obd_io_group *oig,
85                       struct oig_callback_context *occ, int rc);
86 void oig_release(struct obd_io_group *oig);
87 int oig_wait(struct obd_io_group *oig);
88
89 char *obd_export_nid2str(struct obd_export *exp);
90
91 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
92 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
93
94 /* obd_config.c */
95 int class_process_config(struct lustre_cfg *lcfg);
96 int class_attach(struct lustre_cfg *lcfg);
97 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
98 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
99 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
100 struct obd_device *class_incref(struct obd_device *obd);
101 void class_decref(struct obd_device *obd);
102
103 #define CFG_F_START     0x01   /* Set when we start updating from a log */
104 #define CFG_F_MARKER    0x02   /* We are within a maker */
105 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
106 #define CFG_F_COMPAT146 0x08   /* Translation to new obd names required */
107 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
108
109
110 /* Passed as data param to class_config_parse_llog */
111 struct config_llog_instance {
112         char *              cfg_instance;
113         struct super_block *cfg_sb;
114         struct obd_uuid     cfg_uuid;
115         int                 cfg_last_idx; /* for partial llog processing */
116         int                 cfg_flags;
117 };
118 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
119                             struct config_llog_instance *cfg);
120 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
121                            struct config_llog_instance *cfg);
122
123 /* list of active configuration logs  */
124 struct config_llog_data {
125         char               *cld_logname;
126         struct ldlm_res_id  cld_resid;
127         struct config_llog_instance cld_cfg;
128         struct list_head    cld_list_chain;
129         atomic_t            cld_refcount;
130         unsigned int        cld_stopping:1;
131 };
132
133 struct lustre_profile {
134         struct list_head lp_list;
135         char * lp_profile;
136         char * lp_osc;
137         char * lp_mdc;
138 };
139
140 struct lustre_profile *class_get_profile(const char * prof);
141 void class_del_profile(const char *prof);
142
143 /* genops.c */
144 #define class_export_get(exp)                                                  \
145 ({                                                                             \
146         struct obd_export *exp_ = exp;                                         \
147         atomic_inc(&exp_->exp_refcount);                                       \
148         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
149                atomic_read(&exp_->exp_refcount));                              \
150         exp_;                                                                  \
151 })
152
153 #define class_export_put(exp)                                                  \
154 do {                                                                           \
155         LASSERT((exp) != NULL);                                                \
156         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
157                atomic_read(&(exp)->exp_refcount) - 1);                         \
158         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
159         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
160         __class_export_put(exp);                                               \
161 } while (0)
162 void __class_export_put(struct obd_export *);
163 struct obd_export *class_new_export(struct obd_device *obddev,
164                                     struct obd_uuid *cluuid);
165 void class_unlink_export(struct obd_export *exp);
166
167 struct obd_import *class_import_get(struct obd_import *);
168 void class_import_put(struct obd_import *);
169 struct obd_import *class_new_import(struct obd_device *obd);
170 void class_destroy_import(struct obd_import *exp);
171
172 struct obd_type *class_search_type(const char *name);
173 struct obd_type *class_get_type(const char *name);
174 void class_put_type(struct obd_type *type);
175 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
176                   struct obd_uuid *cluuid);
177 int class_disconnect(struct obd_export *exp);
178 void class_fail_export(struct obd_export *exp);
179 void class_disconnect_exports(struct obd_device *obddev);
180 void class_disconnect_stale_exports(struct obd_device *obddev);
181 int class_manual_cleanup(struct obd_device *obd);
182
183 /* obdo.c */
184 #ifdef __KERNEL__
185 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
186 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
187 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
188 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
189 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
190 #endif
191 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
192 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
193 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
194
195
196 #define OBT(dev)        (dev)->obd_type
197 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
198 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
199 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
200
201 /* Ensure obd_setup: used for cleanup which must be called
202    while obd is stopping */
203 #define OBD_CHECK_DEV(obd)                                      \
204 do {                                                            \
205         if (!(obd)) {                                           \
206                 CERROR("NULL device\n");                        \
207                 RETURN(-ENODEV);                                \
208         }                                                       \
209 } while (0)
210
211 /* ensure obd_setup and !obd_stopping */
212 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
213 do {                                                            \
214         OBD_CHECK_DEV(obd);                                     \
215         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
216                 CERROR("Device %d not setup\n",                 \
217                        (obd)->obd_minor);                       \
218                 RETURN(-ENODEV);                                \
219         }                                                       \
220 } while (0)
221
222
223 #ifdef LPROCFS
224 #define OBD_COUNTER_OFFSET(op)                                  \
225         ((offsetof(struct obd_ops, o_ ## op) -                  \
226           offsetof(struct obd_ops, o_iocontrol))                \
227          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
228
229 #define OBD_COUNTER_INCREMENT(obd, op)                          \
230         if ((obd)->obd_stats != NULL) {                         \
231                 unsigned int coffset;                           \
232                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
233                         OBD_COUNTER_OFFSET(op);                 \
234                 LASSERT(coffset < obd->obd_stats->ls_num);      \
235                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
236         }
237
238 #define MD_COUNTER_OFFSET(op)                                  \
239         ((offsetof(struct md_ops, m_ ## op) -                  \
240           offsetof(struct md_ops, m_getstatus))                \
241          / sizeof(((struct md_ops *)(0))->m_getstatus))
242
243 #define MD_COUNTER_INCREMENT(obd, op)                           \
244         if ((obd)->md_stats != NULL) {                          \
245                 unsigned int coffset;                           \
246                 coffset = (unsigned int)(obd)->md_cntr_base +   \
247                         MD_COUNTER_OFFSET(op);                  \
248                 LASSERT(coffset < (obd)->md_stats->ls_num);     \
249                 lprocfs_counter_incr((obd)->md_stats, coffset); \
250         }
251
252 #else
253 #define OBD_COUNTER_OFFSET(op)
254 #define OBD_COUNTER_INCREMENT(obd, op)
255 #define MD_COUNTER_INCREMENT(obd, op)
256 #endif
257
258 #define OBD_CHECK_MD_OP(obd, op, err)                           \
259 do {                                                            \
260         if (!OBT(obd) || !MDP((obd), op)) {                     \
261                 if (err)                                        \
262                         CERROR("md_" #op ": dev %s/%d no operation\n", \
263                                obd->obd_name, obd->obd_minor);  \
264                 RETURN(err);                                    \
265         }                                                       \
266 } while (0)
267
268 #define EXP_CHECK_MD_OP(exp, op)                                \
269 do {                                                            \
270         if ((exp) == NULL) {                                    \
271                 CERROR("obd_" #op ": NULL export\n");           \
272                 RETURN(-ENODEV);                                \
273         }                                                       \
274         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
275                 CERROR("obd_" #op ": cleaned up obd\n");        \
276                 RETURN(-EOPNOTSUPP);                            \
277         }                                                       \
278         if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
279                 CERROR("obd_" #op ": dev %s/%d no operation\n", \
280                        (exp)->exp_obd->obd_name,                \
281                        (exp)->exp_obd->obd_minor);              \
282                 RETURN(-EOPNOTSUPP);                            \
283         }                                                       \
284 } while (0)
285
286
287 #define OBD_CHECK_DT_OP(obd, op, err)                           \
288 do {                                                            \
289         if (!OBT(obd) || !OBP((obd), op)) {                     \
290                 if (err)                                        \
291                         CERROR("obd_" #op ": dev %d no operation\n",    \
292                                obd->obd_minor);                 \
293                 RETURN(err);                                    \
294         }                                                       \
295 } while (0)
296
297 #define EXP_CHECK_DT_OP(exp, op)                                \
298 do {                                                            \
299         if ((exp) == NULL) {                                    \
300                 CERROR("obd_" #op ": NULL export\n");           \
301                 RETURN(-ENODEV);                                \
302         }                                                       \
303         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
304                 CERROR("obd_" #op ": cleaned up obd\n");        \
305                 RETURN(-EOPNOTSUPP);                            \
306         }                                                       \
307         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
308                 CERROR("obd_" #op ": dev %d no operation\n",    \
309                        (exp)->exp_obd->obd_minor);              \
310                 RETURN(-EOPNOTSUPP);                            \
311         }                                                       \
312 } while (0)
313
314 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
315 do {                                                            \
316         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
317                 if (err)                                        \
318                         CERROR("lop_" #op ": dev %d no operation\n",    \
319                                ctxt->loc_obd->obd_minor);                         \
320                 RETURN(err);                                    \
321         }                                                       \
322 } while (0)
323
324 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
325                                void *key, __u32 *vallen, void *val)
326 {
327         int rc;
328         ENTRY;
329
330         EXP_CHECK_DT_OP(exp, get_info);
331         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
332
333         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
334         RETURN(rc);
335 }
336
337 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
338                                void *key, obd_count vallen, void *val)
339 {
340         int rc;
341         ENTRY;
342
343         EXP_CHECK_DT_OP(exp, set_info);
344         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
345
346         rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
347         RETURN(rc);
348 }
349
350 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
351 {
352         int rc;
353         struct lu_device_type *ldt;
354         ENTRY;
355
356         ldt = obd->obd_type->typ_lu;
357         if (ldt != NULL) {
358                 struct lu_device *d;
359
360                 d = ldt->ldt_ops->ldto_device_alloc(ldt, cfg);
361                 if (!IS_ERR(d)) {
362                         obd->obd_lu_dev = d;
363                         d->ld_obd = obd;
364                         rc = 0;
365                 } else
366                         rc = PTR_ERR(d);
367         } else {
368                 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
369                 OBD_COUNTER_INCREMENT(obd, setup);
370                 rc = OBP(obd, setup)(obd, cfg);
371         }
372         RETURN(rc);
373 }
374
375 static inline int obd_precleanup(struct obd_device *obd,
376                                  enum obd_cleanup_stage cleanup_stage)
377 {
378         int rc;
379         ENTRY;
380
381         OBD_CHECK_DT_OP(obd, precleanup, 0);
382         OBD_COUNTER_INCREMENT(obd, precleanup);
383
384         rc = OBP(obd, precleanup)(obd, cleanup_stage);
385         RETURN(rc);
386 }
387
388 static inline int obd_cleanup(struct obd_device *obd)
389 {
390         int rc;
391         struct lu_device *d;
392         struct lu_device_type *ldt;
393         ENTRY;
394
395         OBD_CHECK_DEV(obd);
396
397         ldt = obd->obd_type->typ_lu;
398         d = obd->obd_lu_dev;
399         if (ldt != NULL && d != NULL) {
400                 ldt->ldt_ops->ldto_device_free(d);
401                 obd->obd_lu_dev = NULL;
402                 rc = 0;
403         } else {
404                 OBD_CHECK_DT_OP(obd, cleanup, 0);
405                 rc = OBP(obd, cleanup)(obd);
406         }
407         OBD_COUNTER_INCREMENT(obd, cleanup);
408         RETURN(rc);
409 }
410
411 static inline int
412 obd_process_config(struct obd_device *obd, int datalen, void *data)
413 {
414         int rc;
415         struct lu_device *d;
416         struct lu_device_type *ldt;
417         ENTRY;
418
419         OBD_CHECK_DEV(obd);
420
421         ldt = obd->obd_type->typ_lu;
422         d = obd->obd_lu_dev;
423         if (ldt != NULL && d != NULL) {
424                 rc = d->ld_ops->ldo_process_config(d,
425                                                    (struct lustre_cfg *)data);
426         } else {
427                 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
428                 rc = OBP(obd, process_config)(obd, datalen, data);
429         }
430         OBD_COUNTER_INCREMENT(obd, process_config);
431
432         RETURN(rc);
433 }
434
435 /* Pack an in-memory MD struct for storage on disk.
436  * Returns +ve size of packed MD (0 for free), or -ve error.
437  *
438  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
439  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
440  * If @*disk_tgt == NULL, it will be allocated
441  */
442 static inline int obd_packmd(struct obd_export *exp,
443                              struct lov_mds_md **disk_tgt,
444                              struct lov_stripe_md *mem_src)
445 {
446         int rc;
447         ENTRY;
448
449         EXP_CHECK_DT_OP(exp, packmd);
450         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
451
452         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
453         RETURN(rc);
454 }
455
456 static inline int obd_size_diskmd(struct obd_export *exp,
457                                   struct lov_stripe_md *mem_src)
458 {
459         return obd_packmd(exp, NULL, mem_src);
460 }
461
462 /* helper functions */
463 static inline int obd_alloc_diskmd(struct obd_export *exp,
464                                    struct lov_mds_md **disk_tgt)
465 {
466         LASSERT(disk_tgt);
467         LASSERT(*disk_tgt == NULL);
468         return obd_packmd(exp, disk_tgt, NULL);
469 }
470
471 static inline int obd_free_diskmd(struct obd_export *exp,
472                                   struct lov_mds_md **disk_tgt)
473 {
474         LASSERT(disk_tgt);
475         LASSERT(*disk_tgt);
476         return obd_packmd(exp, disk_tgt, NULL);
477 }
478
479 /* Unpack an MD struct from disk to in-memory format.
480  * Returns +ve size of unpacked MD (0 for free), or -ve error.
481  *
482  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
483  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
484  * If @*mem_tgt == NULL, it will be allocated
485  */
486 static inline int obd_unpackmd(struct obd_export *exp,
487                                struct lov_stripe_md **mem_tgt,
488                                struct lov_mds_md *disk_src,
489                                int disk_len)
490 {
491         int rc;
492         ENTRY;
493
494         EXP_CHECK_DT_OP(exp, unpackmd);
495         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
496
497         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
498         RETURN(rc);
499 }
500
501 /* helper functions */
502 static inline int obd_alloc_memmd(struct obd_export *exp,
503                                   struct lov_stripe_md **mem_tgt)
504 {
505         LASSERT(mem_tgt);
506         LASSERT(*mem_tgt == NULL);
507         return obd_unpackmd(exp, mem_tgt, NULL, 0);
508 }
509
510 static inline int obd_free_memmd(struct obd_export *exp,
511                                  struct lov_stripe_md **mem_tgt)
512 {
513         LASSERT(mem_tgt);
514         LASSERT(*mem_tgt);
515         return obd_unpackmd(exp, mem_tgt, NULL, 0);
516 }
517
518 static inline int obd_checkmd(struct obd_export *exp,
519                               struct obd_export *md_exp,
520                               struct lov_stripe_md *mem_tgt)
521 {
522         int rc;
523         ENTRY;
524
525         EXP_CHECK_DT_OP(exp, checkmd);
526         OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
527
528         rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
529         RETURN(rc);
530 }
531
532 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
533                              struct lov_stripe_md **ea,
534                              struct obd_trans_info *oti)
535 {
536         int rc;
537         ENTRY;
538
539         EXP_CHECK_DT_OP(exp, create);
540         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
541
542         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
543         RETURN(rc);
544 }
545
546 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
547                               struct lov_stripe_md *ea,
548                               struct obd_trans_info *oti,
549                               struct obd_export *md_exp)
550 {
551         int rc;
552         ENTRY;
553
554         EXP_CHECK_DT_OP(exp, destroy);
555         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
556
557         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
558         RETURN(rc);
559 }
560
561 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
562                               struct lov_stripe_md *ea)
563 {
564         int rc;
565         ENTRY;
566
567         EXP_CHECK_DT_OP(exp, getattr);
568         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
569
570         rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
571         RETURN(rc);
572 }
573
574 static inline int obd_getattr_async(struct obd_export *exp,
575                                     struct obdo *obdo, struct lov_stripe_md *ea,
576                                     struct ptlrpc_request_set *set)
577 {
578         int rc;
579         ENTRY;
580
581         EXP_CHECK_DT_OP(exp, getattr);
582         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
583
584         rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
585         RETURN(rc);
586 }
587
588 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
589                               struct lov_stripe_md *ea,
590                               struct obd_trans_info *oti)
591 {
592         int rc;
593         ENTRY;
594
595         EXP_CHECK_DT_OP(exp, setattr);
596         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
597
598         rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
599         RETURN(rc);
600 }
601
602 static inline int obd_setattr_async(struct obd_export *exp,
603                                     struct obdo *obdo,
604                                     struct lov_stripe_md *ea,
605                                     struct obd_trans_info *oti)
606 {
607         int rc;
608         ENTRY;
609
610         EXP_CHECK_DT_OP(exp, setattr_async);
611         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
612
613         rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
614         RETURN(rc);
615 }
616
617 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
618                                int priority)
619 {
620         struct obd_device *obd = imp->imp_obd;
621         int rc;
622         ENTRY;
623
624         OBD_CHECK_DEV_ACTIVE(obd);
625         OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
626         OBD_COUNTER_INCREMENT(obd, add_conn);
627
628         rc = OBP(obd, add_conn)(imp, uuid, priority);
629         RETURN(rc);
630 }
631
632 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
633 {
634         struct obd_device *obd = imp->imp_obd;
635         int rc;
636         ENTRY;
637
638         OBD_CHECK_DEV_ACTIVE(obd);
639         OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
640         OBD_COUNTER_INCREMENT(obd, del_conn);
641
642         rc = OBP(obd, del_conn)(imp, uuid);
643         RETURN(rc);
644 }
645
646 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
647                               struct obd_uuid *cluuid,
648                               struct obd_connect_data *d)
649 {
650         int rc;
651         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
652         ENTRY;
653
654         OBD_CHECK_DEV_ACTIVE(obd);
655         OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
656         OBD_COUNTER_INCREMENT(obd, connect);
657
658         rc = OBP(obd, connect)(conn, obd, cluuid, d);
659         /* check that only subset is granted */
660         LASSERT(ergo(d != NULL,
661                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
662         RETURN(rc);
663 }
664
665 static inline int obd_reconnect(struct obd_export *exp,
666                                 struct obd_device *obd,
667                                 struct obd_uuid *cluuid,
668                                 struct obd_connect_data *d)
669 {
670         int rc;
671         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
672         ENTRY;
673
674         OBD_CHECK_DEV_ACTIVE(obd);
675         OBD_CHECK_DT_OP(obd, reconnect, 0);
676         OBD_COUNTER_INCREMENT(obd, reconnect);
677
678         rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
679         /* check that only subset is granted */
680         LASSERT(ergo(d != NULL,
681                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
682         RETURN(rc);
683 }
684
685 static inline int obd_disconnect(struct obd_export *exp)
686 {
687         int rc;
688         ENTRY;
689
690         EXP_CHECK_DT_OP(exp, disconnect);
691         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
692
693         rc = OBP(exp->exp_obd, disconnect)(exp);
694         RETURN(rc);
695 }
696
697 static inline int obd_fid_alloc(struct obd_export *exp,
698                                 struct lu_fid *fid,
699                                 struct placement_hint *hint)
700 {
701         int rc;
702         ENTRY;
703
704         if (OBP(exp->exp_obd, fid_alloc) == NULL)
705                 RETURN(-ENOTSUPP);
706
707         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
708
709         rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
710         RETURN(rc);
711 }
712
713 static inline int obd_fid_delete(struct obd_export *exp,
714                                  struct lu_fid *fid)
715 {
716         int rc;
717         ENTRY;
718
719         if (OBP(exp->exp_obd, fid_delete) == NULL)
720                 RETURN(0);
721
722         OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
723         rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
724         RETURN(rc);
725 }
726
727 static inline int obd_init_export(struct obd_export *exp)
728 {
729         int rc = 0;
730
731         ENTRY;
732         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
733             OBP((exp)->exp_obd, init_export))
734                 rc = OBP(exp->exp_obd, init_export)(exp);
735         RETURN(rc);
736 }
737
738 static inline int obd_destroy_export(struct obd_export *exp)
739 {
740         ENTRY;
741         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
742             OBP((exp)->exp_obd, destroy_export))
743                 OBP(exp->exp_obd, destroy_export)(exp);
744         RETURN(0);
745 }
746
747 static inline struct dentry *
748 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
749 {
750         LASSERT(exp->exp_obd);
751
752         return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
753                                exp->exp_obd);
754 }
755
756 static inline int
757 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
758 {
759         LASSERT(exp->exp_obd);
760         CERROR("FIXME what's the story here?  This needs to be an obd fn?\n");
761 #if 0
762         return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
763                               dentry, exp->exp_obd);
764 #endif
765         return 0;
766 }
767
768 #ifndef time_before
769 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
770 #endif
771
772 /* @max_age is the oldest time in jiffies that we accept using a cached data.
773  * If the cache is older than @max_age we will get a new value from the
774  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
775 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
776                              unsigned long max_age)
777 {
778         int rc = 0;
779         ENTRY;
780
781         if (obd == NULL)
782                 RETURN(-EINVAL);
783
784         OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
785         OBD_COUNTER_INCREMENT(obd, statfs);
786
787         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
788         if (time_before(obd->obd_osfs_age, max_age)) {
789                 rc = OBP(obd, statfs)(obd, osfs, max_age);
790                 if (rc == 0) {
791                         spin_lock(&obd->obd_osfs_lock);
792                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
793                         obd->obd_osfs_age = jiffies;
794                         spin_unlock(&obd->obd_osfs_lock);
795                 }
796         } else {
797                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
798                 spin_lock(&obd->obd_osfs_lock);
799                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
800                 spin_unlock(&obd->obd_osfs_lock);
801         }
802         RETURN(rc);
803 }
804
805 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
806                            struct lov_stripe_md *ea, obd_size start,
807                            obd_size end)
808 {
809         int rc;
810         ENTRY;
811
812         OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
813         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
814
815         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
816         RETURN(rc);
817 }
818
819 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
820                             struct lov_stripe_md *ea, obd_size start,
821                             obd_size end, struct obd_trans_info *oti)
822 {
823         int rc;
824         ENTRY;
825
826         EXP_CHECK_DT_OP(exp, punch);
827         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
828
829         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
830         RETURN(rc);
831 }
832
833 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
834                           struct lov_stripe_md *ea, obd_count oa_bufs,
835                           struct brw_page *pg, struct obd_trans_info *oti)
836 {
837         int rc;
838         ENTRY;
839
840         EXP_CHECK_DT_OP(exp, brw);
841         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
842
843         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
844                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
845                        "or OBD_BRW_CHECK\n");
846                 LBUG();
847         }
848
849         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
850         RETURN(rc);
851 }
852
853 static inline int obd_brw_async(int cmd, struct obd_export *exp,
854                                 struct obdo *oa, struct lov_stripe_md *ea,
855                                 obd_count oa_bufs, struct brw_page *pg,
856                                 struct ptlrpc_request_set *set,
857                                 struct obd_trans_info *oti)
858 {
859         int rc;
860         ENTRY;
861
862         EXP_CHECK_DT_OP(exp, brw_async);
863         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
864
865         if (!(cmd & OBD_BRW_RWMASK)) {
866                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
867                 LBUG();
868         }
869
870         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
871                                           oti);
872         RETURN(rc);
873 }
874
875 static inline  int obd_prep_async_page(struct obd_export *exp,
876                                        struct lov_stripe_md *lsm,
877                                        struct lov_oinfo *loi,
878                                        struct page *page, obd_off offset,
879                                        struct obd_async_page_ops *ops,
880                                        void *data, void **res)
881 {
882         int ret;
883         ENTRY;
884
885         OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
886         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
887
888         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
889                                                  ops, data, res);
890         RETURN(ret);
891 }
892
893 static inline int obd_queue_async_io(struct obd_export *exp,
894                                      struct lov_stripe_md *lsm,
895                                      struct lov_oinfo *loi, void *cookie,
896                                      int cmd, obd_off off, int count,
897                                      obd_flag brw_flags, obd_flag async_flags)
898 {
899         int rc;
900         ENTRY;
901
902         OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
903         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
904         LASSERT(cmd & OBD_BRW_RWMASK);
905
906         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
907                                                count, brw_flags, async_flags);
908         RETURN(rc);
909 }
910
911 static inline int obd_set_async_flags(struct obd_export *exp,
912                                       struct lov_stripe_md *lsm,
913                                       struct lov_oinfo *loi, void *cookie,
914                                       obd_flag async_flags)
915 {
916         int rc;
917         ENTRY;
918
919         OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
920         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
921
922         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
923                                                 async_flags);
924         RETURN(rc);
925 }
926
927 static inline int obd_queue_group_io(struct obd_export *exp,
928                                      struct lov_stripe_md *lsm,
929                                      struct lov_oinfo *loi,
930                                      struct obd_io_group *oig,
931                                      void *cookie, int cmd, obd_off off,
932                                      int count, obd_flag brw_flags,
933                                      obd_flag async_flags)
934 {
935         int rc;
936         ENTRY;
937
938         OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
939         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
940         LASSERT(cmd & OBD_BRW_RWMASK);
941
942         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
943                                                cmd, off, count, brw_flags,
944                                                async_flags);
945         RETURN(rc);
946 }
947
948 static inline int obd_trigger_group_io(struct obd_export *exp,
949                                        struct lov_stripe_md *lsm,
950                                        struct lov_oinfo *loi,
951                                        struct obd_io_group *oig)
952 {
953         int rc;
954         ENTRY;
955
956         OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
957         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
958
959         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
960         RETURN(rc);
961 }
962
963 static inline int obd_teardown_async_page(struct obd_export *exp,
964                                           struct lov_stripe_md *lsm,
965                                           struct lov_oinfo *loi, void *cookie)
966 {
967         int rc;
968         ENTRY;
969
970         OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
971         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
972
973         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
974         RETURN(rc);
975 }
976
977 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
978                              int objcount, struct obd_ioobj *obj,
979                              int niocount, struct niobuf_remote *remote,
980                              struct niobuf_local *local,
981                              struct obd_trans_info *oti)
982 {
983         int rc;
984         ENTRY;
985
986         OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
987         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
988
989         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
990                                        remote, local, oti);
991         RETURN(rc);
992 }
993
994 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
995                                int objcount, struct obd_ioobj *obj,
996                                int niocount, struct niobuf_local *local,
997                                struct obd_trans_info *oti, int rc)
998 {
999         ENTRY;
1000
1001         OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1002         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1003
1004         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1005                                          local, oti, rc);
1006         RETURN(rc);
1007 }
1008
1009 static inline int obd_merge_lvb(struct obd_export *exp,
1010                                 struct lov_stripe_md *lsm,
1011                                 struct ost_lvb *lvb, int kms_only)
1012 {
1013         int rc;
1014         ENTRY;
1015
1016         OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1017         OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1018
1019         rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1020         RETURN(rc);
1021 }
1022
1023 static inline int obd_adjust_kms(struct obd_export *exp,
1024                                  struct lov_stripe_md *lsm, obd_off size,
1025                                  int shrink)
1026 {
1027         int rc;
1028         ENTRY;
1029
1030         OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1031         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1032
1033         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1034         RETURN(rc);
1035 }
1036
1037 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1038                                 int len, void *karg, void *uarg)
1039 {
1040         int rc;
1041         ENTRY;
1042
1043         EXP_CHECK_DT_OP(exp, iocontrol);
1044         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1045
1046         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1047         RETURN(rc);
1048 }
1049
1050 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1051                               __u32 type, ldlm_policy_data_t *policy,
1052                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1053                               void *gl_cb, void *data, __u32 lvb_len,
1054                               void *lvb_swabber, struct lustre_handle *lockh)
1055 {
1056         int rc;
1057         ENTRY;
1058
1059         EXP_CHECK_DT_OP(exp, enqueue);
1060         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1061
1062         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1063                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
1064                                         lvb_swabber, lockh);
1065         RETURN(rc);
1066 }
1067
1068 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1069                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1070                             int *flags, void *data, struct lustre_handle *lockh)
1071 {
1072         int rc;
1073         ENTRY;
1074
1075         EXP_CHECK_DT_OP(exp, match);
1076         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1077
1078         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1079                                       lockh);
1080         RETURN(rc);
1081 }
1082
1083 static inline int obd_change_cbdata(struct obd_export *exp,
1084                                     struct lov_stripe_md *lsm,
1085                                     ldlm_iterator_t it, void *data)
1086 {
1087         int rc;
1088         ENTRY;
1089
1090         EXP_CHECK_DT_OP(exp, change_cbdata);
1091         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1092
1093         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1094         RETURN(rc);
1095 }
1096
1097 static inline int obd_cancel(struct obd_export *exp,
1098                              struct lov_stripe_md *ea, __u32 mode,
1099                              struct lustre_handle *lockh)
1100 {
1101         int rc;
1102         ENTRY;
1103
1104         EXP_CHECK_DT_OP(exp, cancel);
1105         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1106
1107         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1108         RETURN(rc);
1109 }
1110
1111 static inline int obd_cancel_unused(struct obd_export *exp,
1112                                     struct lov_stripe_md *ea,
1113                                     int flags, void *opaque)
1114 {
1115         int rc;
1116         ENTRY;
1117
1118         EXP_CHECK_DT_OP(exp, cancel_unused);
1119         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1120
1121         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1122         RETURN(rc);
1123 }
1124
1125 static inline int obd_join_lru(struct obd_export *exp,
1126                                struct lov_stripe_md *ea, int join)
1127 {
1128         int rc;
1129         ENTRY;
1130
1131         EXP_CHECK_DT_OP(exp, join_lru);
1132         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1133
1134         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1135         RETURN(rc);
1136 }
1137
1138 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1139                                  struct obdo *oa,
1140                                  int objcount, struct obd_ioobj *obj,
1141                                  int niocount, struct niobuf_remote *remote)
1142 {
1143         int rc;
1144
1145         EXP_CHECK_DT_OP(exp, preprw);
1146         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1147
1148         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1149                                            niocount, remote);
1150         class_export_put(exp);
1151         return(rc);
1152 }
1153
1154 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1155                           struct obd_client_handle *handle, int flag)
1156 {
1157         int rc;
1158
1159         EXP_CHECK_DT_OP(exp, pin);
1160         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1161
1162         rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1163         return(rc);
1164 }
1165
1166 static inline int obd_unpin(struct obd_export *exp,
1167                             struct obd_client_handle *handle, int flag)
1168 {
1169         int rc;
1170
1171         EXP_CHECK_DT_OP(exp, unpin);
1172         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1173
1174         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1175         return(rc);
1176 }
1177
1178
1179 static inline void obd_import_event(struct obd_device *obd,
1180                                     struct obd_import *imp,
1181                                     enum obd_import_event event)
1182 {
1183         if (!obd) {
1184                 CERROR("NULL device\n");
1185                 EXIT;
1186                 return;
1187         }
1188         if (obd->obd_set_up && OBP(obd, import_event)) {
1189                 OBD_COUNTER_INCREMENT(obd, import_event);
1190                 OBP(obd, import_event)(obd, imp, event);
1191         }
1192 }
1193
1194 static inline int obd_notify(struct obd_device *obd,
1195                              struct obd_device *watched,
1196                              enum obd_notify_event ev,
1197                              void *data)
1198 {
1199         OBD_CHECK_DEV(obd);
1200
1201         /* the check for async_recov is a complete hack - I'm hereby
1202            overloading the meaning to also mean "this was called from
1203            mds_postsetup".  I know that my mds is able to handle notifies
1204            by this point, and it needs to get them to execute mds_postrecov. */
1205         if (!obd->obd_set_up && !obd->obd_async_recov) {
1206                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1207                 return -EINVAL;
1208         }
1209
1210         if (!OBP(obd, notify)) {
1211                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1212                 return -ENOSYS;
1213         }
1214
1215         OBD_COUNTER_INCREMENT(obd, notify);
1216         return OBP(obd, notify)(obd, watched, ev, data);
1217 }
1218
1219 static inline int obd_notify_observer(struct obd_device *observer,
1220                                       struct obd_device *observed,
1221                                       enum obd_notify_event ev,
1222                                       void *data)
1223 {
1224         int rc1;
1225         int rc2;
1226
1227         struct obd_notify_upcall *onu;
1228
1229         if (observer->obd_observer)
1230                 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1231         else
1232                 rc1 = 0;
1233         /*
1234          * Also, call non-obd listener, if any
1235          */
1236         onu = &observer->obd_upcall;
1237         if (onu->onu_upcall != NULL)
1238                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1239         else
1240                 rc2 = 0;
1241
1242         return rc1 ? rc1 : rc2;
1243 }
1244
1245 static inline int obd_quotacheck(struct obd_export *exp,
1246                                  struct obd_quotactl *oqctl)
1247 {
1248         int rc;
1249         ENTRY;
1250
1251         EXP_CHECK_DT_OP(exp, quotacheck);
1252         OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1253
1254         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1255         RETURN(rc);
1256 }
1257
1258 static inline int obd_quotactl(struct obd_export *exp,
1259                                struct obd_quotactl *oqctl)
1260 {
1261         int rc;
1262         ENTRY;
1263
1264         EXP_CHECK_DT_OP(exp, quotactl);
1265         OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1266
1267         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1268         RETURN(rc);
1269 }
1270
1271 static inline int obd_health_check(struct obd_device *obd)
1272 {
1273         /* returns: 0 on healthy
1274          *         >0 on unhealthy + reason code/flag
1275          *            however the only suppored reason == 1 right now
1276          *            We'll need to define some better reasons
1277          *            or flags in the future.
1278          *         <0 on error
1279          */
1280         int rc;
1281         ENTRY;
1282
1283         /* don't use EXP_CHECK_OP, because NULL method is normal here */
1284         if (obd == NULL || !OBT(obd)) {
1285                 CERROR("cleaned up obd\n");
1286                 RETURN(-EOPNOTSUPP);
1287         }
1288         if (!obd->obd_set_up || obd->obd_stopping)
1289                 RETURN(0);
1290         if (!OBP(obd, health_check))
1291                 RETURN(0);
1292
1293         rc = OBP(obd, health_check)(obd);
1294         RETURN(rc);
1295 }
1296
1297 static inline int obd_register_observer(struct obd_device *obd,
1298                                         struct obd_device *observer)
1299 {
1300         ENTRY;
1301         OBD_CHECK_DEV(obd);
1302         if (obd->obd_observer && observer)
1303                 RETURN(-EALREADY);
1304         obd->obd_observer = observer;
1305         RETURN(0);
1306 }
1307
1308 /* metadata helpers */
1309 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1310 {
1311         int rc;
1312         ENTRY;
1313
1314         EXP_CHECK_MD_OP(exp, getstatus);
1315         MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1316         rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1317         RETURN(rc);
1318 }
1319
1320 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1321                              obd_valid valid, int ea_size,
1322                              struct ptlrpc_request **request)
1323 {
1324         int rc;
1325         ENTRY;
1326         EXP_CHECK_MD_OP(exp, getattr);
1327         MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1328         rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1329                                         ea_size, request);
1330         RETURN(rc);
1331 }
1332
1333 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1334                                    ldlm_iterator_t it, void *data)
1335 {
1336         int rc;
1337         ENTRY;
1338         EXP_CHECK_MD_OP(exp, change_cbdata);
1339         MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1340         rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1341         RETURN(rc);
1342 }
1343
1344 static inline int md_close(struct obd_export *exp,
1345                            struct md_op_data *op_data,
1346                            struct obd_client_handle *och,
1347                            struct ptlrpc_request **request)
1348 {
1349         int rc;
1350         ENTRY;
1351         EXP_CHECK_MD_OP(exp, close);
1352         MD_COUNTER_INCREMENT(exp->exp_obd, close);
1353         rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1354         RETURN(rc);
1355 }
1356
1357 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1358                             const void *data, int datalen, int mode,
1359                             __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1360                             struct ptlrpc_request **request)
1361 {
1362         int rc;
1363         ENTRY;
1364         EXP_CHECK_MD_OP(exp, create);
1365         MD_COUNTER_INCREMENT(exp->exp_obd, create);
1366         rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1367                                        uid, gid, cap_effective, rdev, request);
1368         RETURN(rc);
1369 }
1370
1371 static inline int md_done_writing(struct obd_export *exp,
1372                                   struct md_op_data *op_data)
1373 {
1374         int rc;
1375         ENTRY;
1376         EXP_CHECK_MD_OP(exp, done_writing);
1377         MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1378         rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1379         RETURN(rc);
1380 }
1381
1382 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1383                              struct lookup_intent *it, int lock_mode,
1384                              struct md_op_data *op_data,
1385                              struct lustre_handle *lockh,
1386                              void *lmm, int lmmsize,
1387                              ldlm_completion_callback cb_completion,
1388                              ldlm_blocking_callback cb_blocking,
1389                              void *cb_data, int extra_lock_flags)
1390 {
1391         int rc;
1392         ENTRY;
1393         EXP_CHECK_MD_OP(exp, enqueue);
1394         MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1395         rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1396                                         op_data, lockh, lmm, lmmsize,
1397                                         cb_completion, cb_blocking,
1398                                         cb_data, extra_lock_flags);
1399         RETURN(rc);
1400 }
1401
1402 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1403                                   const char *filename, int namelen,
1404                                   obd_valid valid, int ea_size,
1405                                   struct ptlrpc_request **request)
1406 {
1407         int rc;
1408         ENTRY;
1409         EXP_CHECK_MD_OP(exp, getattr_name);
1410         MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1411         rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1412                                              valid, ea_size, request);
1413         RETURN(rc);
1414 }
1415
1416 static inline int md_intent_lock(struct obd_export *exp,
1417                                  struct md_op_data *op_data,
1418                                  void *lmm, int lmmsize,
1419                                  struct lookup_intent *it,
1420                                  int flags, struct ptlrpc_request **reqp,
1421                                  ldlm_blocking_callback cb_blocking,
1422                                  int extra_lock_flags)
1423 {
1424         int rc;
1425         ENTRY;
1426         EXP_CHECK_MD_OP(exp, intent_lock);
1427         MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1428         rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1429                                             it, flags, reqp, cb_blocking,
1430                                             extra_lock_flags);
1431         RETURN(rc);
1432 }
1433
1434 static inline int md_link(struct obd_export *exp,
1435                           struct md_op_data *op_data,
1436                           struct ptlrpc_request **request)
1437 {
1438         int rc;
1439         ENTRY;
1440         EXP_CHECK_MD_OP(exp, link);
1441         MD_COUNTER_INCREMENT(exp->exp_obd, link);
1442         rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1443         RETURN(rc);
1444 }
1445
1446 static inline int md_rename(struct obd_export *exp,
1447                             struct md_op_data *op_data,
1448                             const char *old, int oldlen,
1449                             const char *new, int newlen,
1450                             struct ptlrpc_request **request)
1451 {
1452         int rc;
1453         ENTRY;
1454         EXP_CHECK_MD_OP(exp, rename);
1455         MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1456         rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1457                                        newlen, request);
1458         RETURN(rc);
1459 }
1460
1461 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1462                              struct iattr *iattr, void *ea, int ealen,
1463                              void *ea2, int ea2len, struct ptlrpc_request **request)
1464 {
1465         int rc;
1466         ENTRY;
1467         EXP_CHECK_MD_OP(exp, setattr);
1468         MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1469         rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1470                                         ea2, ea2len, request);
1471         RETURN(rc);
1472 }
1473
1474 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1475                           struct ptlrpc_request **request)
1476 {
1477         int rc;
1478         ENTRY;
1479         EXP_CHECK_MD_OP(exp, sync);
1480         MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1481         rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1482         RETURN(rc);
1483 }
1484
1485 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1486                               __u64 offset, struct page *page,
1487                               struct ptlrpc_request **request)
1488 {
1489         int rc;
1490         ENTRY;
1491         EXP_CHECK_MD_OP(exp, readpage);
1492         MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1493         rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1494         RETURN(rc);
1495 }
1496
1497 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1498                             struct ptlrpc_request **request)
1499 {
1500         int rc;
1501         ENTRY;
1502         EXP_CHECK_MD_OP(exp, unlink);
1503         MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1504         rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1505         RETURN(rc);
1506 }
1507
1508 static inline int md_get_lustre_md(struct obd_export *exp,
1509                                    struct ptlrpc_request *req,
1510                                    int offset, struct obd_export *dt_exp,
1511                                    struct lustre_md *md)
1512 {
1513         ENTRY;
1514         EXP_CHECK_MD_OP(exp, get_lustre_md);
1515         MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1516         RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1517                                                 dt_exp, md));
1518 }
1519
1520 static inline int md_free_lustre_md(struct obd_export *exp,
1521                                     struct lustre_md *md)
1522 {
1523         ENTRY;
1524         EXP_CHECK_MD_OP(exp, free_lustre_md);
1525         MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1526         RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1527 }
1528
1529 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1530                               obd_valid valid, const char *name,
1531                               const char *input, int input_size,
1532                               int output_size, int flags,
1533                               struct ptlrpc_request **request)
1534 {
1535         ENTRY;
1536         EXP_CHECK_MD_OP(exp, setxattr);
1537         MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1538         RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1539                                            input_size, output_size, flags,
1540                                            request));
1541 }
1542
1543 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1544                               obd_valid valid, const char *name,
1545                               const char *input, int input_size,
1546                               int output_size, int flags,
1547                               struct ptlrpc_request **request)
1548 {
1549         ENTRY;
1550         EXP_CHECK_MD_OP(exp, getxattr);
1551         MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1552         RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1553                                            input_size, output_size, flags,
1554                                            request));
1555 }
1556
1557 static inline int md_set_open_replay_data(struct obd_export *exp,
1558                                           struct obd_client_handle *och,
1559                                           struct ptlrpc_request *open_req)
1560 {
1561         ENTRY;
1562         EXP_CHECK_MD_OP(exp, set_open_replay_data);
1563         MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1564         RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1565 }
1566
1567 static inline int md_clear_open_replay_data(struct obd_export *exp,
1568                                             struct obd_client_handle *och)
1569 {
1570         ENTRY;
1571         EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1572         MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1573         RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1574 }
1575
1576 static inline int md_set_lock_data(struct obd_export *exp,
1577                                    __u64 *lockh, void *data)
1578 {
1579         ENTRY;
1580         EXP_CHECK_MD_OP(exp, set_lock_data);
1581         MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1582         RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1583 }
1584
1585 static inline int md_cancel_unused(struct obd_export *exp,
1586                                    struct lu_fid *fid,
1587                                    int flags, void *opaque)
1588 {
1589         int rc;
1590         ENTRY;
1591
1592         EXP_CHECK_MD_OP(exp, cancel_unused);
1593         MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1594
1595         rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1596         RETURN(rc);
1597 }
1598
1599 static inline int md_lock_match(struct obd_export *exp, int flags,
1600                                 struct lu_fid *fid, ldlm_type_t type,
1601                                 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1602                                 struct lustre_handle *lockh)
1603 {
1604         ENTRY;
1605         EXP_CHECK_MD_OP(exp, lock_match);
1606         MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1607         RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1608                                              policy, mode, lockh));
1609 }
1610
1611 static inline int md_init_ea_size(struct obd_export *exp,
1612                                   int easize, int def_asize,
1613                                   int cookiesize)
1614 {
1615         ENTRY;
1616         EXP_CHECK_MD_OP(exp, init_ea_size);
1617         MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1618         RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1619                                                def_asize,
1620                                                cookiesize));
1621 }
1622
1623 /* OBD Metadata Support */
1624 extern int obd_init_caches(void);
1625 extern void obd_cleanup_caches(void);
1626
1627 /* support routines */
1628 extern kmem_cache_t *obdo_cachep;
1629 static inline struct obdo *obdo_alloc(void)
1630 {
1631         struct obdo *oa;
1632
1633         OBD_SLAB_ALLOC(oa, obdo_cachep, SLAB_KERNEL, sizeof(*oa));
1634
1635         return oa;
1636 }
1637
1638 static inline void obdo_free(struct obdo *oa)
1639 {
1640         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1641 }
1642
1643 static inline void obdo2fid(struct obdo *oa,
1644                             struct lu_fid *fid)
1645 {
1646         /* something here */
1647 }
1648
1649 static inline void fid2obdo(struct lu_fid *fid,
1650                             struct obdo *oa)
1651 {
1652         /* something here */
1653 }
1654
1655 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1656 #define to_kdev_t(dev) dev
1657 #define kdev_t_to_nr(dev) dev
1658 #endif
1659
1660 /* I'm as embarrassed about this as you are.
1661  *
1662  * <shaver> // XXX do not look into _superhack with remaining eye
1663  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1664 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1665
1666 /* sysctl.c */
1667 extern void obd_sysctl_init (void);
1668 extern void obd_sysctl_clean (void);
1669
1670 /* uuid.c  */
1671 typedef __u8 class_uuid_t[16];
1672 void class_generate_random_uuid(class_uuid_t uuid);
1673 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1674
1675 /* lustre_peer.c    */
1676 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1677 int class_add_uuid(const char *uuid, __u64 nid);
1678 int class_del_uuid (const char *uuid);
1679 void class_init_uuidlist(void);
1680 void class_exit_uuidlist(void);
1681
1682 /* mea.c */
1683 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1684 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1685
1686 #endif /* __LINUX_OBD_CLASS_H */