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>
37 #include <linux/obd_support.h>
38 #include <linux/lustre_import.h>
39 #include <linux/lustre_net.h>
40 #include <linux/obd.h>
41 #include <linux/lustre_lib.h>
42 #include <linux/lustre_idl.h>
43 #include <linux/lustre_mds.h>
44 #include <linux/lustre_dlm.h>
45 #include <linux/lprocfs_status.h>
48 /* OBD Device Declarations */
49 #define MAX_OBD_DEVICES 128
50 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
52 /* OBD Operations Declarations */
53 extern struct obd_device *class_conn2obd(struct lustre_handle *);
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *, char *nm);
58 int class_unregister_type(char *nm);
59 int class_name2dev(char *name);
60 int class_uuid2dev(struct obd_uuid *uuid);
61 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
63 struct obd_export *class_export_get(struct obd_export *);
64 void class_export_put(struct obd_export *);
65 struct obd_export *class_new_export(struct obd_device *obddev);
66 void class_unlink_export(struct obd_export *exp);
68 struct obd_import *class_import_get(struct obd_import *);
69 void class_import_put(struct obd_import *);
70 struct obd_import *class_new_import(void);
71 void class_destroy_import(struct obd_import *exp);
73 struct obd_type *class_get_type(char *name);
74 void class_put_type(struct obd_type *type);
75 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
76 struct obd_uuid *cluuid);
77 int class_disconnect(struct lustre_handle *conn, int failover);
78 void class_disconnect_exports(struct obd_device *obddev, int failover);
79 /* generic operations shared by various OBD types */
80 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
81 int class_multi_cleanup(struct obd_device *obddev);
83 static inline int obd_check_conn(struct lustre_handle *conn)
85 struct obd_device *obd;
87 CERROR("NULL conn\n");
91 obd = class_conn2obd(conn);
97 if (!obd->obd_attached) {
98 CERROR("obd %d not attached\n", obd->obd_minor);
102 if (!obd->obd_set_up) {
103 CERROR("obd %d not setup\n", obd->obd_minor);
107 if (!obd->obd_type) {
108 CERROR("obd %d not typed\n", obd->obd_minor);
112 if (!obd->obd_type->typ_ops) {
113 CERROR("obd_check_conn: obd %d no operations\n",
121 #define OBT(dev) (dev)->obd_type
122 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
124 /* Ensure obd_setup: used for disconnect which might be called while
125 an obd is stopping. */
126 #define OBD_CHECK_SETUP(conn, exp) \
129 CERROR("NULL connection\n"); \
133 exp = class_conn2export(conn); \
135 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
139 if (!(exp)->exp_obd->obd_set_up) { \
140 CERROR("Device %d not setup\n", \
141 (exp)->exp_obd->obd_minor); \
142 class_export_put(exp); \
147 /* Ensure obd_setup and !obd_stopping. */
148 #define OBD_CHECK_ACTIVE(conn, exp) \
151 CERROR("NULL connection\n"); \
155 exp = class_conn2export(conn); \
157 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
161 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
162 CERROR("Device %d not setup\n", \
163 (exp)->exp_obd->obd_minor); \
164 class_export_put(exp); \
169 /* Ensure obd_setup: used for cleanup which must be called
170 while obd is stopping */
171 #define OBD_CHECK_DEV_STOPPING(obd) \
174 CERROR("NULL device\n"); \
178 if (!(obd)->obd_set_up) { \
179 CERROR("Device %d not setup\n", \
184 if (!(obd)->obd_stopping) { \
185 CERROR("Device %d not stopping\n", \
191 /* ensure obd_setup and !obd_stopping */
192 #define OBD_CHECK_DEV_ACTIVE(obd) \
195 CERROR("NULL device\n"); \
199 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
200 CERROR("Device %d not setup\n", \
208 #define OBD_COUNTER_OFFSET(op) \
209 ((offsetof(struct obd_ops, o_ ## op) - \
210 offsetof(struct obd_ops, o_iocontrol)) \
211 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
213 #define OBD_COUNTER_INCREMENT(obd, op) \
214 if ((obd)->obd_stats != NULL) { \
215 unsigned int coffset; \
216 coffset = (unsigned int)(obd)->obd_cntr_base + \
217 OBD_COUNTER_OFFSET(op); \
218 LASSERT(coffset < obd->obd_stats->ls_num); \
219 lprocfs_counter_incr(obd->obd_stats, coffset); \
222 #define OBD_COUNTER_OFFSET(op)
223 #define OBD_COUNTER_INCREMENT(obd, op)
226 #define OBD_CHECK_OP(obd, op) \
228 if (!OBP((obd), op)) { \
229 CERROR("obd_" #op ": dev %d no operation\n", \
231 RETURN(-EOPNOTSUPP); \
235 static inline int obd_get_info(struct lustre_handle *conn, __u32 keylen,
236 void *key, __u32 *vallen, void *val)
238 struct obd_export *exp;
242 OBD_CHECK_ACTIVE(conn, exp);
243 OBD_CHECK_OP(exp->exp_obd, get_info);
244 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
246 rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
247 class_export_put(exp);
251 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
252 void *key, obd_count vallen, void *val)
254 struct obd_export *exp;
258 OBD_CHECK_ACTIVE(conn, exp);
259 OBD_CHECK_OP(exp->exp_obd, set_info);
260 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
262 rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
263 class_export_put(exp);
267 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
272 OBD_CHECK_OP(obd, setup);
273 OBD_COUNTER_INCREMENT(obd, setup);
275 rc = OBP(obd, setup)(obd, datalen, data);
279 static inline int obd_cleanup(struct obd_device *obd, int force, int failover)
284 OBD_CHECK_DEV_STOPPING(obd);
285 OBD_CHECK_OP(obd, cleanup);
286 OBD_COUNTER_INCREMENT(obd, cleanup);
288 rc = OBP(obd, cleanup)(obd, force, failover);
292 /* Pack an in-memory MD struct for storage on disk.
293 * Returns +ve size of packed MD (0 for free), or -ve error.
295 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
296 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
297 * If @*disk_tgt == NULL, it will be allocated
299 static inline int obd_packmd(struct lustre_handle *conn,
300 struct lov_mds_md **disk_tgt,
301 struct lov_stripe_md *mem_src)
303 struct obd_export *exp;
307 OBD_CHECK_ACTIVE(conn, exp);
308 OBD_CHECK_OP(exp->exp_obd, packmd);
309 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
311 rc = OBP(exp->exp_obd, packmd)(conn, disk_tgt, mem_src);
312 class_export_put(exp);
316 static inline int obd_size_diskmd(struct lustre_handle *conn,
317 struct lov_stripe_md *mem_src)
319 return obd_packmd(conn, NULL, mem_src);
322 /* helper functions */
323 static inline int obd_alloc_diskmd(struct lustre_handle *conn,
324 struct lov_mds_md **disk_tgt)
327 LASSERT(*disk_tgt == NULL);
328 return obd_packmd(conn, disk_tgt, NULL);
331 static inline int obd_free_diskmd(struct lustre_handle *conn,
332 struct lov_mds_md **disk_tgt)
336 return obd_packmd(conn, disk_tgt, NULL);
339 /* Unpack an MD struct from disk to in-memory format.
340 * Returns +ve size of unpacked MD (0 for free), or -ve error.
342 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
343 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
344 * If @*mem_tgt == NULL, it will be allocated
346 static inline int obd_unpackmd(struct lustre_handle *conn,
347 struct lov_stripe_md **mem_tgt,
348 struct lov_mds_md *disk_src,
351 struct obd_export *exp;
355 OBD_CHECK_ACTIVE(conn, exp);
356 OBD_CHECK_OP(exp->exp_obd, unpackmd);
357 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
359 rc = OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, disk_src, disk_len);
360 class_export_put(exp);
364 static inline int obd_size_memmd(struct lustre_handle *conn,
365 struct lov_mds_md *disk_src,
368 return obd_unpackmd(conn, NULL, disk_src, disk_len);
371 /* helper functions */
372 static inline int obd_alloc_memmd(struct lustre_handle *conn,
373 struct lov_stripe_md **mem_tgt)
376 LASSERT(*mem_tgt == NULL);
377 return obd_unpackmd(conn, mem_tgt, NULL, 0);
380 static inline int obd_free_memmd(struct lustre_handle *conn,
381 struct lov_stripe_md **mem_tgt)
385 return obd_unpackmd(conn, mem_tgt, NULL, 0);
388 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
389 struct lov_stripe_md **ea,
390 struct obd_trans_info *oti)
392 struct obd_export *exp;
396 OBD_CHECK_ACTIVE(conn, exp);
397 OBD_CHECK_OP(exp->exp_obd, create);
398 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
400 rc = OBP(exp->exp_obd, create)(conn, obdo, ea, oti);
401 class_export_put(exp);
405 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
406 struct lov_stripe_md *ea,
407 struct obd_trans_info *oti)
409 struct obd_export *exp;
413 OBD_CHECK_ACTIVE(conn, exp);
414 OBD_CHECK_OP(exp->exp_obd, destroy);
415 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
417 rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea, oti);
418 class_export_put(exp);
422 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
423 struct lov_stripe_md *ea)
425 struct obd_export *exp;
429 OBD_CHECK_ACTIVE(conn, exp);
430 OBD_CHECK_OP(exp->exp_obd, getattr);
431 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
433 rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
434 class_export_put(exp);
438 static inline int obd_getattr_async(struct lustre_handle *conn,
439 struct obdo *obdo, struct lov_stripe_md *ea,
440 struct ptlrpc_request_set *set)
442 struct obd_export *exp;
446 OBD_CHECK_SETUP(conn, exp);
447 OBD_CHECK_OP(exp->exp_obd, getattr);
448 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
450 rc = OBP(exp->exp_obd, getattr_async)(conn, obdo, ea, set);
451 class_export_put(exp);
455 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
456 struct lov_stripe_md *ea,
457 struct obd_trans_info *oti)
459 struct obd_export *exp;
463 OBD_CHECK_ACTIVE(conn, exp);
464 OBD_CHECK_OP(exp->exp_obd, close);
465 OBD_COUNTER_INCREMENT(exp->exp_obd, close);
467 rc = OBP(exp->exp_obd, close)(conn, obdo, ea, oti);
468 class_export_put(exp);
472 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
473 struct lov_stripe_md *ea, struct obd_trans_info *oti,
474 struct obd_client_handle *och)
476 struct obd_export *exp;
480 OBD_CHECK_ACTIVE(conn, exp);
481 OBD_CHECK_OP(exp->exp_obd, open);
482 OBD_COUNTER_INCREMENT(exp->exp_obd, open);
484 rc = OBP(exp->exp_obd, open)(conn, obdo, ea, oti, och);
485 class_export_put(exp);
489 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
490 struct lov_stripe_md *ea,
491 struct obd_trans_info *oti)
493 struct obd_export *exp;
497 OBD_CHECK_ACTIVE(conn, exp);
498 OBD_CHECK_OP(exp->exp_obd, setattr);
499 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
501 rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea, oti);
502 class_export_put(exp);
506 static inline int obd_connect(struct lustre_handle *conn,
507 struct obd_device *obd, struct obd_uuid *cluuid)
512 OBD_CHECK_DEV_ACTIVE(obd);
513 OBD_CHECK_OP(obd, connect);
514 OBD_COUNTER_INCREMENT(obd, connect);
516 rc = OBP(obd, connect)(conn, obd, cluuid);
520 static inline int obd_disconnect(struct lustre_handle *conn, int failover)
522 struct obd_export *exp;
526 OBD_CHECK_SETUP(conn, exp);
527 OBD_CHECK_OP(exp->exp_obd, disconnect);
528 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
530 rc = OBP(exp->exp_obd, disconnect)(conn, failover);
531 class_export_put(exp);
535 static inline void obd_destroy_export(struct obd_export *exp)
538 if (OBP(exp->exp_obd, destroy_export))
539 OBP(exp->exp_obd, destroy_export)(exp);
543 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
545 struct obd_export *exp;
549 OBD_CHECK_ACTIVE(conn, exp);
550 OBD_CHECK_OP(exp->exp_obd, statfs);
551 OBD_COUNTER_INCREMENT(exp->exp_obd, statfs);
553 rc = OBP(exp->exp_obd, statfs)(conn, osfs);
554 class_export_put(exp);
558 static inline int obd_syncfs(struct obd_export *exp)
563 OBD_CHECK_OP(exp->exp_obd, syncfs);
564 OBD_COUNTER_INCREMENT(exp->exp_obd, syncfs);
566 rc = OBP(exp->exp_obd, syncfs)(exp);
570 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
571 struct lov_stripe_md *ea, obd_size start,
572 obd_size end, struct obd_trans_info *oti)
574 struct obd_export *exp;
578 OBD_CHECK_ACTIVE(conn, exp);
579 OBD_CHECK_OP(exp->exp_obd, punch);
580 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
582 rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end, oti);
583 class_export_put(exp);
587 static inline int obd_brw(int cmd, struct lustre_handle *conn,
588 struct lov_stripe_md *ea, obd_count oa_bufs,
589 struct brw_page *pg, struct obd_trans_info *oti)
591 struct obd_export *exp;
595 OBD_CHECK_ACTIVE(conn, exp);
596 OBD_CHECK_OP(exp->exp_obd, brw);
597 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
599 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
600 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
601 "or OBD_BRW_CHECK\n");
605 rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, oti);
606 class_export_put(exp);
610 static inline int obd_brw_async(int cmd, struct lustre_handle *conn,
611 struct lov_stripe_md *ea, obd_count oa_bufs,
613 struct ptlrpc_request_set *set,
614 struct obd_trans_info *oti)
616 struct obd_export *exp;
620 OBD_CHECK_ACTIVE(conn, exp);
621 OBD_CHECK_OP(exp->exp_obd, brw_async);
622 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
624 if (!(cmd & OBD_BRW_RWMASK)) {
625 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
629 rc = OBP(exp->exp_obd, brw_async)(cmd, conn, ea, oa_bufs, pg, set, oti);
630 class_export_put(exp);
634 static inline int obd_preprw(int cmd, struct obd_export *exp,
635 int objcount, struct obd_ioobj *obj,
636 int niocount, struct niobuf_remote *remote,
637 struct niobuf_local *local, void **desc_private,
638 struct obd_trans_info *oti)
643 OBD_CHECK_OP(exp->exp_obd, preprw);
644 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
646 rc = OBP(exp->exp_obd, preprw)(cmd, exp, objcount, obj, niocount,
647 remote, local, desc_private, oti);
651 static inline int obd_commitrw(int cmd, struct obd_export *exp,
652 int objcount, struct obd_ioobj *obj,
653 int niocount, struct niobuf_local *local,
654 void *desc_private, struct obd_trans_info *oti)
659 OBD_CHECK_OP(exp->exp_obd, commitrw);
660 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
662 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, objcount, obj, niocount,
663 local, desc_private, oti);
667 static inline int obd_iocontrol(unsigned int cmd, struct lustre_handle *conn,
668 int len, void *karg, void *uarg)
670 struct obd_export *exp;
674 OBD_CHECK_ACTIVE(conn, exp);
675 OBD_CHECK_OP(exp->exp_obd, iocontrol);
676 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
678 rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
679 class_export_put(exp);
683 static inline int obd_enqueue(struct lustre_handle *conn,
684 struct lov_stripe_md *ea,
685 struct lustre_handle *parent_lock,
686 __u32 type, void *cookie, int cookielen,
687 __u32 mode, int *flags, void *cb, void *data,
688 struct lustre_handle *lockh)
690 struct obd_export *exp;
694 OBD_CHECK_ACTIVE(conn, exp);
695 OBD_CHECK_OP(exp->exp_obd, enqueue);
696 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
698 rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
699 cookie, cookielen, mode, flags, cb,
701 class_export_put(exp);
705 static inline int obd_match(struct lustre_handle *conn,
706 struct lov_stripe_md *ea, __u32 type, void *cookie,
707 int cookielen, __u32 mode, int *flags, void *data,
708 struct lustre_handle *lockh)
710 struct obd_export *exp;
714 OBD_CHECK_ACTIVE(conn, exp);
715 OBD_CHECK_OP(exp->exp_obd, match);
716 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
718 rc = OBP(exp->exp_obd, match)(conn, ea, type, cookie, cookielen, mode,
720 class_export_put(exp);
725 static inline int obd_cancel(struct lustre_handle *conn,
726 struct lov_stripe_md *ea, __u32 mode,
727 struct lustre_handle *lockh)
729 struct obd_export *exp;
733 OBD_CHECK_ACTIVE(conn, exp);
734 OBD_CHECK_OP(exp->exp_obd, cancel);
735 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
737 rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
738 class_export_put(exp);
742 static inline int obd_cancel_unused(struct lustre_handle *conn,
743 struct lov_stripe_md *ea, int flags,
746 struct obd_export *exp;
750 OBD_CHECK_ACTIVE(conn, exp);
751 OBD_CHECK_OP(exp->exp_obd, cancel_unused);
752 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
754 rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, flags, opaque);
755 class_export_put(exp);
759 static inline int obd_san_preprw(int cmd, struct lustre_handle *conn,
760 int objcount, struct obd_ioobj *obj,
761 int niocount, struct niobuf_remote *remote)
763 struct obd_export *exp;
766 OBD_CHECK_ACTIVE(conn, exp);
767 OBD_CHECK_OP(exp->exp_obd, preprw);
768 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
770 rc = OBP(exp->exp_obd, san_preprw)(cmd, conn, objcount, obj,
772 class_export_put(exp);
777 /* OBD Metadata Support */
779 extern int obd_init_caches(void);
780 extern void obd_cleanup_caches(void);
782 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
784 return (struct lustre_handle *)&oa->o_inline;
787 /* support routines */
788 extern kmem_cache_t *obdo_cachep;
789 static inline struct obdo *obdo_alloc(void)
793 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
796 memset(oa, 0, sizeof (*oa));
801 static inline void obdo_free(struct obdo *oa)
805 kmem_cache_free(obdo_cachep, oa);
808 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
809 #define to_kdev_t(dev) dev
810 #define kdev_t_to_nr(dev) dev
814 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
816 unsigned int ia_valid = attr->ia_valid;
818 if (ia_valid & ATTR_ATIME) {
819 oa->o_atime = LTIME_S(attr->ia_atime);
820 oa->o_valid |= OBD_MD_FLATIME;
822 if (ia_valid & ATTR_MTIME) {
823 oa->o_mtime = LTIME_S(attr->ia_mtime);
824 oa->o_valid |= OBD_MD_FLMTIME;
826 if (ia_valid & ATTR_CTIME) {
827 oa->o_ctime = LTIME_S(attr->ia_ctime);
828 oa->o_valid |= OBD_MD_FLCTIME;
830 if (ia_valid & ATTR_SIZE) {
831 oa->o_size = attr->ia_size;
832 oa->o_valid |= OBD_MD_FLSIZE;
834 if (ia_valid & ATTR_MODE) {
835 oa->o_mode = attr->ia_mode;
836 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
837 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
838 oa->o_mode &= ~S_ISGID;
840 if (ia_valid & ATTR_UID) {
841 oa->o_uid = attr->ia_uid;
842 oa->o_valid |= OBD_MD_FLUID;
844 if (ia_valid & ATTR_GID) {
845 oa->o_gid = attr->ia_gid;
846 oa->o_valid |= OBD_MD_FLGID;
851 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
854 memset(attr, 0, sizeof(*attr));
855 if (valid & OBD_MD_FLATIME) {
856 LTIME_S(attr->ia_atime) = oa->o_atime;
857 attr->ia_valid |= ATTR_ATIME;
859 if (valid & OBD_MD_FLMTIME) {
860 LTIME_S(attr->ia_mtime) = oa->o_mtime;
861 attr->ia_valid |= ATTR_MTIME;
863 if (valid & OBD_MD_FLCTIME) {
864 LTIME_S(attr->ia_ctime) = oa->o_ctime;
865 attr->ia_valid |= ATTR_CTIME;
867 if (valid & OBD_MD_FLSIZE) {
868 attr->ia_size = oa->o_size;
869 attr->ia_valid |= ATTR_SIZE;
871 if (valid & OBD_MD_FLTYPE) {
872 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
873 attr->ia_valid |= ATTR_MODE;
875 if (valid & OBD_MD_FLMODE) {
876 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
877 attr->ia_valid |= ATTR_MODE;
878 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
879 attr->ia_mode &= ~S_ISGID;
881 if (valid & OBD_MD_FLUID)
883 attr->ia_uid = oa->o_uid;
884 attr->ia_valid |= ATTR_UID;
886 if (valid & OBD_MD_FLGID) {
887 attr->ia_gid = oa->o_gid;
888 attr->ia_valid |= ATTR_GID;
893 /* WARNING: the file systems must take care not to tinker with
894 attributes they don't manage (such as blocks). */
897 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
900 if (valid & OBD_MD_FLATIME)
901 dst->o_atime = LTIME_S(src->i_atime);
902 if (valid & OBD_MD_FLMTIME)
903 dst->o_mtime = LTIME_S(src->i_mtime);
904 if (valid & OBD_MD_FLCTIME)
905 dst->o_ctime = LTIME_S(src->i_ctime);
906 if (valid & OBD_MD_FLSIZE)
907 dst->o_size = src->i_size;
908 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
909 dst->o_blocks = src->i_blocks;
910 if (valid & OBD_MD_FLBLKSZ)
911 dst->o_blksize = src->i_blksize;
912 if (valid & OBD_MD_FLTYPE)
913 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
914 if (valid & OBD_MD_FLMODE)
915 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
916 if (valid & OBD_MD_FLUID)
917 dst->o_uid = src->i_uid;
918 if (valid & OBD_MD_FLGID)
919 dst->o_gid = src->i_gid;
920 if (valid & OBD_MD_FLFLAGS)
921 dst->o_flags = src->i_flags;
922 if (valid & OBD_MD_FLNLINK)
923 dst->o_nlink = src->i_nlink;
924 if (valid & OBD_MD_FLGENER)
925 dst->o_generation = src->i_generation;
926 if (valid & OBD_MD_FLRDEV)
927 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
929 dst->o_valid |= (valid & ~OBD_MD_FLID);
932 static inline void obdo_refresh_inode(struct inode *dst, struct obdo *src,
935 valid &= src->o_valid;
937 if (valid & OBD_MD_FLATIME && src->o_atime > LTIME_S(dst->i_atime))
938 LTIME_S(dst->i_atime) = src->o_atime;
939 if (valid & OBD_MD_FLMTIME && src->o_mtime > LTIME_S(dst->i_mtime))
940 LTIME_S(dst->i_mtime) = src->o_mtime;
941 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
942 LTIME_S(dst->i_ctime) = src->o_ctime;
943 if (valid & OBD_MD_FLSIZE && src->o_size > dst->i_size)
944 dst->i_size = src->o_size;
945 /* allocation of space */
946 if (valid & OBD_MD_FLBLOCKS && src->o_blocks > dst->i_blocks)
947 dst->i_blocks = src->o_blocks;
950 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
953 valid &= src->o_valid;
955 if (valid & OBD_MD_FLATIME)
956 LTIME_S(dst->i_atime) = src->o_atime;
957 if (valid & OBD_MD_FLMTIME)
958 LTIME_S(dst->i_mtime) = src->o_mtime;
959 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
960 LTIME_S(dst->i_ctime) = src->o_ctime;
961 if (valid & OBD_MD_FLSIZE)
962 dst->i_size = src->o_size;
963 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
964 dst->i_blocks = src->o_blocks;
965 if (valid & OBD_MD_FLBLKSZ)
966 dst->i_blksize = src->o_blksize;
967 if (valid & OBD_MD_FLTYPE)
968 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
969 if (valid & OBD_MD_FLMODE)
970 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
971 if (valid & OBD_MD_FLUID)
972 dst->i_uid = src->o_uid;
973 if (valid & OBD_MD_FLGID)
974 dst->i_gid = src->o_gid;
975 if (valid & OBD_MD_FLFLAGS)
976 dst->i_flags = src->o_flags;
977 if (valid & OBD_MD_FLNLINK)
978 dst->i_nlink = src->o_nlink;
979 if (valid & OBD_MD_FLGENER)
980 dst->i_generation = src->o_generation;
981 if (valid & OBD_MD_FLRDEV)
982 dst->i_rdev = to_kdev_t(src->o_rdev);
986 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
990 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
991 (unsigned long long)src->o_id, src->o_valid,
992 (unsigned long long)dst->o_id);
994 if (valid & OBD_MD_FLATIME)
995 dst->o_atime = src->o_atime;
996 if (valid & OBD_MD_FLMTIME)
997 dst->o_mtime = src->o_mtime;
998 if (valid & OBD_MD_FLCTIME)
999 dst->o_ctime = src->o_ctime;
1000 if (valid & OBD_MD_FLSIZE)
1001 dst->o_size = src->o_size;
1002 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
1003 dst->o_blocks = src->o_blocks;
1004 if (valid & OBD_MD_FLBLKSZ)
1005 dst->o_blksize = src->o_blksize;
1006 if (valid & OBD_MD_FLTYPE)
1007 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
1008 if (valid & OBD_MD_FLMODE)
1009 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
1010 if (valid & OBD_MD_FLUID)
1011 dst->o_uid = src->o_uid;
1012 if (valid & OBD_MD_FLGID)
1013 dst->o_gid = src->o_gid;
1014 if (valid & OBD_MD_FLFLAGS)
1015 dst->o_flags = src->o_flags;
1017 if (valid & OBD_MD_FLOBDFLG)
1018 dst->o_obdflags = src->o_obdflags;
1020 if (valid & OBD_MD_FLNLINK)
1021 dst->o_nlink = src->o_nlink;
1022 if (valid & OBD_MD_FLGENER)
1023 dst->o_generation = src->o_generation;
1024 if (valid & OBD_MD_FLRDEV)
1025 dst->o_rdev = src->o_rdev;
1026 if (valid & OBD_MD_FLINLINE &&
1027 src->o_obdflags & OBD_FL_INLINEDATA) {
1028 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
1029 dst->o_obdflags |= OBD_FL_INLINEDATA;
1032 dst->o_valid |= valid;
1036 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
1037 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
1042 if ( compare & OBD_MD_FLATIME )
1043 res = (res || (dst->o_atime != src->o_atime));
1044 if ( compare & OBD_MD_FLMTIME )
1045 res = (res || (dst->o_mtime != src->o_mtime));
1046 if ( compare & OBD_MD_FLCTIME )
1047 res = (res || (dst->o_ctime != src->o_ctime));
1048 if ( compare & OBD_MD_FLSIZE )
1049 res = (res || (dst->o_size != src->o_size));
1050 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
1051 res = (res || (dst->o_blocks != src->o_blocks));
1052 if ( compare & OBD_MD_FLBLKSZ )
1053 res = (res || (dst->o_blksize != src->o_blksize));
1054 if ( compare & OBD_MD_FLTYPE )
1055 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
1056 if ( compare & OBD_MD_FLMODE )
1057 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
1058 if ( compare & OBD_MD_FLUID )
1059 res = (res || (dst->o_uid != src->o_uid));
1060 if ( compare & OBD_MD_FLGID )
1061 res = (res || (dst->o_gid != src->o_gid));
1062 if ( compare & OBD_MD_FLFLAGS )
1063 res = (res || (dst->o_flags != src->o_flags));
1064 if ( compare & OBD_MD_FLNLINK )
1065 res = (res || (dst->o_nlink != src->o_nlink));
1066 if ( compare & OBD_MD_FLGENER )
1067 res = (res || (dst->o_generation != src->o_generation));
1068 /* XXX Don't know if thses should be included here - wasn't previously
1069 if ( compare & OBD_MD_FLINLINE )
1070 res = (res || memcmp(dst->o_inline, src->o_inline));
1075 /* I'm as embarrassed about this as you are.
1077 * <shaver> // XXX do not look into _superhack with remaining eye
1078 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1079 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1080 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1084 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
1085 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
1087 struct obd_class_user_state {
1088 struct obd_device *ocus_current_obd;
1089 struct list_head ocus_conns;
1092 struct obd_class_user_conn {
1093 struct list_head ocuc_chain;
1094 struct lustre_handle ocuc_conn;
1099 extern void obd_sysctl_init (void);
1100 extern void obd_sysctl_clean (void);
1103 typedef __u8 class_uuid_t[16];
1104 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1105 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1108 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1109 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1110 int class_del_uuid (char *uuid);
1111 void class_init_uuidlist(void);
1112 void class_exit_uuidlist(void);
1114 #endif /* __LINUX_OBD_CLASS_H */