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