Whamcloud - gitweb
Land b_smallfix onto HEAD (20040223_1817)
[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 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_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 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
612                              unsigned long max_age)
613 {
614         int rc = 0;
615         ENTRY;
616
617         if (obd == NULL)
618                 RETURN(-EINVAL);
619
620         OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
621         OBD_COUNTER_INCREMENT(obd, statfs);
622
623         CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
624         if (time_before(obd->obd_osfs_age, max_age)) {
625                 rc = OBP(obd, statfs)(obd, osfs, max_age);
626                 spin_lock(&obd->obd_osfs_lock);
627                 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
628                 obd->obd_osfs_age = jiffies;
629                 spin_unlock(&obd->obd_osfs_lock);
630         } else {
631                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
632                 spin_lock(&obd->obd_osfs_lock);
633                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
634                 spin_unlock(&obd->obd_osfs_lock);
635         }
636         RETURN(rc);
637 }
638
639 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
640                            struct lov_stripe_md *ea, obd_size start, 
641                            obd_size end)
642 {
643         int rc;
644         ENTRY;
645
646         OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
647         OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
648
649         rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
650         RETURN(rc);
651 }
652
653 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
654                             struct lov_stripe_md *ea, obd_size start,
655                             obd_size end, struct obd_trans_info *oti)
656 {
657         int rc;
658         ENTRY;
659
660         EXP_CHECK_OP(exp, punch);
661         OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
662
663         rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
664         RETURN(rc);
665 }
666
667 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
668                           struct lov_stripe_md *ea, obd_count oa_bufs,
669                           struct brw_page *pg, struct obd_trans_info *oti)
670 {
671         int rc;
672         ENTRY;
673
674         EXP_CHECK_OP(exp, brw);
675         OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
676
677         if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
678                 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
679                        "or OBD_BRW_CHECK\n");
680                 LBUG();
681         }
682
683         rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
684         RETURN(rc);
685 }
686
687 static inline int obd_brw_async(int cmd, struct obd_export *exp,
688                                 struct obdo *oa, struct lov_stripe_md *ea,
689                                 obd_count oa_bufs, struct brw_page *pg,
690                                 struct ptlrpc_request_set *set,
691                                 struct obd_trans_info *oti)
692 {
693         int rc;
694         ENTRY;
695
696         EXP_CHECK_OP(exp, brw_async);
697         OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
698
699         if (!(cmd & OBD_BRW_RWMASK)) {
700                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
701                 LBUG();
702         }
703
704         rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
705                                           oti);
706         RETURN(rc);
707 }
708
709 static inline  int obd_prep_async_page(struct obd_export *exp, 
710                                        struct lov_stripe_md *lsm,
711                                        struct lov_oinfo *loi, 
712                                        struct page *page, obd_off offset, 
713                                        struct obd_async_page_ops *ops, 
714                                        void *data, void **res)
715 {
716         int ret;
717         ENTRY;
718
719         OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
720         OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
721
722         ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
723                                                  ops, data, res);
724         RETURN(ret);
725 }
726
727 static inline int obd_queue_async_io(struct obd_export *exp,
728                                      struct lov_stripe_md *lsm,
729                                      struct lov_oinfo *loi, void *cookie,
730                                      int cmd, obd_off off, int count,
731                                      obd_flag brw_flags, obd_flag async_flags)
732 {
733         int rc;
734         ENTRY;
735
736         OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
737         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
738         LASSERT(cmd & OBD_BRW_RWMASK);
739
740         rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
741                                                count, brw_flags, async_flags);
742         RETURN(rc);
743 }
744
745 static inline int obd_set_async_flags(struct obd_export *exp,
746                                       struct lov_stripe_md *lsm,
747                                       struct lov_oinfo *loi, void *cookie,
748                                       obd_flag async_flags)
749 {
750         int rc;
751         ENTRY;
752
753         OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
754         OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
755
756         rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie, 
757                                                 async_flags);
758         RETURN(rc);
759 }
760
761 static inline int obd_queue_group_io(struct obd_export *exp, 
762                                      struct lov_stripe_md *lsm, 
763                                      struct lov_oinfo *loi, 
764                                      struct obd_io_group *oig, 
765                                      void *cookie, int cmd, obd_off off, 
766                                      int count, obd_flag brw_flags,
767                                      obd_flag async_flags)
768 {
769         int rc;
770         ENTRY;
771
772         OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
773         OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
774         LASSERT(cmd & OBD_BRW_RWMASK);
775
776         rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie, 
777                                                cmd, off, count, brw_flags,
778                                                async_flags);
779         RETURN(rc);
780 }
781
782 static inline int obd_trigger_group_io(struct obd_export *exp, 
783                                        struct lov_stripe_md *lsm, 
784                                        struct lov_oinfo *loi,
785                                        struct obd_io_group *oig)
786 {
787         int rc;
788         ENTRY;
789
790         OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
791         OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
792
793         rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
794         RETURN(rc);
795 }
796
797 static inline int obd_teardown_async_page(struct obd_export *exp,
798                                           struct lov_stripe_md *lsm,
799                                           struct lov_oinfo *loi, void *cookie)
800 {
801         int rc;
802         ENTRY;
803
804         OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
805         OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
806
807         rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
808         RETURN(rc);
809 }
810
811 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
812                              int objcount, struct obd_ioobj *obj,
813                              int niocount, struct niobuf_remote *remote,
814                              struct niobuf_local *local,
815                              struct obd_trans_info *oti)
816 {
817         int rc;
818         ENTRY;
819
820         OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
821         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
822
823         rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
824                                        remote, local, oti);
825         RETURN(rc);
826 }
827
828 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
829                                int objcount, struct obd_ioobj *obj,
830                                int niocount, struct niobuf_local *local,
831                                struct obd_trans_info *oti)
832 {
833         int rc;
834         ENTRY;
835
836         OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
837         OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
838
839         rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
840                                          local, oti);
841         RETURN(rc);
842 }
843
844 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
845                                 int len, void *karg, void *uarg)
846 {
847         int rc;
848         ENTRY;
849
850         EXP_CHECK_OP(exp, iocontrol);
851         OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
852
853         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
854         RETURN(rc);
855 }
856
857 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
858                               __u32 type, ldlm_policy_data_t *policy,
859                               __u32 mode, int *flags, void *bl_cb, void *cp_cb,
860                               void *gl_cb, void *data, __u32 lvb_len,
861                               void *lvb_swabber, struct lustre_handle *lockh)
862 {
863         int rc;
864         ENTRY;
865
866         EXP_CHECK_OP(exp, enqueue);
867         OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
868
869         rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
870                                         bl_cb, cp_cb, gl_cb, data, lvb_len,
871                                         lvb_swabber, lockh);
872         RETURN(rc);
873 }
874
875 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
876                             __u32 type, ldlm_policy_data_t *policy, __u32 mode,
877                             int *flags, void *data, struct lustre_handle *lockh)
878 {
879         int rc;
880         ENTRY;
881
882         EXP_CHECK_OP(exp, match);
883         OBD_COUNTER_INCREMENT(exp->exp_obd, match);
884
885         rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
886                                       lockh);
887         RETURN(rc);
888 }
889
890 static inline int obd_change_cbdata(struct obd_export *exp,
891                                     struct lov_stripe_md *lsm, 
892                                     ldlm_iterator_t it, void *data)
893 {
894         int rc;
895         ENTRY;
896
897         EXP_CHECK_OP(exp, change_cbdata);
898         OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
899
900         rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
901         RETURN(rc);
902 }
903
904 static inline int obd_cancel(struct obd_export *exp,
905                              struct lov_stripe_md *ea, __u32 mode,
906                              struct lustre_handle *lockh)
907 {
908         int rc;
909         ENTRY;
910
911         EXP_CHECK_OP(exp, cancel);
912         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
913
914         rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
915         RETURN(rc);
916 }
917
918 static inline int obd_cancel_unused(struct obd_export *exp,
919                                     struct lov_stripe_md *ea, int flags,
920                                     void *opaque)
921 {
922         int rc;
923         ENTRY;
924
925         EXP_CHECK_OP(exp, cancel_unused);
926         OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
927
928         rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
929         RETURN(rc);
930 }
931
932
933 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
934                                  struct obdo *oa,
935                                  int objcount, struct obd_ioobj *obj,
936                                  int niocount, struct niobuf_remote *remote)
937 {
938         int rc;
939
940         EXP_CHECK_OP(exp, preprw);
941         OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
942
943         rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
944                                            niocount, remote);
945         class_export_put(exp);
946         return(rc);
947 }
948
949 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
950                           int type, struct obd_client_handle *handle, int flag)
951 {
952         int rc;
953
954         EXP_CHECK_OP(exp, pin);
955         OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
956
957         rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
958         return(rc);
959 }
960
961 static inline int obd_unpin(struct obd_export *exp,
962                             struct obd_client_handle *handle, int flag)
963 {
964         int rc;
965
966         EXP_CHECK_OP(exp, unpin);
967         OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
968
969         rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
970         return(rc);
971 }
972
973 static inline void obd_invalidate_import(struct obd_device *obd,
974                                          struct obd_import *imp)
975 {
976         if (obd->obd_set_up && OBP(obd, invalidate_import)) {
977                 OBD_COUNTER_INCREMENT(obd, invalidate_import);
978                 OBP(obd, invalidate_import)(obd, imp);
979         }
980 }
981
982 static inline int obd_notify(struct obd_device *obd,
983                              struct obd_device *watched,
984                              int active)
985 {
986         if (!obd->obd_set_up) {
987                 CERROR("obd %s not set up\n", obd->obd_name);
988                 return -EINVAL;
989         }
990
991         if (!OBP(obd, notify)) {
992                 CERROR("obd %s has no notify handler\n", obd->obd_name);
993                 return -ENOSYS;
994         }
995
996         OBD_COUNTER_INCREMENT(obd, notify);
997         return OBP(obd, notify)(obd, watched, active);
998 }
999
1000 static inline int obd_register_observer(struct obd_device *obd,
1001                                         struct obd_device *observer)
1002 {
1003         ENTRY;
1004         if (obd->obd_observer && observer)
1005                 RETURN(-EALREADY);
1006         obd->obd_observer = observer;
1007         RETURN(0);
1008 }
1009
1010 /* OBD Metadata Support */
1011
1012 extern int obd_init_caches(void);
1013 extern void obd_cleanup_caches(void);
1014
1015 /* support routines */
1016 extern kmem_cache_t *obdo_cachep;
1017 static inline struct obdo *obdo_alloc(void)
1018 {
1019         struct obdo *oa;
1020
1021         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1022         if (oa == NULL)
1023                 LBUG();
1024         CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1025         memset(oa, 0, sizeof (*oa));
1026
1027         return oa;
1028 }
1029
1030 static inline void obdo_free(struct obdo *oa)
1031 {
1032         if (!oa)
1033                 return;
1034         CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1035         kmem_cache_free(obdo_cachep, oa);
1036 }
1037
1038 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1039 #define to_kdev_t(dev) dev
1040 #define kdev_t_to_nr(dev) dev
1041 #endif
1042
1043 /* I'm as embarrassed about this as you are.
1044  *
1045  * <shaver> // XXX do not look into _superhack with remaining eye
1046  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1047 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1048 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1049
1050 /* sysctl.c */
1051 extern void obd_sysctl_init (void);
1052 extern void obd_sysctl_clean (void);
1053
1054 /* uuid.c  */
1055 typedef __u8 class_uuid_t[16];
1056 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1057 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1058
1059 /* lustre_peer.c    */
1060 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1061 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1062 int class_del_uuid (char *uuid);
1063 void class_init_uuidlist(void);
1064 void class_exit_uuidlist(void);
1065 #endif /* __LINUX_OBD_CLASS_H */