1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 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
29 # include <linux/list.h>
32 #include <asm/segment.h>
33 #include <asm/uaccess.h>
34 #include <linux/types.h>
36 #include <linux/time.h>
38 #include <linux/obd_support.h>
39 #include <linux/obd.h>
40 #include <linux/lustre_lib.h>
41 #include <linux/lustre_idl.h>
42 #include <linux/lustre_mds.h>
47 * ======== OBD Device Declarations ===========
49 #define MAX_OBD_DEVICES 128
50 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
52 #define OBD_ATTACHED 0x1
53 #define OBD_SET_UP 0x2
55 extern struct proc_dir_entry *
56 proc_lustre_register_obd_device(struct obd_device *obd);
57 extern void proc_lustre_release_obd_device(struct obd_device *obd);
58 extern void proc_lustre_remove_obd_entry(const char* name,
59 struct obd_device *obd);
62 * ======== OBD Operations Declarations ===========
66 extern struct obd_export *class_conn2export(struct lustre_handle *conn);
67 extern struct obd_device *class_conn2obd(struct lustre_handle *conn);
68 extern int class_rconn2export(struct lustre_handle *conn,
69 struct lustre_handle *rconn);
73 struct lustre_handle exp_rconnh; /* remote connection handle */
74 struct lustre_handle exp_impconnh;
75 struct list_head exp_chain;
76 struct obd_device *exp_obd;
77 struct ptlrpc_connection *exp_connection;
78 struct mds_export_data exp_mds_data;
80 struct ldlm_export_data exp_ldlm_data;
81 struct ost_export_data exp_ost_data;
83 void *exp_data; /* device specific data */
91 struct lustre_handle imp_expconnh;
92 struct list_head imp_chain;
93 struct obd_device *imp_obd;
95 void *imp_data; /* device specific data */
98 static inline int obd_check_conn(struct lustre_handle *conn)
100 struct obd_device *obd;
102 CERROR("NULL conn\n");
105 obd = class_conn2obd(conn);
107 CERROR("NULL obd\n");
111 if (!obd->obd_flags & OBD_ATTACHED ) {
112 CERROR("obd %d not attached\n", obd->obd_minor);
116 if (!obd->obd_flags & OBD_SET_UP) {
117 CERROR("obd %d not setup\n", obd->obd_minor);
121 if (!obd->obd_type) {
122 CERROR("obd %d not typed\n", obd->obd_minor);
126 if (!obd->obd_type->typ_ops) {
127 CERROR("obd_check_conn: obd %d no operations\n",
135 #define OBT(dev) (dev)->obd_type
136 #define OBP(dev,op) (dev)->obd_type->typ_ops->o_ ## op
138 #define OBD_CHECK_SETUP(conn, export) \
141 CERROR("NULL connection\n"); \
145 export = class_conn2export(conn); \
147 CERROR("No export\n"); \
151 if (!((export)->exp_obd->obd_flags & OBD_SET_UP)) { \
152 CERROR("Device %d not setup\n", \
153 (export)->exp_obd->obd_minor); \
158 #define OBD_CHECK_DEVSETUP(obd) \
161 CERROR("NULL device\n"); \
165 if ( !((obd)->obd_flags & OBD_SET_UP) ) { \
166 CERROR("Device %d not setup\n", \
172 #define OBD_CHECK_OP(obd,op) \
174 if (!OBP((obd),op)) { \
175 CERROR("obd_" #op ": dev %d no operation\n", \
177 RETURN(-EOPNOTSUPP); \
181 static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
182 void *key, obd_count *vallen, void **val)
185 struct obd_export *export;
186 OBD_CHECK_SETUP(conn, export);
187 OBD_CHECK_OP(export->exp_obd,get_info);
189 rc = OBP(export->exp_obd, get_info)(conn, keylen, key, vallen, val);
193 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
194 void *key, obd_count vallen, void *val)
197 struct obd_export *export;
198 OBD_CHECK_SETUP(conn, export);
199 OBD_CHECK_OP(export->exp_obd,set_info);
201 rc = OBP(export->exp_obd, set_info)(conn, keylen, key, vallen, val);
205 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
209 OBD_CHECK_OP(obd,setup);
211 rc = OBP(obd, setup)(obd, datalen, data);
215 static inline int obd_cleanup(struct obd_device *obd)
219 OBD_CHECK_DEVSETUP(obd);
220 OBD_CHECK_OP(obd,cleanup);
222 rc = OBP(obd, cleanup)(obd);
226 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md **ea)
229 struct obd_export *export;
230 OBD_CHECK_SETUP(conn, export);
231 OBD_CHECK_OP(export->exp_obd,create);
233 rc = OBP(export->exp_obd, create)(conn, obdo, ea);
237 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md *ea)
240 struct obd_export *export;
241 OBD_CHECK_SETUP(conn, export);
242 OBD_CHECK_OP(export->exp_obd,destroy);
244 rc = OBP(export->exp_obd, destroy)(conn, obdo, ea);
248 static inline int obd_getattr(struct lustre_handle *conn,
250 struct lov_stripe_md *ea)
253 struct obd_export *export;
254 OBD_CHECK_SETUP(conn, export);
255 OBD_CHECK_OP(export->exp_obd,getattr);
257 rc = OBP(export->exp_obd, getattr)(conn, obdo, ea);
261 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md *md)
264 struct obd_export *export;
265 OBD_CHECK_SETUP(conn, export);
266 OBD_CHECK_OP(export->exp_obd,close);
268 rc = OBP(export->exp_obd, close)(conn, obdo, md);
271 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
272 struct lov_stripe_md *md)
275 struct obd_export *export;
276 OBD_CHECK_SETUP(conn, export);
277 OBD_CHECK_OP(export->exp_obd,open);
279 rc = OBP(export->exp_obd, open) (conn, obdo, md);
283 static inline int obd_setattr(struct lustre_handle *conn,
285 struct lov_stripe_md *ea)
288 struct obd_export *export;
289 OBD_CHECK_SETUP(conn, export);
290 OBD_CHECK_OP(export->exp_obd,setattr);
292 rc = OBP(export->exp_obd, setattr)(conn, obdo, ea);
296 static inline int obd_connect(struct lustre_handle *conn, struct obd_device *obd,
300 OBD_CHECK_DEVSETUP(obd);
301 OBD_CHECK_OP(obd,connect);
303 rc = OBP(obd, connect)(conn, obd, cluuid);
307 static inline int obd_disconnect(struct lustre_handle *conn)
310 struct obd_export *export;
311 OBD_CHECK_SETUP(conn, export);
312 OBD_CHECK_OP(export->exp_obd,disconnect);
314 rc = OBP(export->exp_obd, disconnect)(conn);
318 static inline int obd_statfs(struct lustre_handle *conn, struct statfs *buf)
321 struct obd_export *export;
322 OBD_CHECK_SETUP(conn, export);
323 OBD_CHECK_OP(export->exp_obd,statfs);
325 rc = OBP(export->exp_obd, statfs)(conn, buf);
329 static inline int obd_punch(struct lustre_handle *conn, struct obdo *tgt,
330 struct lov_stripe_md *md,
331 obd_size count, obd_off offset)
334 struct obd_export *export;
335 OBD_CHECK_SETUP(conn, export);
336 OBD_CHECK_OP(export->exp_obd,punch);
338 rc = OBP(export->exp_obd, punch)(conn, tgt, md, count, offset);
342 static inline int obd_brw(int cmd, struct lustre_handle *conn,
343 struct lov_stripe_md *md,
346 brw_callback_t callback, void *data)
349 struct obd_export *export;
350 OBD_CHECK_SETUP(conn, export);
351 OBD_CHECK_OP(export->exp_obd,brw);
353 if (!(cmd & OBD_BRW_RWMASK)) {
354 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
358 rc = OBP(export->exp_obd, brw)(cmd, conn, md, oa_bufs, pg, callback, data);
362 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
363 int objcount, struct obd_ioobj *obj,
364 int niocount, struct niobuf_remote *remote,
365 struct niobuf_local *local, void **desc_private)
368 struct obd_export *export;
369 OBD_CHECK_SETUP(conn, export);
370 OBD_CHECK_OP(export->exp_obd,preprw);
372 rc = OBP(export->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
373 remote, local, desc_private);
377 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
378 int objcount, struct obd_ioobj *obj,
379 int niocount, struct niobuf_local *local,
383 struct obd_export *export;
384 OBD_CHECK_SETUP(conn, export);
385 OBD_CHECK_OP(export->exp_obd,commitrw);
387 rc = OBP(export->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
388 local, desc_private);
392 static inline int obd_iocontrol(int cmd, struct lustre_handle *conn,
393 int len, void *karg, void *uarg)
396 struct obd_export *export;
397 OBD_CHECK_SETUP(conn, export);
398 OBD_CHECK_OP(export->exp_obd,iocontrol);
400 rc = OBP(export->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
404 static inline int obd_enqueue(struct lustre_handle *conn,
405 struct lov_stripe_md *md,
406 struct lustre_handle *parent_lock,
407 __u32 type, void *cookie, int cookielen,
408 __u32 mode, int *flags, void *cb, void *data,
409 int datalen, struct lustre_handle *lockh)
412 struct obd_export *export;
413 OBD_CHECK_SETUP(conn, export);
414 OBD_CHECK_OP(export->exp_obd,enqueue);
416 rc = OBP(export->exp_obd, enqueue)(conn, md, parent_lock, type,
417 cookie, cookielen, mode, flags, cb,
418 data, datalen, lockh);
422 static inline int obd_cancel(struct lustre_handle *conn, struct lov_stripe_md *md, __u32 mode,
423 struct lustre_handle *lockh)
426 struct obd_export *export;
427 OBD_CHECK_SETUP(conn, export);
428 OBD_CHECK_OP(export->exp_obd,cancel);
430 rc = OBP(export->exp_obd, cancel)(conn, md, mode, lockh);
437 * ======== OBD Metadata Support ===========
440 extern int obd_init_caches(void);
441 extern void obd_cleanup_caches(void);
443 static inline int obdo_has_inline(struct obdo *obdo)
445 return (obdo->o_valid & OBD_MD_FLINLINE &&
446 obdo->o_obdflags & OBD_FL_INLINEDATA);
450 /* support routines */
451 extern kmem_cache_t *obdo_cachep;
452 static inline struct obdo *obdo_alloc(void)
454 struct obdo *oa = NULL;
456 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
459 memset(oa, 0, sizeof (*oa));
463 static inline void obdo_free(struct obdo *oa)
467 kmem_cache_free(obdo_cachep, oa);
471 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
473 unsigned int ia_valid = attr->ia_valid;
475 if (ia_valid & ATTR_ATIME) {
476 oa->o_atime = attr->ia_atime;
477 oa->o_valid |= OBD_MD_FLATIME;
479 if (ia_valid & ATTR_MTIME) {
480 oa->o_mtime = attr->ia_mtime;
481 oa->o_valid |= OBD_MD_FLMTIME;
483 if (ia_valid & ATTR_CTIME) {
484 oa->o_ctime = attr->ia_ctime;
485 oa->o_valid |= OBD_MD_FLCTIME;
487 if (ia_valid & ATTR_SIZE) {
488 oa->o_size = attr->ia_size;
489 oa->o_valid |= OBD_MD_FLSIZE;
491 if (ia_valid & ATTR_MODE) {
492 oa->o_mode = attr->ia_mode;
493 oa->o_valid |= OBD_MD_FLMODE;
494 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
495 oa->o_mode &= ~S_ISGID;
497 if (ia_valid & ATTR_UID)
499 oa->o_uid = attr->ia_uid;
500 oa->o_valid |= OBD_MD_FLUID;
502 if (ia_valid & ATTR_GID) {
503 oa->o_gid = attr->ia_gid;
504 oa->o_valid |= OBD_MD_FLGID;
509 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
511 unsigned int ia_valid = oa->o_valid;
513 memset(attr, 0, sizeof(*attr));
514 if (ia_valid & OBD_MD_FLATIME) {
515 attr->ia_atime = oa->o_atime;
516 attr->ia_valid |= ATTR_ATIME;
518 if (ia_valid & OBD_MD_FLMTIME) {
519 attr->ia_mtime = oa->o_mtime;
520 attr->ia_valid |= ATTR_MTIME;
522 if (ia_valid & OBD_MD_FLCTIME) {
523 attr->ia_ctime = oa->o_ctime;
524 attr->ia_valid |= ATTR_CTIME;
526 if (ia_valid & OBD_MD_FLSIZE) {
527 attr->ia_size = oa->o_size;
528 attr->ia_valid |= ATTR_SIZE;
530 if (ia_valid & OBD_MD_FLMODE) {
531 attr->ia_mode = oa->o_mode;
532 attr->ia_valid |= ATTR_MODE;
533 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
534 attr->ia_mode &= ~S_ISGID;
536 if (ia_valid & OBD_MD_FLUID)
538 attr->ia_uid = oa->o_uid;
539 attr->ia_valid |= ATTR_UID;
541 if (ia_valid & OBD_MD_FLGID) {
542 attr->ia_gid = oa->o_gid;
543 attr->ia_valid |= ATTR_GID;
548 /* WARNING: the file systems must take care not to tinker with
549 attributes they don't manage (such as blocks). */
551 static inline void obdo_from_inode(struct obdo *dst, struct inode *src)
553 if ( dst->o_valid & OBD_MD_FLID )
554 dst->o_id = src->i_ino;
555 if ( dst->o_valid & OBD_MD_FLATIME )
556 dst->o_atime = src->i_atime;
557 if ( dst->o_valid & OBD_MD_FLMTIME )
558 dst->o_mtime = src->i_mtime;
559 if ( dst->o_valid & OBD_MD_FLCTIME )
560 dst->o_ctime = src->i_ctime;
561 if ( dst->o_valid & OBD_MD_FLSIZE )
562 dst->o_size = src->i_size;
563 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
564 dst->o_blocks = src->i_blocks;
565 if ( dst->o_valid & OBD_MD_FLBLKSZ )
566 dst->o_blksize = src->i_blksize;
567 if ( dst->o_valid & OBD_MD_FLMODE )
568 dst->o_mode = src->i_mode;
569 if ( dst->o_valid & OBD_MD_FLUID )
570 dst->o_uid = src->i_uid;
571 if ( dst->o_valid & OBD_MD_FLGID )
572 dst->o_gid = src->i_gid;
573 if ( dst->o_valid & OBD_MD_FLFLAGS )
574 dst->o_flags = src->i_flags;
575 if ( dst->o_valid & OBD_MD_FLNLINK )
576 dst->o_nlink = src->i_nlink;
577 if ( dst->o_valid & OBD_MD_FLGENER )
578 dst->o_generation = src->i_generation;
579 if ( dst->o_valid & OBD_MD_FLRDEV )
580 dst->o_rdev = src->i_rdev;
583 static inline void obdo_to_inode(struct inode *dst, struct obdo *src)
586 if ( src->o_valid & OBD_MD_FLID )
587 dst->i_ino = src->o_id;
588 if ( src->o_valid & OBD_MD_FLATIME )
589 dst->i_atime = src->o_atime;
590 if ( src->o_valid & OBD_MD_FLMTIME )
591 dst->i_mtime = src->o_mtime;
592 if ( src->o_valid & OBD_MD_FLCTIME )
593 dst->i_ctime = src->o_ctime;
594 if ( src->o_valid & OBD_MD_FLSIZE )
595 dst->i_size = src->o_size;
596 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
597 dst->i_blocks = src->o_blocks;
598 if ( src->o_valid & OBD_MD_FLBLKSZ )
599 dst->i_blksize = src->o_blksize;
600 if ( src->o_valid & OBD_MD_FLMODE )
601 dst->i_mode = src->o_mode;
602 if ( src->o_valid & OBD_MD_FLUID )
603 dst->i_uid = src->o_uid;
604 if ( src->o_valid & OBD_MD_FLGID )
605 dst->i_gid = src->o_gid;
606 if ( src->o_valid & OBD_MD_FLFLAGS )
607 dst->i_flags = src->o_flags;
608 if ( src->o_valid & OBD_MD_FLNLINK )
609 dst->i_nlink = src->o_nlink;
610 if ( src->o_valid & OBD_MD_FLGENER )
611 dst->i_generation = src->o_generation;
612 if ( src->o_valid & OBD_MD_FLRDEV )
613 dst->i_rdev = src->o_rdev;
618 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src)
621 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
622 (unsigned long long)src->o_id, src->o_valid,
623 (unsigned long long)dst->o_id);
625 if ( src->o_valid & OBD_MD_FLATIME )
626 dst->o_atime = src->o_atime;
627 if ( src->o_valid & OBD_MD_FLMTIME )
628 dst->o_mtime = src->o_mtime;
629 if ( src->o_valid & OBD_MD_FLCTIME )
630 dst->o_ctime = src->o_ctime;
631 if ( src->o_valid & OBD_MD_FLSIZE )
632 dst->o_size = src->o_size;
633 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
634 dst->o_blocks = src->o_blocks;
635 if ( src->o_valid & OBD_MD_FLBLKSZ )
636 dst->o_blksize = src->o_blksize;
637 if ( src->o_valid & OBD_MD_FLMODE )
638 dst->o_mode = src->o_mode;
639 if ( src->o_valid & OBD_MD_FLUID )
640 dst->o_uid = src->o_uid;
641 if ( src->o_valid & OBD_MD_FLGID )
642 dst->o_gid = src->o_gid;
643 if ( src->o_valid & OBD_MD_FLFLAGS )
644 dst->o_flags = src->o_flags;
646 if ( src->o_valid & OBD_MD_FLOBDFLG )
647 dst->o_obdflags = src->o_obdflags;
649 if ( src->o_valid & OBD_MD_FLNLINK )
650 dst->o_nlink = src->o_nlink;
651 if ( src->o_valid & OBD_MD_FLGENER )
652 dst->o_generation = src->o_generation;
653 if ( src->o_valid & OBD_MD_FLRDEV )
654 dst->o_rdev = src->o_rdev;
655 if ( src->o_valid & OBD_MD_FLINLINE &&
656 src->o_obdflags & OBD_FL_INLINEDATA) {
657 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
658 dst->o_obdflags |= OBD_FL_INLINEDATA;
661 dst->o_valid |= src->o_valid;
665 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
666 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
671 if ( compare & OBD_MD_FLATIME )
672 res = (res || (dst->o_atime != src->o_atime));
673 if ( compare & OBD_MD_FLMTIME )
674 res = (res || (dst->o_mtime != src->o_mtime));
675 if ( compare & OBD_MD_FLCTIME )
676 res = (res || (dst->o_ctime != src->o_ctime));
677 if ( compare & OBD_MD_FLSIZE )
678 res = (res || (dst->o_size != src->o_size));
679 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
680 res = (res || (dst->o_blocks != src->o_blocks));
681 if ( compare & OBD_MD_FLBLKSZ )
682 res = (res || (dst->o_blksize != src->o_blksize));
683 if ( compare & OBD_MD_FLMODE )
684 res = (res || (dst->o_mode != src->o_mode));
685 if ( compare & OBD_MD_FLUID )
686 res = (res || (dst->o_uid != src->o_uid));
687 if ( compare & OBD_MD_FLGID )
688 res = (res || (dst->o_gid != src->o_gid));
689 if ( compare & OBD_MD_FLFLAGS )
690 res = (res || (dst->o_flags != src->o_flags));
691 if ( compare & OBD_MD_FLNLINK )
692 res = (res || (dst->o_nlink != src->o_nlink));
693 if ( compare & OBD_MD_FLGENER )
694 res = (res || (dst->o_generation != src->o_generation));
695 /* XXX Don't know if thses should be included here - wasn't previously
696 if ( compare & OBD_MD_FLINLINE )
697 res = (res || memcmp(dst->o_inline, src->o_inline));
704 int class_register_type(struct obd_ops *ops, char *nm);
705 int class_unregister_type(char *nm);
706 int class_name2dev(char *name);
707 int class_uuid2dev(char *name);
708 struct obd_device *class_uuid2obd(char *name);
709 struct obd_export *class_new_export(struct obd_device *obddev);
710 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
712 int class_disconnect(struct lustre_handle *conn);
713 void class_disconnect_all(struct obd_device *obddev);
714 struct obd_export *class_conn2export(struct lustre_handle *);
716 /* generic operations shared by various OBD types */
717 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
718 int class_multi_cleanup(struct obd_device *obddev);
724 extern void obd_sysctl_init (void);
725 extern void obd_sysctl_clean (void);
727 #endif /* __LINUX_CLASS_OBD_H */