Whamcloud - gitweb
eda2851da653806d88d3aa3e6f06b91c4e1cbd3f
[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/time.h>
35 #include <linux/timer.h>
36 #endif
37
38 #include <linux/obd_support.h>
39 #include <linux/lustre_import.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lprocfs_status.h>
45
46 /* OBD Device Declarations */
47 #define MAX_OBD_DEVICES 520
48 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
49 extern spinlock_t obd_dev_lock;
50
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
54
55 /* genops.c */
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *, char *nm);
58 int class_unregister_type(char *nm);
59
60 struct obd_device *class_newdev(struct obd_type *type, char *name);
61 void class_release_dev(struct obd_device *obd);
62
63 int class_name2dev(char *name);
64 struct obd_device *class_name2obd(char *name);
65 int class_uuid2dev(struct obd_uuid *uuid);
66 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
67 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid, 
68                                           char * typ_name,
69                                           struct obd_uuid *grp_uuid);
70 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
71                                              struct obd_uuid *grp_uuid);
72 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid, 
73                                            int *next);
74
75 int oig_init(struct obd_io_group **oig);
76 void oig_add_one(struct obd_io_group *oig,
77                   struct oig_callback_context *occ);
78 void oig_complete_one(struct obd_io_group *oig, 
79                        struct oig_callback_context *occ, int rc);
80 void oig_release(struct obd_io_group *oig);
81 int oig_wait(struct obd_io_group *oig);
82
83 /* config.c */
84 int class_process_config(struct lustre_cfg *lcfg);
85 int class_attach(struct lustre_cfg *lcfg);
86 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
87 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
88 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
89 void class_decref(struct obd_device *obd);
90
91 /* Passed as data param to class_config_parse_llog */
92 struct config_llog_instance {
93         char * cfg_instance;
94         struct obd_uuid cfg_uuid;
95         ptl_nid_t  cfg_local_nid;
96 };
97 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name, 
98                             struct config_llog_instance *cfg);
99 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name, 
100                            struct config_llog_instance *cfg);
101
102 struct lustre_profile {
103         struct list_head lp_list;
104         char * lp_profile;
105         char * lp_osc;
106         char * lp_mdc;
107 };
108
109 struct lustre_profile *class_get_profile(char * prof);
110 void class_del_profile(char *prof);
111
112 #define class_export_get(exp)                                                  \
113 ({                                                                             \
114         struct obd_export *exp_ = exp;                                         \
115         atomic_inc(&exp_->exp_refcount);                                       \
116         CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
117                atomic_read(&exp_->exp_refcount));                              \
118         exp_;                                                                  \
119 })
120
121 #define class_export_put(exp)                                                  \
122 do {                                                                           \
123         LASSERT((exp) != NULL);                                                \
124         CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
125                atomic_read(&(exp)->exp_refcount) - 1);                         \
126         LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
127         LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
128         __class_export_put(exp);                                               \
129 } while (0)
130 void __class_export_put(struct obd_export *);
131 struct obd_export *class_new_export(struct obd_device *obddev);
132 void class_unlink_export(struct obd_export *exp);
133 void class_update_export_timer(struct obd_export *exp, time_t extra_delay);
134
135 struct obd_import *class_import_get(struct obd_import *);
136 void class_import_put(struct obd_import *);
137 struct obd_import *class_new_import(void);
138 void class_destroy_import(struct obd_import *exp);
139
140 struct obd_type *class_get_type(char *name);
141 void class_put_type(struct obd_type *type);
142 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
143                   struct obd_uuid *cluuid);
144 int class_disconnect(struct obd_export *exp);
145 void class_disconnect_exports(struct obd_device *obddev);
146 void class_disconnect_stale_exports(struct obd_device *obddev);
147 /* generic operations shared by various OBD types */
148 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
149 int class_multi_cleanup(struct obd_device *obddev);
150
151 /* obdo.c */
152 #ifdef __KERNEL__
153 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
154 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
155 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
156 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
157 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
158 #endif
159 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
160 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
161 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
162
163 /* ping evictor */
164 void ping_evictor_start(void);
165 void ping_evictor_stop(void);
166
167
168 #define OBT(dev)        (dev)->obd_type
169 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
170 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
171
172 /* Ensure obd_setup: used for cleanup which must be called
173    while obd is stopping */
174 #define OBD_CHECK_DEV(obd)                                      \
175 do {                                                            \
176         if (!(obd)) {                                           \
177                 CERROR("NULL device\n");                        \
178                 RETURN(-ENODEV);                                \
179         }                                                       \
180 } while (0)
181
182 /* ensure obd_setup and !obd_stopping */
183 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
184 do {                                                            \
185         OBD_CHECK_DEV(obd);                                     \
186         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
187                 CERROR("Device %d not setup\n",                 \
188                        (obd)->obd_minor);                       \
189                 RETURN(-ENODEV);                                \
190         }                                                       \
191 } while (0)
192
193
194 #ifdef LPROCFS
195 #define OBD_COUNTER_OFFSET(op)                                  \
196         ((offsetof(struct obd_ops, o_ ## op) -                  \
197           offsetof(struct obd_ops, o_iocontrol))                \
198          / sizeof(((struct obd_ops *)(0))->o_iocontrol))
199
200 #define OBD_COUNTER_INCREMENT(obd, op)                          \
201         if ((obd)->obd_stats != NULL) {                         \
202                 unsigned int coffset;                           \
203                 coffset = (unsigned int)(obd)->obd_cntr_base +  \
204                         OBD_COUNTER_OFFSET(op);                 \
205                 LASSERT(coffset < obd->obd_stats->ls_num);      \
206                 lprocfs_counter_incr(obd->obd_stats, coffset);  \
207         }
208 #else
209 #define OBD_COUNTER_OFFSET(op)
210 #define OBD_COUNTER_INCREMENT(obd, op)
211 #endif
212
213 #define OBD_CHECK_OP(obd, op, err)                              \
214 do {                                                            \
215         if (!OBT(obd) || !OBP((obd), op)) {\
216                 if (err)                                        \
217                         CERROR("obd_" #op ": dev %d no operation\n",    \
218                                obd->obd_minor);                         \
219                 RETURN(err);                                    \
220         }                                                       \
221 } while (0)
222
223 #define EXP_CHECK_OP(exp, op)                                   \
224 do {                                                            \
225         if ((exp) == NULL) {                                    \
226                 CERROR("obd_" #op ": NULL export\n");           \
227                 RETURN(-ENODEV);                                \
228         }                                                       \
229         if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
230                 CERROR("obd_" #op ": cleaned up obd\n");        \
231                 RETURN(-EOPNOTSUPP);                            \
232         }                                                       \
233         if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
234                 CERROR("obd_" #op ": dev %d no operation\n",    \
235                        (exp)->exp_obd->obd_minor);              \
236                 RETURN(-EOPNOTSUPP);                            \
237         }                                                       \
238 } while (0)
239
240 #define CTXT_CHECK_OP(ctxt, op, err)                                         \
241 do {                                                            \
242         if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
243                 if (err)                                        \
244                         CERROR("lop_" #op ": dev %d no operation\n",    \
245                                ctxt->loc_obd->obd_minor);                         \
246                 RETURN(err);                                    \
247         }                                                       \
248 } while (0)
249
250 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
251                                void *key, __u32 *vallen, void *val)
252 {
253         int rc;
254         ENTRY;
255
256         EXP_CHECK_OP(exp, get_info);
257         OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
258
259         rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
260         RETURN(rc);
261 }
262
263 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
264                                void *key, obd_count vallen, void *val)
265 {
266         int rc;
267         ENTRY;
268
269         EXP_CHECK_OP(exp, set_info);
270         OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
271
272         rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
273         RETURN(rc);
274 }
275
276 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
277 {
278         int rc;
279         ENTRY;
280
281         OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
282         OBD_COUNTER_INCREMENT(obd, setup);
283
284         rc = OBP(obd, setup)(obd, datalen, data);
285         RETURN(rc);
286 }
287
288 static inline int obd_precleanup(struct obd_device *obd, int cleanup_stage)
289 {
290         int rc;
291         ENTRY;
292
293         OBD_CHECK_OP(obd, precleanup, 0);
294         OBD_COUNTER_INCREMENT(obd, precleanup);
295
296         rc = OBP(obd, precleanup)(obd, cleanup_stage);
297         RETURN(rc);
298 }
299
300 static inline int obd_cleanup(struct obd_device *obd)
301 {
302         int rc;
303         ENTRY;
304         
305         OBD_CHECK_DEV(obd);                                     
306         OBD_CHECK_OP(obd, cleanup, 0);
307         OBD_COUNTER_INCREMENT(obd, cleanup);
308
309         rc = OBP(obd, cleanup)(obd);
310         RETURN(rc);
311 }
312
313 static inline int
314 obd_process_config(struct obd_device *obd, int datalen, void *data)
315 {
316         int rc;
317         ENTRY;
318  
319         OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
320         OBD_COUNTER_INCREMENT(obd, process_config);
321  
322         rc = OBP(obd, process_config)(obd, datalen, data);
323         RETURN(rc);
324 }
325
326 /* Pack an in-memory MD struct for storage on disk.
327  * Returns +ve size of packed MD (0 for free), or -ve error.
328  *
329  * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
330  * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
331  * If @*disk_tgt == NULL, it will be allocated
332  */
333 static inline int obd_packmd(struct obd_export *exp,
334                              struct lov_mds_md **disk_tgt,
335                              struct lov_stripe_md *mem_src)
336 {
337         int rc;
338         ENTRY;
339
340         EXP_CHECK_OP(exp, packmd);
341         OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
342
343         rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
344         RETURN(rc);
345 }
346
347 static inline int obd_size_diskmd(struct obd_export *exp,
348                                   struct lov_stripe_md *mem_src)
349 {
350         return obd_packmd(exp, NULL, mem_src);
351 }
352
353 /* helper functions */
354 static inline int obd_alloc_diskmd(struct obd_export *exp,
355                                    struct lov_mds_md **disk_tgt)
356 {
357         LASSERT(disk_tgt);
358         LASSERT(*disk_tgt == NULL);
359         return obd_packmd(exp, disk_tgt, NULL);
360 }
361
362 static inline int obd_free_diskmd(struct obd_export *exp,
363                                   struct lov_mds_md **disk_tgt)
364 {
365         LASSERT(disk_tgt);
366         LASSERT(*disk_tgt);
367         return obd_packmd(exp, disk_tgt, NULL);
368 }
369
370 /* Unpack an MD struct from disk to in-memory format.
371  * Returns +ve size of unpacked MD (0 for free), or -ve error.
372  *
373  * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
374  * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
375  * If @*mem_tgt == NULL, it will be allocated
376  */
377 static inline int obd_unpackmd(struct obd_export *exp,
378                                struct lov_stripe_md **mem_tgt,
379                                struct lov_mds_md *disk_src,
380                                int disk_len)
381 {
382         int rc;
383         ENTRY;
384
385         EXP_CHECK_OP(exp, unpackmd);
386         OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
387
388         rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
389         RETURN(rc);
390 }
391
392 /* helper functions */
393 static inline int obd_alloc_memmd(struct obd_export *exp,
394                                   struct lov_stripe_md **mem_tgt)
395 {
396         LASSERT(mem_tgt);
397         LASSERT(*mem_tgt == NULL);
398         return obd_unpackmd(exp, mem_tgt, NULL, 0);
399 }
400
401 static inline int obd_free_memmd(struct obd_export *exp,
402                                  struct lov_stripe_md **mem_tgt)
403 {
404         LASSERT(mem_tgt);
405         LASSERT(*mem_tgt);
406         return obd_unpackmd(exp, mem_tgt, NULL, 0);
407 }
408
409 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
410                              struct lov_stripe_md **ea,
411                              struct obd_trans_info *oti)
412 {
413         int rc;
414         ENTRY;
415
416         EXP_CHECK_OP(exp, create);
417         OBD_COUNTER_INCREMENT(exp->exp_obd, create);
418
419         rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
420         RETURN(rc);
421 }
422
423 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
424                               struct lov_stripe_md *ea,
425                               struct obd_trans_info *oti)
426 {
427         int rc;
428         ENTRY;
429
430         EXP_CHECK_OP(exp, destroy);
431         OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
432
433         rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
434         RETURN(rc);
435 }
436
437 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
438                               struct lov_stripe_md *ea)
439 {
440         int rc;
441         ENTRY;
442
443         EXP_CHECK_OP(exp, getattr);
444         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
445
446         rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
447         RETURN(rc);
448 }
449
450 static inline int obd_getattr_async(struct obd_export *exp,
451                                     struct obdo *obdo, struct lov_stripe_md *ea,
452                                     struct ptlrpc_request_set *set)
453 {
454         int rc;
455         ENTRY;
456
457         EXP_CHECK_OP(exp, getattr);
458         OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
459
460         rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
461         RETURN(rc);
462 }
463
464 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
465                               struct lov_stripe_md *ea,
466                               struct obd_trans_info *oti)
467 {
468         int rc;
469         ENTRY;
470
471         EXP_CHECK_OP(exp, setattr);
472         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
473
474         rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
475         RETURN(rc);
476 }
477
478 static inline int obd_setattr_async(struct obd_export *exp, 
479                                     struct obdo *obdo,
480                                     struct lov_stripe_md *ea,
481                                     struct obd_trans_info *oti)
482 {
483         int rc;
484         ENTRY;
485                                                                                                                              
486         EXP_CHECK_OP(exp, setattr_async);
487         OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
488                                                                                                                              
489         rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
490         RETURN(rc);
491 }
492
493 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
494                                int priority)
495 {
496         struct obd_device *obd = imp->imp_obd;
497         int rc;
498         ENTRY;
499
500         OBD_CHECK_DEV_ACTIVE(obd);
501         OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
502         OBD_COUNTER_INCREMENT(obd, add_conn);
503
504         rc = OBP(obd, add_conn)(imp, uuid, priority);
505         RETURN(rc);
506 }
507
508 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
509 {
510         struct obd_device *obd = imp->imp_obd;
511         int rc;
512         ENTRY;
513
514         OBD_CHECK_DEV_ACTIVE(obd);
515         OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
516         OBD_COUNTER_INCREMENT(obd, del_conn);
517
518         rc = OBP(obd, del_conn)(imp, uuid);
519         RETURN(rc);
520 }
521
522 static inline int obd_connect(struct lustre_handle *conn, struct obd_device *obd,
523                               struct obd_uuid *cluuid,
524                               struct obd_connect_data *data)
525 {
526         int rc;
527         ENTRY;
528
529         OBD_CHECK_DEV_ACTIVE(obd);
530         OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
531         OBD_COUNTER_INCREMENT(obd, connect);
532
533         rc = OBP(obd, connect)(conn, obd, cluuid, data);
534         RETURN(rc);
535 }
536
537 static inline int obd_disconnect(struct obd_export *exp)
538 {
539         int rc;
540         ENTRY;
541
542         EXP_CHECK_OP(exp, disconnect);
543         OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
544
545         rc = OBP(exp->exp_obd, disconnect)(exp);
546         RETURN(rc);
547 }
548
549 static inline int obd_init_export(struct obd_export *exp)
550 {
551         int rc = 0;
552
553         ENTRY;
554         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
555             OBP((exp)->exp_obd, init_export))
556                 rc = OBP(exp->exp_obd, init_export)(exp);
557         RETURN(rc);
558 }
559
560 static inline int obd_destroy_export(struct obd_export *exp)
561 {
562         ENTRY;
563         if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
564             OBP((exp)->exp_obd, destroy_export))
565                 OBP(exp->exp_obd, destroy_export)(exp);
566         RETURN(0);
567 }
568
569 static inline struct dentry *
570 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
571 {
572         LASSERT(exp->exp_obd);
573
574         return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
575                                exp->exp_obd);
576 }
577
578 #ifndef time_before
579 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
580 #endif
581
582 /* @max_age is the oldest time in jiffies that we accept using a cached data.
583  * If the cache is older than @max_age we will get a new value from the
584  * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
585 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
586                              unsigned long max_age)
587 {
588         int rc = 0;
589         ENTRY;
590
591         if (obd == NULL)
592                 RETURN(-EINVAL);
593
594         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
595         OBD_COUNTER_INCREMENT(obd, statfs);
596
597         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
598         if (time_before(obd->obd_osfs_age, max_age)) {
599                 rc = OBP(obd, statfs)(obd, osfs, max_age);
600                 if (rc == 0) {
601                         spin_lock(&obd->obd_osfs_lock);
602                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
603                         obd->obd_osfs_age = jiffies;
604                         spin_unlock(&obd->obd_osfs_lock);
605                 }
606         } else {
607                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
608                 spin_lock(&obd->obd_osfs_lock);
609                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
610                 spin_unlock(&obd->obd_osfs_lock);
611         }
612         RETURN(rc);
613 }
614
615 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
616                            struct lov_stripe_md *ea, obd_size start, 
617                            obd_size end)
618 {
619         int rc;
620         ENTRY;
621
622         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
623         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
624
625         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
626         RETURN(rc);
627 }
628
629 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
630                             struct lov_stripe_md *ea, obd_size start,
631                             obd_size end, struct obd_trans_info *oti)
632 {
633         int rc;
634         ENTRY;
635
636         EXP_CHECK_OP(exp, punch);
637         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
638
639         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
640         RETURN(rc);
641 }
642
643 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
644                           struct lov_stripe_md *ea, obd_count oa_bufs,
645                           struct brw_page *pg, struct obd_trans_info *oti)
646 {
647         int rc;
648         ENTRY;
649
650         EXP_CHECK_OP(exp, brw);
651         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
652
653         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
654                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
655                        "or OBD_BRW_CHECK\n");
656                 LBUG();
657         }
658
659         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
660         RETURN(rc);
661 }
662
663 static inline int obd_brw_async(int cmd, struct obd_export *exp,
664                                 struct obdo *oa, struct lov_stripe_md *ea,
665                                 obd_count oa_bufs, struct brw_page *pg,
666                                 struct ptlrpc_request_set *set,
667                                 struct obd_trans_info *oti)
668 {
669         int rc;
670         ENTRY;
671
672         EXP_CHECK_OP(exp, brw_async);
673         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
674
675         if (!(cmd & OBD_BRW_RWMASK)) {
676                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
677                 LBUG();
678         }
679
680         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
681                                           oti);
682         RETURN(rc);
683 }
684
685 static inline  int obd_prep_async_page(struct obd_export *exp, 
686                                        struct lov_stripe_md *lsm,
687                                        struct lov_oinfo *loi, 
688                                        struct page *page, obd_off offset, 
689                                        struct obd_async_page_ops *ops, 
690                                        void *data, void **res)
691 {
692         int ret;
693         ENTRY;
694
695         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
696         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
697
698         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
699                                                  ops, data, res);
700         RETURN(ret);
701 }
702
703 static inline int obd_queue_async_io(struct obd_export *exp,
704                                      struct lov_stripe_md *lsm,
705                                      struct lov_oinfo *loi, void *cookie,
706                                      int cmd, obd_off off, int count,
707                                      obd_flag brw_flags, obd_flag async_flags)
708 {
709         int rc;
710         ENTRY;
711
712         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
713         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
714         LASSERT(cmd & OBD_BRW_RWMASK);
715
716         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
717                                                count, brw_flags, async_flags);
718         RETURN(rc);
719 }
720
721 static inline int obd_set_async_flags(struct obd_export *exp,
722                                       struct lov_stripe_md *lsm,
723                                       struct lov_oinfo *loi, void *cookie,
724                                       obd_flag async_flags)
725 {
726         int rc;
727         ENTRY;
728
729         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
730         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
731
732         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie, 
733                                                 async_flags);
734         RETURN(rc);
735 }
736
737 static inline int obd_queue_group_io(struct obd_export *exp, 
738                                      struct lov_stripe_md *lsm, 
739                                      struct lov_oinfo *loi, 
740                                      struct obd_io_group *oig, 
741                                      void *cookie, int cmd, obd_off off, 
742                                      int count, obd_flag brw_flags,
743                                      obd_flag async_flags)
744 {
745         int rc;
746         ENTRY;
747
748         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
749         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
750         LASSERT(cmd & OBD_BRW_RWMASK);
751
752         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie, 
753                                                cmd, off, count, brw_flags,
754                                                async_flags);
755         RETURN(rc);
756 }
757
758 static inline int obd_trigger_group_io(struct obd_export *exp, 
759                                        struct lov_stripe_md *lsm, 
760                                        struct lov_oinfo *loi,
761                                        struct obd_io_group *oig)
762 {
763         int rc;
764         ENTRY;
765
766         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
767         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
768
769         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
770         RETURN(rc);
771 }
772
773 static inline int obd_teardown_async_page(struct obd_export *exp,
774                                           struct lov_stripe_md *lsm,
775                                           struct lov_oinfo *loi, void *cookie)
776 {
777         int rc;
778         ENTRY;
779
780         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
781         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
782
783         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
784         RETURN(rc);
785 }
786
787 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
788                              int objcount, struct obd_ioobj *obj,
789                              int niocount, struct niobuf_remote *remote,
790                              struct niobuf_local *local,
791                              struct obd_trans_info *oti)
792 {
793         int rc;
794         ENTRY;
795
796         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
797         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
798
799         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
800                                        remote, local, oti);
801         RETURN(rc);
802 }
803
804 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
805                                int objcount, struct obd_ioobj *obj,
806                                int niocount, struct niobuf_local *local,
807                                struct obd_trans_info *oti, int rc)
808 {
809         ENTRY;
810
811         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
812         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
813
814         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
815                                          local, oti, rc);
816         RETURN(rc);
817 }
818
819 static inline int obd_adjust_kms(struct obd_export *exp,
820                                  struct lov_stripe_md *lsm, obd_off size,
821                                  int shrink)
822 {
823         int rc;
824         ENTRY;
825
826         OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
827         OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
828
829         rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
830         RETURN(rc);
831 }
832
833 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
834                                 int len, void *karg, void *uarg)
835 {
836         int rc;
837         ENTRY;
838
839         EXP_CHECK_OP(exp, iocontrol);
840         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
841
842         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
843         RETURN(rc);
844 }
845
846 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
847                               __u32 type, ldlm_policy_data_t *policy,
848                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
849                               void *gl_cb, void *data, __u32 lvb_len,
850                               void *lvb_swabber, struct lustre_handle *lockh)
851 {
852         int rc;
853         ENTRY;
854
855         EXP_CHECK_OP(exp, enqueue);
856         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
857
858         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
859                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
860                                         lvb_swabber, lockh);
861         RETURN(rc);
862 }
863
864 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
865                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
866                             int *flags, void *data, struct lustre_handle *lockh)
867 {
868         int rc;
869         ENTRY;
870
871         EXP_CHECK_OP(exp, match);
872         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
873
874         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
875                                       lockh);
876         RETURN(rc);
877 }
878
879 static inline int obd_change_cbdata(struct obd_export *exp,
880                                     struct lov_stripe_md *lsm, 
881                                     ldlm_iterator_t it, void *data)
882 {
883         int rc;
884         ENTRY;
885
886         EXP_CHECK_OP(exp, change_cbdata);
887         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
888
889         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
890         RETURN(rc);
891 }
892
893 static inline int obd_cancel(struct obd_export *exp,
894                              struct lov_stripe_md *ea, __u32 mode,
895                              struct lustre_handle *lockh)
896 {
897         int rc;
898         ENTRY;
899
900         EXP_CHECK_OP(exp, cancel);
901         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
902
903         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
904         RETURN(rc);
905 }
906
907 static inline int obd_cancel_unused(struct obd_export *exp,
908                                     struct lov_stripe_md *ea, int flags,
909                                     void *opaque)
910 {
911         int rc;
912         ENTRY;
913
914         EXP_CHECK_OP(exp, cancel_unused);
915         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
916
917         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
918         RETURN(rc);
919 }
920
921 static inline int obd_join_lru(struct obd_export *exp,
922                                struct lov_stripe_md *ea, int join)
923 {
924         int rc;
925         ENTRY;
926
927         EXP_CHECK_OP(exp, join_lru);
928         OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
929
930         rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
931         RETURN(rc);
932 }
933
934 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
935                                  struct obdo *oa,
936                                  int objcount, struct obd_ioobj *obj,
937                                  int niocount, struct niobuf_remote *remote)
938 {
939         int rc;
940
941         EXP_CHECK_OP(exp, preprw);
942         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
943
944         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
945                                            niocount, remote);
946         class_export_put(exp);
947         return(rc);
948 }
949
950 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
951                           int type, struct obd_client_handle *handle, int flag)
952 {
953         int rc;
954
955         EXP_CHECK_OP(exp, pin);
956         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
957
958         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
959         return(rc);
960 }
961
962 static inline int obd_unpin(struct obd_export *exp,
963                             struct obd_client_handle *handle, int flag)
964 {
965         int rc;
966
967         EXP_CHECK_OP(exp, unpin);
968         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
969
970         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
971         return(rc);
972 }
973
974
975 static inline void obd_import_event(struct obd_device *obd,
976                                     struct obd_import *imp,
977                                     enum obd_import_event event)
978 {
979         if (!obd) {
980                 CERROR("NULL device\n");
981                 EXIT;
982                 return;
983         }
984         if (obd->obd_set_up && OBP(obd, import_event)) {
985                 OBD_COUNTER_INCREMENT(obd, import_event);
986                 OBP(obd, import_event)(obd, imp, event);
987         }
988 }
989
990 static inline int obd_notify(struct obd_device *obd,
991                              struct obd_device *watched,
992                              int active)
993 {
994         OBD_CHECK_DEV(obd);
995         if (!obd->obd_set_up) {
996                 CERROR("obd %s not set up\n", obd->obd_name);
997                 return -EINVAL;
998         }
999
1000         if (!OBP(obd, notify)) {
1001                 CERROR("obd %s has no notify handler\n", obd->obd_name);
1002                 return -ENOSYS;
1003         }
1004
1005         OBD_COUNTER_INCREMENT(obd, notify);
1006         return OBP(obd, notify)(obd, watched, active);
1007 }
1008
1009 static inline int obd_quotacheck(struct obd_export *exp,
1010                                  struct obd_quotactl *oqctl)
1011 {
1012         int rc;
1013         ENTRY;
1014
1015         EXP_CHECK_OP(exp, quotacheck);
1016         OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1017
1018         rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1019         RETURN(rc);
1020
1021
1022 static inline int obd_quotactl(struct obd_export *exp,
1023                                struct obd_quotactl *oqctl)
1024 {
1025         int rc;
1026         ENTRY;
1027
1028         EXP_CHECK_OP(exp, quotactl);
1029         OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1030
1031         rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1032         RETURN(rc);
1033
1034
1035
1036 static inline int obd_register_observer(struct obd_device *obd,
1037                                         struct obd_device *observer)
1038 {
1039         ENTRY;
1040         OBD_CHECK_DEV(obd);
1041         if (obd->obd_observer && observer)
1042                 RETURN(-EALREADY);
1043         obd->obd_observer = observer;
1044         RETURN(0);
1045 }
1046
1047 /* OBD Metadata Support */
1048
1049 extern int obd_init_caches(void);
1050 extern void obd_cleanup_caches(void);
1051
1052 /* support routines */
1053 extern kmem_cache_t *obdo_cachep;
1054 static inline struct obdo *obdo_alloc(void)
1055 {
1056         struct obdo *oa;
1057
1058         OBD_SLAB_ALLOC(oa, obdo_cachep, SLAB_KERNEL, sizeof(*oa));
1059
1060         return oa;
1061 }
1062
1063 /* qunit hash stuff */
1064 extern kmem_cache_t *qunit_cachep;
1065 extern struct list_head qunit_hash[];
1066 extern spinlock_t qunit_hash_lock;
1067
1068 static inline void obdo_free(struct obdo *oa)
1069 {
1070         OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1071 }
1072
1073 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1074 #define to_kdev_t(dev) dev
1075 #define kdev_t_to_nr(dev) dev
1076 #endif
1077
1078 /* I'm as embarrassed about this as you are.
1079  *
1080  * <shaver> // XXX do not look into _superhack with remaining eye
1081  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1082 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1083 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1084
1085 /* sysctl.c */
1086 extern void obd_sysctl_init (void);
1087 extern void obd_sysctl_clean (void);
1088
1089 /* uuid.c  */
1090 typedef __u8 class_uuid_t[16];
1091 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1092 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1093
1094 /* lustre_peer.c    */
1095 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1096 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1097 int class_del_uuid (char *uuid);
1098 void class_init_uuidlist(void);
1099 void class_exit_uuidlist(void);
1100
1101 #endif /* __LINUX_OBD_CLASS_H */