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)->counters != NULL) { \
215 struct lprocfs_counters* cntrs = obd->counters; \
216 unsigned int coffset; \
217 coffset = (obd)->cntr_base + OBD_COUNTER_OFFSET(op); \
218 LASSERT(coffset < cntrs->num); \
219 LPROCFS_COUNTER_INCBY1(&cntrs->cntr[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); \
233 OBD_COUNTER_INCREMENT(obd, op); \
236 static inline int obd_get_info(struct lustre_handle *conn, __u32 keylen,
237 void *key, __u32 *vallen, void *val)
239 struct obd_export *exp;
243 OBD_CHECK_ACTIVE(conn, exp);
244 OBD_CHECK_OP(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);
261 rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
262 class_export_put(exp);
266 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
271 OBD_CHECK_OP(obd, setup);
273 rc = OBP(obd, setup)(obd, datalen, data);
277 static inline int obd_cleanup(struct obd_device *obd, int force, int failover)
282 OBD_CHECK_DEV_STOPPING(obd);
283 OBD_CHECK_OP(obd, cleanup);
285 rc = OBP(obd, cleanup)(obd, force, failover);
289 /* Pack an in-memory MD struct for storage on disk.
290 * Returns +ve size of packed MD (0 for free), or -ve error.
292 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
293 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
294 * If @*disk_tgt == NULL, it will be allocated
296 static inline int obd_packmd(struct lustre_handle *conn,
297 struct lov_mds_md **disk_tgt,
298 struct lov_stripe_md *mem_src)
300 struct obd_export *exp;
304 OBD_CHECK_ACTIVE(conn, exp);
305 OBD_CHECK_OP(exp->exp_obd, packmd);
307 rc = OBP(exp->exp_obd, packmd)(conn, disk_tgt, mem_src);
308 class_export_put(exp);
312 static inline int obd_size_diskmd(struct lustre_handle *conn,
313 struct lov_stripe_md *mem_src)
315 return obd_packmd(conn, NULL, mem_src);
318 /* helper functions */
319 static inline int obd_alloc_diskmd(struct lustre_handle *conn,
320 struct lov_mds_md **disk_tgt)
323 LASSERT(*disk_tgt == NULL);
324 return obd_packmd(conn, disk_tgt, NULL);
327 static inline int obd_free_diskmd(struct lustre_handle *conn,
328 struct lov_mds_md **disk_tgt)
332 return obd_packmd(conn, disk_tgt, NULL);
335 /* Unpack an MD struct from disk to in-memory format.
336 * Returns +ve size of unpacked MD (0 for free), or -ve error.
338 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
339 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
340 * If @*mem_tgt == NULL, it will be allocated
342 static inline int obd_unpackmd(struct lustre_handle *conn,
343 struct lov_stripe_md **mem_tgt,
344 struct lov_mds_md *disk_src,
347 struct obd_export *exp;
351 OBD_CHECK_ACTIVE(conn, exp);
352 OBD_CHECK_OP(exp->exp_obd, unpackmd);
354 rc = OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, disk_src, disk_len);
355 class_export_put(exp);
359 static inline int obd_size_memmd(struct lustre_handle *conn,
360 struct lov_mds_md *disk_src,
363 return obd_unpackmd(conn, NULL, disk_src, disk_len);
366 /* helper functions */
367 static inline int obd_alloc_memmd(struct lustre_handle *conn,
368 struct lov_stripe_md **mem_tgt)
371 LASSERT(*mem_tgt == NULL);
372 return obd_unpackmd(conn, mem_tgt, NULL, 0);
375 static inline int obd_free_memmd(struct lustre_handle *conn,
376 struct lov_stripe_md **mem_tgt)
380 return obd_unpackmd(conn, mem_tgt, NULL, 0);
383 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
384 struct lov_stripe_md **ea,
385 struct obd_trans_info *oti)
387 struct obd_export *exp;
391 OBD_CHECK_ACTIVE(conn, exp);
392 OBD_CHECK_OP(exp->exp_obd, create);
394 rc = OBP(exp->exp_obd, create)(conn, obdo, ea, oti);
395 class_export_put(exp);
399 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
400 struct lov_stripe_md *ea,
401 struct obd_trans_info *oti)
403 struct obd_export *exp;
407 OBD_CHECK_ACTIVE(conn, exp);
408 OBD_CHECK_OP(exp->exp_obd, destroy);
410 rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea, oti);
411 class_export_put(exp);
415 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
416 struct lov_stripe_md *ea)
418 struct obd_export *exp;
422 OBD_CHECK_ACTIVE(conn, exp);
423 OBD_CHECK_OP(exp->exp_obd, getattr);
425 rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
426 class_export_put(exp);
430 static inline int obd_getattr_async(struct lustre_handle *conn, struct obdo *obdo,
431 struct lov_stripe_md *ea,
432 struct ptlrpc_request_set *set)
434 struct obd_export *exp;
438 OBD_CHECK_SETUP(conn, exp);
439 OBD_CHECK_OP(exp->exp_obd, getattr);
441 rc = OBP(exp->exp_obd, getattr_async)(conn, obdo, ea, set);
442 class_export_put(exp);
446 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
447 struct lov_stripe_md *ea,
448 struct obd_trans_info *oti)
450 struct obd_export *exp;
454 OBD_CHECK_ACTIVE(conn, exp);
455 OBD_CHECK_OP(exp->exp_obd, close);
457 rc = OBP(exp->exp_obd, close)(conn, obdo, ea, oti);
458 class_export_put(exp);
462 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
463 struct lov_stripe_md *ea, struct obd_trans_info *oti,
464 struct obd_client_handle *och)
466 struct obd_export *exp;
470 OBD_CHECK_ACTIVE(conn, exp);
471 OBD_CHECK_OP(exp->exp_obd, open);
473 rc = OBP(exp->exp_obd, open)(conn, obdo, ea, oti, och);
474 class_export_put(exp);
478 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
479 struct lov_stripe_md *ea,
480 struct obd_trans_info *oti)
482 struct obd_export *exp;
486 OBD_CHECK_ACTIVE(conn, exp);
487 OBD_CHECK_OP(exp->exp_obd, setattr);
489 rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea, oti);
490 class_export_put(exp);
494 static inline int obd_connect(struct lustre_handle *conn,
495 struct obd_device *obd, struct obd_uuid *cluuid)
500 OBD_CHECK_DEV_ACTIVE(obd);
501 OBD_CHECK_OP(obd, connect);
503 rc = OBP(obd, connect)(conn, obd, cluuid);
507 static inline int obd_disconnect(struct lustre_handle *conn, int failover)
509 struct obd_export *exp;
513 OBD_CHECK_SETUP(conn, exp);
514 OBD_CHECK_OP(exp->exp_obd, disconnect);
516 rc = OBP(exp->exp_obd, disconnect)(conn, failover);
517 class_export_put(exp);
521 static inline void obd_destroy_export(struct obd_export *exp)
524 if (OBP(exp->exp_obd, destroy_export))
525 OBP(exp->exp_obd, destroy_export)(exp);
529 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
531 struct obd_export *exp;
535 OBD_CHECK_ACTIVE(conn, exp);
536 OBD_CHECK_OP(exp->exp_obd, statfs);
538 rc = OBP(exp->exp_obd, statfs)(conn, osfs);
539 class_export_put(exp);
543 static inline int obd_syncfs(struct obd_export *exp)
548 OBD_CHECK_OP(exp->exp_obd, syncfs);
550 rc = OBP(exp->exp_obd, syncfs)(exp);
554 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
555 struct lov_stripe_md *ea, obd_size start,
556 obd_size end, struct obd_trans_info *oti)
558 struct obd_export *exp;
562 OBD_CHECK_ACTIVE(conn, exp);
563 OBD_CHECK_OP(exp->exp_obd, punch);
565 rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end, oti);
566 class_export_put(exp);
570 static inline int obd_brw(int cmd, struct lustre_handle *conn,
571 struct lov_stripe_md *ea, obd_count oa_bufs,
572 struct brw_page *pg, struct obd_trans_info *oti)
574 struct obd_export *exp;
578 OBD_CHECK_ACTIVE(conn, exp);
579 OBD_CHECK_OP(exp->exp_obd, brw);
581 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
582 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
583 "or OBD_BRW_CHECK\n");
587 rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, oti);
588 class_export_put(exp);
592 static inline int obd_brw_async(int cmd, struct lustre_handle *conn,
593 struct lov_stripe_md *ea, obd_count oa_bufs,
595 struct ptlrpc_request_set *set,
596 struct obd_trans_info *oti)
598 struct obd_export *exp;
602 OBD_CHECK_ACTIVE(conn, exp);
603 OBD_CHECK_OP(exp->exp_obd, brw_async);
605 if (!(cmd & OBD_BRW_RWMASK)) {
606 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
610 rc = OBP(exp->exp_obd, brw_async)(cmd, conn, ea, oa_bufs, pg, set, oti);
611 class_export_put(exp);
615 static inline int obd_preprw(int cmd, struct obd_export *exp,
616 int objcount, struct obd_ioobj *obj,
617 int niocount, struct niobuf_remote *remote,
618 struct niobuf_local *local, void **desc_private,
619 struct obd_trans_info *oti)
624 OBD_CHECK_OP(exp->exp_obd, preprw);
626 rc = OBP(exp->exp_obd, preprw)(cmd, exp, objcount, obj, niocount,
627 remote, local, desc_private, oti);
631 static inline int obd_commitrw(int cmd, struct obd_export *exp,
632 int objcount, struct obd_ioobj *obj,
633 int niocount, struct niobuf_local *local,
634 void *desc_private, struct obd_trans_info *oti)
639 OBD_CHECK_OP(exp->exp_obd, commitrw);
641 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, objcount, obj, niocount,
642 local, desc_private, oti);
646 static inline int obd_iocontrol(unsigned int cmd, struct lustre_handle *conn,
647 int len, void *karg, void *uarg)
649 struct obd_export *exp;
653 OBD_CHECK_ACTIVE(conn, exp);
654 OBD_CHECK_OP(exp->exp_obd, iocontrol);
656 rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
657 class_export_put(exp);
661 static inline int obd_enqueue(struct lustre_handle *conn,
662 struct lov_stripe_md *ea,
663 struct lustre_handle *parent_lock,
664 __u32 type, void *cookie, int cookielen,
665 __u32 mode, int *flags, void *cb, void *data,
666 int datalen, struct lustre_handle *lockh)
668 struct obd_export *exp;
672 OBD_CHECK_ACTIVE(conn, exp);
673 OBD_CHECK_OP(exp->exp_obd, enqueue);
675 rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
676 cookie, cookielen, mode, flags, cb,
677 data, datalen, lockh);
678 class_export_put(exp);
682 static inline int obd_match(struct lustre_handle *conn,
683 struct lov_stripe_md *ea,
684 __u32 type, void *cookie, int cookielen,
685 __u32 mode, int *flags,
686 struct lustre_handle *lockh)
688 struct obd_export *exp;
692 OBD_CHECK_ACTIVE(conn, exp);
693 OBD_CHECK_OP(exp->exp_obd, match);
695 rc = OBP(exp->exp_obd, match)(conn, ea, type, cookie, cookielen, mode,
697 class_export_put(exp);
702 static inline int obd_cancel(struct lustre_handle *conn,
703 struct lov_stripe_md *ea, __u32 mode,
704 struct lustre_handle *lockh)
706 struct obd_export *exp;
710 OBD_CHECK_ACTIVE(conn, exp);
711 OBD_CHECK_OP(exp->exp_obd, cancel);
713 rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
714 class_export_put(exp);
718 static inline int obd_cancel_unused(struct lustre_handle *conn,
719 struct lov_stripe_md *ea, int flags,
722 struct obd_export *exp;
726 OBD_CHECK_ACTIVE(conn, exp);
727 OBD_CHECK_OP(exp->exp_obd, cancel_unused);
729 rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, flags, opaque);
730 class_export_put(exp);
734 static inline int obd_san_preprw(int cmd, struct lustre_handle *conn,
735 int objcount, struct obd_ioobj *obj,
736 int niocount, struct niobuf_remote *remote)
738 struct obd_export *exp;
741 OBD_CHECK_ACTIVE(conn, exp);
742 OBD_CHECK_OP(exp->exp_obd, preprw);
744 rc = OBP(exp->exp_obd, san_preprw)(cmd, conn, objcount, obj,
746 class_export_put(exp);
751 /* OBD Metadata Support */
753 extern int obd_init_caches(void);
754 extern void obd_cleanup_caches(void);
756 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
758 return (struct lustre_handle *)&oa->o_inline;
761 /* support routines */
762 extern kmem_cache_t *obdo_cachep;
763 static inline struct obdo *obdo_alloc(void)
767 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
770 memset(oa, 0, sizeof (*oa));
775 static inline void obdo_free(struct obdo *oa)
779 kmem_cache_free(obdo_cachep, oa);
782 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
783 #define to_kdev_t(dev) dev
784 #define kdev_t_to_nr(dev) dev
788 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
790 unsigned int ia_valid = attr->ia_valid;
792 if (ia_valid & ATTR_ATIME) {
793 oa->o_atime = LTIME_S(attr->ia_atime);
794 oa->o_valid |= OBD_MD_FLATIME;
796 if (ia_valid & ATTR_MTIME) {
797 oa->o_mtime = LTIME_S(attr->ia_mtime);
798 oa->o_valid |= OBD_MD_FLMTIME;
800 if (ia_valid & ATTR_CTIME) {
801 oa->o_ctime = LTIME_S(attr->ia_ctime);
802 oa->o_valid |= OBD_MD_FLCTIME;
804 if (ia_valid & ATTR_SIZE) {
805 oa->o_size = attr->ia_size;
806 oa->o_valid |= OBD_MD_FLSIZE;
808 if (ia_valid & ATTR_MODE) {
809 oa->o_mode = attr->ia_mode;
810 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
811 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
812 oa->o_mode &= ~S_ISGID;
814 if (ia_valid & ATTR_UID) {
815 oa->o_uid = attr->ia_uid;
816 oa->o_valid |= OBD_MD_FLUID;
818 if (ia_valid & ATTR_GID) {
819 oa->o_gid = attr->ia_gid;
820 oa->o_valid |= OBD_MD_FLGID;
825 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
828 memset(attr, 0, sizeof(*attr));
829 if (valid & OBD_MD_FLATIME) {
830 LTIME_S(attr->ia_atime) = oa->o_atime;
831 attr->ia_valid |= ATTR_ATIME;
833 if (valid & OBD_MD_FLMTIME) {
834 LTIME_S(attr->ia_mtime) = oa->o_mtime;
835 attr->ia_valid |= ATTR_MTIME;
837 if (valid & OBD_MD_FLCTIME) {
838 LTIME_S(attr->ia_ctime) = oa->o_ctime;
839 attr->ia_valid |= ATTR_CTIME;
841 if (valid & OBD_MD_FLSIZE) {
842 attr->ia_size = oa->o_size;
843 attr->ia_valid |= ATTR_SIZE;
845 if (valid & OBD_MD_FLTYPE) {
846 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
847 attr->ia_valid |= ATTR_MODE;
849 if (valid & OBD_MD_FLMODE) {
850 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
851 attr->ia_valid |= ATTR_MODE;
852 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
853 attr->ia_mode &= ~S_ISGID;
855 if (valid & OBD_MD_FLUID)
857 attr->ia_uid = oa->o_uid;
858 attr->ia_valid |= ATTR_UID;
860 if (valid & OBD_MD_FLGID) {
861 attr->ia_gid = oa->o_gid;
862 attr->ia_valid |= ATTR_GID;
867 /* WARNING: the file systems must take care not to tinker with
868 attributes they don't manage (such as blocks). */
871 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
874 if (valid & OBD_MD_FLATIME)
875 dst->o_atime = LTIME_S(src->i_atime);
876 if (valid & OBD_MD_FLMTIME)
877 dst->o_mtime = LTIME_S(src->i_mtime);
878 if (valid & OBD_MD_FLCTIME)
879 dst->o_ctime = LTIME_S(src->i_ctime);
880 if (valid & OBD_MD_FLSIZE)
881 dst->o_size = src->i_size;
882 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
883 dst->o_blocks = src->i_blocks;
884 if (valid & OBD_MD_FLBLKSZ)
885 dst->o_blksize = src->i_blksize;
886 if (valid & OBD_MD_FLTYPE)
887 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
888 if (valid & OBD_MD_FLMODE)
889 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
890 if (valid & OBD_MD_FLUID)
891 dst->o_uid = src->i_uid;
892 if (valid & OBD_MD_FLGID)
893 dst->o_gid = src->i_gid;
894 if (valid & OBD_MD_FLFLAGS)
895 dst->o_flags = src->i_flags;
896 if (valid & OBD_MD_FLNLINK)
897 dst->o_nlink = src->i_nlink;
898 if (valid & OBD_MD_FLGENER)
899 dst->o_generation = src->i_generation;
900 if (valid & OBD_MD_FLRDEV)
901 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
903 dst->o_valid |= (valid & ~OBD_MD_FLID);
906 static inline void obdo_refresh_inode(struct inode *dst, struct obdo *src,
909 valid &= src->o_valid;
911 if (valid & OBD_MD_FLATIME && src->o_atime > LTIME_S(dst->i_atime))
912 LTIME_S(dst->i_atime) = src->o_atime;
913 if (valid & OBD_MD_FLMTIME && src->o_mtime > LTIME_S(dst->i_mtime))
914 LTIME_S(dst->i_mtime) = src->o_mtime;
915 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
916 LTIME_S(dst->i_ctime) = src->o_ctime;
917 if (valid & OBD_MD_FLSIZE && src->o_size > dst->i_size)
918 dst->i_size = src->o_size;
919 /* allocation of space */
920 if (valid & OBD_MD_FLBLOCKS && src->o_blocks > dst->i_blocks)
921 dst->i_blocks = src->o_blocks;
924 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
927 valid &= src->o_valid;
929 if (valid & OBD_MD_FLATIME)
930 LTIME_S(dst->i_atime) = src->o_atime;
931 if (valid & OBD_MD_FLMTIME)
932 LTIME_S(dst->i_mtime) = src->o_mtime;
933 if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
934 LTIME_S(dst->i_ctime) = src->o_ctime;
935 if (valid & OBD_MD_FLSIZE)
936 dst->i_size = src->o_size;
937 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
938 dst->i_blocks = src->o_blocks;
939 if (valid & OBD_MD_FLBLKSZ)
940 dst->i_blksize = src->o_blksize;
941 if (valid & OBD_MD_FLTYPE)
942 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
943 if (valid & OBD_MD_FLMODE)
944 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
945 if (valid & OBD_MD_FLUID)
946 dst->i_uid = src->o_uid;
947 if (valid & OBD_MD_FLGID)
948 dst->i_gid = src->o_gid;
949 if (valid & OBD_MD_FLFLAGS)
950 dst->i_flags = src->o_flags;
951 if (valid & OBD_MD_FLNLINK)
952 dst->i_nlink = src->o_nlink;
953 if (valid & OBD_MD_FLGENER)
954 dst->i_generation = src->o_generation;
955 if (valid & OBD_MD_FLRDEV)
956 dst->i_rdev = to_kdev_t(src->o_rdev);
960 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
964 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
965 (unsigned long long)src->o_id, src->o_valid,
966 (unsigned long long)dst->o_id);
968 if (valid & OBD_MD_FLATIME)
969 dst->o_atime = src->o_atime;
970 if (valid & OBD_MD_FLMTIME)
971 dst->o_mtime = src->o_mtime;
972 if (valid & OBD_MD_FLCTIME)
973 dst->o_ctime = src->o_ctime;
974 if (valid & OBD_MD_FLSIZE)
975 dst->o_size = src->o_size;
976 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
977 dst->o_blocks = src->o_blocks;
978 if (valid & OBD_MD_FLBLKSZ)
979 dst->o_blksize = src->o_blksize;
980 if (valid & OBD_MD_FLTYPE)
981 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
982 if (valid & OBD_MD_FLMODE)
983 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
984 if (valid & OBD_MD_FLUID)
985 dst->o_uid = src->o_uid;
986 if (valid & OBD_MD_FLGID)
987 dst->o_gid = src->o_gid;
988 if (valid & OBD_MD_FLFLAGS)
989 dst->o_flags = src->o_flags;
991 if (valid & OBD_MD_FLOBDFLG)
992 dst->o_obdflags = src->o_obdflags;
994 if (valid & OBD_MD_FLNLINK)
995 dst->o_nlink = src->o_nlink;
996 if (valid & OBD_MD_FLGENER)
997 dst->o_generation = src->o_generation;
998 if (valid & OBD_MD_FLRDEV)
999 dst->o_rdev = src->o_rdev;
1000 if (valid & OBD_MD_FLINLINE &&
1001 src->o_obdflags & OBD_FL_INLINEDATA) {
1002 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
1003 dst->o_obdflags |= OBD_FL_INLINEDATA;
1006 dst->o_valid |= valid;
1010 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
1011 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
1016 if ( compare & OBD_MD_FLATIME )
1017 res = (res || (dst->o_atime != src->o_atime));
1018 if ( compare & OBD_MD_FLMTIME )
1019 res = (res || (dst->o_mtime != src->o_mtime));
1020 if ( compare & OBD_MD_FLCTIME )
1021 res = (res || (dst->o_ctime != src->o_ctime));
1022 if ( compare & OBD_MD_FLSIZE )
1023 res = (res || (dst->o_size != src->o_size));
1024 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
1025 res = (res || (dst->o_blocks != src->o_blocks));
1026 if ( compare & OBD_MD_FLBLKSZ )
1027 res = (res || (dst->o_blksize != src->o_blksize));
1028 if ( compare & OBD_MD_FLTYPE )
1029 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
1030 if ( compare & OBD_MD_FLMODE )
1031 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
1032 if ( compare & OBD_MD_FLUID )
1033 res = (res || (dst->o_uid != src->o_uid));
1034 if ( compare & OBD_MD_FLGID )
1035 res = (res || (dst->o_gid != src->o_gid));
1036 if ( compare & OBD_MD_FLFLAGS )
1037 res = (res || (dst->o_flags != src->o_flags));
1038 if ( compare & OBD_MD_FLNLINK )
1039 res = (res || (dst->o_nlink != src->o_nlink));
1040 if ( compare & OBD_MD_FLGENER )
1041 res = (res || (dst->o_generation != src->o_generation));
1042 /* XXX Don't know if thses should be included here - wasn't previously
1043 if ( compare & OBD_MD_FLINLINE )
1044 res = (res || memcmp(dst->o_inline, src->o_inline));
1049 /* I'm as embarrassed about this as you are.
1051 * <shaver> // XXX do not look into _superhack with remaining eye
1052 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1053 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1054 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1058 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
1059 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
1061 struct obd_class_user_state {
1062 struct obd_device *ocus_current_obd;
1063 struct list_head ocus_conns;
1066 struct obd_class_user_conn {
1067 struct list_head ocuc_chain;
1068 struct lustre_handle ocuc_conn;
1073 extern void obd_sysctl_init (void);
1074 extern void obd_sysctl_clean (void);
1077 typedef __u8 class_uuid_t[16];
1078 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1079 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1082 int lustre_uuid_to_peer(char *uuid, struct lustre_peer *peer);
1083 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1084 int class_del_uuid (char *uuid);
1085 void class_init_uuidlist(void);
1086 void class_exit_uuidlist(void);
1088 #endif /* __LINUX_OBD_CLASS_H */