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