1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
27 #include <sys/types.h>
28 #include <portals/list.h>
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
34 #include <linux/time.h>
35 #include <linux/timer.h>
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/lustre_mds.h>
45 #include <linux/lustre_dlm.h>
46 #include <linux/lprocfs_status.h>
49 /* OBD Device Declarations */
50 #define MAX_OBD_DEVICES 128
51 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
53 /* OBD Operations Declarations */
54 extern struct obd_device *class_conn2obd(struct lustre_handle *);
57 struct obd_export *class_conn2export(struct lustre_handle *);
58 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *, char *nm);
59 int class_unregister_type(char *nm);
60 int class_name2dev(char *name);
61 struct obd_device *class_name2obd(char *name);
62 int class_uuid2dev(struct obd_uuid *uuid);
63 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
65 struct obd_export *class_export_get(struct obd_export *);
66 void class_export_put(struct obd_export *);
67 struct obd_export *class_new_export(struct obd_device *obddev);
68 void class_unlink_export(struct obd_export *exp);
70 struct obd_import *class_import_get(struct obd_import *);
71 void class_import_put(struct obd_import *);
72 struct obd_import *class_new_import(void);
73 void class_destroy_import(struct obd_import *exp);
75 struct obd_type *class_get_type(char *name);
76 void class_put_type(struct obd_type *type);
77 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
78 struct obd_uuid *cluuid);
79 int class_disconnect(struct lustre_handle *conn, int failover);
80 void class_disconnect_exports(struct obd_device *obddev, int failover);
81 /* generic operations shared by various OBD types */
82 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
83 int class_multi_cleanup(struct obd_device *obddev);
87 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
88 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
89 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
90 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
91 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
93 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
94 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
96 static inline int obd_check_conn(struct lustre_handle *conn)
98 struct obd_device *obd;
100 CERROR("NULL conn\n");
104 obd = class_conn2obd(conn);
106 CERROR("NULL obd\n");
110 if (!obd->obd_attached) {
111 CERROR("obd %d not attached\n", obd->obd_minor);
115 if (!obd->obd_set_up) {
116 CERROR("obd %d not setup\n", obd->obd_minor);
120 if (!obd->obd_type) {
121 CERROR("obd %d not typed\n", obd->obd_minor);
125 if (!obd->obd_type->typ_ops) {
126 CERROR("obd_check_conn: obd %d no operations\n",
134 #define OBT(dev) (dev)->obd_type
135 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
137 /* Ensure obd_setup: used for disconnect which might be called while
138 an obd is stopping. */
139 #define OBD_CHECK_SETUP(conn, exp) \
142 CERROR("NULL connection\n"); \
146 exp = class_conn2export(conn); \
148 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
152 if (!(exp)->exp_obd->obd_set_up) { \
153 CERROR("Device %d not setup\n", \
154 (exp)->exp_obd->obd_minor); \
155 class_export_put(exp); \
160 /* Ensure obd_setup and !obd_stopping. */
161 #define OBD_CHECK_ACTIVE(conn, exp) \
164 CERROR("NULL connection\n"); \
168 exp = class_conn2export(conn); \
170 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
174 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
175 CERROR("Device %d not setup\n", \
176 (exp)->exp_obd->obd_minor); \
177 class_export_put(exp); \
182 /* Ensure obd_setup: used for cleanup which must be called
183 while obd is stopping */
184 #define OBD_CHECK_DEV_STOPPING(obd) \
187 CERROR("NULL device\n"); \
191 if (!(obd)->obd_set_up) { \
192 CERROR("Device %d not setup\n", \
197 if (!(obd)->obd_stopping) { \
198 CERROR("Device %d not stopping\n", \
204 /* ensure obd_setup and !obd_stopping */
205 #define OBD_CHECK_DEV_ACTIVE(obd) \
208 CERROR("NULL device\n"); \
212 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
213 CERROR("Device %d not setup\n", \
221 #define OBD_COUNTER_OFFSET(op) \
222 ((offsetof(struct obd_ops, o_ ## op) - \
223 offsetof(struct obd_ops, o_iocontrol)) \
224 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
226 #define OBD_COUNTER_INCREMENT(obd, op) \
227 if ((obd)->obd_stats != NULL) { \
228 unsigned int coffset; \
229 coffset = (unsigned int)(obd)->obd_cntr_base + \
230 OBD_COUNTER_OFFSET(op); \
231 LASSERT(coffset < obd->obd_stats->ls_num); \
232 lprocfs_counter_incr(obd->obd_stats, coffset); \
235 #define OBD_COUNTER_OFFSET(op)
236 #define OBD_COUNTER_INCREMENT(obd, op)
239 #define OBD_CHECK_OP(obd, op) \
241 if (!OBP((obd), op)) { \
242 CERROR("obd_" #op ": dev %d no operation\n", \
244 RETURN(-EOPNOTSUPP); \
248 static inline int obd_get_info(struct lustre_handle *conn, __u32 keylen,
249 void *key, __u32 *vallen, void *val)
251 struct obd_export *exp;
255 OBD_CHECK_ACTIVE(conn, exp);
256 OBD_CHECK_OP(exp->exp_obd, get_info);
257 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
259 rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
260 class_export_put(exp);
264 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
265 void *key, obd_count vallen, void *val)
267 struct obd_export *exp;
271 OBD_CHECK_ACTIVE(conn, exp);
272 OBD_CHECK_OP(exp->exp_obd, set_info);
273 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
275 rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
276 class_export_put(exp);
280 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
285 OBD_CHECK_OP(obd, setup);
286 OBD_COUNTER_INCREMENT(obd, setup);
288 rc = OBP(obd, setup)(obd, datalen, data);
292 static inline int obd_cleanup(struct obd_device *obd, int flags)
297 OBD_CHECK_DEV_STOPPING(obd);
298 OBD_CHECK_OP(obd, cleanup);
299 OBD_COUNTER_INCREMENT(obd, cleanup);
301 rc = OBP(obd, cleanup)(obd, flags);
305 /* Pack an in-memory MD struct for storage on disk.
306 * Returns +ve size of packed MD (0 for free), or -ve error.
308 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
309 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
310 * If @*disk_tgt == NULL, it will be allocated
312 static inline int obd_packmd(struct lustre_handle *conn,
313 struct lov_mds_md **disk_tgt,
314 struct lov_stripe_md *mem_src)
316 struct obd_export *exp;
320 OBD_CHECK_ACTIVE(conn, exp);
321 OBD_CHECK_OP(exp->exp_obd, packmd);
322 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
324 rc = OBP(exp->exp_obd, packmd)(conn, disk_tgt, mem_src);
325 class_export_put(exp);
329 static inline int obd_size_diskmd(struct lustre_handle *conn,
330 struct lov_stripe_md *mem_src)
332 return obd_packmd(conn, NULL, mem_src);
335 /* helper functions */
336 static inline int obd_alloc_diskmd(struct lustre_handle *conn,
337 struct lov_mds_md **disk_tgt)
340 LASSERT(*disk_tgt == NULL);
341 return obd_packmd(conn, disk_tgt, NULL);
344 static inline int obd_free_diskmd(struct lustre_handle *conn,
345 struct lov_mds_md **disk_tgt)
349 return obd_packmd(conn, disk_tgt, NULL);
352 /* Unpack an MD struct from disk to in-memory format.
353 * Returns +ve size of unpacked MD (0 for free), or -ve error.
355 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
356 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
357 * If @*mem_tgt == NULL, it will be allocated
359 static inline int obd_unpackmd(struct lustre_handle *conn,
360 struct lov_stripe_md **mem_tgt,
361 struct lov_mds_md *disk_src,
364 struct obd_export *exp;
368 OBD_CHECK_ACTIVE(conn, exp);
369 OBD_CHECK_OP(exp->exp_obd, unpackmd);
370 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
372 rc = OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, disk_src, disk_len);
373 class_export_put(exp);
377 static inline int obd_size_memmd(struct lustre_handle *conn,
378 struct lov_mds_md *disk_src,
381 return obd_unpackmd(conn, NULL, disk_src, disk_len);
384 /* helper functions */
385 static inline int obd_alloc_memmd(struct lustre_handle *conn,
386 struct lov_stripe_md **mem_tgt)
389 LASSERT(*mem_tgt == NULL);
390 return obd_unpackmd(conn, mem_tgt, NULL, 0);
393 static inline int obd_free_memmd(struct lustre_handle *conn,
394 struct lov_stripe_md **mem_tgt)
398 return obd_unpackmd(conn, mem_tgt, NULL, 0);
401 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
402 struct lov_stripe_md **ea,
403 struct obd_trans_info *oti)
405 struct obd_export *exp;
409 OBD_CHECK_ACTIVE(conn, exp);
410 OBD_CHECK_OP(exp->exp_obd, create);
411 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
413 rc = OBP(exp->exp_obd, create)(conn, obdo, ea, oti);
414 class_export_put(exp);
418 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
419 struct lov_stripe_md *ea,
420 struct obd_trans_info *oti)
422 struct obd_export *exp;
426 OBD_CHECK_ACTIVE(conn, exp);
427 OBD_CHECK_OP(exp->exp_obd, destroy);
428 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
430 rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea, oti);
431 class_export_put(exp);
435 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
436 struct lov_stripe_md *ea)
438 struct obd_export *exp;
442 OBD_CHECK_ACTIVE(conn, exp);
443 OBD_CHECK_OP(exp->exp_obd, getattr);
444 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
446 rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
447 class_export_put(exp);
451 static inline int obd_getattr_async(struct lustre_handle *conn,
452 struct obdo *obdo, struct lov_stripe_md *ea,
453 struct ptlrpc_request_set *set)
455 struct obd_export *exp;
459 OBD_CHECK_SETUP(conn, exp);
460 OBD_CHECK_OP(exp->exp_obd, getattr);
461 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
463 rc = OBP(exp->exp_obd, getattr_async)(conn, obdo, ea, set);
464 class_export_put(exp);
468 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
469 struct lov_stripe_md *ea,
470 struct obd_trans_info *oti)
472 struct obd_export *exp;
476 OBD_CHECK_ACTIVE(conn, exp);
477 OBD_CHECK_OP(exp->exp_obd, close);
478 OBD_COUNTER_INCREMENT(exp->exp_obd, close);
480 rc = OBP(exp->exp_obd, close)(conn, obdo, ea, oti);
481 class_export_put(exp);
485 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
486 struct lov_stripe_md *ea, struct obd_trans_info *oti,
487 struct obd_client_handle *och)
489 struct obd_export *exp;
493 OBD_CHECK_ACTIVE(conn, exp);
494 OBD_CHECK_OP(exp->exp_obd, open);
495 OBD_COUNTER_INCREMENT(exp->exp_obd, open);
497 rc = OBP(exp->exp_obd, open)(conn, obdo, ea, oti, och);
498 class_export_put(exp);
502 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
503 struct lov_stripe_md *ea,
504 struct obd_trans_info *oti)
506 struct obd_export *exp;
510 OBD_CHECK_ACTIVE(conn, exp);
511 OBD_CHECK_OP(exp->exp_obd, setattr);
512 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
514 rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea, oti);
515 class_export_put(exp);
519 static inline int obd_connect(struct lustre_handle *conn,
520 struct obd_device *obd, struct obd_uuid *cluuid)
525 OBD_CHECK_DEV_ACTIVE(obd);
526 OBD_CHECK_OP(obd, connect);
527 OBD_COUNTER_INCREMENT(obd, connect);
529 rc = OBP(obd, connect)(conn, obd, cluuid);
533 static inline int obd_disconnect(struct lustre_handle *conn, int flags)
535 struct obd_export *exp;
539 OBD_CHECK_SETUP(conn, exp);
540 OBD_CHECK_OP(exp->exp_obd, disconnect);
541 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
543 rc = OBP(exp->exp_obd, disconnect)(conn, flags);
544 class_export_put(exp);
548 static inline void obd_destroy_export(struct obd_export *exp)
551 if (OBP(exp->exp_obd, destroy_export))
552 OBP(exp->exp_obd, destroy_export)(exp);
557 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
560 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
561 unsigned long max_age)
569 OBD_CHECK_OP(obd, statfs);
570 OBD_COUNTER_INCREMENT(obd, statfs);
572 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
573 if (obd->obd_osfs_age == 0 || time_before(obd->obd_osfs_age, max_age)) {
574 rc = OBP(obd, statfs)(obd, osfs, max_age);
575 spin_lock(&obd->obd_dev_lock);
576 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
577 obd->obd_osfs_age = jiffies;
578 spin_unlock(&obd->obd_dev_lock);
580 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
581 spin_lock(&obd->obd_dev_lock);
582 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
583 spin_unlock(&obd->obd_dev_lock);
588 static inline int obd_syncfs(struct obd_export *exp)
593 OBD_CHECK_OP(exp->exp_obd, syncfs);
594 OBD_COUNTER_INCREMENT(exp->exp_obd, syncfs);
596 rc = OBP(exp->exp_obd, syncfs)(exp);
600 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
601 struct lov_stripe_md *ea, obd_size start,
602 obd_size end, struct obd_trans_info *oti)
604 struct obd_export *exp;
608 OBD_CHECK_ACTIVE(conn, exp);
609 OBD_CHECK_OP(exp->exp_obd, punch);
610 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
612 rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end, oti);
613 class_export_put(exp);
617 static inline int obd_brw(int cmd, struct lustre_handle *conn, struct obdo *oa,
618 struct lov_stripe_md *ea, obd_count oa_bufs,
619 struct brw_page *pg, struct obd_trans_info *oti)
621 struct obd_export *exp;
625 OBD_CHECK_ACTIVE(conn, exp);
626 OBD_CHECK_OP(exp->exp_obd, brw);
627 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
629 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
630 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
631 "or OBD_BRW_CHECK\n");
635 rc = OBP(exp->exp_obd, brw)(cmd, conn, oa, ea, oa_bufs, pg, oti);
636 class_export_put(exp);
640 static inline int obd_brw_async(int cmd, struct lustre_handle *conn,
641 struct obdo *oa, struct lov_stripe_md *ea,
642 obd_count oa_bufs, struct brw_page *pg,
643 struct ptlrpc_request_set *set,
644 struct obd_trans_info *oti)
646 struct obd_export *exp;
650 OBD_CHECK_ACTIVE(conn, exp);
651 OBD_CHECK_OP(exp->exp_obd, brw_async);
652 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
654 if (!(cmd & OBD_BRW_RWMASK)) {
655 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
659 rc = OBP(exp->exp_obd, brw_async)(cmd, conn, oa, ea, oa_bufs, pg, set,
661 class_export_put(exp);
665 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
666 int objcount, struct obd_ioobj *obj,
667 int niocount, struct niobuf_remote *remote,
668 struct niobuf_local *local,
669 struct obd_trans_info *oti)
674 OBD_CHECK_OP(exp->exp_obd, preprw);
675 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
677 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
682 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
683 int objcount, struct obd_ioobj *obj,
684 int niocount, struct niobuf_local *local,
685 struct obd_trans_info *oti)
690 OBD_CHECK_OP(exp->exp_obd, commitrw);
691 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
693 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
698 static inline int obd_iocontrol(unsigned int cmd, struct lustre_handle *conn,
699 int len, void *karg, void *uarg)
701 struct obd_export *exp;
705 OBD_CHECK_ACTIVE(conn, exp);
706 OBD_CHECK_OP(exp->exp_obd, iocontrol);
707 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
709 rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
710 class_export_put(exp);
714 static inline int obd_enqueue(struct lustre_handle *conn,
715 struct lov_stripe_md *ea,
716 struct lustre_handle *parent_lock,
717 __u32 type, void *cookie, int cookielen,
718 __u32 mode, int *flags, void *cb, void *data,
719 struct lustre_handle *lockh)
721 struct obd_export *exp;
725 OBD_CHECK_ACTIVE(conn, exp);
726 OBD_CHECK_OP(exp->exp_obd, enqueue);
727 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
729 rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
730 cookie, cookielen, mode, flags, cb,
732 class_export_put(exp);
736 static inline int obd_match(struct lustre_handle *conn,
737 struct lov_stripe_md *ea, __u32 type, void *cookie,
738 int cookielen, __u32 mode, int *flags, void *data,
739 struct lustre_handle *lockh)
741 struct obd_export *exp;
745 OBD_CHECK_ACTIVE(conn, exp);
746 OBD_CHECK_OP(exp->exp_obd, match);
747 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
749 rc = OBP(exp->exp_obd, match)(conn, ea, type, cookie, cookielen, mode,
751 class_export_put(exp);
756 static inline int obd_cancel(struct lustre_handle *conn,
757 struct lov_stripe_md *ea, __u32 mode,
758 struct lustre_handle *lockh)
760 struct obd_export *exp;
764 OBD_CHECK_ACTIVE(conn, exp);
765 OBD_CHECK_OP(exp->exp_obd, cancel);
766 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
768 rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
769 class_export_put(exp);
773 static inline int obd_cancel_unused(struct lustre_handle *conn,
774 struct lov_stripe_md *ea, int flags,
777 struct obd_export *exp;
781 OBD_CHECK_ACTIVE(conn, exp);
782 OBD_CHECK_OP(exp->exp_obd, cancel_unused);
783 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
785 rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, flags, opaque);
786 class_export_put(exp);
790 static inline int obd_log_add(struct lustre_handle *conn,
791 struct llog_handle *cathandle,
792 struct llog_trans_hdr *rec,
793 struct lov_stripe_md *lsm,
794 struct llog_cookie *logcookies,
797 struct obd_export *exp;
801 OBD_CHECK_SETUP(conn, exp);
802 OBD_CHECK_OP(exp->exp_obd, log_add);
803 OBD_COUNTER_INCREMENT(exp->exp_obd, log_add);
805 rc = OBP(exp->exp_obd, log_add)(conn, cathandle, rec, lsm, logcookies,
807 class_export_put(exp);
811 static inline int obd_log_cancel(struct lustre_handle *conn,
812 struct lov_stripe_md *lsm, int count,
813 struct llog_cookie *cookies, int flags)
815 struct obd_export *exp;
819 OBD_CHECK_SETUP(conn, exp);
820 OBD_CHECK_OP(exp->exp_obd, log_cancel);
821 OBD_COUNTER_INCREMENT(exp->exp_obd, log_cancel);
823 rc = OBP(exp->exp_obd, log_cancel)(conn, lsm, count, cookies, flags);
824 class_export_put(exp);
828 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
830 int objcount, struct obd_ioobj *obj,
831 int niocount, struct niobuf_remote *remote)
835 OBD_CHECK_OP(exp->exp_obd, preprw);
836 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
838 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
840 class_export_put(exp);
844 static inline int obd_pin(struct lustre_handle *conn, obd_id ino, __u32 gen,
845 int type, struct obd_client_handle *handle, int flag)
847 struct obd_export *exp;
850 OBD_CHECK_ACTIVE(conn, exp);
851 OBD_CHECK_OP(exp->exp_obd, pin);
852 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
854 rc = OBP(exp->exp_obd, pin)(conn, ino, gen, type, handle, flag);
855 class_export_put(exp);
859 static inline int obd_unpin(struct lustre_handle *conn,
860 struct obd_client_handle *handle, int flag)
862 struct obd_export *exp;
865 OBD_CHECK_ACTIVE(conn, exp);
866 OBD_CHECK_OP(exp->exp_obd, unpin);
867 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
869 rc = OBP(exp->exp_obd, unpin)(conn, handle, flag);
870 class_export_put(exp);
874 static inline int obd_mark_page_dirty(struct lustre_handle *conn,
875 struct lov_stripe_md *lsm,
876 unsigned long offset)
878 struct obd_export *exp;
881 OBD_CHECK_SETUP(conn, exp);
882 OBD_CHECK_OP(exp->exp_obd, mark_page_dirty);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, mark_page_dirty);
885 rc = OBP(exp->exp_obd, mark_page_dirty)(conn, lsm, offset);
886 class_export_put(exp);
890 static inline int obd_clear_dirty_pages(struct lustre_handle *conn,
891 struct lov_stripe_md *lsm,
894 unsigned long *cleared)
896 struct obd_export *exp;
899 OBD_CHECK_SETUP(conn, exp);
900 OBD_CHECK_OP(exp->exp_obd, clear_dirty_pages);
901 OBD_COUNTER_INCREMENT(exp->exp_obd, clear_dirty_pages);
903 rc = OBP(exp->exp_obd, clear_dirty_pages)(conn, lsm, start, end,
905 class_export_put(exp);
909 static inline int obd_last_dirty_offset(struct lustre_handle *conn,
910 struct lov_stripe_md *lsm,
911 unsigned long *offset)
913 struct obd_export *exp;
916 OBD_CHECK_SETUP(conn, exp);
917 OBD_CHECK_OP(exp->exp_obd, last_dirty_offset);
918 OBD_COUNTER_INCREMENT(exp->exp_obd, last_dirty_offset);
920 rc = OBP(exp->exp_obd, last_dirty_offset)(conn, lsm, offset);
921 class_export_put(exp);
925 /* OBD Metadata Support */
927 extern int obd_init_caches(void);
928 extern void obd_cleanup_caches(void);
930 /* support routines */
931 extern kmem_cache_t *obdo_cachep;
932 static inline struct obdo *obdo_alloc(void)
936 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
939 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
940 memset(oa, 0, sizeof (*oa));
945 static inline void obdo_free(struct obdo *oa)
949 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
950 kmem_cache_free(obdo_cachep, oa);
953 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
954 #define to_kdev_t(dev) dev
955 #define kdev_t_to_nr(dev) dev
958 /* I'm as embarrassed about this as you are.
960 * <shaver> // XXX do not look into _superhack with remaining eye
961 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
962 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
963 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
965 struct obd_class_user_state {
966 struct obd_device *ocus_current_obd;
967 struct list_head ocus_conns;
970 struct obd_class_user_conn {
971 struct list_head ocuc_chain;
972 struct lustre_handle ocuc_conn;
977 extern void obd_sysctl_init (void);
978 extern void obd_sysctl_clean (void);
981 typedef __u8 class_uuid_t[16];
982 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
983 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
986 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
987 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
988 int class_del_uuid (char *uuid);
989 void class_init_uuidlist(void);
990 void class_exit_uuidlist(void);
992 #endif /* __LINUX_OBD_CLASS_H */