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