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