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