Whamcloud - gitweb
- first parts of lock management: module & resource hash +
[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/lustre_dlm.h>
72 #include <linux/obd_snap.h>
73 #include <linux/obd_trace.h>
74 /* #include <linux/obd_fc.h> */
75 #include <linux/obd_raid1.h>
76 #include <linux/obd_ost.h>
77 #include <linux/obd_osc.h>
78
79 #ifdef __KERNEL__
80 /* corresponds to one of the obd's */
81 struct obd_device {
82         struct obd_type *obd_type;
83         int obd_minor;
84         int obd_flags;
85         int obd_refcnt; 
86         obd_devicename obd_fsname; 
87         struct proc_dir_entry *obd_proc_entry;
88         int obd_multi_count;
89         struct obd_conn obd_multi_conn[MAX_MULTI];
90         unsigned int obd_gen_last_id;
91         unsigned long obd_gen_prealloc_quota;
92         struct list_head obd_gen_clients;
93         struct list_head obd_req_list;
94         wait_queue_head_t obd_req_waitq;
95         union {
96                 struct ext2_obd ext2;
97                 struct filter_obd filter;
98                 struct mds_obd mds;
99                 struct raid1_obd raid1;
100                 struct snap_obd snap;
101                 struct trace_obd trace;
102                 struct ost_obd ost;
103                 struct osc_obd osc;
104                 struct ldlm_obd ldlm;
105         } u;
106 };
107
108 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
109 extern void proc_lustre_release_obd_device(struct obd_device *obd);
110 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
111
112 /*
113  *  ======== OBD Operations Declarations ===========
114  */
115
116 #define OBD_BRW_READ    1
117 #define OBD_BRW_WRITE   2
118 #define OBD_BRW_RWMASK  OBD_BRW_READ | OBD_BRW_WRITE
119 #define OBD_BRW_CREATE  4
120
121 struct obd_ops {
122         int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
123                            void *uarg);
124         int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
125                           obd_count *vallen, void **val);
126         int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
127                           obd_count vallen, void *val);
128         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
129         int (*o_detach)(struct obd_device *dev);
130         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
131         int (*o_cleanup)(struct obd_device *dev);
132         int (*o_connect)(struct obd_conn *conn);
133         int (*o_disconnect)(struct obd_conn *conn);
134         int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
135         int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
136         int (*o_create)(struct obd_conn *conn,  struct obdo *oa);
137         int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
138         int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
139         int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
140         int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
141                       obd_size *count, obd_off offset);
142         int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
143                        obd_size *count, obd_off offset);
144         int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
145                      struct obdo **oa, obd_count *oa_bufs, struct page **buf,
146                      obd_size *count, obd_off *offset, obd_flag *flags);
147         int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
148                        obd_off offset);
149         int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
150                       obd_off offset);
151         int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
152                          struct obdo *src, obd_size count, obd_off offset);
153         int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
154                       struct obd_conn *srconn, struct obdo *src,
155                       obd_size count, obd_off offset);
156         int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
157                          obd_id *startid, obd_gr group, void *data);
158         int (*o_preprw)(int cmd, struct obd_conn *conn, 
159                         int objcount, struct obd_ioobj *obj, 
160                         int niocount, struct niobuf *nb, 
161                         struct niobuf *res);
162         int (*o_commitrw)(int cmd, struct obd_conn *conn, 
163                           int objcount, struct obd_ioobj *obj, 
164                           int niocount, struct niobuf *res);
165 };
166
167 struct obd_request {
168         struct obdo *oa;
169         struct obd_conn *conn;
170         __u32 plen1;
171         char *pbuf1;
172 };
173
174 static inline int obd_check_conn(struct obd_conn *conn) 
175 {
176         struct obd_device *obd;
177         if (!conn) {
178                 printk("obd_check_conn: NULL conn\n");
179                 return -ENOTCONN;
180         }
181         obd = conn->oc_dev;
182         if (!obd) {
183                 printk("obd_check_conn: NULL obd\n");
184                 return -ENODEV;
185         }
186
187         if (!obd->obd_flags & OBD_ATTACHED ) {
188                 printk("obd_check_conn: obd %d not attached\n", obd->obd_minor); 
189                 return -ENODEV;
190         }
191
192         if (!obd->obd_flags & OBD_SET_UP) {
193                 printk("obd_check_conn: obd %d not setup\n", obd->obd_minor); 
194                 return -ENODEV;
195         }
196
197         if (!obd->obd_type) {
198                 printk("obd_check_conn: obd %d not typed\n", obd->obd_minor);
199                 return -ENODEV;
200         }
201
202         if (!obd->obd_type->typ_ops) {
203                 printk("obd_check_conn: obd %d no operations\n", obd->obd_minor);
204                 return -EOPNOTSUPP;
205         }
206         return 0;
207 }
208
209 #define OBT(dev)        dev->obd_type
210 #define OBP(dev,op)     dev->obd_type->typ_ops->o_ ## op
211
212 #define OBD_CHECK_SETUP(conn)                                                   \
213 do {                                                                            \
214         if (!(conn)) {                                                            \
215                 CERROR("NULL connection\n");                                    \
216                 return -EINVAL;                                                 \
217         }                                                                       \
218                                                                                 \
219         if (!((conn)->oc_dev)) {                                                    \
220                 CERROR("NULL device\n");                                        \
221                 return -EINVAL;                                                 \
222         }                                                                       \
223                                                                                 \
224         if ( !((conn)->oc_dev->obd_flags & OBD_SET_UP) ) {                        \
225                 CERROR("Device %d not setup\n", (conn)->oc_dev->obd_minor);       \
226                 return -EINVAL;                                                 \
227         }                                                                       \
228 } while (0)
229
230 #define OBD_CHECK_OP(conn,op)                                   \
231 do {                                                            \
232         int rc = obd_check_conn(conn);                          \
233         if (rc) {                                               \
234                 printk("obd: error in operation: " #op "\n");   \
235                 return rc;                                      \
236         }                                                       \
237         if (!OBP(conn->oc_dev,op)) {                            \
238                 printk("obd_" #op ": dev %d no operation\n",    \
239                        conn->oc_dev->obd_minor);                \
240                 return -EOPNOTSUPP;                             \
241         }                                                       \
242 } while (0)
243
244 static inline int obd_get_info(struct obd_conn *conn, obd_count keylen, void *key,
245                           obd_count *vallen, void **val)
246 {
247         int rc;
248         OBD_CHECK_SETUP(conn);
249         OBD_CHECK_OP(conn,get_info);
250         
251         rc = OBP(conn->oc_dev, get_info)(conn, keylen, key, vallen, val);
252         EXIT;
253         return rc;
254 }
255
256 static inline int obd_set_info(struct obd_conn *conn, obd_count keylen, void *key,
257                           obd_count vallen, void *val)
258 {
259         int rc;
260         OBD_CHECK_SETUP(conn);
261         OBD_CHECK_OP(conn,set_info);
262         
263         rc = OBP(conn->oc_dev, set_info)(conn, keylen, key, vallen, val);
264         EXIT;
265         return rc;
266 }
267
268 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
269 {
270         struct obd_conn conn;
271         int rc;
272         conn.oc_dev = obd;
273
274         OBD_CHECK_OP((&conn),setup);
275         
276         rc = OBP(conn.oc_dev, setup)(obd, datalen, data);
277         EXIT;
278         return rc;
279 }
280
281 static inline int obd_cleanup(struct obd_device *obd)
282 {
283         struct obd_conn conn;
284         int rc;
285         conn.oc_dev = obd;
286
287         OBD_CHECK_SETUP(&conn);
288         OBD_CHECK_OP((&conn),cleanup);
289         
290         rc = OBP(conn.oc_dev, cleanup)(obd);
291         EXIT;
292         return rc;
293 }
294
295 static inline int obd_create(struct obd_conn *conn, struct obdo *obdo) 
296 {
297         int rc;
298         OBD_CHECK_SETUP(conn);
299         OBD_CHECK_OP(conn,create);
300         
301         rc = OBP(conn->oc_dev, create)(conn, obdo);
302         EXIT;
303         return rc;
304 }
305
306 static inline int obd_destroy(struct obd_conn *conn, struct obdo *obdo) 
307 {
308         int rc;
309         OBD_CHECK_SETUP(conn);
310         OBD_CHECK_OP(conn,destroy);
311         
312         rc = OBP(conn->oc_dev, destroy)(conn, obdo);
313         EXIT;
314         return rc;
315 }
316
317 static inline int obd_getattr(struct obd_conn *conn, struct obdo *obdo) 
318 {
319         int rc;
320         OBD_CHECK_SETUP(conn);
321         OBD_CHECK_OP(conn,getattr);
322         
323         rc = OBP(conn->oc_dev, getattr)(conn, obdo);
324         EXIT;
325         return rc;
326 }
327
328 static inline int obd_setattr(struct obd_conn *conn, struct obdo *obdo) 
329 {
330         int rc;
331         OBD_CHECK_SETUP(conn);
332         OBD_CHECK_OP(conn,setattr);
333         
334         rc = OBP(conn->oc_dev, setattr)(conn, obdo);
335         EXIT;
336         return rc;
337 }
338
339 static inline int obd_connect(struct obd_conn *conn)
340 {
341         int rc;
342         OBD_CHECK_SETUP(conn);
343         OBD_CHECK_OP(conn,connect);
344         
345         rc = OBP(conn->oc_dev, connect)(conn);
346         EXIT;
347         return rc;
348 }
349
350 static inline int obd_disconnect(struct obd_conn *conn)
351 {
352         int rc;
353         OBD_CHECK_SETUP(conn);
354         OBD_CHECK_OP(conn,disconnect);
355         
356         rc = OBP(conn->oc_dev, disconnect)(conn);
357         EXIT;
358         return rc;
359 }
360
361 static inline int obd_statfs(struct obd_conn *conn, struct statfs *buf)
362 {
363         int rc;
364         OBD_CHECK_SETUP(conn);
365         OBD_CHECK_OP(conn,statfs);
366         
367         rc = OBP(conn->oc_dev, statfs)(conn, buf);
368         EXIT;
369         return rc;
370 }
371
372 static inline int obd_punch(struct obd_conn *conn, struct obdo *tgt, obd_size count, obd_off offset)
373 {
374         int rc;
375         OBD_CHECK_SETUP(conn);
376         OBD_CHECK_OP(conn,punch);
377         
378         rc = OBP(conn->oc_dev, punch)(conn, tgt, count, offset);
379         EXIT;
380         return rc;
381 }
382
383 static inline int obd_brw(int rw, struct obd_conn *conn, obd_count num_oa,
384                      struct obdo **oa, obd_count *oa_bufs, struct page **buf,
385                      obd_size *count, obd_off *offset, obd_flag *flags)
386 {
387         int rc;
388         OBD_CHECK_SETUP(conn);
389         OBD_CHECK_OP(conn,brw);
390         
391         rc = OBP(conn->oc_dev, brw)(rw, conn, num_oa, oa, oa_bufs, buf,
392                                     count, offset, flags);
393         EXIT;
394         return rc;
395 }
396
397 static inline int obd_preprw(int cmd, struct obd_conn *conn, 
398                              int objcount, struct obd_ioobj *obj, 
399                              int niocount, struct niobuf *nb, 
400                              struct niobuf *res)
401 {
402         int rc;
403         OBD_CHECK_SETUP(conn);
404         OBD_CHECK_OP(conn, preprw);
405         
406         rc = OBP(conn->oc_dev, preprw)(cmd, conn, objcount, obj, niocount, nb, res);
407         EXIT;
408         return rc;
409 }
410
411 static inline int obd_commitrw(int cmd, struct obd_conn *conn, 
412                         int objcount, struct obd_ioobj *obj, 
413                         int niocount, struct niobuf *res)
414 {
415         int rc;
416         OBD_CHECK_SETUP(conn);
417         OBD_CHECK_OP(conn, commitrw);
418         
419         rc = OBP(conn->oc_dev, commitrw)(cmd, conn, objcount, obj, niocount, res);
420         EXIT;
421         return rc;
422 }
423
424
425 #endif 
426
427 /*
428  *  ======== OBD Metadata Support  ===========
429  */
430
431 extern int obd_init_obdo_cache(void);
432 extern void obd_cleanup_obdo_cache(void);
433
434
435 static inline int obdo_has_inline(struct obdo *obdo)
436 {
437         return (obdo->o_valid & OBD_MD_FLINLINE &&
438                 obdo->o_obdflags & OBD_FL_INLINEDATA);
439 };
440
441 static inline int obdo_has_obdmd(struct obdo *obdo)
442 {
443         return (obdo->o_valid & OBD_MD_FLOBDMD &&
444                 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
445 };
446
447 #ifdef __KERNEL__
448 /* support routines */
449 extern kmem_cache_t *obdo_cachep;
450
451 static __inline__ struct obdo *obdo_alloc(void)
452 {
453         struct obdo *oa = NULL;
454
455         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
456         memset(oa, 0, sizeof (*oa));
457
458         return oa;
459 }
460
461 static __inline__ void obdo_free(struct obdo *oa)
462 {
463         if ( !oa ) 
464                 return;
465         kmem_cache_free(obdo_cachep, oa);
466 }
467
468 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
469                                            obd_mode mode, obd_flag valid)
470 {
471         struct obdo *oa;
472         int err;
473
474         ENTRY;
475         oa = obdo_alloc();
476         if ( !oa ) {
477                 EXIT;
478                 return ERR_PTR(-ENOMEM);
479         }
480
481         oa->o_id = id;
482         oa->o_mode = mode;
483         oa->o_valid = valid;
484         if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
485                 obdo_free(oa);
486                 EXIT;
487                 return ERR_PTR(err);
488         }
489         EXIT;
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                src->o_id, src->o_valid, dst->o_id);
641 #endif
642         if ( src->o_valid & OBD_MD_FLATIME ) 
643                 dst->o_atime = src->o_atime;
644         if ( src->o_valid & OBD_MD_FLMTIME ) 
645                 dst->o_mtime = src->o_mtime;
646         if ( src->o_valid & OBD_MD_FLCTIME ) 
647                 dst->o_ctime = src->o_ctime;
648         if ( src->o_valid & OBD_MD_FLSIZE ) 
649                 dst->o_size = src->o_size;
650         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
651                 dst->o_blocks = src->o_blocks;
652         if ( src->o_valid & OBD_MD_FLBLKSZ )
653                 dst->o_blksize = src->o_blksize;
654         if ( src->o_valid & OBD_MD_FLMODE ) 
655                 dst->o_mode = src->o_mode;
656         if ( src->o_valid & OBD_MD_FLUID ) 
657                 dst->o_uid = src->o_uid;
658         if ( src->o_valid & OBD_MD_FLGID ) 
659                 dst->o_gid = src->o_gid;
660         if ( src->o_valid & OBD_MD_FLFLAGS ) 
661                 dst->o_flags = src->o_flags;
662         /*
663         if ( src->o_valid & OBD_MD_FLOBDFLG ) 
664                 dst->o_obdflags = src->o_obdflags;
665         */
666         if ( src->o_valid & OBD_MD_FLNLINK ) 
667                 dst->o_nlink = src->o_nlink;
668         if ( src->o_valid & OBD_MD_FLGENER ) 
669                 dst->o_generation = src->o_generation;
670         if ( src->o_valid & OBD_MD_FLINLINE &&
671              src->o_obdflags & OBD_FL_INLINEDATA) {
672                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
673                 dst->o_obdflags |= OBD_FL_INLINEDATA;
674         }
675         if ( src->o_valid & OBD_MD_FLOBDMD &&
676              src->o_obdflags & OBD_FL_OBDMDEXISTS) {
677                 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
678                 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
679         }
680
681         dst->o_valid |= src->o_valid;
682 }
683
684
685 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
686 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
687                                   obd_flag compare)
688 {
689         int res = 0;
690
691         if ( compare & OBD_MD_FLATIME )
692                 res = (res || (dst->o_atime != src->o_atime));
693         if ( compare & OBD_MD_FLMTIME )
694                 res = (res || (dst->o_mtime != src->o_mtime));
695         if ( compare & OBD_MD_FLCTIME )
696                 res = (res || (dst->o_ctime != src->o_ctime));
697         if ( compare & OBD_MD_FLSIZE )
698                 res = (res || (dst->o_size != src->o_size));
699         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
700                 res = (res || (dst->o_blocks != src->o_blocks));
701         if ( compare & OBD_MD_FLBLKSZ )
702                 res = (res || (dst->o_blksize != src->o_blksize));
703         if ( compare & OBD_MD_FLMODE )
704                 res = (res || (dst->o_mode != src->o_mode));
705         if ( compare & OBD_MD_FLUID )
706                 res = (res || (dst->o_uid != src->o_uid));
707         if ( compare & OBD_MD_FLGID )
708                 res = (res || (dst->o_gid != src->o_gid));
709         if ( compare & OBD_MD_FLFLAGS ) 
710                 res = (res || (dst->o_flags != src->o_flags));
711         if ( compare & OBD_MD_FLNLINK )
712                 res = (res || (dst->o_nlink != src->o_nlink));
713         if ( compare & OBD_MD_FLGENER )
714                 res = (res || (dst->o_generation != src->o_generation));
715         /* XXX Don't know if thses should be included here - wasn't previously
716         if ( compare & OBD_MD_FLINLINE )
717                 res = (res || memcmp(dst->o_inline, src->o_inline));
718         if ( compare & OBD_MD_FLOBDMD )
719                 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
720         */
721         return res;
722 }
723
724
725 #ifdef __KERNEL__
726 int obd_register_type(struct obd_ops *ops, char *nm);
727 int obd_unregister_type(char *nm);
728
729 struct obd_client {
730         struct list_head cli_chain;
731         struct obd_device *cli_obd;
732         unsigned int cli_id;
733         unsigned long cli_prealloc_quota;
734         struct list_head cli_prealloc_inodes;
735 };
736
737
738 struct obd_prealloc_inode {
739         struct list_head obd_prealloc_chain;
740         unsigned long inode;
741 };
742
743 /* generic operations shared by various OBD types */
744 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
745 int gen_multi_cleanup(struct obd_device *obddev);
746 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
747 int gen_multi_detach(struct obd_device *obddev);
748 int gen_connect (struct obd_conn *conn);
749 int gen_disconnect(struct obd_conn *conn);
750 struct obd_client *gen_client(const struct obd_conn *);
751 int gen_cleanup(struct obd_device *obddev);
752 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
753                   struct obd_conn *src_conn, struct obdo *src,
754                   obd_size count, obd_off offset);
755
756 #endif
757
758 /* sysctl.c */
759 extern void obd_sysctl_init (void);
760 extern void obd_sysctl_clean (void);
761
762 #endif /* __LINUX_CLASS_OBD_H */