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