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