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
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>
39 #include <linux/obd_support.h>
40 #include <linux/lustre_import.h>
41 #include <linux/lustre_net.h>
42 #include <linux/obd.h>
43 #include <linux/lustre_lib.h>
44 #include <linux/lustre_idl.h>
45 #include <linux/lustre_mds.h>
46 #include <linux/lustre_dlm.h>
47 #include <linux/lprocfs_status.h>
50 /* OBD Device Declarations */
51 #define MAX_OBD_DEVICES 128
52 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
54 #define OBD_ATTACHED 0x01
55 #define OBD_SET_UP 0x02
56 #define OBD_RECOVERING 0x04
57 #define OBD_ABORT_RECOVERY 0x08
58 #define OBD_REPLAYABLE 0x10
59 #define OBD_NO_TRANSNO 0x20 /* XXX needs better name */
61 /* OBD Operations Declarations */
62 extern struct obd_device *class_conn2obd(struct lustre_handle *);
63 extern struct obd_export *class_conn2export(struct lustre_handle *);
65 static inline int obd_check_conn(struct lustre_handle *conn)
67 struct obd_device *obd;
69 CERROR("NULL conn\n");
73 obd = class_conn2obd(conn);
79 if (!obd->obd_flags & OBD_ATTACHED ) {
80 CERROR("obd %d not attached\n", obd->obd_minor);
84 if (!obd->obd_flags & OBD_SET_UP) {
85 CERROR("obd %d not setup\n", obd->obd_minor);
90 CERROR("obd %d not typed\n", obd->obd_minor);
94 if (!obd->obd_type->typ_ops) {
95 CERROR("obd_check_conn: obd %d no operations\n",
103 #define OBT(dev) (dev)->obd_type
104 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
106 #define OBD_CHECK_SETUP(conn, exp) \
109 CERROR("NULL connection\n"); \
113 exp = class_conn2export(conn); \
115 CERROR("No export for conn "LPX64":"LPX64"\n", \
116 conn->addr, conn->cookie); \
120 if (!((exp)->exp_obd->obd_flags & OBD_SET_UP)) { \
121 CERROR("Device %d not setup\n", \
122 (exp)->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)
153 struct obd_export *exp;
157 OBD_CHECK_SETUP(conn, exp);
158 OBD_CHECK_OP(exp->exp_obd, get_info);
160 rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
164 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
165 void *key, obd_count vallen, void *val)
167 struct obd_export *exp;
171 OBD_CHECK_SETUP(conn, exp);
172 OBD_CHECK_OP(exp->exp_obd, set_info);
174 rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
178 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
183 OBD_CHECK_OP(obd, setup);
185 rc = OBP(obd, setup)(obd, datalen, data);
189 static inline int obd_cleanup(struct obd_device *obd)
194 OBD_CHECK_DEVSETUP(obd);
195 OBD_CHECK_OP(obd, cleanup);
197 rc = OBP(obd, cleanup)(obd);
201 /* Pack an in-memory MD struct for sending to the MDS and/or disk.
202 * Returns +ve size of packed MD (0 for free), or -ve error.
204 * If @wire_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
205 * If @*wire_tgt != NULL and @mem_src == NULL, @*wire_tgt will be freed.
206 * If @*wire_tgt == NULL, it will be allocated
208 static inline int obd_packmd(struct lustre_handle *conn,
209 struct lov_mds_md **wire_tgt,
210 struct lov_stripe_md *mem_src)
212 struct obd_export *exp;
215 OBD_CHECK_SETUP(conn, exp);
216 OBD_CHECK_OP(exp->exp_obd, packmd);
218 RETURN(OBP(exp->exp_obd, packmd)(conn, wire_tgt, mem_src));
221 static inline int obd_size_wiremd(struct lustre_handle *conn,
222 struct lov_stripe_md *mem_src)
224 return obd_packmd(conn, NULL, mem_src);
227 /* helper functions */
228 static inline int obd_alloc_wiremd(struct lustre_handle *conn,
229 struct lov_mds_md **wire_tgt)
232 LASSERT(*wire_tgt == NULL);
233 return obd_packmd(conn, wire_tgt, NULL);
236 static inline int obd_free_wiremd(struct lustre_handle *conn,
237 struct lov_mds_md **wire_tgt)
241 return obd_packmd(conn, wire_tgt, NULL);
244 /* Unpack an MD struct from the MDS and/or disk to in-memory format.
245 * Returns +ve size of unpacked MD (0 for free), or -ve error.
247 * If @mem_tgt == NULL, MD size is returned (max size if @wire_src == NULL).
248 * If @*mem_tgt != NULL and @wire_src == NULL, @*mem_tgt will be freed.
249 * If @*mem_tgt == NULL, it will be allocated
251 static inline int obd_unpackmd(struct lustre_handle *conn,
252 struct lov_stripe_md **mem_tgt,
253 struct lov_mds_md *wire_src)
255 struct obd_export *exp;
258 OBD_CHECK_SETUP(conn, exp);
259 OBD_CHECK_OP(exp->exp_obd, unpackmd);
261 RETURN(OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, wire_src));
264 static inline int obd_size_memmd(struct lustre_handle *conn,
265 struct lov_mds_md *wire_src)
267 return obd_unpackmd(conn, NULL, wire_src);
270 /* helper functions */
271 static inline int obd_alloc_memmd(struct lustre_handle *conn,
272 struct lov_stripe_md **mem_tgt)
275 LASSERT(*mem_tgt == NULL);
276 return obd_unpackmd(conn, mem_tgt, NULL);
279 static inline int obd_free_memmd(struct lustre_handle *conn,
280 struct lov_stripe_md **mem_tgt)
284 return obd_unpackmd(conn, mem_tgt, NULL);
287 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
288 struct lov_stripe_md **ea,
289 struct obd_trans_info *oti)
291 struct obd_export *exp;
295 OBD_CHECK_SETUP(conn, exp);
296 OBD_CHECK_OP(exp->exp_obd, create);
298 rc = OBP(exp->exp_obd, create)(conn, obdo, ea, oti);
302 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
303 struct lov_stripe_md *ea,
304 struct obd_trans_info *oti)
306 struct obd_export *exp;
310 OBD_CHECK_SETUP(conn, exp);
311 OBD_CHECK_OP(exp->exp_obd, destroy);
313 rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea, oti);
317 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
318 struct lov_stripe_md *ea)
320 struct obd_export *exp;
324 OBD_CHECK_SETUP(conn, exp);
325 OBD_CHECK_OP(exp->exp_obd, getattr);
327 rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
331 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
332 struct lov_stripe_md *ea,
333 struct obd_trans_info *oti)
335 struct obd_export *exp;
339 OBD_CHECK_SETUP(conn, exp);
340 OBD_CHECK_OP(exp->exp_obd, close);
342 rc = OBP(exp->exp_obd, close)(conn, obdo, ea, oti);
346 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
347 struct lov_stripe_md *ea, struct obd_trans_info *oti)
349 struct obd_export *exp;
353 OBD_CHECK_SETUP(conn, exp);
354 OBD_CHECK_OP(exp->exp_obd, open);
356 rc = OBP(exp->exp_obd, open)(conn, obdo, ea, oti);
360 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
361 struct lov_stripe_md *ea,
362 struct obd_trans_info *oti)
364 struct obd_export *exp;
368 OBD_CHECK_SETUP(conn, exp);
369 OBD_CHECK_OP(exp->exp_obd, setattr);
371 rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea, oti);
375 static inline int obd_connect(struct lustre_handle *conn,
376 struct obd_device *obd, struct obd_uuid *cluuid,
377 struct recovd_obd *recovd,
378 ptlrpc_recovery_cb_t recover)
383 OBD_CHECK_DEVSETUP(obd);
384 OBD_CHECK_OP(obd, connect);
386 rc = OBP(obd, connect)(conn, obd, cluuid, recovd, recover);
390 static inline int obd_disconnect(struct lustre_handle *conn)
392 struct obd_export *exp;
396 OBD_CHECK_SETUP(conn, exp);
397 OBD_CHECK_OP(exp->exp_obd, disconnect);
399 rc = OBP(exp->exp_obd, disconnect)(conn);
403 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
405 struct obd_export *exp;
409 OBD_CHECK_SETUP(conn, exp);
410 OBD_CHECK_OP(exp->exp_obd, statfs);
412 rc = OBP(exp->exp_obd, statfs)(conn, osfs);
416 static inline int obd_syncfs(struct lustre_handle *conn)
418 struct obd_export *exp;
422 OBD_CHECK_SETUP(conn, exp);
423 OBD_CHECK_OP(exp->exp_obd, syncfs);
425 rc = OBP(exp->exp_obd, syncfs)(conn);
429 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
430 struct lov_stripe_md *ea, obd_size start,
431 obd_size end, struct obd_trans_info *oti)
433 struct obd_export *exp;
437 OBD_CHECK_SETUP(conn, exp);
438 OBD_CHECK_OP(exp->exp_obd, punch);
440 rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end, oti);
444 static inline int obd_brw(int cmd, struct lustre_handle *conn,
445 struct lov_stripe_md *ea, obd_count oa_bufs,
446 struct brw_page *pg, struct obd_brw_set *set,
447 struct obd_trans_info *oti)
449 struct obd_export *exp;
453 OBD_CHECK_SETUP(conn, exp);
454 OBD_CHECK_OP(exp->exp_obd, brw);
456 if (!(cmd & OBD_BRW_RWMASK)) {
457 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
461 rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, set, oti);
465 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
466 int objcount, struct obd_ioobj *obj,
467 int niocount, struct niobuf_remote *remote,
468 struct niobuf_local *local, void **desc_private,
469 struct obd_trans_info *oti)
471 struct obd_export *exp;
475 OBD_CHECK_SETUP(conn, exp);
476 OBD_CHECK_OP(exp->exp_obd, preprw);
478 rc = OBP(exp->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
479 remote, local, desc_private, oti);
483 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
484 int objcount, struct obd_ioobj *obj,
485 int niocount, struct niobuf_local *local,
486 void *desc_private, struct obd_trans_info *oti)
488 struct obd_export *exp;
492 OBD_CHECK_SETUP(conn, exp);
493 OBD_CHECK_OP(exp->exp_obd, commitrw);
495 rc = OBP(exp->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
496 local, desc_private, oti);
500 static inline int obd_iocontrol(unsigned int cmd, struct lustre_handle *conn,
501 int len, void *karg, void *uarg)
503 struct obd_export *exp;
507 OBD_CHECK_SETUP(conn, exp);
508 OBD_CHECK_OP(exp->exp_obd, iocontrol);
510 rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
514 static inline int obd_enqueue(struct lustre_handle *conn,
515 struct lov_stripe_md *ea,
516 struct lustre_handle *parent_lock,
517 __u32 type, void *cookie, int cookielen,
518 __u32 mode, int *flags, void *cb, void *data,
519 int datalen, struct lustre_handle *lockh)
521 struct obd_export *exp;
525 OBD_CHECK_SETUP(conn, exp);
526 OBD_CHECK_OP(exp->exp_obd, enqueue);
528 rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
529 cookie, cookielen, mode, flags, cb,
530 data, datalen, lockh);
534 static inline int obd_cancel(struct lustre_handle *conn,
535 struct lov_stripe_md *ea, __u32 mode,
536 struct lustre_handle *lockh)
538 struct obd_export *exp;
542 OBD_CHECK_SETUP(conn, exp);
543 OBD_CHECK_OP(exp->exp_obd, cancel);
545 rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
549 static inline int obd_cancel_unused(struct lustre_handle *conn,
550 struct lov_stripe_md *ea, int local)
552 struct obd_export *exp;
556 OBD_CHECK_SETUP(conn, exp);
557 OBD_CHECK_OP(exp->exp_obd, cancel_unused);
559 rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, local);
563 static inline int obd_san_preprw(int cmd, struct lustre_handle *conn,
564 int objcount, struct obd_ioobj *obj,
565 int niocount, struct niobuf_remote *remote)
567 struct obd_export *exp;
570 OBD_CHECK_SETUP(conn, exp);
571 OBD_CHECK_OP(exp->exp_obd, preprw);
573 rc = OBP(exp->exp_obd, san_preprw)(cmd, conn, objcount, obj,
579 /* OBD Metadata Support */
581 extern int obd_init_caches(void);
582 extern void obd_cleanup_caches(void);
584 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
586 return (struct lustre_handle *)&oa->o_inline;
589 /* support routines */
590 extern kmem_cache_t *obdo_cachep;
591 static inline struct obdo *obdo_alloc(void)
595 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
598 memset(oa, 0, sizeof (*oa));
603 static inline void obdo_free(struct obdo *oa)
607 kmem_cache_free(obdo_cachep, oa);
611 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
613 unsigned int ia_valid = attr->ia_valid;
615 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
616 if (ia_valid & ATTR_ATIME) {
617 oa->o_atime = attr->ia_atime;
618 oa->o_valid |= OBD_MD_FLATIME;
620 if (ia_valid & ATTR_MTIME) {
621 oa->o_mtime = attr->ia_mtime;
622 oa->o_valid |= OBD_MD_FLMTIME;
624 if (ia_valid & ATTR_CTIME) {
625 oa->o_ctime = attr->ia_ctime;
626 oa->o_valid |= OBD_MD_FLCTIME;
629 if (ia_valid & ATTR_ATIME) {
630 oa->o_atime = attr->ia_atime.tv_sec;
631 oa->o_valid |= OBD_MD_FLATIME;
633 if (ia_valid & ATTR_MTIME) {
634 oa->o_mtime = attr->ia_mtime.tv_sec;
635 oa->o_valid |= OBD_MD_FLMTIME;
637 if (ia_valid & ATTR_CTIME) {
638 oa->o_ctime = attr->ia_ctime.tv_sec;
639 oa->o_valid |= OBD_MD_FLCTIME;
643 if (ia_valid & ATTR_SIZE) {
644 oa->o_size = attr->ia_size;
645 oa->o_valid |= OBD_MD_FLSIZE;
647 if (ia_valid & ATTR_MODE) {
648 oa->o_mode = attr->ia_mode;
649 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
650 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
651 oa->o_mode &= ~S_ISGID;
653 if (ia_valid & ATTR_UID) {
654 oa->o_uid = attr->ia_uid;
655 oa->o_valid |= OBD_MD_FLUID;
657 if (ia_valid & ATTR_GID) {
658 oa->o_gid = attr->ia_gid;
659 oa->o_valid |= OBD_MD_FLGID;
664 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
667 memset(attr, 0, sizeof(*attr));
668 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
669 if (valid & OBD_MD_FLATIME) {
670 attr->ia_atime = oa->o_atime;
671 attr->ia_valid |= ATTR_ATIME;
673 if (valid & OBD_MD_FLMTIME) {
674 attr->ia_mtime = oa->o_mtime;
675 attr->ia_valid |= ATTR_MTIME;
677 if (valid & OBD_MD_FLCTIME) {
678 attr->ia_ctime = oa->o_ctime;
679 attr->ia_valid |= ATTR_CTIME;
682 if (valid & OBD_MD_FLATIME) {
683 attr->ia_atime.tv_sec = oa->o_atime;
684 attr->ia_valid |= ATTR_ATIME;
686 if (valid & OBD_MD_FLMTIME) {
687 attr->ia_mtime.tv_sec = oa->o_mtime;
688 attr->ia_valid |= ATTR_MTIME;
690 if (valid & OBD_MD_FLCTIME) {
691 attr->ia_ctime.tv_sec = oa->o_ctime;
692 attr->ia_valid |= ATTR_CTIME;
695 if (valid & OBD_MD_FLSIZE) {
696 attr->ia_size = oa->o_size;
697 attr->ia_valid |= ATTR_SIZE;
699 if (valid & OBD_MD_FLTYPE) {
700 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
701 attr->ia_valid |= ATTR_MODE;
703 if (valid & OBD_MD_FLMODE) {
704 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
705 attr->ia_valid |= ATTR_MODE;
706 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
707 attr->ia_mode &= ~S_ISGID;
709 if (valid & OBD_MD_FLUID)
711 attr->ia_uid = oa->o_uid;
712 attr->ia_valid |= ATTR_UID;
714 if (valid & OBD_MD_FLGID) {
715 attr->ia_gid = oa->o_gid;
716 attr->ia_valid |= ATTR_GID;
721 /* WARNING: the file systems must take care not to tinker with
722 attributes they don't manage (such as blocks). */
724 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
725 #define to_kdev_t(dev) dev
726 #define kdev_t_to_nr(dev) dev
729 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
732 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
733 if (valid & OBD_MD_FLATIME)
734 dst->o_atime = src->i_atime;
735 if (valid & OBD_MD_FLMTIME)
736 dst->o_mtime = src->i_mtime;
737 if (valid & OBD_MD_FLCTIME)
738 dst->o_ctime = src->i_ctime;
740 if (valid & OBD_MD_FLATIME)
741 dst->o_atime = src->i_atime.tv_sec;
742 if (valid & OBD_MD_FLMTIME)
743 dst->o_mtime = src->i_mtime.tv_sec;
744 if (valid & OBD_MD_FLCTIME)
745 dst->o_ctime = src->i_ctime.tv_sec;
747 if (valid & OBD_MD_FLSIZE)
748 dst->o_size = src->i_size;
749 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
750 dst->o_blocks = src->i_blocks;
751 if (valid & OBD_MD_FLBLKSZ)
752 dst->o_blksize = src->i_blksize;
753 if (valid & OBD_MD_FLTYPE)
754 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
755 if (valid & OBD_MD_FLMODE)
756 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
757 if (valid & OBD_MD_FLUID)
758 dst->o_uid = src->i_uid;
759 if (valid & OBD_MD_FLGID)
760 dst->o_gid = src->i_gid;
761 if (valid & OBD_MD_FLFLAGS)
762 dst->o_flags = src->i_flags;
763 if (valid & OBD_MD_FLNLINK)
764 dst->o_nlink = src->i_nlink;
765 if (valid & OBD_MD_FLGENER)
766 dst->o_generation = src->i_generation;
767 if (valid & OBD_MD_FLRDEV)
768 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
770 dst->o_valid |= (valid & ~OBD_MD_FLID);
773 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
776 valid &= src->o_valid;
778 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
779 if (valid & OBD_MD_FLATIME)
780 dst->i_atime = src->o_atime;
781 if (valid & OBD_MD_FLMTIME)
782 dst->i_mtime = src->o_mtime;
783 if (valid & OBD_MD_FLCTIME && src->o_ctime > dst->i_ctime)
784 dst->i_ctime = src->o_ctime;
786 if (valid & OBD_MD_FLATIME)
787 dst->i_atime.tv_sec = src->o_atime;
788 if (valid & OBD_MD_FLMTIME)
789 dst->i_mtime.tv_sec = src->o_mtime;
790 if (valid & OBD_MD_FLCTIME && src->o_ctime > dst->i_ctime.tv_sec)
791 dst->i_ctime.tv_sec = src->o_ctime;
793 if (valid & OBD_MD_FLSIZE)
794 dst->i_size = src->o_size;
795 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
796 dst->i_blocks = src->o_blocks;
797 if (valid & OBD_MD_FLBLKSZ)
798 dst->i_blksize = src->o_blksize;
799 if (valid & OBD_MD_FLTYPE)
800 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
801 if (valid & OBD_MD_FLMODE)
802 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
803 if (valid & OBD_MD_FLUID)
804 dst->i_uid = src->o_uid;
805 if (valid & OBD_MD_FLGID)
806 dst->i_gid = src->o_gid;
807 if (valid & OBD_MD_FLFLAGS)
808 dst->i_flags = src->o_flags;
809 if (valid & OBD_MD_FLNLINK)
810 dst->i_nlink = src->o_nlink;
811 if (valid & OBD_MD_FLGENER)
812 dst->i_generation = src->o_generation;
813 if (valid & OBD_MD_FLRDEV)
814 dst->i_rdev = to_kdev_t(src->o_rdev);
818 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
822 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
823 (unsigned long long)src->o_id, src->o_valid,
824 (unsigned long long)dst->o_id);
826 if (valid & OBD_MD_FLATIME)
827 dst->o_atime = src->o_atime;
828 if (valid & OBD_MD_FLMTIME)
829 dst->o_mtime = src->o_mtime;
830 if (valid & OBD_MD_FLCTIME)
831 dst->o_ctime = src->o_ctime;
832 if (valid & OBD_MD_FLSIZE)
833 dst->o_size = src->o_size;
834 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
835 dst->o_blocks = src->o_blocks;
836 if (valid & OBD_MD_FLBLKSZ)
837 dst->o_blksize = src->o_blksize;
838 if (valid & OBD_MD_FLTYPE)
839 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
840 if (valid & OBD_MD_FLMODE)
841 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
842 if (valid & OBD_MD_FLUID)
843 dst->o_uid = src->o_uid;
844 if (valid & OBD_MD_FLGID)
845 dst->o_gid = src->o_gid;
846 if (valid & OBD_MD_FLFLAGS)
847 dst->o_flags = src->o_flags;
849 if (valid & OBD_MD_FLOBDFLG)
850 dst->o_obdflags = src->o_obdflags;
852 if (valid & OBD_MD_FLNLINK)
853 dst->o_nlink = src->o_nlink;
854 if (valid & OBD_MD_FLGENER)
855 dst->o_generation = src->o_generation;
856 if (valid & OBD_MD_FLRDEV)
857 dst->o_rdev = src->o_rdev;
858 if (valid & OBD_MD_FLINLINE &&
859 src->o_obdflags & OBD_FL_INLINEDATA) {
860 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
861 dst->o_obdflags |= OBD_FL_INLINEDATA;
864 dst->o_valid |= valid;
868 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
869 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
874 if ( compare & OBD_MD_FLATIME )
875 res = (res || (dst->o_atime != src->o_atime));
876 if ( compare & OBD_MD_FLMTIME )
877 res = (res || (dst->o_mtime != src->o_mtime));
878 if ( compare & OBD_MD_FLCTIME )
879 res = (res || (dst->o_ctime != src->o_ctime));
880 if ( compare & OBD_MD_FLSIZE )
881 res = (res || (dst->o_size != src->o_size));
882 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
883 res = (res || (dst->o_blocks != src->o_blocks));
884 if ( compare & OBD_MD_FLBLKSZ )
885 res = (res || (dst->o_blksize != src->o_blksize));
886 if ( compare & OBD_MD_FLTYPE )
887 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
888 if ( compare & OBD_MD_FLMODE )
889 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
890 if ( compare & OBD_MD_FLUID )
891 res = (res || (dst->o_uid != src->o_uid));
892 if ( compare & OBD_MD_FLGID )
893 res = (res || (dst->o_gid != src->o_gid));
894 if ( compare & OBD_MD_FLFLAGS )
895 res = (res || (dst->o_flags != src->o_flags));
896 if ( compare & OBD_MD_FLNLINK )
897 res = (res || (dst->o_nlink != src->o_nlink));
898 if ( compare & OBD_MD_FLGENER )
899 res = (res || (dst->o_generation != src->o_generation));
900 /* XXX Don't know if thses should be included here - wasn't previously
901 if ( compare & OBD_MD_FLINLINE )
902 res = (res || memcmp(dst->o_inline, src->o_inline));
908 /* I'm as embarrassed about this as you are.
910 * <shaver> // XXX do not look into _superhack with remaining eye
911 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
912 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
913 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp,
916 int class_register_type(struct obd_ops *ops, struct lprocfs_vars* vars,
918 int class_unregister_type(char *nm);
919 int class_name2dev(char *name);
920 int class_uuid2dev(struct obd_uuid *uuid);
921 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
922 struct obd_export *class_new_export(struct obd_device *obddev);
923 struct obd_type *class_get_type(char *name);
924 void class_put_type(struct obd_type *type);
925 void class_destroy_export(struct obd_export *exp);
926 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
927 struct obd_uuid *cluuid);
928 int class_disconnect(struct lustre_handle *conn);
929 void class_disconnect_all(struct obd_device *obddev);
931 /* generic operations shared by various OBD types */
932 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
933 int class_multi_cleanup(struct obd_device *obddev);
935 extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
937 static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
939 /* reuse list_entry's member-pointer offset stuff */
940 return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
945 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
946 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
947 void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src);
948 void obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src);
951 struct obd_class_user_state {
952 struct obd_device *ocus_current_obd;
953 struct list_head ocus_conns;
956 struct obd_class_user_conn {
957 struct list_head ocuc_chain;
958 struct lustre_handle ocuc_conn;
963 extern void obd_sysctl_init (void);
964 extern void obd_sysctl_clean (void);
967 typedef __u8 class_uuid_t[16];
968 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
969 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
972 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
973 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
974 int class_del_uuid (char *uuid);
975 void class_init_uuidlist(void);
976 void class_exit_uuidlist(void);
978 #endif /* __LINUX_OBD_CLASS_H */