Whamcloud - gitweb
- add open and close calls: initial purpose is to support I/O to open,
[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_open)(struct obd_conn *conn, struct obdo *oa);
141         int (*o_close)(struct obd_conn *conn, struct obdo *oa);
142         int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
143                       obd_size *count, obd_off offset);
144         int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
145                        obd_size *count, obd_off offset);
146         int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
147                      struct obdo **oa, obd_count *oa_bufs, struct page **buf,
148                      obd_size *count, obd_off *offset, obd_flag *flags);
149         int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
150                        obd_off offset);
151         int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
152                       obd_off offset);
153         int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
154                          struct obdo *src, obd_size count, obd_off offset);
155         int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
156                       struct obd_conn *srconn, struct obdo *src,
157                       obd_size count, obd_off offset);
158         int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
159                          obd_id *startid, obd_gr group, void *data);
160         int (*o_preprw)(int cmd, struct obd_conn *conn, 
161                         int objcount, struct obd_ioobj *obj, 
162                         int niocount, struct niobuf *nb, 
163                         struct niobuf *res);
164         int (*o_commitrw)(int cmd, struct obd_conn *conn, 
165                           int objcount, struct obd_ioobj *obj, 
166                           int niocount, struct niobuf *res);
167 };
168
169 struct obd_request {
170         struct obdo *oa;
171         struct obd_conn *conn;
172         __u32 plen1;
173         char *pbuf1;
174 };
175
176 static inline int obd_check_conn(struct obd_conn *conn) 
177 {
178         struct obd_device *obd;
179         if (!conn) {
180                 printk("obd_check_conn: NULL conn\n");
181                 return -ENOTCONN;
182         }
183         obd = conn->oc_dev;
184         if (!obd) {
185                 printk("obd_check_conn: NULL obd\n");
186                 return -ENODEV;
187         }
188
189         if (!obd->obd_flags & OBD_ATTACHED ) {
190                 printk("obd_check_conn: obd %d not attached\n", obd->obd_minor); 
191                 return -ENODEV;
192         }
193
194         if (!obd->obd_flags & OBD_SET_UP) {
195                 printk("obd_check_conn: obd %d not setup\n", obd->obd_minor); 
196                 return -ENODEV;
197         }
198
199         if (!obd->obd_type) {
200                 printk("obd_check_conn: obd %d not typed\n", obd->obd_minor);
201                 return -ENODEV;
202         }
203
204         if (!obd->obd_type->typ_ops) {
205                 printk("obd_check_conn: obd %d no operations\n", obd->obd_minor);
206                 return -EOPNOTSUPP;
207         }
208         return 0;
209 }
210
211 #define OBT(dev)        dev->obd_type
212 #define OBP(dev,op)     dev->obd_type->typ_ops->o_ ## op
213
214 #define OBD_CHECK_SETUP(conn)                                                   \
215 do {                                                                            \
216         if (!(conn)) {                                                            \
217                 CERROR("NULL connection\n");                                    \
218                 return -EINVAL;                                                 \
219         }                                                                       \
220                                                                                 \
221         if (!((conn)->oc_dev)) {                                                    \
222                 CERROR("NULL device\n");                                        \
223                 return -EINVAL;                                                 \
224         }                                                                       \
225                                                                                 \
226         if ( !((conn)->oc_dev->obd_flags & OBD_SET_UP) ) {                        \
227                 CERROR("Device %d not setup\n", (conn)->oc_dev->obd_minor);       \
228                 return -EINVAL;                                                 \
229         }                                                                       \
230 } while (0)
231
232 #define OBD_CHECK_OP(conn,op)                                   \
233 do {                                                            \
234         int rc = obd_check_conn(conn);                          \
235         if (rc) {                                               \
236                 printk("obd: error in operation: " #op "\n");   \
237                 return rc;                                      \
238         }                                                       \
239         if (!OBP(conn->oc_dev,op)) {                            \
240                 printk("obd_" #op ": dev %d no operation\n",    \
241                        conn->oc_dev->obd_minor);                \
242                 return -EOPNOTSUPP;                             \
243         }                                                       \
244 } while (0)
245
246 static inline int obd_get_info(struct obd_conn *conn, obd_count keylen, void *key,
247                           obd_count *vallen, void **val)
248 {
249         int rc;
250         OBD_CHECK_SETUP(conn);
251         OBD_CHECK_OP(conn,get_info);
252         
253         rc = OBP(conn->oc_dev, get_info)(conn, keylen, key, vallen, val);
254         EXIT;
255         return rc;
256 }
257
258 static inline int obd_set_info(struct obd_conn *conn, obd_count keylen, void *key,
259                           obd_count vallen, void *val)
260 {
261         int rc;
262         OBD_CHECK_SETUP(conn);
263         OBD_CHECK_OP(conn,set_info);
264         
265         rc = OBP(conn->oc_dev, set_info)(conn, keylen, key, vallen, val);
266         EXIT;
267         return rc;
268 }
269
270 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
271 {
272         struct obd_conn conn;
273         int rc;
274         conn.oc_dev = obd;
275
276         OBD_CHECK_OP((&conn),setup);
277         
278         rc = OBP(conn.oc_dev, setup)(obd, datalen, data);
279         EXIT;
280         return rc;
281 }
282
283 static inline int obd_cleanup(struct obd_device *obd)
284 {
285         struct obd_conn conn;
286         int rc;
287         conn.oc_dev = obd;
288
289         OBD_CHECK_SETUP(&conn);
290         OBD_CHECK_OP((&conn),cleanup);
291         
292         rc = OBP(conn.oc_dev, cleanup)(obd);
293         EXIT;
294         return rc;
295 }
296
297 static inline int obd_create(struct obd_conn *conn, struct obdo *obdo) 
298 {
299         int rc;
300         OBD_CHECK_SETUP(conn);
301         OBD_CHECK_OP(conn,create);
302         
303         rc = OBP(conn->oc_dev, create)(conn, obdo);
304         EXIT;
305         return rc;
306 }
307
308 static inline int obd_destroy(struct obd_conn *conn, struct obdo *obdo) 
309 {
310         int rc;
311         OBD_CHECK_SETUP(conn);
312         OBD_CHECK_OP(conn,destroy);
313         
314         rc = OBP(conn->oc_dev, destroy)(conn, obdo);
315         EXIT;
316         return rc;
317 }
318
319 static inline int obd_getattr(struct obd_conn *conn, struct obdo *obdo) 
320 {
321         int rc;
322         OBD_CHECK_SETUP(conn);
323         OBD_CHECK_OP(conn,getattr);
324         
325         rc = OBP(conn->oc_dev, getattr)(conn, obdo);
326         EXIT;
327         return rc;
328 }
329
330 static inline int obd_close(struct obd_conn *conn, struct obdo *obdo) 
331 {
332         int rc;
333         OBD_CHECK_SETUP(conn);
334         OBD_CHECK_OP(conn,close);
335         
336         rc = OBP(conn->oc_dev, close)(conn, obdo);
337         EXIT;
338         return rc;
339 }
340 static inline int obd_open(struct obd_conn *conn, struct obdo *obdo) 
341 {
342         int rc;
343         OBD_CHECK_SETUP(conn);
344         OBD_CHECK_OP(conn,open);
345         
346         rc = OBP(conn->oc_dev, open) (conn, obdo);
347         EXIT;
348         return rc;
349 }
350
351 static inline int obd_setattr(struct obd_conn *conn, struct obdo *obdo) 
352 {
353         int rc;
354         OBD_CHECK_SETUP(conn);
355         OBD_CHECK_OP(conn,setattr);
356         
357         rc = OBP(conn->oc_dev, setattr)(conn, obdo);
358         EXIT;
359         return rc;
360 }
361
362 static inline int obd_connect(struct obd_conn *conn)
363 {
364         int rc;
365         OBD_CHECK_SETUP(conn);
366         OBD_CHECK_OP(conn,connect);
367         
368         rc = OBP(conn->oc_dev, connect)(conn);
369         EXIT;
370         return rc;
371 }
372
373 static inline int obd_disconnect(struct obd_conn *conn)
374 {
375         int rc;
376         OBD_CHECK_SETUP(conn);
377         OBD_CHECK_OP(conn,disconnect);
378         
379         rc = OBP(conn->oc_dev, disconnect)(conn);
380         EXIT;
381         return rc;
382 }
383
384 static inline int obd_statfs(struct obd_conn *conn, struct statfs *buf)
385 {
386         int rc;
387         OBD_CHECK_SETUP(conn);
388         OBD_CHECK_OP(conn,statfs);
389         
390         rc = OBP(conn->oc_dev, statfs)(conn, buf);
391         EXIT;
392         return rc;
393 }
394
395 static inline int obd_punch(struct obd_conn *conn, struct obdo *tgt, obd_size count, obd_off offset)
396 {
397         int rc;
398         OBD_CHECK_SETUP(conn);
399         OBD_CHECK_OP(conn,punch);
400         
401         rc = OBP(conn->oc_dev, punch)(conn, tgt, count, offset);
402         EXIT;
403         return rc;
404 }
405
406 static inline int obd_brw(int rw, struct obd_conn *conn, obd_count num_oa,
407                      struct obdo **oa, obd_count *oa_bufs, struct page **buf,
408                      obd_size *count, obd_off *offset, obd_flag *flags)
409 {
410         int rc;
411         OBD_CHECK_SETUP(conn);
412         OBD_CHECK_OP(conn,brw);
413         
414         rc = OBP(conn->oc_dev, brw)(rw, conn, num_oa, oa, oa_bufs, buf,
415                                     count, offset, flags);
416         EXIT;
417         return rc;
418 }
419
420 static inline int obd_preprw(int cmd, struct obd_conn *conn, 
421                              int objcount, struct obd_ioobj *obj, 
422                              int niocount, struct niobuf *nb, 
423                              struct niobuf *res)
424 {
425         int rc;
426         OBD_CHECK_SETUP(conn);
427         OBD_CHECK_OP(conn, preprw);
428         
429         rc = OBP(conn->oc_dev, preprw)(cmd, conn, objcount, obj, niocount, nb, res);
430         EXIT;
431         return rc;
432 }
433
434 static inline int obd_commitrw(int cmd, struct obd_conn *conn, 
435                         int objcount, struct obd_ioobj *obj, 
436                         int niocount, struct niobuf *res)
437 {
438         int rc;
439         OBD_CHECK_SETUP(conn);
440         OBD_CHECK_OP(conn, commitrw);
441         
442         rc = OBP(conn->oc_dev, commitrw)(cmd, conn, objcount, obj, niocount, res);
443         EXIT;
444         return rc;
445 }
446
447
448 #endif 
449
450 /*
451  *  ======== OBD Metadata Support  ===========
452  */
453
454 extern int obd_init_obdo_cache(void);
455 extern void obd_cleanup_obdo_cache(void);
456
457
458 static inline int obdo_has_inline(struct obdo *obdo)
459 {
460         return (obdo->o_valid & OBD_MD_FLINLINE &&
461                 obdo->o_obdflags & OBD_FL_INLINEDATA);
462 };
463
464 static inline int obdo_has_obdmd(struct obdo *obdo)
465 {
466         return (obdo->o_valid & OBD_MD_FLOBDMD &&
467                 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
468 };
469
470 #ifdef __KERNEL__
471 /* support routines */
472 extern kmem_cache_t *obdo_cachep;
473
474 static __inline__ struct obdo *obdo_alloc(void)
475 {
476         struct obdo *oa = NULL;
477
478         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
479         memset(oa, 0, sizeof (*oa));
480
481         return oa;
482 }
483
484 static __inline__ void obdo_free(struct obdo *oa)
485 {
486         if ( !oa ) 
487                 return;
488         kmem_cache_free(obdo_cachep, oa);
489 }
490
491 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
492                                            obd_mode mode, obd_flag valid)
493 {
494         struct obdo *oa;
495         int err;
496
497         ENTRY;
498         oa = obdo_alloc();
499         if ( !oa ) {
500                 EXIT;
501                 return ERR_PTR(-ENOMEM);
502         }
503
504         oa->o_id = id;
505         oa->o_mode = mode;
506         oa->o_valid = valid;
507         if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
508                 obdo_free(oa);
509                 EXIT;
510                 return ERR_PTR(err);
511         }
512         EXIT;
513         return oa;
514 }
515
516 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
517 {
518         unsigned int ia_valid = attr->ia_valid;
519
520         if (ia_valid & ATTR_ATIME) {
521                 oa->o_atime = attr->ia_atime;
522                 oa->o_valid |= OBD_MD_FLATIME;
523         }
524         if (ia_valid & ATTR_MTIME) {
525                 oa->o_mtime = attr->ia_mtime;
526                 oa->o_valid |= OBD_MD_FLMTIME;
527         }
528         if (ia_valid & ATTR_CTIME) {
529                 oa->o_ctime = attr->ia_ctime;
530                 oa->o_valid |= OBD_MD_FLCTIME;
531         }
532         if (ia_valid & ATTR_SIZE) {
533                 oa->o_size = attr->ia_size;
534                 oa->o_valid |= OBD_MD_FLSIZE;
535         }
536         if (ia_valid & ATTR_MODE) {
537                 oa->o_mode = attr->ia_mode;
538                 oa->o_valid |= OBD_MD_FLMODE;
539                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
540                         oa->o_mode &= ~S_ISGID;
541         }
542         if (ia_valid & ATTR_UID)
543         {
544                 oa->o_uid = attr->ia_uid;
545                 oa->o_valid |= OBD_MD_FLUID;
546         }
547         if (ia_valid & ATTR_GID) {
548                 oa->o_gid = attr->ia_gid;
549                 oa->o_valid |= OBD_MD_FLGID;
550         }
551 }
552
553
554 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
555 {
556         unsigned int ia_valid = oa->o_valid;
557         
558         memset(attr, 0, sizeof(*attr));
559         if (ia_valid & OBD_MD_FLATIME) {
560                 attr->ia_atime = oa->o_atime;
561                 attr->ia_valid |= ATTR_ATIME;
562         }
563         if (ia_valid & OBD_MD_FLMTIME) {
564                 attr->ia_mtime = oa->o_mtime;
565                 attr->ia_valid |= ATTR_MTIME;
566         }
567         if (ia_valid & OBD_MD_FLCTIME) {
568                 attr->ia_ctime = oa->o_ctime;
569                 attr->ia_valid |= ATTR_CTIME;
570         }
571         if (ia_valid & OBD_MD_FLSIZE) {
572                 attr->ia_size = oa->o_size;
573                 attr->ia_valid |= ATTR_SIZE;
574         }
575         if (ia_valid & OBD_MD_FLMODE) {
576                 attr->ia_mode = oa->o_mode;
577                 attr->ia_valid |= ATTR_MODE;
578                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
579                         attr->ia_mode &= ~S_ISGID;
580         }
581         if (ia_valid & OBD_MD_FLUID)
582         {
583                 attr->ia_uid = oa->o_uid;
584                 attr->ia_valid |= ATTR_UID;
585         }
586         if (ia_valid & OBD_MD_FLGID) {
587                 attr->ia_gid = oa->o_gid;
588                 attr->ia_valid |= ATTR_GID;
589         }
590 }
591
592
593 /* WARNING: the file systems must take care not to tinker with
594    attributes they don't manage (such as blocks). */
595
596 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
597 {
598         if ( dst->o_valid & OBD_MD_FLID )
599                 dst->o_id = src->i_ino;
600         if ( dst->o_valid & OBD_MD_FLATIME )
601                 dst->o_atime = src->i_atime;
602         if ( dst->o_valid & OBD_MD_FLMTIME )
603                 dst->o_mtime = src->i_mtime;
604         if ( dst->o_valid & OBD_MD_FLCTIME )
605                 dst->o_ctime = src->i_ctime;
606         if ( dst->o_valid & OBD_MD_FLSIZE )
607                 dst->o_size = src->i_size;
608         if ( dst->o_valid & OBD_MD_FLBLOCKS )   /* allocation of space */
609                 dst->o_blocks = src->i_blocks;
610         if ( dst->o_valid & OBD_MD_FLBLKSZ )
611                 dst->o_blksize = src->i_blksize;
612         if ( dst->o_valid & OBD_MD_FLMODE )
613                 dst->o_mode = src->i_mode;
614         if ( dst->o_valid & OBD_MD_FLUID )
615                 dst->o_uid = src->i_uid;
616         if ( dst->o_valid & OBD_MD_FLGID )
617                 dst->o_gid = src->i_gid;
618         if ( dst->o_valid & OBD_MD_FLFLAGS )
619                 dst->o_flags = src->i_flags;
620         if ( dst->o_valid & OBD_MD_FLNLINK )
621                 dst->o_nlink = src->i_nlink;
622         if ( dst->o_valid & OBD_MD_FLGENER ) 
623                 dst->o_generation = src->i_generation;
624 }
625
626 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
627 {
628
629         if ( src->o_valid & OBD_MD_FLID )
630                 dst->i_ino = src->o_id;
631         if ( src->o_valid & OBD_MD_FLATIME ) 
632                 dst->i_atime = src->o_atime;
633         if ( src->o_valid & OBD_MD_FLMTIME ) 
634                 dst->i_mtime = src->o_mtime;
635         if ( src->o_valid & OBD_MD_FLCTIME ) 
636                 dst->i_ctime = src->o_ctime;
637         if ( src->o_valid & OBD_MD_FLSIZE ) 
638                 dst->i_size = src->o_size;
639         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
640                 dst->i_blocks = src->o_blocks;
641         if ( src->o_valid & OBD_MD_FLBLKSZ )
642                 dst->i_blksize = src->o_blksize;
643         if ( src->o_valid & OBD_MD_FLMODE ) 
644                 dst->i_mode = src->o_mode;
645         if ( src->o_valid & OBD_MD_FLUID ) 
646                 dst->i_uid = src->o_uid;
647         if ( src->o_valid & OBD_MD_FLGID ) 
648                 dst->i_gid = src->o_gid;
649         if ( src->o_valid & OBD_MD_FLFLAGS ) 
650                 dst->i_flags = src->o_flags;
651         if ( src->o_valid & OBD_MD_FLNLINK )
652                 dst->i_nlink = src->o_nlink;
653         if ( src->o_valid & OBD_MD_FLGENER )
654                 dst->i_generation = src->o_generation;
655 }
656
657 #endif 
658
659 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
660 {
661 #ifdef __KERNEL__
662         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
663                src->o_id, src->o_valid, dst->o_id);
664 #endif
665         if ( src->o_valid & OBD_MD_FLATIME ) 
666                 dst->o_atime = src->o_atime;
667         if ( src->o_valid & OBD_MD_FLMTIME ) 
668                 dst->o_mtime = src->o_mtime;
669         if ( src->o_valid & OBD_MD_FLCTIME ) 
670                 dst->o_ctime = src->o_ctime;
671         if ( src->o_valid & OBD_MD_FLSIZE ) 
672                 dst->o_size = src->o_size;
673         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
674                 dst->o_blocks = src->o_blocks;
675         if ( src->o_valid & OBD_MD_FLBLKSZ )
676                 dst->o_blksize = src->o_blksize;
677         if ( src->o_valid & OBD_MD_FLMODE ) 
678                 dst->o_mode = src->o_mode;
679         if ( src->o_valid & OBD_MD_FLUID ) 
680                 dst->o_uid = src->o_uid;
681         if ( src->o_valid & OBD_MD_FLGID ) 
682                 dst->o_gid = src->o_gid;
683         if ( src->o_valid & OBD_MD_FLFLAGS ) 
684                 dst->o_flags = src->o_flags;
685         /*
686         if ( src->o_valid & OBD_MD_FLOBDFLG ) 
687                 dst->o_obdflags = src->o_obdflags;
688         */
689         if ( src->o_valid & OBD_MD_FLNLINK ) 
690                 dst->o_nlink = src->o_nlink;
691         if ( src->o_valid & OBD_MD_FLGENER ) 
692                 dst->o_generation = src->o_generation;
693         if ( src->o_valid & OBD_MD_FLINLINE &&
694              src->o_obdflags & OBD_FL_INLINEDATA) {
695                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
696                 dst->o_obdflags |= OBD_FL_INLINEDATA;
697         }
698         if ( src->o_valid & OBD_MD_FLOBDMD &&
699              src->o_obdflags & OBD_FL_OBDMDEXISTS) {
700                 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
701                 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
702         }
703
704         dst->o_valid |= src->o_valid;
705 }
706
707
708 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
709 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
710                                   obd_flag compare)
711 {
712         int res = 0;
713
714         if ( compare & OBD_MD_FLATIME )
715                 res = (res || (dst->o_atime != src->o_atime));
716         if ( compare & OBD_MD_FLMTIME )
717                 res = (res || (dst->o_mtime != src->o_mtime));
718         if ( compare & OBD_MD_FLCTIME )
719                 res = (res || (dst->o_ctime != src->o_ctime));
720         if ( compare & OBD_MD_FLSIZE )
721                 res = (res || (dst->o_size != src->o_size));
722         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
723                 res = (res || (dst->o_blocks != src->o_blocks));
724         if ( compare & OBD_MD_FLBLKSZ )
725                 res = (res || (dst->o_blksize != src->o_blksize));
726         if ( compare & OBD_MD_FLMODE )
727                 res = (res || (dst->o_mode != src->o_mode));
728         if ( compare & OBD_MD_FLUID )
729                 res = (res || (dst->o_uid != src->o_uid));
730         if ( compare & OBD_MD_FLGID )
731                 res = (res || (dst->o_gid != src->o_gid));
732         if ( compare & OBD_MD_FLFLAGS ) 
733                 res = (res || (dst->o_flags != src->o_flags));
734         if ( compare & OBD_MD_FLNLINK )
735                 res = (res || (dst->o_nlink != src->o_nlink));
736         if ( compare & OBD_MD_FLGENER )
737                 res = (res || (dst->o_generation != src->o_generation));
738         /* XXX Don't know if thses should be included here - wasn't previously
739         if ( compare & OBD_MD_FLINLINE )
740                 res = (res || memcmp(dst->o_inline, src->o_inline));
741         if ( compare & OBD_MD_FLOBDMD )
742                 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
743         */
744         return res;
745 }
746
747
748 #ifdef __KERNEL__
749 int obd_register_type(struct obd_ops *ops, char *nm);
750 int obd_unregister_type(char *nm);
751
752 struct obd_client {
753         struct list_head cli_chain;
754         struct obd_device *cli_obd;
755         unsigned int cli_id;
756         unsigned long cli_prealloc_quota;
757         struct list_head cli_prealloc_inodes;
758 };
759
760
761 struct obd_prealloc_inode {
762         struct list_head obd_prealloc_chain;
763         unsigned long inode;
764 };
765
766 /* generic operations shared by various OBD types */
767 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
768 int gen_multi_cleanup(struct obd_device *obddev);
769 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
770 int gen_multi_detach(struct obd_device *obddev);
771 int gen_connect (struct obd_conn *conn);
772 int gen_disconnect(struct obd_conn *conn);
773 struct obd_client *gen_client(const struct obd_conn *);
774 int gen_cleanup(struct obd_device *obddev);
775 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
776                   struct obd_conn *src_conn, struct obdo *src,
777                   obd_size count, obd_off offset);
778
779 #endif
780
781 /* sysctl.c */
782 extern void obd_sysctl_init (void);
783 extern void obd_sysctl_clean (void);
784
785 #endif /* __LINUX_CLASS_OBD_H */