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>
43 #include <linux/lustre_dlm.h>
48 * ======== OBD Device Declarations ===========
50 #define MAX_OBD_DEVICES 128
51 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
53 #define OBD_ATTACHED 0x1
54 #define OBD_SET_UP 0x2
56 extern struct proc_dir_entry *
57 proc_lustre_register_obd_device(struct obd_device *obd);
58 extern void proc_lustre_release_obd_device(struct obd_device *obd);
59 extern void proc_lustre_remove_obd_entry(const char* name,
60 struct obd_device *obd);
63 * ======== OBD Operations Declarations ===========
67 static inline int obd_check_conn(struct lustre_handle *conn)
69 struct obd_device *obd;
71 CERROR("NULL conn\n");
74 obd = class_conn2obd(conn);
80 if (!obd->obd_flags & OBD_ATTACHED ) {
81 CERROR("obd %d not attached\n", obd->obd_minor);
85 if (!obd->obd_flags & OBD_SET_UP) {
86 CERROR("obd %d not setup\n", obd->obd_minor);
91 CERROR("obd %d not typed\n", obd->obd_minor);
95 if (!obd->obd_type->typ_ops) {
96 CERROR("obd_check_conn: obd %d no operations\n",
104 #define OBT(dev) (dev)->obd_type
105 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
107 #define OBD_CHECK_SETUP(conn, export) \
110 CERROR("NULL connection\n"); \
114 export = class_conn2export(conn); \
116 CERROR("No export\n"); \
120 if (!((export)->exp_obd->obd_flags & OBD_SET_UP)) { \
121 CERROR("Device %d not setup\n", \
122 (export)->exp_obd->obd_minor); \
127 #define OBD_CHECK_DEVSETUP(obd) \
130 CERROR("NULL device\n"); \
134 if ( !((obd)->obd_flags & OBD_SET_UP) ) { \
135 CERROR("Device %d not setup\n", \
141 #define OBD_CHECK_OP(obd, op) \
143 if (!OBP((obd),op)) { \
144 CERROR("obd_" #op ": dev %d no operation\n", \
146 RETURN(-EOPNOTSUPP); \
150 static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
151 void *key, obd_count *vallen, void **val)
154 struct obd_export *export;
155 OBD_CHECK_SETUP(conn, export);
156 OBD_CHECK_OP(export->exp_obd, get_info);
158 rc = OBP(export->exp_obd, get_info)(conn, keylen, key, vallen, val);
162 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
163 void *key, obd_count vallen, void *val)
166 struct obd_export *export;
167 OBD_CHECK_SETUP(conn, export);
168 OBD_CHECK_OP(export->exp_obd, set_info);
170 rc = OBP(export->exp_obd, set_info)(conn, keylen, key, vallen, val);
174 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
178 OBD_CHECK_OP(obd, setup);
180 rc = OBP(obd, setup)(obd, datalen, data);
184 static inline int obd_cleanup(struct obd_device *obd)
188 OBD_CHECK_DEVSETUP(obd);
189 OBD_CHECK_OP(obd, cleanup);
191 rc = OBP(obd, cleanup)(obd);
195 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
196 struct lov_stripe_md **ea)
199 struct obd_export *export;
200 OBD_CHECK_SETUP(conn, export);
201 OBD_CHECK_OP(export->exp_obd, create);
203 #define OBD_MD_FLNEEDED (OBD_MD_FLID | OBD_MD_FLMODE)
204 //if (obdo->o_valid & OBD_MD_FLNEEDED != OBD_MD_FLNEEDED)
206 #undef OBD_MD_FLNEEDED
207 rc = OBP(export->exp_obd, create)(conn, obdo, ea);
211 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
212 struct lov_stripe_md *ea)
215 struct obd_export *export;
216 OBD_CHECK_SETUP(conn, export);
217 OBD_CHECK_OP(export->exp_obd, destroy);
219 rc = OBP(export->exp_obd, destroy)(conn, obdo, ea);
223 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
224 struct lov_stripe_md *ea)
227 struct obd_export *export;
228 OBD_CHECK_SETUP(conn, export);
229 OBD_CHECK_OP(export->exp_obd, getattr);
231 rc = OBP(export->exp_obd, getattr)(conn, obdo, ea);
235 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
236 struct lov_stripe_md *ea)
239 struct obd_export *export;
240 OBD_CHECK_SETUP(conn, export);
241 OBD_CHECK_OP(export->exp_obd, close);
243 rc = OBP(export->exp_obd, close)(conn, obdo, ea);
247 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
248 struct lov_stripe_md *ea)
251 struct obd_export *export;
252 OBD_CHECK_SETUP(conn, export);
253 OBD_CHECK_OP(export->exp_obd, open);
255 rc = OBP(export->exp_obd, open)(conn, obdo, ea);
259 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
260 struct lov_stripe_md *ea)
263 struct obd_export *export;
264 OBD_CHECK_SETUP(conn, export);
265 OBD_CHECK_OP(export->exp_obd,setattr);
267 rc = OBP(export->exp_obd, setattr)(conn, obdo, ea);
271 static inline int obd_connect(struct lustre_handle *conn,
272 struct obd_device *obd, obd_uuid_t cluuid)
275 OBD_CHECK_DEVSETUP(obd);
276 OBD_CHECK_OP(obd, connect);
278 rc = OBP(obd, connect)(conn, obd, cluuid);
282 static inline int obd_disconnect(struct lustre_handle *conn)
285 struct obd_export *export;
286 OBD_CHECK_SETUP(conn, export);
287 OBD_CHECK_OP(export->exp_obd, disconnect);
289 rc = OBP(export->exp_obd, disconnect)(conn);
293 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
296 struct obd_export *export;
297 OBD_CHECK_SETUP(conn, export);
298 OBD_CHECK_OP(export->exp_obd, statfs);
300 rc = OBP(export->exp_obd, statfs)(conn, osfs);
304 static inline int obd_punch(struct lustre_handle *conn, struct obdo *tgt,
305 struct lov_stripe_md *ea,
306 obd_size count, obd_off offset)
309 struct obd_export *export;
310 OBD_CHECK_SETUP(conn, export);
311 OBD_CHECK_OP(export->exp_obd,punch);
313 rc = OBP(export->exp_obd, punch)(conn, tgt, ea, count, offset);
317 static inline int obd_brw(int cmd, struct lustre_handle *conn,
318 struct lov_stripe_md *ea, obd_count oa_bufs,
320 brw_callback_t callback, void *data)
323 struct obd_export *export;
324 OBD_CHECK_SETUP(conn, export);
325 OBD_CHECK_OP(export->exp_obd,brw);
327 if (!(cmd & OBD_BRW_RWMASK)) {
328 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
332 rc = OBP(export->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, callback,
337 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
338 int objcount, struct obd_ioobj *obj,
339 int niocount, struct niobuf_remote *remote,
340 struct niobuf_local *local, void **desc_private)
343 struct obd_export *export;
344 OBD_CHECK_SETUP(conn, export);
345 OBD_CHECK_OP(export->exp_obd, preprw);
347 rc = OBP(export->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
348 remote, local, desc_private);
352 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
353 int objcount, struct obd_ioobj *obj,
354 int niocount, struct niobuf_local *local,
358 struct obd_export *export;
359 OBD_CHECK_SETUP(conn, export);
360 OBD_CHECK_OP(export->exp_obd, commitrw);
362 rc = OBP(export->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
363 local, desc_private);
367 static inline int obd_iocontrol(int cmd, struct lustre_handle *conn,
368 int len, void *karg, void *uarg)
371 struct obd_export *export;
372 OBD_CHECK_SETUP(conn, export);
373 OBD_CHECK_OP(export->exp_obd, iocontrol);
375 rc = OBP(export->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
379 static inline int obd_enqueue(struct lustre_handle *conn,
380 struct lov_stripe_md *ea,
381 struct lustre_handle *parent_lock,
382 __u32 type, void *cookie, int cookielen,
383 __u32 mode, int *flags, void *cb, void *data,
384 int datalen, struct lustre_handle *lockh)
387 struct obd_export *export;
388 OBD_CHECK_SETUP(conn, export);
389 OBD_CHECK_OP(export->exp_obd,enqueue);
391 rc = OBP(export->exp_obd, enqueue)(conn, ea, parent_lock, type,
392 cookie, cookielen, mode, flags, cb,
393 data, datalen, lockh);
397 static inline int obd_cancel(struct lustre_handle *conn,
398 struct lov_stripe_md *ea, __u32 mode,
399 struct lustre_handle *lockh)
402 struct obd_export *export;
403 OBD_CHECK_SETUP(conn, export);
404 OBD_CHECK_OP(export->exp_obd,cancel);
406 rc = OBP(export->exp_obd, cancel)(conn, ea, mode, lockh);
410 static inline int obd_cancel_unused(struct lustre_handle *conn,
411 struct lov_stripe_md *lsm, int local)
414 struct obd_export *export;
415 OBD_CHECK_SETUP(conn, export);
416 OBD_CHECK_OP(export->exp_obd, cancel_unused);
418 rc = OBP(export->exp_obd, cancel_unused)(conn, lsm, local);
425 * ======== OBD Metadata Support ===========
428 extern int obd_init_caches(void);
429 extern void obd_cleanup_caches(void);
431 static inline int obdo_has_inline(struct obdo *obdo)
433 return (obdo->o_valid & OBD_MD_FLINLINE &&
434 obdo->o_obdflags & OBD_FL_INLINEDATA);
438 /* support routines */
439 extern kmem_cache_t *obdo_cachep;
440 static inline struct obdo *obdo_alloc(void)
442 struct obdo *oa = NULL;
444 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
447 memset(oa, 0, sizeof (*oa));
451 static inline void obdo_free(struct obdo *oa)
455 kmem_cache_free(obdo_cachep, oa);
459 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
461 unsigned int ia_valid = attr->ia_valid;
463 if (ia_valid & ATTR_ATIME) {
464 oa->o_atime = attr->ia_atime;
465 oa->o_valid |= OBD_MD_FLATIME;
467 if (ia_valid & ATTR_MTIME) {
468 oa->o_mtime = attr->ia_mtime;
469 oa->o_valid |= OBD_MD_FLMTIME;
471 if (ia_valid & ATTR_CTIME) {
472 oa->o_ctime = attr->ia_ctime;
473 oa->o_valid |= OBD_MD_FLCTIME;
475 if (ia_valid & ATTR_SIZE) {
476 oa->o_size = attr->ia_size;
477 oa->o_valid |= OBD_MD_FLSIZE;
479 if (ia_valid & ATTR_MODE) {
480 oa->o_mode = attr->ia_mode;
481 oa->o_valid |= OBD_MD_FLMODE;
482 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
483 oa->o_mode &= ~S_ISGID;
485 if (ia_valid & ATTR_UID)
487 oa->o_uid = attr->ia_uid;
488 oa->o_valid |= OBD_MD_FLUID;
490 if (ia_valid & ATTR_GID) {
491 oa->o_gid = attr->ia_gid;
492 oa->o_valid |= OBD_MD_FLGID;
497 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
500 memset(attr, 0, sizeof(*attr));
501 if (valid & OBD_MD_FLATIME) {
502 attr->ia_atime = oa->o_atime;
503 attr->ia_valid |= ATTR_ATIME;
505 if (valid & OBD_MD_FLMTIME) {
506 attr->ia_mtime = oa->o_mtime;
507 attr->ia_valid |= ATTR_MTIME;
509 if (valid & OBD_MD_FLCTIME) {
510 attr->ia_ctime = oa->o_ctime;
511 attr->ia_valid |= ATTR_CTIME;
513 if (valid & OBD_MD_FLSIZE) {
514 attr->ia_size = oa->o_size;
515 attr->ia_valid |= ATTR_SIZE;
517 if (valid & OBD_MD_FLMODE) {
518 attr->ia_mode = oa->o_mode;
519 attr->ia_valid |= ATTR_MODE;
520 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
521 attr->ia_mode &= ~S_ISGID;
523 if (valid & OBD_MD_FLUID)
525 attr->ia_uid = oa->o_uid;
526 attr->ia_valid |= ATTR_UID;
528 if (valid & OBD_MD_FLGID) {
529 attr->ia_gid = oa->o_gid;
530 attr->ia_valid |= ATTR_GID;
535 /* WARNING: the file systems must take care not to tinker with
536 attributes they don't manage (such as blocks). */
538 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
541 // if (valid & OBD_MD_FLID)
542 // dst->o_id = src->i_ino;
543 if (valid & OBD_MD_FLATIME)
544 dst->o_atime = src->i_atime;
545 if (valid & OBD_MD_FLMTIME)
546 dst->o_mtime = src->i_mtime;
547 if (valid & OBD_MD_FLCTIME)
548 dst->o_ctime = src->i_ctime;
549 if (valid & OBD_MD_FLSIZE)
550 dst->o_size = src->i_size;
551 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
552 dst->o_blocks = src->i_blocks;
553 if (valid & OBD_MD_FLBLKSZ)
554 dst->o_blksize = src->i_blksize;
555 if (valid & OBD_MD_FLMODE)
556 dst->o_mode = src->i_mode;
557 if (valid & OBD_MD_FLUID)
558 dst->o_uid = src->i_uid;
559 if (valid & OBD_MD_FLGID)
560 dst->o_gid = src->i_gid;
561 if (valid & OBD_MD_FLFLAGS)
562 dst->o_flags = src->i_flags;
563 if (valid & OBD_MD_FLNLINK)
564 dst->o_nlink = src->i_nlink;
565 if (valid & OBD_MD_FLGENER)
566 dst->o_generation = src->i_generation;
567 if (valid & OBD_MD_FLRDEV)
568 dst->o_rdev = src->i_rdev;
570 dst->o_valid |= (valid & ~OBD_MD_FLID);
573 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
576 // if (valid & OBD_MD_FLID)
577 // dst->i_ino = src->o_id;
578 if (valid & OBD_MD_FLATIME)
579 dst->i_atime = src->o_atime;
580 if (valid & OBD_MD_FLMTIME)
581 dst->i_mtime = src->o_mtime;
582 if (valid & OBD_MD_FLCTIME)
583 dst->i_ctime = src->o_ctime;
584 if (valid & OBD_MD_FLSIZE)
585 dst->i_size = src->o_size;
586 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
587 dst->i_blocks = src->o_blocks;
588 if (valid & OBD_MD_FLBLKSZ)
589 dst->i_blksize = src->o_blksize;
590 if (valid & OBD_MD_FLMODE)
591 dst->i_mode = src->o_mode;
592 if (valid & OBD_MD_FLUID)
593 dst->i_uid = src->o_uid;
594 if (valid & OBD_MD_FLGID)
595 dst->i_gid = src->o_gid;
596 if (valid & OBD_MD_FLFLAGS)
597 dst->i_flags = src->o_flags;
598 if (valid & OBD_MD_FLNLINK)
599 dst->i_nlink = src->o_nlink;
600 if (valid & OBD_MD_FLGENER)
601 dst->i_generation = src->o_generation;
602 if (valid & OBD_MD_FLRDEV)
603 dst->i_rdev = src->o_rdev;
607 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
611 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
612 (unsigned long long)src->o_id, src->o_valid,
613 (unsigned long long)dst->o_id);
615 if (valid & OBD_MD_FLATIME)
616 dst->o_atime = src->o_atime;
617 if (valid & OBD_MD_FLMTIME)
618 dst->o_mtime = src->o_mtime;
619 if (valid & OBD_MD_FLCTIME)
620 dst->o_ctime = src->o_ctime;
621 if (valid & OBD_MD_FLSIZE)
622 dst->o_size = src->o_size;
623 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
624 dst->o_blocks = src->o_blocks;
625 if (valid & OBD_MD_FLBLKSZ)
626 dst->o_blksize = src->o_blksize;
627 if (valid & OBD_MD_FLMODE)
628 dst->o_mode = src->o_mode;
629 if (valid & OBD_MD_FLUID)
630 dst->o_uid = src->o_uid;
631 if (valid & OBD_MD_FLGID)
632 dst->o_gid = src->o_gid;
633 if (valid & OBD_MD_FLFLAGS)
634 dst->o_flags = src->o_flags;
636 if (valid & OBD_MD_FLOBDFLG)
637 dst->o_obdflags = src->o_obdflags;
639 if (valid & OBD_MD_FLNLINK)
640 dst->o_nlink = src->o_nlink;
641 if (valid & OBD_MD_FLGENER)
642 dst->o_generation = src->o_generation;
643 if (valid & OBD_MD_FLRDEV)
644 dst->o_rdev = src->o_rdev;
645 if (valid & OBD_MD_FLINLINE &&
646 src->o_obdflags & OBD_FL_INLINEDATA) {
647 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
648 dst->o_obdflags |= OBD_FL_INLINEDATA;
651 dst->o_valid |= valid;
655 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
656 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
661 if ( compare & OBD_MD_FLATIME )
662 res = (res || (dst->o_atime != src->o_atime));
663 if ( compare & OBD_MD_FLMTIME )
664 res = (res || (dst->o_mtime != src->o_mtime));
665 if ( compare & OBD_MD_FLCTIME )
666 res = (res || (dst->o_ctime != src->o_ctime));
667 if ( compare & OBD_MD_FLSIZE )
668 res = (res || (dst->o_size != src->o_size));
669 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
670 res = (res || (dst->o_blocks != src->o_blocks));
671 if ( compare & OBD_MD_FLBLKSZ )
672 res = (res || (dst->o_blksize != src->o_blksize));
673 if ( compare & OBD_MD_FLMODE )
674 res = (res || (dst->o_mode != src->o_mode));
675 if ( compare & OBD_MD_FLUID )
676 res = (res || (dst->o_uid != src->o_uid));
677 if ( compare & OBD_MD_FLGID )
678 res = (res || (dst->o_gid != src->o_gid));
679 if ( compare & OBD_MD_FLFLAGS )
680 res = (res || (dst->o_flags != src->o_flags));
681 if ( compare & OBD_MD_FLNLINK )
682 res = (res || (dst->o_nlink != src->o_nlink));
683 if ( compare & OBD_MD_FLGENER )
684 res = (res || (dst->o_generation != src->o_generation));
685 /* XXX Don't know if thses should be included here - wasn't previously
686 if ( compare & OBD_MD_FLINLINE )
687 res = (res || memcmp(dst->o_inline, src->o_inline));
694 int class_register_type(struct obd_ops *ops, char *nm);
695 int class_unregister_type(char *nm);
696 int class_name2dev(char *name);
697 int class_uuid2dev(char *uuid);
698 struct obd_device *class_uuid2obd(char *uuid);
699 struct obd_export *class_new_export(struct obd_device *obddev);
700 void class_destroy_export(struct obd_export *exp);
701 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
703 int class_disconnect(struct lustre_handle *conn);
704 void class_disconnect_all(struct obd_device *obddev);
706 /* generic operations shared by various OBD types */
707 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
708 int class_multi_cleanup(struct obd_device *obddev);
710 extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
712 /* == mds_client_free if MDS running here */
713 extern int (*mds_destroy_export)(struct obd_export *exp);
714 /* == ldlm_client_free if(?) DLM running here */
715 extern int (*ldlm_destroy_export)(struct obd_export *exp);
717 static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
719 /* reuse list_entry's member-pointer offset stuff */
720 return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
726 extern void obd_sysctl_init (void);
727 extern void obd_sysctl_clean (void);
730 typedef __u8 class_uuid_t[16];
731 //int class_uuid_parse(obd_uuid_t in, class_uuid_t out);
732 void class_uuid_unparse(class_uuid_t in, obd_uuid_t out);
733 #endif /* __LINUX_CLASS_OBD_H */