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