Whamcloud - gitweb
b=191
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
25
26 #ifndef __KERNEL__
27 # include <stdint.h>
28 # define __KERNEL__
29 # include <linux/list.h>
30 # undef __KERNEL__
31 #else
32 #include <asm/segment.h>
33 #include <asm/uaccess.h>
34 #include <linux/types.h>
35 #include <linux/fs.h>
36 #include <linux/time.h>
37
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>
44 #include <linux/lprocfs_status.h>
45 #endif
46
47
48 /* OBD Device Declarations */
49 #define MAX_OBD_DEVICES 128
50 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51
52 #define OBD_ATTACHED 0x1
53 #define OBD_SET_UP   0x2
54
55 /* OBD Operations Declarations */
56
57 #ifdef __KERNEL__
58 static inline int obd_check_conn(struct lustre_handle *conn)
59 {
60         struct obd_device *obd;
61         if (!conn) {
62                 CERROR("NULL conn\n");
63                 RETURN(-ENOTCONN);
64         }
65         obd = class_conn2obd(conn);
66         if (!obd) {
67                 CERROR("NULL obd\n");
68                 RETURN(-ENODEV);
69         }
70
71         if (!obd->obd_flags & OBD_ATTACHED ) {
72                 CERROR("obd %d not attached\n", obd->obd_minor);
73                 RETURN(-ENODEV);
74         }
75
76         if (!obd->obd_flags & OBD_SET_UP) {
77                 CERROR("obd %d not setup\n", obd->obd_minor);
78                 RETURN(-ENODEV);
79         }
80
81         if (!obd->obd_type) {
82                 CERROR("obd %d not typed\n", obd->obd_minor);
83                 RETURN(-ENODEV);
84         }
85
86         if (!obd->obd_type->typ_ops) {
87                 CERROR("obd_check_conn: obd %d no operations\n",
88                        obd->obd_minor);
89                 RETURN(-EOPNOTSUPP);
90         }
91         return 0;
92 }
93
94
95 #define OBT(dev)        (dev)->obd_type
96 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
97
98 #define OBD_CHECK_SETUP(conn, exp)                              \
99 do {                                                            \
100         if (!(conn)) {                                          \
101                 CERROR("NULL connection\n");                    \
102                 RETURN(-EINVAL);                                \
103         }                                                       \
104                                                                 \
105         exp = class_conn2export(conn);                          \
106         if (!(exp)) {                                           \
107                 CERROR("No export\n");                          \
108                 RETURN(-EINVAL);                                \
109         }                                                       \
110                                                                 \
111         if (!((exp)->exp_obd->obd_flags & OBD_SET_UP)) {        \
112                 CERROR("Device %d not setup\n",                 \
113                        (exp)->exp_obd->obd_minor);              \
114                 RETURN(-EINVAL);                                \
115         }                                                       \
116 } while (0)
117
118 #define OBD_CHECK_DEVSETUP(obd)                                 \
119 do {                                                            \
120         if (!(obd)) {                                           \
121                 CERROR("NULL device\n");                        \
122                 RETURN(-EINVAL);                                \
123         }                                                       \
124                                                                 \
125         if (!((obd)->obd_flags & OBD_SET_UP)) {                 \
126                 CERROR("Device %d not setup\n",                 \
127                        (obd)->obd_minor);                       \
128                 RETURN(-EINVAL);                                \
129         }                                                       \
130 } while (0)
131
132 #define OBD_CHECK_OP(obd, op)                                   \
133 do {                                                            \
134         if (!OBP((obd), op)) {                                  \
135                 CERROR("obd_" #op ": dev %d no operation\n",    \
136                        obd->obd_minor);                         \
137                 RETURN(-EOPNOTSUPP);                            \
138         }                                                       \
139 } while (0)
140
141 static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
142                                void *key, obd_count *vallen, void **val)
143 {
144         struct obd_export *exp;
145         int rc;
146
147         OBD_CHECK_SETUP(conn, exp);
148         OBD_CHECK_OP(exp->exp_obd, get_info);
149
150         rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
151         RETURN(rc);
152 }
153
154 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
155                                void *key, obd_count vallen, void *val)
156 {
157         struct obd_export *exp;
158         int rc;
159
160         OBD_CHECK_SETUP(conn, exp);
161         OBD_CHECK_OP(exp->exp_obd, set_info);
162
163         rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
164         RETURN(rc);
165 }
166
167 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
168 {
169         int rc;
170
171         OBD_CHECK_OP(obd, setup);
172
173         rc = OBP(obd, setup)(obd, datalen, data);
174         RETURN(rc);
175 }
176
177 static inline int obd_cleanup(struct obd_device *obd)
178 {
179         int rc;
180
181         OBD_CHECK_DEVSETUP(obd);
182         OBD_CHECK_OP(obd, cleanup);
183
184         rc = OBP(obd, cleanup)(obd);
185         RETURN(rc);
186 }
187
188 /* Pack an in-memory MD struct for sending to the MDS and/or disk.
189  * Returns +ve size of packed MD (0 for free), or -ve error.
190  *
191  * If @wire_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
192  * If @*wire_tgt != NULL and @mem_src == NULL, @*wire_tgt will be freed.
193  * If @*wire_tgt == NULL, it will be allocated
194  */
195 static inline int obd_packmd(struct lustre_handle *conn,
196                              struct lov_mds_md **wire_tgt,
197                              struct lov_stripe_md *mem_src)
198 {
199         struct obd_export *exp;
200
201         OBD_CHECK_SETUP(conn, exp);
202         OBD_CHECK_OP(exp->exp_obd, packmd);
203
204         RETURN(OBP(exp->exp_obd, packmd)(conn, wire_tgt, mem_src));
205 }
206
207 static inline int obd_size_wiremd(struct lustre_handle *conn,
208                                   struct lov_stripe_md *mem_src)
209 {
210         return obd_packmd(conn, NULL, mem_src);
211 }
212
213 /* helper functions */
214 static inline int obd_alloc_wiremd(struct lustre_handle *conn,
215                                    struct lov_mds_md **wire_tgt)
216 {
217         LASSERT(wire_tgt);
218         LASSERT(*wire_tgt == NULL);
219         return obd_packmd(conn, wire_tgt, NULL);
220 }
221
222 static inline int obd_free_wiremd(struct lustre_handle *conn,
223                                   struct lov_mds_md **wire_tgt)
224 {
225         LASSERT(wire_tgt);
226         LASSERT(*wire_tgt);
227         return obd_packmd(conn, wire_tgt, NULL);
228 }
229
230 /* Unpack an MD struct from the MDS and/or disk to in-memory format.
231  * Returns +ve size of unpacked MD (0 for free), or -ve error.
232  *
233  * If @mem_tgt == NULL, MD size is returned (max size if @wire_src == NULL).
234  * If @*mem_tgt != NULL and @wire_src == NULL, @*mem_tgt will be freed.
235  * If @*mem_tgt == NULL, it will be allocated
236  */
237 static inline int obd_unpackmd(struct lustre_handle *conn,
238                                struct lov_stripe_md **mem_tgt,
239                                struct lov_mds_md *wire_src)
240 {
241         struct obd_export *exp;
242
243         OBD_CHECK_SETUP(conn, exp);
244         OBD_CHECK_OP(exp->exp_obd, unpackmd);
245
246         RETURN(OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, wire_src));
247 }
248
249 static inline int obd_size_memmd(struct lustre_handle *conn,
250                                  struct lov_mds_md *wire_src)
251 {
252         return obd_unpackmd(conn, NULL, wire_src);
253 }
254
255 /* helper functions */
256 static inline int obd_alloc_memmd(struct lustre_handle *conn,
257                                   struct lov_stripe_md **mem_tgt)
258 {
259         LASSERT(mem_tgt);
260         LASSERT(*mem_tgt == NULL);
261         return obd_unpackmd(conn, mem_tgt, NULL);
262 }
263
264 static inline int obd_free_memmd(struct lustre_handle *conn,
265                                  struct lov_stripe_md **mem_tgt)
266 {
267         LASSERT(mem_tgt);
268         LASSERT(*mem_tgt);
269         return obd_unpackmd(conn, mem_tgt, NULL);
270 }
271
272 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
273                              struct lov_stripe_md **ea)
274 {
275         struct obd_export *exp;
276         int rc;
277
278         OBD_CHECK_SETUP(conn, exp);
279         OBD_CHECK_OP(exp->exp_obd, create);
280
281         rc = OBP(exp->exp_obd, create)(conn, obdo, ea);
282         RETURN(rc);
283 }
284
285 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
286                               struct lov_stripe_md *ea)
287 {
288         struct obd_export *exp;
289         int rc;
290
291         OBD_CHECK_SETUP(conn, exp);
292         OBD_CHECK_OP(exp->exp_obd, destroy);
293
294         rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea);
295         RETURN(rc);
296 }
297
298 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
299                               struct lov_stripe_md *ea)
300 {
301         struct obd_export *exp;
302         int rc;
303
304         OBD_CHECK_SETUP(conn, exp);
305         OBD_CHECK_OP(exp->exp_obd, getattr);
306
307         rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
308         RETURN(rc);
309 }
310
311 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
312                             struct lov_stripe_md *ea)
313 {
314         struct obd_export *exp;
315         int rc;
316
317         OBD_CHECK_SETUP(conn, exp);
318         OBD_CHECK_OP(exp->exp_obd, close);
319
320         rc = OBP(exp->exp_obd, close)(conn, obdo, ea);
321         RETURN(rc);
322 }
323
324 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
325                            struct lov_stripe_md *ea)
326 {
327         struct obd_export *exp;
328         int rc;
329
330         OBD_CHECK_SETUP(conn, exp);
331         OBD_CHECK_OP(exp->exp_obd, open);
332
333         rc = OBP(exp->exp_obd, open)(conn, obdo, ea);
334         RETURN(rc);
335 }
336
337 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
338                               struct lov_stripe_md *ea)
339 {
340         struct obd_export *exp;
341         int rc;
342
343         OBD_CHECK_SETUP(conn, exp);
344         OBD_CHECK_OP(exp->exp_obd, setattr);
345
346         rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea);
347         RETURN(rc);
348 }
349
350 static inline int obd_connect(struct lustre_handle *conn,
351                               struct obd_device *obd, obd_uuid_t cluuid,
352                               struct recovd_obd *recovd,
353                               ptlrpc_recovery_cb_t recover)
354 {
355         int rc;
356
357         OBD_CHECK_DEVSETUP(obd);
358         OBD_CHECK_OP(obd, connect);
359
360         rc = OBP(obd, connect)(conn, obd, cluuid, recovd, recover);
361         RETURN(rc);
362 }
363
364 static inline int obd_disconnect(struct lustre_handle *conn)
365 {
366         struct obd_export *exp;
367         int rc;
368
369         OBD_CHECK_SETUP(conn, exp);
370         OBD_CHECK_OP(exp->exp_obd, disconnect);
371
372         rc = OBP(exp->exp_obd, disconnect)(conn);
373         RETURN(rc);
374 }
375
376 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
377 {
378         struct obd_export *exp;
379         int rc;
380
381         OBD_CHECK_SETUP(conn, exp);
382         OBD_CHECK_OP(exp->exp_obd, statfs);
383
384         rc = OBP(exp->exp_obd, statfs)(conn, osfs);
385         RETURN(rc);
386 }
387
388 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
389                             struct lov_stripe_md *ea,
390                             obd_size start, obd_size end)
391 {
392         struct obd_export *exp;
393         int rc;
394
395         OBD_CHECK_SETUP(conn, exp);
396         OBD_CHECK_OP(exp->exp_obd, punch);
397
398         rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end);
399         RETURN(rc);
400 }
401
402 static inline int obd_brw(int cmd, struct lustre_handle *conn,
403                           struct lov_stripe_md *ea, obd_count oa_bufs,
404                           struct brw_page *pg, struct obd_brw_set *set)
405 {
406         struct obd_export *exp;
407         int rc;
408
409         OBD_CHECK_SETUP(conn, exp);
410         OBD_CHECK_OP(exp->exp_obd, brw);
411
412         if (!(cmd & OBD_BRW_RWMASK)) {
413                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
414                 LBUG();
415         }
416
417         rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, set);
418         RETURN(rc);
419 }
420
421 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
422                              int objcount, struct obd_ioobj *obj,
423                              int niocount, struct niobuf_remote *remote,
424                              struct niobuf_local *local, void **desc_private)
425 {
426         struct obd_export *exp;
427         int rc;
428
429         OBD_CHECK_SETUP(conn, exp);
430         OBD_CHECK_OP(exp->exp_obd, preprw);
431
432         rc = OBP(exp->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
433                                        remote, local, desc_private);
434         RETURN(rc);
435 }
436
437 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
438                                int objcount, struct obd_ioobj *obj,
439                                int niocount, struct niobuf_local *local,
440                                void *desc_private)
441 {
442         struct obd_export *exp;
443         int rc;
444
445         OBD_CHECK_SETUP(conn, exp);
446         OBD_CHECK_OP(exp->exp_obd, commitrw);
447
448         rc = OBP(exp->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
449                                          local, desc_private);
450         RETURN(rc);
451 }
452
453 static inline int obd_iocontrol(int cmd, struct lustre_handle *conn,
454                                 int len, void *karg, void *uarg)
455 {
456         struct obd_export *exp;
457         int rc;
458
459         OBD_CHECK_SETUP(conn, exp);
460         OBD_CHECK_OP(exp->exp_obd, iocontrol);
461
462         rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
463         RETURN(rc);
464 }
465
466 static inline int obd_enqueue(struct lustre_handle *conn,
467                               struct lov_stripe_md *ea,
468                               struct lustre_handle *parent_lock,
469                               __u32 type, void *cookie, int cookielen,
470                               __u32 mode, int *flags, void *cb, void *data,
471                               int datalen, struct lustre_handle *lockh)
472 {
473         struct obd_export *exp;
474         int rc;
475
476         OBD_CHECK_SETUP(conn, exp);
477         OBD_CHECK_OP(exp->exp_obd, enqueue);
478
479         rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
480                                         cookie, cookielen, mode, flags, cb,
481                                         data, datalen, lockh);
482         RETURN(rc);
483 }
484
485 static inline int obd_cancel(struct lustre_handle *conn,
486                              struct lov_stripe_md *ea, __u32 mode,
487                              struct lustre_handle *lockh)
488 {
489         struct obd_export *exp;
490         int rc;
491
492         OBD_CHECK_SETUP(conn, exp);
493         OBD_CHECK_OP(exp->exp_obd, cancel);
494
495         rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
496         RETURN(rc);
497 }
498
499 static inline int obd_cancel_unused(struct lustre_handle *conn,
500                                     struct lov_stripe_md *ea, int local)
501 {
502         struct obd_export *exp;
503         int rc;
504
505         OBD_CHECK_SETUP(conn, exp);
506         OBD_CHECK_OP(exp->exp_obd, cancel_unused);
507
508         rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, local);
509         RETURN(rc);
510 }
511
512 #endif
513
514 /* OBD Metadata Support */
515
516 extern int obd_init_caches(void);
517 extern void obd_cleanup_caches(void);
518
519 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
520 {
521         return (struct lustre_handle *)&oa->o_inline;
522 }
523
524 static inline void obd_oa2handle(struct lustre_handle *handle, struct obdo *oa)
525 {
526         if (oa->o_valid |= OBD_MD_FLHANDLE) {
527                 struct lustre_handle *oa_handle = obdo_handle(oa);
528                 memcpy(handle, oa_handle, sizeof(*handle));
529         }
530 }
531
532 static inline void obd_handle2oa(struct obdo *oa, struct lustre_handle *handle)
533 {
534         if (handle->addr) {
535                 struct lustre_handle *oa_handle = obdo_handle(oa);
536                 memcpy(oa_handle, handle, sizeof(*handle));
537                 oa->o_valid |= OBD_MD_FLHANDLE;
538         }
539 }
540
541 #ifdef __KERNEL__
542 /* support routines */
543 extern kmem_cache_t *obdo_cachep;
544 static inline struct obdo *obdo_alloc(void)
545 {
546         struct obdo *oa;
547
548         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
549         if (oa == NULL)
550                 LBUG();
551         memset(oa, 0, sizeof (*oa));
552
553         return oa;
554 }
555
556 static inline void obdo_free(struct obdo *oa)
557 {
558         if (!oa)
559                 return;
560         kmem_cache_free(obdo_cachep, oa);
561 }
562
563 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
564 {
565         unsigned int ia_valid = attr->ia_valid;
566
567         if (ia_valid & ATTR_ATIME) {
568                 oa->o_atime = attr->ia_atime;
569                 oa->o_valid |= OBD_MD_FLATIME;
570         }
571         if (ia_valid & ATTR_MTIME) {
572                 oa->o_mtime = attr->ia_mtime;
573                 oa->o_valid |= OBD_MD_FLMTIME;
574         }
575         if (ia_valid & ATTR_CTIME) {
576                 oa->o_ctime = attr->ia_ctime;
577                 oa->o_valid |= OBD_MD_FLCTIME;
578         }
579         if (ia_valid & ATTR_SIZE) {
580                 oa->o_size = attr->ia_size;
581                 oa->o_valid |= OBD_MD_FLSIZE;
582         }
583         if (ia_valid & ATTR_MODE) {
584                 oa->o_mode = attr->ia_mode;
585                 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
586                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
587                         oa->o_mode &= ~S_ISGID;
588         }
589         if (ia_valid & ATTR_UID) {
590                 oa->o_uid = attr->ia_uid;
591                 oa->o_valid |= OBD_MD_FLUID;
592         }
593         if (ia_valid & ATTR_GID) {
594                 oa->o_gid = attr->ia_gid;
595                 oa->o_valid |= OBD_MD_FLGID;
596         }
597 }
598
599
600 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
601                                    obd_flag valid)
602 {
603         memset(attr, 0, sizeof(*attr));
604         if (valid & OBD_MD_FLATIME) {
605                 attr->ia_atime = oa->o_atime;
606                 attr->ia_valid |= ATTR_ATIME;
607         }
608         if (valid & OBD_MD_FLMTIME) {
609                 attr->ia_mtime = oa->o_mtime;
610                 attr->ia_valid |= ATTR_MTIME;
611         }
612         if (valid & OBD_MD_FLCTIME) {
613                 attr->ia_ctime = oa->o_ctime;
614                 attr->ia_valid |= ATTR_CTIME;
615         }
616         if (valid & OBD_MD_FLSIZE) {
617                 attr->ia_size = oa->o_size;
618                 attr->ia_valid |= ATTR_SIZE;
619         }
620         if (valid & OBD_MD_FLTYPE) {
621                 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
622                 attr->ia_valid |= ATTR_MODE;
623         }
624         if (valid & OBD_MD_FLMODE) {
625                 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
626                 attr->ia_valid |= ATTR_MODE;
627                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
628                         attr->ia_mode &= ~S_ISGID;
629         }
630         if (valid & OBD_MD_FLUID)
631         {
632                 attr->ia_uid = oa->o_uid;
633                 attr->ia_valid |= ATTR_UID;
634         }
635         if (valid & OBD_MD_FLGID) {
636                 attr->ia_gid = oa->o_gid;
637                 attr->ia_valid |= ATTR_GID;
638         }
639 }
640
641
642 /* WARNING: the file systems must take care not to tinker with
643    attributes they don't manage (such as blocks). */
644
645 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
646 #define to_kdev_t(dev) dev
647 #define kdev_t_to_nr(dev) dev
648 #endif
649
650 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
651                                    obd_flag valid)
652 {
653 //        if (valid & OBD_MD_FLID)
654 //                dst->o_id = src->i_ino;
655         if (valid & OBD_MD_FLATIME)
656                 dst->o_atime = src->i_atime;
657         if (valid & OBD_MD_FLMTIME)
658                 dst->o_mtime = src->i_mtime;
659         if (valid & OBD_MD_FLCTIME)
660                 dst->o_ctime = src->i_ctime;
661         if (valid & OBD_MD_FLSIZE)
662                 dst->o_size = src->i_size;
663         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
664                 dst->o_blocks = src->i_blocks;
665         if (valid & OBD_MD_FLBLKSZ)
666                 dst->o_blksize = src->i_blksize;
667         if (valid & OBD_MD_FLTYPE)
668                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
669         if (valid & OBD_MD_FLMODE)
670                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
671         if (valid & OBD_MD_FLUID)
672                 dst->o_uid = src->i_uid;
673         if (valid & OBD_MD_FLGID)
674                 dst->o_gid = src->i_gid;
675         if (valid & OBD_MD_FLFLAGS)
676                 dst->o_flags = src->i_flags;
677         if (valid & OBD_MD_FLNLINK)
678                 dst->o_nlink = src->i_nlink;
679         if (valid & OBD_MD_FLGENER)
680                 dst->o_generation = src->i_generation;
681         if (valid & OBD_MD_FLRDEV)
682                 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
683
684         dst->o_valid |= (valid & ~OBD_MD_FLID);
685 }
686
687 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
688                                  obd_flag valid)
689 {
690 //        if (valid & OBD_MD_FLID)
691 //                dst->i_ino = src->o_id;
692         if (valid & OBD_MD_FLATIME)
693                 dst->i_atime = src->o_atime;
694         if (valid & OBD_MD_FLMTIME)
695                 dst->i_mtime = src->o_mtime;
696         if (valid & OBD_MD_FLCTIME)
697                 dst->i_ctime = src->o_ctime;
698         if (valid & OBD_MD_FLSIZE)
699                 dst->i_size = src->o_size;
700         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
701                 dst->i_blocks = src->o_blocks;
702         if (valid & OBD_MD_FLBLKSZ)
703                 dst->i_blksize = src->o_blksize;
704         if (valid & OBD_MD_FLTYPE)
705                 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
706         if (valid & OBD_MD_FLMODE)
707                 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
708         if (valid & OBD_MD_FLUID)
709                 dst->i_uid = src->o_uid;
710         if (valid & OBD_MD_FLGID)
711                 dst->i_gid = src->o_gid;
712         if (valid & OBD_MD_FLFLAGS)
713                 dst->i_flags = src->o_flags;
714         if (valid & OBD_MD_FLNLINK)
715                 dst->i_nlink = src->o_nlink;
716         if (valid & OBD_MD_FLGENER)
717                 dst->i_generation = src->o_generation;
718         if (valid & OBD_MD_FLRDEV)
719                 dst->i_rdev = to_kdev_t(src->o_rdev);
720 }
721 #endif
722
723 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
724                                obd_flag valid)
725 {
726 #ifdef __KERNEL__
727         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
728                (unsigned long long)src->o_id, src->o_valid,
729                (unsigned long long)dst->o_id);
730 #endif
731         if (valid & OBD_MD_FLATIME)
732                 dst->o_atime = src->o_atime;
733         if (valid & OBD_MD_FLMTIME)
734                 dst->o_mtime = src->o_mtime;
735         if (valid & OBD_MD_FLCTIME)
736                 dst->o_ctime = src->o_ctime;
737         if (valid & OBD_MD_FLSIZE)
738                 dst->o_size = src->o_size;
739         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
740                 dst->o_blocks = src->o_blocks;
741         if (valid & OBD_MD_FLBLKSZ)
742                 dst->o_blksize = src->o_blksize;
743         if (valid & OBD_MD_FLTYPE)
744                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
745         if (valid & OBD_MD_FLMODE)
746                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
747         if (valid & OBD_MD_FLUID)
748                 dst->o_uid = src->o_uid;
749         if (valid & OBD_MD_FLGID)
750                 dst->o_gid = src->o_gid;
751         if (valid & OBD_MD_FLFLAGS)
752                 dst->o_flags = src->o_flags;
753         /*
754         if (valid & OBD_MD_FLOBDFLG)
755                 dst->o_obdflags = src->o_obdflags;
756         */
757         if (valid & OBD_MD_FLNLINK)
758                 dst->o_nlink = src->o_nlink;
759         if (valid & OBD_MD_FLGENER)
760                 dst->o_generation = src->o_generation;
761         if (valid & OBD_MD_FLRDEV)
762                 dst->o_rdev = src->o_rdev;
763         if (valid & OBD_MD_FLINLINE &&
764              src->o_obdflags & OBD_FL_INLINEDATA) {
765                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
766                 dst->o_obdflags |= OBD_FL_INLINEDATA;
767         }
768
769         dst->o_valid |= valid;
770 }
771
772
773 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
774 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
775                               obd_flag compare)
776 {
777         int res = 0;
778
779         if ( compare & OBD_MD_FLATIME )
780                 res = (res || (dst->o_atime != src->o_atime));
781         if ( compare & OBD_MD_FLMTIME )
782                 res = (res || (dst->o_mtime != src->o_mtime));
783         if ( compare & OBD_MD_FLCTIME )
784                 res = (res || (dst->o_ctime != src->o_ctime));
785         if ( compare & OBD_MD_FLSIZE )
786                 res = (res || (dst->o_size != src->o_size));
787         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
788                 res = (res || (dst->o_blocks != src->o_blocks));
789         if ( compare & OBD_MD_FLBLKSZ )
790                 res = (res || (dst->o_blksize != src->o_blksize));
791         if ( compare & OBD_MD_FLTYPE )
792                 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
793         if ( compare & OBD_MD_FLMODE )
794                 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
795         if ( compare & OBD_MD_FLUID )
796                 res = (res || (dst->o_uid != src->o_uid));
797         if ( compare & OBD_MD_FLGID )
798                 res = (res || (dst->o_gid != src->o_gid));
799         if ( compare & OBD_MD_FLFLAGS )
800                 res = (res || (dst->o_flags != src->o_flags));
801         if ( compare & OBD_MD_FLNLINK )
802                 res = (res || (dst->o_nlink != src->o_nlink));
803         if ( compare & OBD_MD_FLGENER )
804                 res = (res || (dst->o_generation != src->o_generation));
805         /* XXX Don't know if thses should be included here - wasn't previously
806         if ( compare & OBD_MD_FLINLINE )
807                 res = (res || memcmp(dst->o_inline, src->o_inline));
808         */
809         return res;
810 }
811
812
813 #ifdef __KERNEL__
814 /* I'm as embarrassed about this as you are.
815  *
816  * <shaver> // XXX do not look into _superhack with remaining eye
817  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */ 
818 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
819
820 int class_register_type(struct obd_ops *ops, struct lprocfs_vars* vars, 
821                         char *nm);
822 int class_unregister_type(char *nm);
823 int class_name2dev(char *name);
824 int class_uuid2dev(char *uuid);
825 struct obd_device *class_uuid2obd(char *uuid);
826 struct obd_export *class_new_export(struct obd_device *obddev);
827 struct obd_type *class_nm_to_type(char* name);
828 void class_destroy_export(struct obd_export *exp);
829 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
830                   obd_uuid_t cluuid);
831 int class_disconnect(struct lustre_handle *conn);
832 void class_disconnect_all(struct obd_device *obddev);
833
834 /* generic operations shared by various OBD types */
835 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
836 int class_multi_cleanup(struct obd_device *obddev);
837
838 extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
839
840 static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
841 {
842         /* reuse list_entry's member-pointer offset stuff */
843         return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
844 }
845
846 #endif
847
848 /* sysctl.c */
849 extern void obd_sysctl_init (void);
850 extern void obd_sysctl_clean (void);
851
852 /* uuid.c  */
853 typedef __u8 class_uuid_t[16];
854 //int class_uuid_parse(obd_uuid_t in, class_uuid_t out);
855 void class_uuid_unparse(class_uuid_t in, obd_uuid_t out);
856 #endif /* __LINUX_CLASS_OBD_H */